diff options
Diffstat (limited to 'src/testcurl/test_digestauth.c')
-rw-r--r-- | src/testcurl/test_digestauth.c | 81 |
1 files changed, 53 insertions, 28 deletions
diff --git a/src/testcurl/test_digestauth.c b/src/testcurl/test_digestauth.c index 912efa11..b8b77674 100644 --- a/src/testcurl/test_digestauth.c +++ b/src/testcurl/test_digestauth.c | |||
@@ -57,8 +57,12 @@ struct CBC | |||
57 | size_t size; | 57 | size_t size; |
58 | }; | 58 | }; |
59 | 59 | ||
60 | |||
60 | static size_t | 61 | static size_t |
61 | copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) | 62 | copyBuffer (void *ptr, |
63 | size_t size, | ||
64 | size_t nmemb, | ||
65 | void *ctx) | ||
62 | { | 66 | { |
63 | struct CBC *cbc = ctx; | 67 | struct CBC *cbc = ctx; |
64 | 68 | ||
@@ -69,6 +73,7 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) | |||
69 | return size * nmemb; | 73 | return size * nmemb; |
70 | } | 74 | } |
71 | 75 | ||
76 | |||
72 | static int | 77 | static int |
73 | ahc_echo (void *cls, | 78 | ahc_echo (void *cls, |
74 | struct MHD_Connection *connection, | 79 | struct MHD_Connection *connection, |
@@ -95,30 +100,33 @@ ahc_echo (void *cls, | |||
95 | response = MHD_create_response_from_buffer (strlen (DENIED), | 100 | response = MHD_create_response_from_buffer (strlen (DENIED), |
96 | DENIED, | 101 | DENIED, |
97 | MHD_RESPMEM_PERSISTENT); | 102 | MHD_RESPMEM_PERSISTENT); |
98 | ret = MHD_queue_auth_fail_response(connection, realm, | 103 | ret = MHD_queue_auth_fail_response (connection, |
99 | MY_OPAQUE, | 104 | realm, |
100 | response, | 105 | MY_OPAQUE, |
101 | MHD_NO); | 106 | response, |
107 | MHD_NO); | ||
102 | MHD_destroy_response(response); | 108 | MHD_destroy_response(response); |
103 | return ret; | 109 | return ret; |
104 | } | 110 | } |
105 | ret = MHD_digest_auth_check(connection, realm, | 111 | ret = MHD_digest_auth_check (connection, |
106 | username, | 112 | realm, |
107 | password, | 113 | username, |
108 | 300); | 114 | password, |
109 | free(username); | 115 | 300); |
116 | free (username); | ||
110 | if ( (ret == MHD_INVALID_NONCE) || | 117 | if ( (ret == MHD_INVALID_NONCE) || |
111 | (ret == MHD_NO) ) | 118 | (ret == MHD_NO) ) |
112 | { | 119 | { |
113 | response = MHD_create_response_from_buffer(strlen (DENIED), | 120 | response = MHD_create_response_from_buffer (strlen (DENIED), |
114 | DENIED, | 121 | DENIED, |
115 | MHD_RESPMEM_PERSISTENT); | 122 | MHD_RESPMEM_PERSISTENT); |
116 | if (NULL == response) | 123 | if (NULL == response) |
117 | return MHD_NO; | 124 | return MHD_NO; |
118 | ret = MHD_queue_auth_fail_response(connection, realm, | 125 | ret = MHD_queue_auth_fail_response (connection, |
119 | MY_OPAQUE, | 126 | realm, |
120 | response, | 127 | MY_OPAQUE, |
121 | (ret == MHD_INVALID_NONCE) ? MHD_YES : MHD_NO); | 128 | response, |
129 | (MHD_INVALID_NONCE == ret) ? MHD_YES : MHD_NO); | ||
122 | MHD_destroy_response(response); | 130 | MHD_destroy_response(response); |
123 | return ret; | 131 | return ret; |
124 | } | 132 | } |
@@ -159,7 +167,8 @@ testDigestAuth () | |||
159 | cbc.size = 2048; | 167 | cbc.size = 2048; |
160 | cbc.pos = 0; | 168 | cbc.pos = 0; |
161 | #ifndef WINDOWS | 169 | #ifndef WINDOWS |
162 | fd = open("/dev/urandom", O_RDONLY); | 170 | fd = open ("/dev/urandom", |
171 | O_RDONLY); | ||
163 | if (-1 == fd) | 172 | if (-1 == fd) |
164 | { | 173 | { |
165 | fprintf (stderr, | 174 | fprintf (stderr, |
@@ -170,7 +179,9 @@ testDigestAuth () | |||
170 | } | 179 | } |
171 | while (off < 8) | 180 | while (off < 8) |
172 | { | 181 | { |
173 | len = read(fd, rnd, 8); | 182 | len = read (fd, |
183 | rnd, | ||
184 | 8); | ||
174 | if (len == (size_t)-1) | 185 | if (len == (size_t)-1) |
175 | { | 186 | { |
176 | fprintf (stderr, | 187 | fprintf (stderr, |
@@ -187,18 +198,25 @@ testDigestAuth () | |||
187 | { | 198 | { |
188 | HCRYPTPROV cc; | 199 | HCRYPTPROV cc; |
189 | BOOL b; | 200 | BOOL b; |
190 | b = CryptAcquireContext (&cc, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT); | 201 | |
202 | b = CryptAcquireContext (&cc, | ||
203 | NULL, | ||
204 | NULL, | ||
205 | PROV_RSA_FULL, | ||
206 | CRYPT_VERIFYCONTEXT); | ||
191 | if (b == 0) | 207 | if (b == 0) |
192 | { | 208 | { |
193 | fprintf (stderr, "Failed to acquire crypto provider context: %lu\n", | 209 | fprintf (stderr, |
194 | GetLastError ()); | 210 | "Failed to acquire crypto provider context: %lu\n", |
211 | GetLastError ()); | ||
195 | return 1; | 212 | return 1; |
196 | } | 213 | } |
197 | b = CryptGenRandom (cc, 8, (BYTE*)rnd); | 214 | b = CryptGenRandom (cc, 8, (BYTE*)rnd); |
198 | if (b == 0) | 215 | if (b == 0) |
199 | { | 216 | { |
200 | fprintf (stderr, "Failed to generate 8 random bytes: %lu\n", | 217 | fprintf (stderr, |
201 | GetLastError ()); | 218 | "Failed to generate 8 random bytes: %lu\n", |
219 | GetLastError ()); | ||
202 | } | 220 | } |
203 | CryptReleaseContext (cc, 0); | 221 | CryptReleaseContext (cc, 0); |
204 | if (b == 0) | 222 | if (b == 0) |
@@ -206,7 +224,8 @@ testDigestAuth () | |||
206 | } | 224 | } |
207 | #endif | 225 | #endif |
208 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | 226 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, |
209 | port, NULL, NULL, &ahc_echo, PAGE, | 227 | port, NULL, NULL, |
228 | &ahc_echo, PAGE, | ||
210 | MHD_OPTION_DIGEST_AUTH_RANDOM, sizeof (rnd), rnd, | 229 | MHD_OPTION_DIGEST_AUTH_RANDOM, sizeof (rnd), rnd, |
211 | MHD_OPTION_NONCE_NC_SIZE, 300, | 230 | MHD_OPTION_NONCE_NC_SIZE, 300, |
212 | MHD_OPTION_END); | 231 | MHD_OPTION_END); |
@@ -215,9 +234,15 @@ testDigestAuth () | |||
215 | if (0 == port) | 234 | if (0 == port) |
216 | { | 235 | { |
217 | const union MHD_DaemonInfo *dinfo; | 236 | const union MHD_DaemonInfo *dinfo; |
218 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | 237 | |
219 | if (NULL == dinfo || 0 == dinfo->port) | 238 | dinfo = MHD_get_daemon_info (d, |
220 | { MHD_stop_daemon (d); return 32; } | 239 | MHD_DAEMON_INFO_BIND_PORT); |
240 | if ( (NULL == dinfo) || | ||
241 | (0 == dinfo->port) ) | ||
242 | { | ||
243 | MHD_stop_daemon (d); | ||
244 | return 32; | ||
245 | } | ||
221 | port = (int)dinfo->port; | 246 | port = (int)dinfo->port; |
222 | } | 247 | } |
223 | snprintf (url, | 248 | snprintf (url, |