diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libssl/src/apps/s_cb.c | 618 |
1 files changed, 289 insertions, 329 deletions
diff --git a/src/lib/libssl/src/apps/s_cb.c b/src/lib/libssl/src/apps/s_cb.c index 8e702075e0..6c341d924c 100644 --- a/src/lib/libssl/src/apps/s_cb.c +++ b/src/lib/libssl/src/apps/s_cb.c | |||
@@ -5,21 +5,21 @@ | |||
5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
8 | * | 8 | * |
9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
11 | * apply to all code found in this distribution, be it the RC4, RSA, | 11 | * apply to all code found in this distribution, be it the RC4, RSA, |
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
13 | * included with this distribution is covered by the same copyright terms | 13 | * included with this distribution is covered by the same copyright terms |
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
15 | * | 15 | * |
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
18 | * If this package is used in a product, Eric Young should be given attribution | 18 | * If this package is used in a product, Eric Young should be given attribution |
19 | * as the author of the parts of the library used. | 19 | * as the author of the parts of the library used. |
20 | * This can be in the form of a textual message at program startup or | 20 | * This can be in the form of a textual message at program startup or |
21 | * in documentation (online or textual) provided with the package. | 21 | * in documentation (online or textual) provided with the package. |
22 | * | 22 | * |
23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
25 | * are met: | 25 | * are met: |
@@ -34,10 +34,10 @@ | |||
34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 37 | * 4. If you include any Windows specific code (or a derivative thereof) from |
38 | * the apps directory (application code) you must include an acknowledgement: | 38 | * the apps directory (application code) you must include an acknowledgement: |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
40 | * | 40 | * |
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -49,7 +49,7 @@ | |||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
52 | * | 52 | * |
53 | * The licence and distribution terms for any publically available version or | 53 | * The licence and distribution terms for any publically available version or |
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
@@ -63,7 +63,7 @@ | |||
63 | * are met: | 63 | * are met: |
64 | * | 64 | * |
65 | * 1. Redistributions of source code must retain the above copyright | 65 | * 1. Redistributions of source code must retain the above copyright |
66 | * notice, this list of conditions and the following disclaimer. | 66 | * notice, this list of conditions and the following disclaimer. |
67 | * | 67 | * |
68 | * 2. Redistributions in binary form must reproduce the above copyright | 68 | * 2. Redistributions in binary form must reproduce the above copyright |
69 | * notice, this list of conditions and the following disclaimer in | 69 | * notice, this list of conditions and the following disclaimer in |
@@ -124,104 +124,99 @@ | |||
124 | 124 | ||
125 | #define COOKIE_SECRET_LENGTH 16 | 125 | #define COOKIE_SECRET_LENGTH 16 |
126 | 126 | ||
127 | int verify_depth=0; | 127 | int verify_depth = 0; |
128 | int verify_error=X509_V_OK; | 128 | int verify_error = X509_V_OK; |
129 | int verify_return_error=0; | 129 | int verify_return_error = 0; |
130 | unsigned char cookie_secret[COOKIE_SECRET_LENGTH]; | 130 | unsigned char cookie_secret[COOKIE_SECRET_LENGTH]; |
131 | int cookie_initialized=0; | 131 | int cookie_initialized = 0; |
132 | 132 | ||
133 | int verify_callback(int ok, X509_STORE_CTX *ctx) | 133 | int |
134 | { | 134 | verify_callback(int ok, X509_STORE_CTX *ctx) |
135 | { | ||
135 | X509 *err_cert; | 136 | X509 *err_cert; |
136 | int err,depth; | 137 | int err, depth; |
137 | 138 | ||
138 | err_cert=X509_STORE_CTX_get_current_cert(ctx); | 139 | err_cert = X509_STORE_CTX_get_current_cert(ctx); |
139 | err= X509_STORE_CTX_get_error(ctx); | 140 | err = X509_STORE_CTX_get_error(ctx); |
140 | depth= X509_STORE_CTX_get_error_depth(ctx); | 141 | depth = X509_STORE_CTX_get_error_depth(ctx); |
141 | 142 | ||
142 | BIO_printf(bio_err,"depth=%d ",depth); | 143 | BIO_printf(bio_err, "depth=%d ", depth); |
143 | if (err_cert) | 144 | if (err_cert) { |
144 | { | ||
145 | X509_NAME_print_ex(bio_err, X509_get_subject_name(err_cert), | 145 | X509_NAME_print_ex(bio_err, X509_get_subject_name(err_cert), |
146 | 0, XN_FLAG_ONELINE); | 146 | 0, XN_FLAG_ONELINE); |
147 | BIO_puts(bio_err, "\n"); | 147 | BIO_puts(bio_err, "\n"); |
148 | } | 148 | } else |
149 | else | ||
150 | BIO_puts(bio_err, "<no cert>\n"); | 149 | BIO_puts(bio_err, "<no cert>\n"); |
151 | if (!ok) | 150 | if (!ok) { |
152 | { | 151 | BIO_printf(bio_err, "verify error:num=%d:%s\n", err, |
153 | BIO_printf(bio_err,"verify error:num=%d:%s\n",err, | 152 | X509_verify_cert_error_string(err)); |
154 | X509_verify_cert_error_string(err)); | 153 | if (verify_depth >= depth) { |
155 | if (verify_depth >= depth) | ||
156 | { | ||
157 | if (!verify_return_error) | 154 | if (!verify_return_error) |
158 | ok=1; | 155 | ok = 1; |
159 | verify_error=X509_V_OK; | 156 | verify_error = X509_V_OK; |
160 | } | 157 | } else { |
161 | else | 158 | ok = 0; |
162 | { | 159 | verify_error = X509_V_ERR_CERT_CHAIN_TOO_LONG; |
163 | ok=0; | ||
164 | verify_error=X509_V_ERR_CERT_CHAIN_TOO_LONG; | ||
165 | } | ||
166 | } | 160 | } |
167 | switch (err) | 161 | } |
168 | { | 162 | switch (err) { |
169 | case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT: | 163 | case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT: |
170 | BIO_puts(bio_err,"issuer= "); | 164 | BIO_puts(bio_err, "issuer= "); |
171 | X509_NAME_print_ex(bio_err, X509_get_issuer_name(err_cert), | 165 | X509_NAME_print_ex(bio_err, X509_get_issuer_name(err_cert), |
172 | 0, XN_FLAG_ONELINE); | 166 | 0, XN_FLAG_ONELINE); |
173 | BIO_puts(bio_err, "\n"); | 167 | BIO_puts(bio_err, "\n"); |
174 | break; | 168 | break; |
175 | case X509_V_ERR_CERT_NOT_YET_VALID: | 169 | case X509_V_ERR_CERT_NOT_YET_VALID: |
176 | case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD: | 170 | case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD: |
177 | BIO_printf(bio_err,"notBefore="); | 171 | BIO_printf(bio_err, "notBefore="); |
178 | ASN1_TIME_print(bio_err,X509_get_notBefore(err_cert)); | 172 | ASN1_TIME_print(bio_err, X509_get_notBefore(err_cert)); |
179 | BIO_printf(bio_err,"\n"); | 173 | BIO_printf(bio_err, "\n"); |
180 | break; | 174 | break; |
181 | case X509_V_ERR_CERT_HAS_EXPIRED: | 175 | case X509_V_ERR_CERT_HAS_EXPIRED: |
182 | case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD: | 176 | case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD: |
183 | BIO_printf(bio_err,"notAfter="); | 177 | BIO_printf(bio_err, "notAfter="); |
184 | ASN1_TIME_print(bio_err,X509_get_notAfter(err_cert)); | 178 | ASN1_TIME_print(bio_err, X509_get_notAfter(err_cert)); |
185 | BIO_printf(bio_err,"\n"); | 179 | BIO_printf(bio_err, "\n"); |
186 | break; | 180 | break; |
187 | case X509_V_ERR_NO_EXPLICIT_POLICY: | 181 | case X509_V_ERR_NO_EXPLICIT_POLICY: |
188 | policies_print(bio_err, ctx); | 182 | policies_print(bio_err, ctx); |
189 | break; | 183 | break; |
190 | } | 184 | } |
191 | if (err == X509_V_OK && ok == 2) | 185 | if (err == X509_V_OK && ok == 2) |
192 | policies_print(bio_err, ctx); | 186 | policies_print(bio_err, ctx); |
193 | 187 | ||
194 | BIO_printf(bio_err,"verify return:%d\n",ok); | 188 | BIO_printf(bio_err, "verify return:%d\n", ok); |
195 | return(ok); | 189 | return (ok); |
196 | } | 190 | } |
197 | 191 | ||
198 | int set_cert_stuff(SSL_CTX *ctx, char *cert_file, char *key_file) | 192 | int |
199 | { | 193 | set_cert_stuff(SSL_CTX *ctx, char *cert_file, char *key_file) |
200 | if (cert_file != NULL) | 194 | { |
201 | { | 195 | if (cert_file != NULL) { |
202 | /* | 196 | /* |
203 | SSL *ssl; | 197 | SSL *ssl; |
204 | X509 *x509; | 198 | X509 *x509; |
205 | */ | 199 | */ |
206 | 200 | ||
207 | if (SSL_CTX_use_certificate_file(ctx,cert_file, | 201 | if (SSL_CTX_use_certificate_file(ctx, cert_file, |
208 | SSL_FILETYPE_PEM) <= 0) | 202 | SSL_FILETYPE_PEM) <= 0) { |
209 | { | 203 | BIO_printf(bio_err, |
210 | BIO_printf(bio_err,"unable to get certificate from '%s'\n",cert_file); | 204 | "unable to get certificate from '%s'\n", cert_file); |
211 | ERR_print_errors(bio_err); | 205 | ERR_print_errors(bio_err); |
212 | return(0); | 206 | return (0); |
213 | } | 207 | } |
214 | if (key_file == NULL) key_file=cert_file; | 208 | if (key_file == NULL) |
215 | if (SSL_CTX_use_PrivateKey_file(ctx,key_file, | 209 | key_file = cert_file; |
216 | SSL_FILETYPE_PEM) <= 0) | 210 | if (SSL_CTX_use_PrivateKey_file(ctx, key_file, |
217 | { | 211 | SSL_FILETYPE_PEM) <= 0) { |
218 | BIO_printf(bio_err,"unable to get private key from '%s'\n",key_file); | 212 | BIO_printf(bio_err, |
213 | "unable to get private key from '%s'\n", key_file); | ||
219 | ERR_print_errors(bio_err); | 214 | ERR_print_errors(bio_err); |
220 | return(0); | 215 | return (0); |
221 | } | 216 | } |
222 | 217 | ||
223 | /* | 218 | /* |
224 | In theory this is no longer needed | 219 | In theory this is no longer needed |
225 | ssl=SSL_new(ctx); | 220 | ssl=SSL_new(ctx); |
226 | x509=SSL_get_certificate(ssl); | 221 | x509=SSL_get_certificate(ssl); |
227 | 222 | ||
@@ -241,113 +236,109 @@ int set_cert_stuff(SSL_CTX *ctx, char *cert_file, char *key_file) | |||
241 | 236 | ||
242 | /* Now we know that a key and cert have been set against | 237 | /* Now we know that a key and cert have been set against |
243 | * the SSL context */ | 238 | * the SSL context */ |
244 | if (!SSL_CTX_check_private_key(ctx)) | 239 | if (!SSL_CTX_check_private_key(ctx)) { |
245 | { | 240 | BIO_printf(bio_err, |
246 | BIO_printf(bio_err,"Private key does not match the certificate public key\n"); | 241 | "Private key does not match the certificate public key\n"); |
247 | return(0); | 242 | return (0); |
248 | } | ||
249 | } | 243 | } |
250 | return(1); | ||
251 | } | 244 | } |
245 | return (1); | ||
246 | } | ||
252 | 247 | ||
253 | int set_cert_key_stuff(SSL_CTX *ctx, X509 *cert, EVP_PKEY *key) | 248 | int |
254 | { | 249 | set_cert_key_stuff(SSL_CTX *ctx, X509 *cert, EVP_PKEY *key) |
250 | { | ||
255 | if (cert == NULL) | 251 | if (cert == NULL) |
256 | return 1; | 252 | return 1; |
257 | if (SSL_CTX_use_certificate(ctx,cert) <= 0) | 253 | if (SSL_CTX_use_certificate(ctx, cert) <= 0) { |
258 | { | 254 | BIO_printf(bio_err, "error setting certificate\n"); |
259 | BIO_printf(bio_err,"error setting certificate\n"); | ||
260 | ERR_print_errors(bio_err); | 255 | ERR_print_errors(bio_err); |
261 | return 0; | 256 | return 0; |
262 | } | 257 | } |
263 | if (SSL_CTX_use_PrivateKey(ctx,key) <= 0) | 258 | if (SSL_CTX_use_PrivateKey(ctx, key) <= 0) { |
264 | { | 259 | BIO_printf(bio_err, "error setting private key\n"); |
265 | BIO_printf(bio_err,"error setting private key\n"); | ||
266 | ERR_print_errors(bio_err); | 260 | ERR_print_errors(bio_err); |
267 | return 0; | 261 | return 0; |
268 | } | 262 | } |
269 | 263 | ||
270 | 264 | /* Now we know that a key and cert have been set against | |
271 | /* Now we know that a key and cert have been set against | 265 | * the SSL context */ |
272 | * the SSL context */ | 266 | if (!SSL_CTX_check_private_key(ctx)) { |
273 | if (!SSL_CTX_check_private_key(ctx)) | 267 | BIO_printf(bio_err, |
274 | { | 268 | "Private key does not match the certificate public key\n"); |
275 | BIO_printf(bio_err,"Private key does not match the certificate public key\n"); | ||
276 | return 0; | 269 | return 0; |
277 | } | ||
278 | return 1; | ||
279 | } | 270 | } |
271 | return 1; | ||
272 | } | ||
280 | 273 | ||
281 | long bio_dump_callback(BIO *bio, int cmd, const char *argp, | 274 | long |
282 | int argi, long argl, long ret) | 275 | bio_dump_callback(BIO *bio, int cmd, const char *argp, |
283 | { | 276 | int argi, long argl, long ret) |
277 | { | ||
284 | BIO *out; | 278 | BIO *out; |
285 | 279 | ||
286 | out=(BIO *)BIO_get_callback_arg(bio); | 280 | out = (BIO *)BIO_get_callback_arg(bio); |
287 | if (out == NULL) return(ret); | 281 | if (out == NULL) |
288 | 282 | return (ret); | |
289 | if (cmd == (BIO_CB_READ|BIO_CB_RETURN)) | 283 | |
290 | { | 284 | if (cmd == (BIO_CB_READ|BIO_CB_RETURN)) { |
291 | BIO_printf(out,"read from %p [%p] (%lu bytes => %ld (0x%lX))\n", | 285 | BIO_printf(out, |
292 | (void *)bio,argp,(unsigned long)argi,ret,ret); | 286 | "read from %p [%p] (%lu bytes => %ld (0x%lX))\n", |
293 | BIO_dump(out,argp,(int)ret); | 287 | (void *)bio, argp, (unsigned long)argi, ret, ret); |
294 | return(ret); | 288 | BIO_dump(out, argp, (int)ret); |
295 | } | 289 | return (ret); |
296 | else if (cmd == (BIO_CB_WRITE|BIO_CB_RETURN)) | 290 | } else if (cmd == (BIO_CB_WRITE|BIO_CB_RETURN)) { |
297 | { | 291 | BIO_printf(out, |
298 | BIO_printf(out,"write to %p [%p] (%lu bytes => %ld (0x%lX))\n", | 292 | "write to %p [%p] (%lu bytes => %ld (0x%lX))\n", |
299 | (void *)bio,argp,(unsigned long)argi,ret,ret); | 293 | (void *)bio, argp, (unsigned long)argi, ret, ret); |
300 | BIO_dump(out,argp,(int)ret); | 294 | BIO_dump(out, argp, (int)ret); |
301 | } | ||
302 | return(ret); | ||
303 | } | 295 | } |
296 | return (ret); | ||
297 | } | ||
304 | 298 | ||
305 | void apps_ssl_info_callback(const SSL *s, int where, int ret) | 299 | void |
306 | { | 300 | apps_ssl_info_callback(const SSL *s, int where, int ret) |
301 | { | ||
307 | const char *str; | 302 | const char *str; |
308 | int w; | 303 | int w; |
309 | 304 | ||
310 | w=where& ~SSL_ST_MASK; | 305 | w = where & ~SSL_ST_MASK; |
311 | |||
312 | if (w & SSL_ST_CONNECT) str="SSL_connect"; | ||
313 | else if (w & SSL_ST_ACCEPT) str="SSL_accept"; | ||
314 | else str="undefined"; | ||
315 | 306 | ||
316 | if (where & SSL_CB_LOOP) | 307 | if (w & SSL_ST_CONNECT) |
317 | { | 308 | str = "SSL_connect"; |
318 | BIO_printf(bio_err,"%s:%s\n",str,SSL_state_string_long(s)); | 309 | else if (w & SSL_ST_ACCEPT) |
319 | } | 310 | str = "SSL_accept"; |
320 | else if (where & SSL_CB_ALERT) | 311 | else |
321 | { | 312 | str = "undefined"; |
322 | str=(where & SSL_CB_READ)?"read":"write"; | 313 | |
323 | BIO_printf(bio_err,"SSL3 alert %s:%s:%s\n", | 314 | if (where & SSL_CB_LOOP) { |
324 | str, | 315 | BIO_printf(bio_err, "%s:%s\n", str, SSL_state_string_long(s)); |
325 | SSL_alert_type_string_long(ret), | 316 | } else if (where & SSL_CB_ALERT) { |
326 | SSL_alert_desc_string_long(ret)); | 317 | str = (where & SSL_CB_READ) ? "read" : "write"; |
327 | } | 318 | BIO_printf(bio_err, "SSL3 alert %s:%s:%s\n", str, |
328 | else if (where & SSL_CB_EXIT) | 319 | SSL_alert_type_string_long(ret), |
329 | { | 320 | SSL_alert_desc_string_long(ret)); |
321 | } else if (where & SSL_CB_EXIT) { | ||
330 | if (ret == 0) | 322 | if (ret == 0) |
331 | BIO_printf(bio_err,"%s:failed in %s\n", | 323 | BIO_printf(bio_err, "%s:failed in %s\n", |
332 | str,SSL_state_string_long(s)); | 324 | str, SSL_state_string_long(s)); |
333 | else if (ret < 0) | 325 | else if (ret < 0) { |
334 | { | 326 | BIO_printf(bio_err, "%s:error in %s\n", |
335 | BIO_printf(bio_err,"%s:error in %s\n", | 327 | str, SSL_state_string_long(s)); |
336 | str,SSL_state_string_long(s)); | ||
337 | } | ||
338 | } | 328 | } |
339 | } | 329 | } |
330 | } | ||
340 | 331 | ||
341 | 332 | ||
342 | void msg_cb(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg) | 333 | void |
343 | { | 334 | msg_cb(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg) |
335 | { | ||
344 | BIO *bio = arg; | 336 | BIO *bio = arg; |
345 | const char *str_write_p, *str_version, *str_content_type = "", *str_details1 = "", *str_details2= ""; | 337 | const char *str_write_p, *str_version, *str_content_type = "", *str_details1 = "", *str_details2 = ""; |
346 | 338 | ||
347 | str_write_p = write_p ? ">>>" : "<<<"; | 339 | str_write_p = write_p ? ">>>" : "<<<"; |
348 | 340 | ||
349 | switch (version) | 341 | switch (version) { |
350 | { | ||
351 | case SSL2_VERSION: | 342 | case SSL2_VERSION: |
352 | str_version = "SSL 2.0"; | 343 | str_version = "SSL 2.0"; |
353 | break; | 344 | break; |
@@ -371,78 +362,68 @@ void msg_cb(int write_p, int version, int content_type, const void *buf, size_t | |||
371 | break; | 362 | break; |
372 | default: | 363 | default: |
373 | str_version = "???"; | 364 | str_version = "???"; |
374 | } | 365 | } |
375 | 366 | ||
376 | if (version == SSL2_VERSION) | 367 | if (version == SSL2_VERSION) { |
377 | { | ||
378 | str_details1 = "???"; | 368 | str_details1 = "???"; |
379 | 369 | ||
380 | if (len > 0) | 370 | if (len > 0) { |
381 | { | 371 | switch (((const unsigned char*)buf)[0]) { |
382 | switch (((const unsigned char*)buf)[0]) | 372 | case 0: |
383 | { | 373 | str_details1 = ", ERROR:"; |
384 | case 0: | 374 | str_details2 = " ???"; |
385 | str_details1 = ", ERROR:"; | 375 | if (len >= 3) { |
386 | str_details2 = " ???"; | 376 | unsigned err = (((const unsigned char*)buf)[1]<<8) + ((const unsigned char*)buf)[2]; |
387 | if (len >= 3) | 377 | |
388 | { | 378 | switch (err) { |
389 | unsigned err = (((const unsigned char*)buf)[1]<<8) + ((const unsigned char*)buf)[2]; | 379 | case 0x0001: |
390 | 380 | str_details2 = " NO-CIPHER-ERROR"; | |
391 | switch (err) | 381 | break; |
392 | { | 382 | case 0x0002: |
393 | case 0x0001: | 383 | str_details2 = " NO-CERTIFICATE-ERROR"; |
394 | str_details2 = " NO-CIPHER-ERROR"; | 384 | break; |
395 | break; | 385 | case 0x0004: |
396 | case 0x0002: | 386 | str_details2 = " BAD-CERTIFICATE-ERROR"; |
397 | str_details2 = " NO-CERTIFICATE-ERROR"; | 387 | break; |
398 | break; | 388 | case 0x0006: |
399 | case 0x0004: | 389 | str_details2 = " UNSUPPORTED-CERTIFICATE-TYPE-ERROR"; |
400 | str_details2 = " BAD-CERTIFICATE-ERROR"; | 390 | break; |
401 | break; | 391 | } |
402 | case 0x0006: | ||
403 | str_details2 = " UNSUPPORTED-CERTIFICATE-TYPE-ERROR"; | ||
404 | break; | ||
405 | } | ||
406 | } | ||
407 | |||
408 | break; | ||
409 | case 1: | ||
410 | str_details1 = ", CLIENT-HELLO"; | ||
411 | break; | ||
412 | case 2: | ||
413 | str_details1 = ", CLIENT-MASTER-KEY"; | ||
414 | break; | ||
415 | case 3: | ||
416 | str_details1 = ", CLIENT-FINISHED"; | ||
417 | break; | ||
418 | case 4: | ||
419 | str_details1 = ", SERVER-HELLO"; | ||
420 | break; | ||
421 | case 5: | ||
422 | str_details1 = ", SERVER-VERIFY"; | ||
423 | break; | ||
424 | case 6: | ||
425 | str_details1 = ", SERVER-FINISHED"; | ||
426 | break; | ||
427 | case 7: | ||
428 | str_details1 = ", REQUEST-CERTIFICATE"; | ||
429 | break; | ||
430 | case 8: | ||
431 | str_details1 = ", CLIENT-CERTIFICATE"; | ||
432 | break; | ||
433 | } | 392 | } |
393 | |||
394 | break; | ||
395 | case 1: | ||
396 | str_details1 = ", CLIENT-HELLO"; | ||
397 | break; | ||
398 | case 2: | ||
399 | str_details1 = ", CLIENT-MASTER-KEY"; | ||
400 | break; | ||
401 | case 3: | ||
402 | str_details1 = ", CLIENT-FINISHED"; | ||
403 | break; | ||
404 | case 4: | ||
405 | str_details1 = ", SERVER-HELLO"; | ||
406 | break; | ||
407 | case 5: | ||
408 | str_details1 = ", SERVER-VERIFY"; | ||
409 | break; | ||
410 | case 6: | ||
411 | str_details1 = ", SERVER-FINISHED"; | ||
412 | break; | ||
413 | case 7: | ||
414 | str_details1 = ", REQUEST-CERTIFICATE"; | ||
415 | break; | ||
416 | case 8: | ||
417 | str_details1 = ", CLIENT-CERTIFICATE"; | ||
418 | break; | ||
434 | } | 419 | } |
435 | } | 420 | } |
421 | } | ||
436 | 422 | ||
437 | if (version == SSL3_VERSION || | 423 | if (version == SSL3_VERSION || version == TLS1_VERSION || |
438 | version == TLS1_VERSION || | 424 | version == TLS1_1_VERSION || version == TLS1_2_VERSION || |
439 | version == TLS1_1_VERSION || | 425 | version == DTLS1_VERSION || version == DTLS1_BAD_VER) { |
440 | version == TLS1_2_VERSION || | 426 | switch (content_type) { |
441 | version == DTLS1_VERSION || | ||
442 | version == DTLS1_BAD_VER) | ||
443 | { | ||
444 | switch (content_type) | ||
445 | { | ||
446 | case 20: | 427 | case 20: |
447 | str_content_type = "ChangeCipherSpec"; | 428 | str_content_type = "ChangeCipherSpec"; |
448 | break; | 429 | break; |
@@ -452,27 +433,24 @@ void msg_cb(int write_p, int version, int content_type, const void *buf, size_t | |||
452 | case 22: | 433 | case 22: |
453 | str_content_type = "Handshake"; | 434 | str_content_type = "Handshake"; |
454 | break; | 435 | break; |
455 | } | 436 | } |
456 | 437 | ||
457 | if (content_type == 21) /* Alert */ | 438 | if (content_type == 21) /* Alert */ |
458 | { | 439 | { |
459 | str_details1 = ", ???"; | 440 | str_details1 = ", ???"; |
460 | 441 | ||
461 | if (len == 2) | 442 | if (len == 2) { |
462 | { | 443 | switch (((const unsigned char*)buf)[0]) { |
463 | switch (((const unsigned char*)buf)[0]) | ||
464 | { | ||
465 | case 1: | 444 | case 1: |
466 | str_details1 = ", warning"; | 445 | str_details1 = ", warning"; |
467 | break; | 446 | break; |
468 | case 2: | 447 | case 2: |
469 | str_details1 = ", fatal"; | 448 | str_details1 = ", fatal"; |
470 | break; | 449 | break; |
471 | } | 450 | } |
472 | 451 | ||
473 | str_details2 = " ???"; | 452 | str_details2 = " ???"; |
474 | switch (((const unsigned char*)buf)[1]) | 453 | switch (((const unsigned char*)buf)[1]) { |
475 | { | ||
476 | case 0: | 454 | case 0: |
477 | str_details2 = " close_notify"; | 455 | str_details2 = " close_notify"; |
478 | break; | 456 | break; |
@@ -560,18 +538,16 @@ void msg_cb(int write_p, int version, int content_type, const void *buf, size_t | |||
560 | case 115: | 538 | case 115: |
561 | str_details2 = " unknown_psk_identity"; | 539 | str_details2 = " unknown_psk_identity"; |
562 | break; | 540 | break; |
563 | } | ||
564 | } | 541 | } |
565 | } | 542 | } |
566 | 543 | } | |
544 | |||
567 | if (content_type == 22) /* Handshake */ | 545 | if (content_type == 22) /* Handshake */ |
568 | { | 546 | { |
569 | str_details1 = "???"; | 547 | str_details1 = "???"; |
570 | 548 | ||
571 | if (len > 0) | 549 | if (len > 0) { |
572 | { | 550 | switch (((const unsigned char*)buf)[0]) { |
573 | switch (((const unsigned char*)buf)[0]) | ||
574 | { | ||
575 | case 0: | 551 | case 0: |
576 | str_details1 = ", HelloRequest"; | 552 | str_details1 = ", HelloRequest"; |
577 | break; | 553 | break; |
@@ -605,143 +581,144 @@ void msg_cb(int write_p, int version, int content_type, const void *buf, size_t | |||
605 | case 20: | 581 | case 20: |
606 | str_details1 = ", Finished"; | 582 | str_details1 = ", Finished"; |
607 | break; | 583 | break; |
608 | } | ||
609 | } | 584 | } |
610 | } | 585 | } |
611 | } | 586 | } |
587 | } | ||
612 | 588 | ||
613 | BIO_printf(bio, "%s %s%s [length %04lx]%s%s\n", str_write_p, str_version, str_content_type, (unsigned long)len, str_details1, str_details2); | 589 | BIO_printf(bio, "%s %s%s [length %04lx]%s%s\n", str_write_p, |
590 | str_version, str_content_type, (unsigned long)len, | ||
591 | str_details1, str_details2); | ||
614 | 592 | ||
615 | if (len > 0) | 593 | if (len > 0) { |
616 | { | ||
617 | size_t num, i; | 594 | size_t num, i; |
618 | 595 | ||
619 | BIO_printf(bio, " "); | 596 | BIO_printf(bio, " "); |
620 | num = len; | 597 | num = len; |
621 | #if 0 | 598 | #if 0 |
622 | if (num > 16) | 599 | if (num > 16) |
623 | num = 16; | 600 | num = 16; |
624 | #endif | 601 | #endif |
625 | for (i = 0; i < num; i++) | 602 | for (i = 0; i < num; i++) { |
626 | { | ||
627 | if (i % 16 == 0 && i > 0) | 603 | if (i % 16 == 0 && i > 0) |
628 | BIO_printf(bio, "\n "); | 604 | BIO_printf(bio, "\n "); |
629 | BIO_printf(bio, " %02x", ((const unsigned char*)buf)[i]); | 605 | BIO_printf(bio, " %02x", |
630 | } | 606 | ((const unsigned char*)buf)[i]); |
607 | } | ||
631 | if (i < len) | 608 | if (i < len) |
632 | BIO_printf(bio, " ..."); | 609 | BIO_printf(bio, " ..."); |
633 | BIO_printf(bio, "\n"); | 610 | BIO_printf(bio, "\n"); |
634 | } | ||
635 | (void)BIO_flush(bio); | ||
636 | } | 611 | } |
612 | (void)BIO_flush(bio); | ||
613 | } | ||
637 | 614 | ||
638 | void tlsext_cb(SSL *s, int client_server, int type, | 615 | void |
639 | unsigned char *data, int len, | 616 | tlsext_cb(SSL *s, int client_server, int type, unsigned char *data, int len, |
640 | void *arg) | 617 | void *arg) |
641 | { | 618 | { |
642 | BIO *bio = arg; | 619 | BIO *bio = arg; |
643 | char *extname; | 620 | char *extname; |
644 | 621 | ||
645 | switch(type) | 622 | switch (type) { |
646 | { | 623 | case TLSEXT_TYPE_server_name: |
647 | case TLSEXT_TYPE_server_name: | ||
648 | extname = "server name"; | 624 | extname = "server name"; |
649 | break; | 625 | break; |
650 | 626 | ||
651 | case TLSEXT_TYPE_max_fragment_length: | 627 | case TLSEXT_TYPE_max_fragment_length: |
652 | extname = "max fragment length"; | 628 | extname = "max fragment length"; |
653 | break; | 629 | break; |
654 | 630 | ||
655 | case TLSEXT_TYPE_client_certificate_url: | 631 | case TLSEXT_TYPE_client_certificate_url: |
656 | extname = "client certificate URL"; | 632 | extname = "client certificate URL"; |
657 | break; | 633 | break; |
658 | 634 | ||
659 | case TLSEXT_TYPE_trusted_ca_keys: | 635 | case TLSEXT_TYPE_trusted_ca_keys: |
660 | extname = "trusted CA keys"; | 636 | extname = "trusted CA keys"; |
661 | break; | 637 | break; |
662 | 638 | ||
663 | case TLSEXT_TYPE_truncated_hmac: | 639 | case TLSEXT_TYPE_truncated_hmac: |
664 | extname = "truncated HMAC"; | 640 | extname = "truncated HMAC"; |
665 | break; | 641 | break; |
666 | 642 | ||
667 | case TLSEXT_TYPE_status_request: | 643 | case TLSEXT_TYPE_status_request: |
668 | extname = "status request"; | 644 | extname = "status request"; |
669 | break; | 645 | break; |
670 | 646 | ||
671 | case TLSEXT_TYPE_user_mapping: | 647 | case TLSEXT_TYPE_user_mapping: |
672 | extname = "user mapping"; | 648 | extname = "user mapping"; |
673 | break; | 649 | break; |
674 | 650 | ||
675 | case TLSEXT_TYPE_client_authz: | 651 | case TLSEXT_TYPE_client_authz: |
676 | extname = "client authz"; | 652 | extname = "client authz"; |
677 | break; | 653 | break; |
678 | 654 | ||
679 | case TLSEXT_TYPE_server_authz: | 655 | case TLSEXT_TYPE_server_authz: |
680 | extname = "server authz"; | 656 | extname = "server authz"; |
681 | break; | 657 | break; |
682 | 658 | ||
683 | case TLSEXT_TYPE_cert_type: | 659 | case TLSEXT_TYPE_cert_type: |
684 | extname = "cert type"; | 660 | extname = "cert type"; |
685 | break; | 661 | break; |
686 | 662 | ||
687 | case TLSEXT_TYPE_elliptic_curves: | 663 | case TLSEXT_TYPE_elliptic_curves: |
688 | extname = "elliptic curves"; | 664 | extname = "elliptic curves"; |
689 | break; | 665 | break; |
690 | 666 | ||
691 | case TLSEXT_TYPE_ec_point_formats: | 667 | case TLSEXT_TYPE_ec_point_formats: |
692 | extname = "EC point formats"; | 668 | extname = "EC point formats"; |
693 | break; | 669 | break; |
694 | 670 | ||
695 | case TLSEXT_TYPE_srp: | 671 | case TLSEXT_TYPE_srp: |
696 | extname = "SRP"; | 672 | extname = "SRP"; |
697 | break; | 673 | break; |
698 | 674 | ||
699 | case TLSEXT_TYPE_signature_algorithms: | 675 | case TLSEXT_TYPE_signature_algorithms: |
700 | extname = "signature algorithms"; | 676 | extname = "signature algorithms"; |
701 | break; | 677 | break; |
702 | 678 | ||
703 | case TLSEXT_TYPE_use_srtp: | 679 | case TLSEXT_TYPE_use_srtp: |
704 | extname = "use SRTP"; | 680 | extname = "use SRTP"; |
705 | break; | 681 | break; |
706 | 682 | ||
707 | case TLSEXT_TYPE_heartbeat: | 683 | case TLSEXT_TYPE_heartbeat: |
708 | extname = "heartbeat"; | 684 | extname = "heartbeat"; |
709 | break; | 685 | break; |
710 | 686 | ||
711 | case TLSEXT_TYPE_session_ticket: | 687 | case TLSEXT_TYPE_session_ticket: |
712 | extname = "session ticket"; | 688 | extname = "session ticket"; |
713 | break; | 689 | break; |
714 | 690 | ||
715 | case TLSEXT_TYPE_renegotiate: | 691 | case TLSEXT_TYPE_renegotiate: |
716 | extname = "renegotiation info"; | 692 | extname = "renegotiation info"; |
717 | break; | 693 | break; |
718 | 694 | ||
719 | #ifdef TLSEXT_TYPE_opaque_prf_input | 695 | #ifdef TLSEXT_TYPE_opaque_prf_input |
720 | case TLSEXT_TYPE_opaque_prf_input: | 696 | case TLSEXT_TYPE_opaque_prf_input: |
721 | extname = "opaque PRF input"; | 697 | extname = "opaque PRF input"; |
722 | break; | 698 | break; |
723 | #endif | 699 | #endif |
724 | #ifdef TLSEXT_TYPE_next_proto_neg | 700 | #ifdef TLSEXT_TYPE_next_proto_neg |
725 | case TLSEXT_TYPE_next_proto_neg: | 701 | case TLSEXT_TYPE_next_proto_neg: |
726 | extname = "next protocol"; | 702 | extname = "next protocol"; |
727 | break; | 703 | break; |
728 | #endif | 704 | #endif |
729 | 705 | ||
730 | default: | 706 | default: |
731 | extname = "unknown"; | 707 | extname = "unknown"; |
732 | break; | 708 | break; |
733 | 709 | ||
734 | } | 710 | } |
735 | 711 | ||
736 | BIO_printf(bio, "TLS %s extension \"%s\" (id=%d), len=%d\n", | 712 | BIO_printf(bio, "TLS %s extension \"%s\" (id=%d), len=%d\n", |
737 | client_server ? "server": "client", | 713 | client_server ? "server" : "client", extname, type, len); |
738 | extname, type, len); | ||
739 | BIO_dump(bio, (char *)data, len); | 714 | BIO_dump(bio, (char *)data, len); |
740 | (void)BIO_flush(bio); | 715 | (void)BIO_flush(bio); |
741 | } | 716 | } |
742 | 717 | ||
743 | int generate_cookie_callback(SSL *ssl, unsigned char *cookie, unsigned int *cookie_len) | 718 | int |
744 | { | 719 | generate_cookie_callback(SSL *ssl, unsigned char *cookie, |
720 | unsigned int *cookie_len) | ||
721 | { | ||
745 | unsigned char *buffer, result[EVP_MAX_MD_SIZE]; | 722 | unsigned char *buffer, result[EVP_MAX_MD_SIZE]; |
746 | unsigned int length, resultlength; | 723 | unsigned int length, resultlength; |
747 | union { | 724 | union { |
@@ -753,23 +730,21 @@ int generate_cookie_callback(SSL *ssl, unsigned char *cookie, unsigned int *cook | |||
753 | } peer; | 730 | } peer; |
754 | 731 | ||
755 | /* Initialize a random secret */ | 732 | /* Initialize a random secret */ |
756 | if (!cookie_initialized) | 733 | if (!cookie_initialized) { |
757 | { | 734 | if (!RAND_bytes(cookie_secret, COOKIE_SECRET_LENGTH)) { |
758 | if (!RAND_bytes(cookie_secret, COOKIE_SECRET_LENGTH)) | 735 | BIO_printf(bio_err, |
759 | { | 736 | "error setting random cookie secret\n"); |
760 | BIO_printf(bio_err,"error setting random cookie secret\n"); | ||
761 | return 0; | 737 | return 0; |
762 | } | ||
763 | cookie_initialized = 1; | ||
764 | } | 738 | } |
739 | cookie_initialized = 1; | ||
740 | } | ||
765 | 741 | ||
766 | /* Read peer information */ | 742 | /* Read peer information */ |
767 | (void)BIO_dgram_get_peer(SSL_get_rbio(ssl), &peer); | 743 | (void)BIO_dgram_get_peer(SSL_get_rbio(ssl), &peer); |
768 | 744 | ||
769 | /* Create buffer with peer's address and port */ | 745 | /* Create buffer with peer's address and port */ |
770 | length = 0; | 746 | length = 0; |
771 | switch (peer.sa.sa_family) | 747 | switch (peer.sa.sa_family) { |
772 | { | ||
773 | case AF_INET: | 748 | case AF_INET: |
774 | length += sizeof(struct in_addr); | 749 | length += sizeof(struct in_addr); |
775 | length += sizeof(peer.s4.sin_port); | 750 | length += sizeof(peer.s4.sin_port); |
@@ -783,53 +758,46 @@ int generate_cookie_callback(SSL *ssl, unsigned char *cookie, unsigned int *cook | |||
783 | default: | 758 | default: |
784 | OPENSSL_assert(0); | 759 | OPENSSL_assert(0); |
785 | break; | 760 | break; |
786 | } | 761 | } |
787 | buffer = malloc(length); | 762 | buffer = malloc(length); |
788 | 763 | ||
789 | if (buffer == NULL) | 764 | if (buffer == NULL) { |
790 | { | 765 | BIO_printf(bio_err, "out of memory\n"); |
791 | BIO_printf(bio_err,"out of memory\n"); | ||
792 | return 0; | 766 | return 0; |
793 | } | 767 | } |
794 | 768 | ||
795 | switch (peer.sa.sa_family) | 769 | switch (peer.sa.sa_family) { |
796 | { | ||
797 | case AF_INET: | 770 | case AF_INET: |
798 | memcpy(buffer, | 771 | memcpy(buffer, &peer.s4.sin_port, sizeof(peer.s4.sin_port)); |
799 | &peer.s4.sin_port, | ||
800 | sizeof(peer.s4.sin_port)); | ||
801 | memcpy(buffer + sizeof(peer.s4.sin_port), | 772 | memcpy(buffer + sizeof(peer.s4.sin_port), |
802 | &peer.s4.sin_addr, | 773 | &peer.s4.sin_addr, sizeof(struct in_addr)); |
803 | sizeof(struct in_addr)); | ||
804 | break; | 774 | break; |
805 | #if OPENSSL_USE_IPV6 | 775 | #if OPENSSL_USE_IPV6 |
806 | case AF_INET6: | 776 | case AF_INET6: |
807 | memcpy(buffer, | 777 | memcpy(buffer, &peer.s6.sin6_port, sizeof(peer.s6.sin6_port)); |
808 | &peer.s6.sin6_port, | ||
809 | sizeof(peer.s6.sin6_port)); | ||
810 | memcpy(buffer + sizeof(peer.s6.sin6_port), | 778 | memcpy(buffer + sizeof(peer.s6.sin6_port), |
811 | &peer.s6.sin6_addr, | 779 | &peer.s6.sin6_addr, sizeof(struct in6_addr)); |
812 | sizeof(struct in6_addr)); | ||
813 | break; | 780 | break; |
814 | #endif | 781 | #endif |
815 | default: | 782 | default: |
816 | OPENSSL_assert(0); | 783 | OPENSSL_assert(0); |
817 | break; | 784 | break; |
818 | } | 785 | } |
819 | 786 | ||
820 | /* Calculate HMAC of buffer using the secret */ | 787 | /* Calculate HMAC of buffer using the secret */ |
821 | HMAC(EVP_sha1(), cookie_secret, COOKIE_SECRET_LENGTH, | 788 | HMAC(EVP_sha1(), cookie_secret, COOKIE_SECRET_LENGTH, |
822 | buffer, length, result, &resultlength); | 789 | buffer, length, result, &resultlength); |
823 | free(buffer); | 790 | free(buffer); |
824 | 791 | ||
825 | memcpy(cookie, result, resultlength); | 792 | memcpy(cookie, result, resultlength); |
826 | *cookie_len = resultlength; | 793 | *cookie_len = resultlength; |
827 | 794 | ||
828 | return 1; | 795 | return 1; |
829 | } | 796 | } |
830 | 797 | ||
831 | int verify_cookie_callback(SSL *ssl, unsigned char *cookie, unsigned int cookie_len) | 798 | int |
832 | { | 799 | verify_cookie_callback(SSL *ssl, unsigned char *cookie, unsigned int cookie_len) |
800 | { | ||
833 | unsigned char *buffer, result[EVP_MAX_MD_SIZE]; | 801 | unsigned char *buffer, result[EVP_MAX_MD_SIZE]; |
834 | unsigned int length, resultlength; | 802 | unsigned int length, resultlength; |
835 | union { | 803 | union { |
@@ -849,8 +817,7 @@ int verify_cookie_callback(SSL *ssl, unsigned char *cookie, unsigned int cookie_ | |||
849 | 817 | ||
850 | /* Create buffer with peer's address and port */ | 818 | /* Create buffer with peer's address and port */ |
851 | length = 0; | 819 | length = 0; |
852 | switch (peer.sa.sa_family) | 820 | switch (peer.sa.sa_family) { |
853 | { | ||
854 | case AF_INET: | 821 | case AF_INET: |
855 | length += sizeof(struct in_addr); | 822 | length += sizeof(struct in_addr); |
856 | length += sizeof(peer.s4.sin_port); | 823 | length += sizeof(peer.s4.sin_port); |
@@ -864,47 +831,40 @@ int verify_cookie_callback(SSL *ssl, unsigned char *cookie, unsigned int cookie_ | |||
864 | default: | 831 | default: |
865 | OPENSSL_assert(0); | 832 | OPENSSL_assert(0); |
866 | break; | 833 | break; |
867 | } | 834 | } |
868 | buffer = malloc(length); | 835 | buffer = malloc(length); |
869 | 836 | ||
870 | if (buffer == NULL) | 837 | if (buffer == NULL) { |
871 | { | 838 | BIO_printf(bio_err, "out of memory\n"); |
872 | BIO_printf(bio_err,"out of memory\n"); | ||
873 | return 0; | 839 | return 0; |
874 | } | 840 | } |
875 | 841 | ||
876 | switch (peer.sa.sa_family) | 842 | switch (peer.sa.sa_family) { |
877 | { | ||
878 | case AF_INET: | 843 | case AF_INET: |
879 | memcpy(buffer, | 844 | memcpy(buffer, &peer.s4.sin_port, sizeof(peer.s4.sin_port)); |
880 | &peer.s4.sin_port, | ||
881 | sizeof(peer.s4.sin_port)); | ||
882 | memcpy(buffer + sizeof(peer.s4.sin_port), | 845 | memcpy(buffer + sizeof(peer.s4.sin_port), |
883 | &peer.s4.sin_addr, | 846 | &peer.s4.sin_addr, sizeof(struct in_addr)); |
884 | sizeof(struct in_addr)); | ||
885 | break; | 847 | break; |
886 | #if OPENSSL_USE_IPV6 | 848 | #if OPENSSL_USE_IPV6 |
887 | case AF_INET6: | 849 | case AF_INET6: |
888 | memcpy(buffer, | 850 | memcpy(buffer, &peer.s6.sin6_port, sizeof(peer.s6.sin6_port)); |
889 | &peer.s6.sin6_port, | ||
890 | sizeof(peer.s6.sin6_port)); | ||
891 | memcpy(buffer + sizeof(peer.s6.sin6_port), | 851 | memcpy(buffer + sizeof(peer.s6.sin6_port), |
892 | &peer.s6.sin6_addr, | 852 | &peer.s6.sin6_addr, sizeof(struct in6_addr)); |
893 | sizeof(struct in6_addr)); | ||
894 | break; | 853 | break; |
895 | #endif | 854 | #endif |
896 | default: | 855 | default: |
897 | OPENSSL_assert(0); | 856 | OPENSSL_assert(0); |
898 | break; | 857 | break; |
899 | } | 858 | } |
900 | 859 | ||
901 | /* Calculate HMAC of buffer using the secret */ | 860 | /* Calculate HMAC of buffer using the secret */ |
902 | HMAC(EVP_sha1(), cookie_secret, COOKIE_SECRET_LENGTH, | 861 | HMAC(EVP_sha1(), cookie_secret, COOKIE_SECRET_LENGTH, |
903 | buffer, length, result, &resultlength); | 862 | buffer, length, result, &resultlength); |
904 | free(buffer); | 863 | free(buffer); |
905 | 864 | ||
906 | if (cookie_len == resultlength && memcmp(result, cookie, resultlength) == 0) | 865 | if (cookie_len == resultlength && |
866 | memcmp(result, cookie, resultlength) == 0) | ||
907 | return 1; | 867 | return 1; |
908 | 868 | ||
909 | return 0; | 869 | return 0; |
910 | } | 870 | } |