diff options
author | djm <> | 2010-10-01 22:59:01 +0000 |
---|---|---|
committer | djm <> | 2010-10-01 22:59:01 +0000 |
commit | fe047d8b632246cb2db3234a0a4f32e5c318857b (patch) | |
tree | 939b752540947d33507b3acc48d76a8bfb7c3dc3 /src/lib/libssl/ssl_lib.c | |
parent | 2ea67f4aa254b09ded62e6e14fc893bbe6381579 (diff) | |
download | openbsd-fe047d8b632246cb2db3234a0a4f32e5c318857b.tar.gz openbsd-fe047d8b632246cb2db3234a0a4f32e5c318857b.tar.bz2 openbsd-fe047d8b632246cb2db3234a0a4f32e5c318857b.zip |
resolve conflicts, fix local changes
Diffstat (limited to 'src/lib/libssl/ssl_lib.c')
-rw-r--r-- | src/lib/libssl/ssl_lib.c | 614 |
1 files changed, 485 insertions, 129 deletions
diff --git a/src/lib/libssl/ssl_lib.c b/src/lib/libssl/ssl_lib.c index 1a961a9e9e..497515f9ec 100644 --- a/src/lib/libssl/ssl_lib.c +++ b/src/lib/libssl/ssl_lib.c | |||
@@ -58,7 +58,7 @@ | |||
58 | * [including the GNU Public Licence.] | 58 | * [including the GNU Public Licence.] |
59 | */ | 59 | */ |
60 | /* ==================================================================== | 60 | /* ==================================================================== |
61 | * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved. | 61 | * Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved. |
62 | * | 62 | * |
63 | * Redistribution and use in source and binary forms, with or without | 63 | * Redistribution and use in source and binary forms, with or without |
64 | * modification, are permitted provided that the following conditions | 64 | * modification, are permitted provided that the following conditions |
@@ -115,6 +115,32 @@ | |||
115 | * ECC cipher suite support in OpenSSL originally developed by | 115 | * ECC cipher suite support in OpenSSL originally developed by |
116 | * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. | 116 | * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. |
117 | */ | 117 | */ |
118 | /* ==================================================================== | ||
119 | * Copyright 2005 Nokia. All rights reserved. | ||
120 | * | ||
121 | * The portions of the attached software ("Contribution") is developed by | ||
122 | * Nokia Corporation and is licensed pursuant to the OpenSSL open source | ||
123 | * license. | ||
124 | * | ||
125 | * The Contribution, originally written by Mika Kousa and Pasi Eronen of | ||
126 | * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites | ||
127 | * support (see RFC 4279) to OpenSSL. | ||
128 | * | ||
129 | * No patent licenses or other rights except those expressly stated in | ||
130 | * the OpenSSL open source license shall be deemed granted or received | ||
131 | * expressly, by implication, estoppel, or otherwise. | ||
132 | * | ||
133 | * No assurances are provided by Nokia that the Contribution does not | ||
134 | * infringe the patent or other intellectual property rights of any third | ||
135 | * party or that the license provides you with all the necessary rights | ||
136 | * to make use of the Contribution. | ||
137 | * | ||
138 | * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN | ||
139 | * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA | ||
140 | * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY | ||
141 | * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR | ||
142 | * OTHERWISE. | ||
143 | */ | ||
118 | 144 | ||
119 | #ifdef REF_CHECK | 145 | #ifdef REF_CHECK |
120 | # include <assert.h> | 146 | # include <assert.h> |
@@ -143,9 +169,9 @@ SSL3_ENC_METHOD ssl3_undef_enc_method={ | |||
143 | ssl_undefined_function, | 169 | ssl_undefined_function, |
144 | (int (*)(SSL *, unsigned char *, unsigned char *, int))ssl_undefined_function, | 170 | (int (*)(SSL *, unsigned char *, unsigned char *, int))ssl_undefined_function, |
145 | (int (*)(SSL*, int))ssl_undefined_function, | 171 | (int (*)(SSL*, int))ssl_undefined_function, |
146 | (int (*)(SSL *, EVP_MD_CTX *, EVP_MD_CTX *, const char*, int, unsigned char *))ssl_undefined_function, | 172 | (int (*)(SSL *, const char*, int, unsigned char *))ssl_undefined_function, |
147 | 0, /* finish_mac_length */ | 173 | 0, /* finish_mac_length */ |
148 | (int (*)(SSL *, EVP_MD_CTX *, unsigned char *))ssl_undefined_function, | 174 | (int (*)(SSL *, int, unsigned char *))ssl_undefined_function, |
149 | NULL, /* client_finished_label */ | 175 | NULL, /* client_finished_label */ |
150 | 0, /* client_finished_label_len */ | 176 | 0, /* client_finished_label_len */ |
151 | NULL, /* server_finished_label */ | 177 | NULL, /* server_finished_label */ |
@@ -204,6 +230,8 @@ int SSL_clear(SSL *s) | |||
204 | } | 230 | } |
205 | 231 | ||
206 | ssl_clear_cipher_ctx(s); | 232 | ssl_clear_cipher_ctx(s); |
233 | ssl_clear_hash_ctx(&s->read_hash); | ||
234 | ssl_clear_hash_ctx(&s->write_hash); | ||
207 | 235 | ||
208 | s->first_packet=0; | 236 | s->first_packet=0; |
209 | 237 | ||
@@ -224,14 +252,15 @@ int SSL_clear(SSL *s) | |||
224 | } | 252 | } |
225 | 253 | ||
226 | /** Used to change an SSL_CTXs default SSL method type */ | 254 | /** Used to change an SSL_CTXs default SSL method type */ |
227 | int SSL_CTX_set_ssl_version(SSL_CTX *ctx,SSL_METHOD *meth) | 255 | int SSL_CTX_set_ssl_version(SSL_CTX *ctx,const SSL_METHOD *meth) |
228 | { | 256 | { |
229 | STACK_OF(SSL_CIPHER) *sk; | 257 | STACK_OF(SSL_CIPHER) *sk; |
230 | 258 | ||
231 | ctx->method=meth; | 259 | ctx->method=meth; |
232 | 260 | ||
233 | sk=ssl_create_cipher_list(ctx->method,&(ctx->cipher_list), | 261 | sk=ssl_create_cipher_list(ctx->method,&(ctx->cipher_list), |
234 | &(ctx->cipher_list_by_id),SSL_DEFAULT_CIPHER_LIST); | 262 | &(ctx->cipher_list_by_id), |
263 | meth->version == SSL2_VERSION ? "SSLv2" : SSL_DEFAULT_CIPHER_LIST); | ||
235 | if ((sk == NULL) || (sk_SSL_CIPHER_num(sk) <= 0)) | 264 | if ((sk == NULL) || (sk_SSL_CIPHER_num(sk) <= 0)) |
236 | { | 265 | { |
237 | SSLerr(SSL_F_SSL_CTX_SET_SSL_VERSION,SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS); | 266 | SSLerr(SSL_F_SSL_CTX_SET_SSL_VERSION,SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS); |
@@ -308,6 +337,7 @@ SSL *SSL_new(SSL_CTX *ctx) | |||
308 | s->trust = ctx->trust; | 337 | s->trust = ctx->trust; |
309 | #endif | 338 | #endif |
310 | s->quiet_shutdown=ctx->quiet_shutdown; | 339 | s->quiet_shutdown=ctx->quiet_shutdown; |
340 | s->max_send_fragment = ctx->max_send_fragment; | ||
311 | 341 | ||
312 | CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX); | 342 | CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX); |
313 | s->ctx=ctx; | 343 | s->ctx=ctx; |
@@ -324,6 +354,7 @@ SSL *SSL_new(SSL_CTX *ctx) | |||
324 | CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX); | 354 | CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX); |
325 | s->initial_ctx=ctx; | 355 | s->initial_ctx=ctx; |
326 | #endif | 356 | #endif |
357 | |||
327 | s->verify_result=X509_V_OK; | 358 | s->verify_result=X509_V_OK; |
328 | 359 | ||
329 | s->method=ctx->method; | 360 | s->method=ctx->method; |
@@ -338,6 +369,11 @@ SSL *SSL_new(SSL_CTX *ctx) | |||
338 | 369 | ||
339 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data); | 370 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data); |
340 | 371 | ||
372 | #ifndef OPENSSL_NO_PSK | ||
373 | s->psk_client_callback=ctx->psk_client_callback; | ||
374 | s->psk_server_callback=ctx->psk_server_callback; | ||
375 | #endif | ||
376 | |||
341 | return(s); | 377 | return(s); |
342 | err: | 378 | err: |
343 | if (s != NULL) | 379 | if (s != NULL) |
@@ -425,7 +461,7 @@ int SSL_has_matching_session_id(const SSL *ssl, const unsigned char *id, | |||
425 | } | 461 | } |
426 | 462 | ||
427 | CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX); | 463 | CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX); |
428 | p = (SSL_SESSION *)lh_retrieve(ssl->ctx->sessions, &r); | 464 | p = lh_SSL_SESSION_retrieve(ssl->ctx->sessions, &r); |
429 | CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX); | 465 | CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX); |
430 | return (p != NULL); | 466 | return (p != NULL); |
431 | } | 467 | } |
@@ -450,6 +486,16 @@ int SSL_set_trust(SSL *s, int trust) | |||
450 | return X509_VERIFY_PARAM_set_trust(s->param, trust); | 486 | return X509_VERIFY_PARAM_set_trust(s->param, trust); |
451 | } | 487 | } |
452 | 488 | ||
489 | int SSL_CTX_set1_param(SSL_CTX *ctx, X509_VERIFY_PARAM *vpm) | ||
490 | { | ||
491 | return X509_VERIFY_PARAM_set1(ctx->param, vpm); | ||
492 | } | ||
493 | |||
494 | int SSL_set1_param(SSL *ssl, X509_VERIFY_PARAM *vpm) | ||
495 | { | ||
496 | return X509_VERIFY_PARAM_set1(ssl->param, vpm); | ||
497 | } | ||
498 | |||
453 | void SSL_free(SSL *s) | 499 | void SSL_free(SSL *s) |
454 | { | 500 | { |
455 | int i; | 501 | int i; |
@@ -504,15 +550,21 @@ void SSL_free(SSL *s) | |||
504 | } | 550 | } |
505 | 551 | ||
506 | ssl_clear_cipher_ctx(s); | 552 | ssl_clear_cipher_ctx(s); |
553 | ssl_clear_hash_ctx(&s->read_hash); | ||
554 | ssl_clear_hash_ctx(&s->write_hash); | ||
507 | 555 | ||
508 | if (s->cert != NULL) ssl_cert_free(s->cert); | 556 | if (s->cert != NULL) ssl_cert_free(s->cert); |
509 | /* Free up if allocated */ | 557 | /* Free up if allocated */ |
510 | 558 | ||
511 | if (s->ctx) SSL_CTX_free(s->ctx); | ||
512 | #ifndef OPENSSL_NO_TLSEXT | 559 | #ifndef OPENSSL_NO_TLSEXT |
513 | if (s->tlsext_hostname) | 560 | if (s->tlsext_hostname) |
514 | OPENSSL_free(s->tlsext_hostname); | 561 | OPENSSL_free(s->tlsext_hostname); |
515 | if (s->initial_ctx) SSL_CTX_free(s->initial_ctx); | 562 | if (s->initial_ctx) SSL_CTX_free(s->initial_ctx); |
563 | #ifndef OPENSSL_NO_EC | ||
564 | if (s->tlsext_ecpointformatlist) OPENSSL_free(s->tlsext_ecpointformatlist); | ||
565 | if (s->tlsext_ellipticcurvelist) OPENSSL_free(s->tlsext_ellipticcurvelist); | ||
566 | #endif /* OPENSSL_NO_EC */ | ||
567 | if (s->tlsext_opaque_prf_input) OPENSSL_free(s->tlsext_opaque_prf_input); | ||
516 | if (s->tlsext_ocsp_exts) | 568 | if (s->tlsext_ocsp_exts) |
517 | sk_X509_EXTENSION_pop_free(s->tlsext_ocsp_exts, | 569 | sk_X509_EXTENSION_pop_free(s->tlsext_ocsp_exts, |
518 | X509_EXTENSION_free); | 570 | X509_EXTENSION_free); |
@@ -521,11 +573,14 @@ void SSL_free(SSL *s) | |||
521 | if (s->tlsext_ocsp_resp) | 573 | if (s->tlsext_ocsp_resp) |
522 | OPENSSL_free(s->tlsext_ocsp_resp); | 574 | OPENSSL_free(s->tlsext_ocsp_resp); |
523 | #endif | 575 | #endif |
576 | |||
524 | if (s->client_CA != NULL) | 577 | if (s->client_CA != NULL) |
525 | sk_X509_NAME_pop_free(s->client_CA,X509_NAME_free); | 578 | sk_X509_NAME_pop_free(s->client_CA,X509_NAME_free); |
526 | 579 | ||
527 | if (s->method != NULL) s->method->ssl_free(s); | 580 | if (s->method != NULL) s->method->ssl_free(s); |
528 | 581 | ||
582 | if (s->ctx) SSL_CTX_free(s->ctx); | ||
583 | |||
529 | #ifndef OPENSSL_NO_KRB5 | 584 | #ifndef OPENSSL_NO_KRB5 |
530 | if (s->kssl_ctx != NULL) | 585 | if (s->kssl_ctx != NULL) |
531 | kssl_ctx_free(s->kssl_ctx); | 586 | kssl_ctx_free(s->kssl_ctx); |
@@ -843,7 +898,7 @@ int SSL_check_private_key(const SSL *ssl) | |||
843 | } | 898 | } |
844 | if (ssl->cert == NULL) | 899 | if (ssl->cert == NULL) |
845 | { | 900 | { |
846 | SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED); | 901 | SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED); |
847 | return 0; | 902 | return 0; |
848 | } | 903 | } |
849 | if (ssl->cert->key->x509 == NULL) | 904 | if (ssl->cert->key->x509 == NULL) |
@@ -986,8 +1041,12 @@ long SSL_ctrl(SSL *s,int cmd,long larg,void *parg) | |||
986 | 1041 | ||
987 | case SSL_CTRL_OPTIONS: | 1042 | case SSL_CTRL_OPTIONS: |
988 | return(s->options|=larg); | 1043 | return(s->options|=larg); |
1044 | case SSL_CTRL_CLEAR_OPTIONS: | ||
1045 | return(s->options&=~larg); | ||
989 | case SSL_CTRL_MODE: | 1046 | case SSL_CTRL_MODE: |
990 | return(s->mode|=larg); | 1047 | return(s->mode|=larg); |
1048 | case SSL_CTRL_CLEAR_MODE: | ||
1049 | return(s->mode &=~larg); | ||
991 | case SSL_CTRL_GET_MAX_CERT_LIST: | 1050 | case SSL_CTRL_GET_MAX_CERT_LIST: |
992 | return(s->max_cert_list); | 1051 | return(s->max_cert_list); |
993 | case SSL_CTRL_SET_MAX_CERT_LIST: | 1052 | case SSL_CTRL_SET_MAX_CERT_LIST: |
@@ -995,12 +1054,22 @@ long SSL_ctrl(SSL *s,int cmd,long larg,void *parg) | |||
995 | s->max_cert_list=larg; | 1054 | s->max_cert_list=larg; |
996 | return(l); | 1055 | return(l); |
997 | case SSL_CTRL_SET_MTU: | 1056 | case SSL_CTRL_SET_MTU: |
998 | if (SSL_version(s) == DTLS1_VERSION) | 1057 | if (SSL_version(s) == DTLS1_VERSION || |
1058 | SSL_version(s) == DTLS1_BAD_VER) | ||
999 | { | 1059 | { |
1000 | s->d1->mtu = larg; | 1060 | s->d1->mtu = larg; |
1001 | return larg; | 1061 | return larg; |
1002 | } | 1062 | } |
1003 | return 0; | 1063 | return 0; |
1064 | case SSL_CTRL_SET_MAX_SEND_FRAGMENT: | ||
1065 | if (larg < 512 || larg > SSL3_RT_MAX_PLAIN_LENGTH) | ||
1066 | return 0; | ||
1067 | s->max_send_fragment = larg; | ||
1068 | return 1; | ||
1069 | case SSL_CTRL_GET_RI_SUPPORT: | ||
1070 | if (s->s3) | ||
1071 | return s->s3->send_connection_binding; | ||
1072 | else return 0; | ||
1004 | default: | 1073 | default: |
1005 | return(s->method->ssl_ctrl(s,cmd,larg,parg)); | 1074 | return(s->method->ssl_ctrl(s,cmd,larg,parg)); |
1006 | } | 1075 | } |
@@ -1019,7 +1088,7 @@ long SSL_callback_ctrl(SSL *s, int cmd, void (*fp)(void)) | |||
1019 | } | 1088 | } |
1020 | } | 1089 | } |
1021 | 1090 | ||
1022 | struct lhash_st *SSL_CTX_sessions(SSL_CTX *ctx) | 1091 | LHASH_OF(SSL_SESSION) *SSL_CTX_sessions(SSL_CTX *ctx) |
1023 | { | 1092 | { |
1024 | return ctx->sessions; | 1093 | return ctx->sessions; |
1025 | } | 1094 | } |
@@ -1062,7 +1131,7 @@ long SSL_CTX_ctrl(SSL_CTX *ctx,int cmd,long larg,void *parg) | |||
1062 | return(ctx->session_cache_mode); | 1131 | return(ctx->session_cache_mode); |
1063 | 1132 | ||
1064 | case SSL_CTRL_SESS_NUMBER: | 1133 | case SSL_CTRL_SESS_NUMBER: |
1065 | return(ctx->sessions->num_items); | 1134 | return(lh_SSL_SESSION_num_items(ctx->sessions)); |
1066 | case SSL_CTRL_SESS_CONNECT: | 1135 | case SSL_CTRL_SESS_CONNECT: |
1067 | return(ctx->stats.sess_connect); | 1136 | return(ctx->stats.sess_connect); |
1068 | case SSL_CTRL_SESS_CONNECT_GOOD: | 1137 | case SSL_CTRL_SESS_CONNECT_GOOD: |
@@ -1087,8 +1156,17 @@ long SSL_CTX_ctrl(SSL_CTX *ctx,int cmd,long larg,void *parg) | |||
1087 | return(ctx->stats.sess_cache_full); | 1156 | return(ctx->stats.sess_cache_full); |
1088 | case SSL_CTRL_OPTIONS: | 1157 | case SSL_CTRL_OPTIONS: |
1089 | return(ctx->options|=larg); | 1158 | return(ctx->options|=larg); |
1159 | case SSL_CTRL_CLEAR_OPTIONS: | ||
1160 | return(ctx->options&=~larg); | ||
1090 | case SSL_CTRL_MODE: | 1161 | case SSL_CTRL_MODE: |
1091 | return(ctx->mode|=larg); | 1162 | return(ctx->mode|=larg); |
1163 | case SSL_CTRL_CLEAR_MODE: | ||
1164 | return(ctx->mode&=~larg); | ||
1165 | case SSL_CTRL_SET_MAX_SEND_FRAGMENT: | ||
1166 | if (larg < 512 || larg > SSL3_RT_MAX_PLAIN_LENGTH) | ||
1167 | return 0; | ||
1168 | ctx->max_send_fragment = larg; | ||
1169 | return 1; | ||
1092 | default: | 1170 | default: |
1093 | return(ctx->method->ssl_ctx_ctrl(ctx,cmd,larg,parg)); | 1171 | return(ctx->method->ssl_ctx_ctrl(ctx,cmd,larg,parg)); |
1094 | } | 1172 | } |
@@ -1193,8 +1271,8 @@ int SSL_CTX_set_cipher_list(SSL_CTX *ctx, const char *str) | |||
1193 | /* ssl_create_cipher_list may return an empty stack if it | 1271 | /* ssl_create_cipher_list may return an empty stack if it |
1194 | * was unable to find a cipher matching the given rule string | 1272 | * was unable to find a cipher matching the given rule string |
1195 | * (for example if the rule string specifies a cipher which | 1273 | * (for example if the rule string specifies a cipher which |
1196 | * has been disabled). This is not an error as far as | 1274 | * has been disabled). This is not an error as far as |
1197 | * ssl_create_cipher_list is concerned, and hence | 1275 | * ssl_create_cipher_list is concerned, and hence |
1198 | * ctx->cipher_list and ctx->cipher_list_by_id has been | 1276 | * ctx->cipher_list and ctx->cipher_list_by_id has been |
1199 | * updated. */ | 1277 | * updated. */ |
1200 | if (sk == NULL) | 1278 | if (sk == NULL) |
@@ -1259,13 +1337,13 @@ char *SSL_get_shared_ciphers(const SSL *s,char *buf,int len) | |||
1259 | } | 1337 | } |
1260 | 1338 | ||
1261 | int ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p, | 1339 | int ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p, |
1262 | int (*put_cb)(const SSL_CIPHER *, unsigned char *)) | 1340 | int (*put_cb)(const SSL_CIPHER *, unsigned char *)) |
1263 | { | 1341 | { |
1264 | int i,j=0; | 1342 | int i,j=0; |
1265 | SSL_CIPHER *c; | 1343 | SSL_CIPHER *c; |
1266 | unsigned char *q; | 1344 | unsigned char *q; |
1267 | #ifndef OPENSSL_NO_KRB5 | 1345 | #ifndef OPENSSL_NO_KRB5 |
1268 | int nokrb5 = !kssl_tgt_is_available(s->kssl_ctx); | 1346 | int nokrb5 = !kssl_tgt_is_available(s->kssl_ctx); |
1269 | #endif /* OPENSSL_NO_KRB5 */ | 1347 | #endif /* OPENSSL_NO_KRB5 */ |
1270 | 1348 | ||
1271 | if (sk == NULL) return(0); | 1349 | if (sk == NULL) return(0); |
@@ -1275,22 +1353,46 @@ int ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p, | |||
1275 | { | 1353 | { |
1276 | c=sk_SSL_CIPHER_value(sk,i); | 1354 | c=sk_SSL_CIPHER_value(sk,i); |
1277 | #ifndef OPENSSL_NO_KRB5 | 1355 | #ifndef OPENSSL_NO_KRB5 |
1278 | if ((c->algorithms & SSL_KRB5) && nokrb5) | 1356 | if (((c->algorithm_mkey & SSL_kKRB5) || (c->algorithm_auth & SSL_aKRB5)) && |
1279 | continue; | 1357 | nokrb5) |
1280 | #endif /* OPENSSL_NO_KRB5 */ | 1358 | continue; |
1281 | 1359 | #endif /* OPENSSL_NO_KRB5 */ | |
1360 | #ifndef OPENSSL_NO_PSK | ||
1361 | /* with PSK there must be client callback set */ | ||
1362 | if (((c->algorithm_mkey & SSL_kPSK) || (c->algorithm_auth & SSL_aPSK)) && | ||
1363 | s->psk_client_callback == NULL) | ||
1364 | continue; | ||
1365 | #endif /* OPENSSL_NO_PSK */ | ||
1282 | j = put_cb ? put_cb(c,p) : ssl_put_cipher_by_char(s,c,p); | 1366 | j = put_cb ? put_cb(c,p) : ssl_put_cipher_by_char(s,c,p); |
1283 | p+=j; | 1367 | p+=j; |
1284 | } | 1368 | } |
1369 | /* If p == q, no ciphers and caller indicates an error. Otherwise | ||
1370 | * add SCSV if not renegotiating. | ||
1371 | */ | ||
1372 | if (p != q && !s->new_session) | ||
1373 | { | ||
1374 | static SSL_CIPHER scsv = | ||
1375 | { | ||
1376 | 0, NULL, SSL3_CK_SCSV, 0, 0, 0, 0, 0, 0, 0, 0, 0 | ||
1377 | }; | ||
1378 | j = put_cb ? put_cb(&scsv,p) : ssl_put_cipher_by_char(s,&scsv,p); | ||
1379 | p+=j; | ||
1380 | #ifdef OPENSSL_RI_DEBUG | ||
1381 | fprintf(stderr, "SCSV sent by client\n"); | ||
1382 | #endif | ||
1383 | } | ||
1384 | |||
1285 | return(p-q); | 1385 | return(p-q); |
1286 | } | 1386 | } |
1287 | 1387 | ||
1288 | STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num, | 1388 | STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num, |
1289 | STACK_OF(SSL_CIPHER) **skp) | 1389 | STACK_OF(SSL_CIPHER) **skp) |
1290 | { | 1390 | { |
1291 | SSL_CIPHER *c; | 1391 | const SSL_CIPHER *c; |
1292 | STACK_OF(SSL_CIPHER) *sk; | 1392 | STACK_OF(SSL_CIPHER) *sk; |
1293 | int i,n; | 1393 | int i,n; |
1394 | if (s->s3) | ||
1395 | s->s3->send_connection_binding = 0; | ||
1294 | 1396 | ||
1295 | n=ssl_put_cipher_by_char(s,NULL,NULL); | 1397 | n=ssl_put_cipher_by_char(s,NULL,NULL); |
1296 | if ((num%n) != 0) | 1398 | if ((num%n) != 0) |
@@ -1308,6 +1410,26 @@ STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num, | |||
1308 | 1410 | ||
1309 | for (i=0; i<num; i+=n) | 1411 | for (i=0; i<num; i+=n) |
1310 | { | 1412 | { |
1413 | /* Check for SCSV */ | ||
1414 | if (s->s3 && (n != 3 || !p[0]) && | ||
1415 | (p[n-2] == ((SSL3_CK_SCSV >> 8) & 0xff)) && | ||
1416 | (p[n-1] == (SSL3_CK_SCSV & 0xff))) | ||
1417 | { | ||
1418 | /* SCSV fatal if renegotiating */ | ||
1419 | if (s->new_session) | ||
1420 | { | ||
1421 | SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,SSL_R_SCSV_RECEIVED_WHEN_RENEGOTIATING); | ||
1422 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE); | ||
1423 | goto err; | ||
1424 | } | ||
1425 | s->s3->send_connection_binding = 1; | ||
1426 | p += n; | ||
1427 | #ifdef OPENSSL_RI_DEBUG | ||
1428 | fprintf(stderr, "SCSV received by server\n"); | ||
1429 | #endif | ||
1430 | continue; | ||
1431 | } | ||
1432 | |||
1311 | c=ssl_get_cipher_by_char(s,p); | 1433 | c=ssl_get_cipher_by_char(s,p); |
1312 | p+=n; | 1434 | p+=n; |
1313 | if (c != NULL) | 1435 | if (c != NULL) |
@@ -1329,6 +1451,7 @@ err: | |||
1329 | return(NULL); | 1451 | return(NULL); |
1330 | } | 1452 | } |
1331 | 1453 | ||
1454 | |||
1332 | #ifndef OPENSSL_NO_TLSEXT | 1455 | #ifndef OPENSSL_NO_TLSEXT |
1333 | /** return a servername extension value if provided in Client Hello, or NULL. | 1456 | /** return a servername extension value if provided in Client Hello, or NULL. |
1334 | * So far, only host_name types are defined (RFC 3546). | 1457 | * So far, only host_name types are defined (RFC 3546). |
@@ -1352,7 +1475,7 @@ int SSL_get_servername_type(const SSL *s) | |||
1352 | } | 1475 | } |
1353 | #endif | 1476 | #endif |
1354 | 1477 | ||
1355 | unsigned long SSL_SESSION_hash(const SSL_SESSION *a) | 1478 | static unsigned long ssl_session_hash(const SSL_SESSION *a) |
1356 | { | 1479 | { |
1357 | unsigned long l; | 1480 | unsigned long l; |
1358 | 1481 | ||
@@ -1369,7 +1492,7 @@ unsigned long SSL_SESSION_hash(const SSL_SESSION *a) | |||
1369 | * SSL_CTX_has_matching_session_id() is checked accordingly. It relies on being | 1492 | * SSL_CTX_has_matching_session_id() is checked accordingly. It relies on being |
1370 | * able to construct an SSL_SESSION that will collide with any existing session | 1493 | * able to construct an SSL_SESSION that will collide with any existing session |
1371 | * with a matching session ID. */ | 1494 | * with a matching session ID. */ |
1372 | int SSL_SESSION_cmp(const SSL_SESSION *a,const SSL_SESSION *b) | 1495 | static int ssl_session_cmp(const SSL_SESSION *a,const SSL_SESSION *b) |
1373 | { | 1496 | { |
1374 | if (a->ssl_version != b->ssl_version) | 1497 | if (a->ssl_version != b->ssl_version) |
1375 | return(1); | 1498 | return(1); |
@@ -1382,27 +1505,19 @@ int SSL_SESSION_cmp(const SSL_SESSION *a,const SSL_SESSION *b) | |||
1382 | * SSL_SESSION_hash and SSL_SESSION_cmp for void* types and casting each | 1505 | * SSL_SESSION_hash and SSL_SESSION_cmp for void* types and casting each |
1383 | * variable. The reason is that the functions aren't static, they're exposed via | 1506 | * variable. The reason is that the functions aren't static, they're exposed via |
1384 | * ssl.h. */ | 1507 | * ssl.h. */ |
1385 | static IMPLEMENT_LHASH_HASH_FN(SSL_SESSION_hash, SSL_SESSION *) | 1508 | static IMPLEMENT_LHASH_HASH_FN(ssl_session, SSL_SESSION) |
1386 | static IMPLEMENT_LHASH_COMP_FN(SSL_SESSION_cmp, SSL_SESSION *) | 1509 | static IMPLEMENT_LHASH_COMP_FN(ssl_session, SSL_SESSION) |
1387 | 1510 | ||
1388 | SSL_CTX *SSL_CTX_new(SSL_METHOD *meth) | 1511 | SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth) |
1389 | { | 1512 | { |
1390 | SSL_CTX *ret=NULL; | 1513 | SSL_CTX *ret=NULL; |
1391 | 1514 | ||
1392 | if (meth == NULL) | 1515 | if (meth == NULL) |
1393 | { | 1516 | { |
1394 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_NULL_SSL_METHOD_PASSED); | 1517 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_NULL_SSL_METHOD_PASSED); |
1395 | return(NULL); | 1518 | return(NULL); |
1396 | } | 1519 | } |
1397 | 1520 | ||
1398 | #ifdef OPENSSL_FIPS | ||
1399 | if (FIPS_mode() && (meth->version < TLS1_VERSION)) | ||
1400 | { | ||
1401 | SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE); | ||
1402 | return NULL; | ||
1403 | } | ||
1404 | #endif | ||
1405 | |||
1406 | if (SSL_get_ex_data_X509_STORE_CTX_idx() < 0) | 1521 | if (SSL_get_ex_data_X509_STORE_CTX_idx() < 0) |
1407 | { | 1522 | { |
1408 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_X509_VERIFICATION_SETUP_PROBLEMS); | 1523 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_X509_VERIFICATION_SETUP_PROBLEMS); |
@@ -1465,15 +1580,14 @@ SSL_CTX *SSL_CTX_new(SSL_METHOD *meth) | |||
1465 | ret->app_gen_cookie_cb=0; | 1580 | ret->app_gen_cookie_cb=0; |
1466 | ret->app_verify_cookie_cb=0; | 1581 | ret->app_verify_cookie_cb=0; |
1467 | 1582 | ||
1468 | ret->sessions=lh_new(LHASH_HASH_FN(SSL_SESSION_hash), | 1583 | ret->sessions=lh_SSL_SESSION_new(); |
1469 | LHASH_COMP_FN(SSL_SESSION_cmp)); | ||
1470 | if (ret->sessions == NULL) goto err; | 1584 | if (ret->sessions == NULL) goto err; |
1471 | ret->cert_store=X509_STORE_new(); | 1585 | ret->cert_store=X509_STORE_new(); |
1472 | if (ret->cert_store == NULL) goto err; | 1586 | if (ret->cert_store == NULL) goto err; |
1473 | 1587 | ||
1474 | ssl_create_cipher_list(ret->method, | 1588 | ssl_create_cipher_list(ret->method, |
1475 | &ret->cipher_list,&ret->cipher_list_by_id, | 1589 | &ret->cipher_list,&ret->cipher_list_by_id, |
1476 | SSL_DEFAULT_CIPHER_LIST); | 1590 | meth->version == SSL2_VERSION ? "SSLv2" : SSL_DEFAULT_CIPHER_LIST); |
1477 | if (ret->cipher_list == NULL | 1591 | if (ret->cipher_list == NULL |
1478 | || sk_SSL_CIPHER_num(ret->cipher_list) <= 0) | 1592 | || sk_SSL_CIPHER_num(ret->cipher_list) <= 0) |
1479 | { | 1593 | { |
@@ -1509,6 +1623,8 @@ SSL_CTX *SSL_CTX_new(SSL_METHOD *meth) | |||
1509 | ret->extra_certs=NULL; | 1623 | ret->extra_certs=NULL; |
1510 | ret->comp_methods=SSL_COMP_get_compression_methods(); | 1624 | ret->comp_methods=SSL_COMP_get_compression_methods(); |
1511 | 1625 | ||
1626 | ret->max_send_fragment = SSL3_RT_MAX_PLAIN_LENGTH; | ||
1627 | |||
1512 | #ifndef OPENSSL_NO_TLSEXT | 1628 | #ifndef OPENSSL_NO_TLSEXT |
1513 | ret->tlsext_servername_callback = 0; | 1629 | ret->tlsext_servername_callback = 0; |
1514 | ret->tlsext_servername_arg = NULL; | 1630 | ret->tlsext_servername_arg = NULL; |
@@ -1522,7 +1638,29 @@ SSL_CTX *SSL_CTX_new(SSL_METHOD *meth) | |||
1522 | ret->tlsext_status_arg = NULL; | 1638 | ret->tlsext_status_arg = NULL; |
1523 | 1639 | ||
1524 | #endif | 1640 | #endif |
1525 | 1641 | #ifndef OPENSSL_NO_PSK | |
1642 | ret->psk_identity_hint=NULL; | ||
1643 | ret->psk_client_callback=NULL; | ||
1644 | ret->psk_server_callback=NULL; | ||
1645 | #endif | ||
1646 | #ifndef OPENSSL_NO_BUF_FREELISTS | ||
1647 | ret->freelist_max_len = SSL_MAX_BUF_FREELIST_LEN_DEFAULT; | ||
1648 | ret->rbuf_freelist = OPENSSL_malloc(sizeof(SSL3_BUF_FREELIST)); | ||
1649 | if (!ret->rbuf_freelist) | ||
1650 | goto err; | ||
1651 | ret->rbuf_freelist->chunklen = 0; | ||
1652 | ret->rbuf_freelist->len = 0; | ||
1653 | ret->rbuf_freelist->head = NULL; | ||
1654 | ret->wbuf_freelist = OPENSSL_malloc(sizeof(SSL3_BUF_FREELIST)); | ||
1655 | if (!ret->wbuf_freelist) | ||
1656 | { | ||
1657 | OPENSSL_free(ret->rbuf_freelist); | ||
1658 | goto err; | ||
1659 | } | ||
1660 | ret->wbuf_freelist->chunklen = 0; | ||
1661 | ret->wbuf_freelist->len = 0; | ||
1662 | ret->wbuf_freelist->head = NULL; | ||
1663 | #endif | ||
1526 | #ifndef OPENSSL_NO_ENGINE | 1664 | #ifndef OPENSSL_NO_ENGINE |
1527 | ret->client_cert_engine = NULL; | 1665 | ret->client_cert_engine = NULL; |
1528 | #ifdef OPENSSL_SSL_CLIENT_ENGINE_AUTO | 1666 | #ifdef OPENSSL_SSL_CLIENT_ENGINE_AUTO |
@@ -1543,6 +1681,10 @@ SSL_CTX *SSL_CTX_new(SSL_METHOD *meth) | |||
1543 | } | 1681 | } |
1544 | #endif | 1682 | #endif |
1545 | #endif | 1683 | #endif |
1684 | /* Default is to connect to non-RI servers. When RI is more widely | ||
1685 | * deployed might change this. | ||
1686 | */ | ||
1687 | ret->options |= SSL_OP_LEGACY_SERVER_CONNECT; | ||
1546 | 1688 | ||
1547 | return(ret); | 1689 | return(ret); |
1548 | err: | 1690 | err: |
@@ -1557,6 +1699,20 @@ static void SSL_COMP_free(SSL_COMP *comp) | |||
1557 | { OPENSSL_free(comp); } | 1699 | { OPENSSL_free(comp); } |
1558 | #endif | 1700 | #endif |
1559 | 1701 | ||
1702 | #ifndef OPENSSL_NO_BUF_FREELISTS | ||
1703 | static void | ||
1704 | ssl_buf_freelist_free(SSL3_BUF_FREELIST *list) | ||
1705 | { | ||
1706 | SSL3_BUF_FREELIST_ENTRY *ent, *next; | ||
1707 | for (ent = list->head; ent; ent = next) | ||
1708 | { | ||
1709 | next = ent->next; | ||
1710 | OPENSSL_free(ent); | ||
1711 | } | ||
1712 | OPENSSL_free(list); | ||
1713 | } | ||
1714 | #endif | ||
1715 | |||
1560 | void SSL_CTX_free(SSL_CTX *a) | 1716 | void SSL_CTX_free(SSL_CTX *a) |
1561 | { | 1717 | { |
1562 | int i; | 1718 | int i; |
@@ -1594,7 +1750,7 @@ void SSL_CTX_free(SSL_CTX *a) | |||
1594 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, a, &a->ex_data); | 1750 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, a, &a->ex_data); |
1595 | 1751 | ||
1596 | if (a->sessions != NULL) | 1752 | if (a->sessions != NULL) |
1597 | lh_free(a->sessions); | 1753 | lh_SSL_SESSION_free(a->sessions); |
1598 | 1754 | ||
1599 | if (a->cert_store != NULL) | 1755 | if (a->cert_store != NULL) |
1600 | X509_STORE_free(a->cert_store); | 1756 | X509_STORE_free(a->cert_store); |
@@ -1614,10 +1770,23 @@ void SSL_CTX_free(SSL_CTX *a) | |||
1614 | #else | 1770 | #else |
1615 | a->comp_methods = NULL; | 1771 | a->comp_methods = NULL; |
1616 | #endif | 1772 | #endif |
1773 | |||
1774 | #ifndef OPENSSL_NO_PSK | ||
1775 | if (a->psk_identity_hint) | ||
1776 | OPENSSL_free(a->psk_identity_hint); | ||
1777 | #endif | ||
1617 | #ifndef OPENSSL_NO_ENGINE | 1778 | #ifndef OPENSSL_NO_ENGINE |
1618 | if (a->client_cert_engine) | 1779 | if (a->client_cert_engine) |
1619 | ENGINE_finish(a->client_cert_engine); | 1780 | ENGINE_finish(a->client_cert_engine); |
1620 | #endif | 1781 | #endif |
1782 | |||
1783 | #ifndef OPENSSL_NO_BUF_FREELISTS | ||
1784 | if (a->wbuf_freelist) | ||
1785 | ssl_buf_freelist_free(a->wbuf_freelist); | ||
1786 | if (a->rbuf_freelist) | ||
1787 | ssl_buf_freelist_free(a->rbuf_freelist); | ||
1788 | #endif | ||
1789 | |||
1621 | OPENSSL_free(a); | 1790 | OPENSSL_free(a); |
1622 | } | 1791 | } |
1623 | 1792 | ||
@@ -1648,13 +1817,13 @@ void SSL_CTX_set_verify_depth(SSL_CTX *ctx,int depth) | |||
1648 | X509_VERIFY_PARAM_set_depth(ctx->param, depth); | 1817 | X509_VERIFY_PARAM_set_depth(ctx->param, depth); |
1649 | } | 1818 | } |
1650 | 1819 | ||
1651 | void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher) | 1820 | void ssl_set_cert_masks(CERT *c, const SSL_CIPHER *cipher) |
1652 | { | 1821 | { |
1653 | CERT_PKEY *cpk; | 1822 | CERT_PKEY *cpk; |
1654 | int rsa_enc,rsa_tmp,rsa_sign,dh_tmp,dh_rsa,dh_dsa,dsa_sign; | 1823 | int rsa_enc,rsa_tmp,rsa_sign,dh_tmp,dh_rsa,dh_dsa,dsa_sign; |
1655 | int rsa_enc_export,dh_rsa_export,dh_dsa_export; | 1824 | int rsa_enc_export,dh_rsa_export,dh_dsa_export; |
1656 | int rsa_tmp_export,dh_tmp_export,kl; | 1825 | int rsa_tmp_export,dh_tmp_export,kl; |
1657 | unsigned long mask,emask; | 1826 | unsigned long mask_k,mask_a,emask_k,emask_a; |
1658 | int have_ecc_cert, ecdh_ok, ecdsa_ok, ecc_pkey_size; | 1827 | int have_ecc_cert, ecdh_ok, ecdsa_ok, ecc_pkey_size; |
1659 | #ifndef OPENSSL_NO_ECDH | 1828 | #ifndef OPENSSL_NO_ECDH |
1660 | int have_ecdh_tmp; | 1829 | int have_ecdh_tmp; |
@@ -1701,60 +1870,77 @@ void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher) | |||
1701 | dh_dsa_export=(dh_dsa && EVP_PKEY_size(cpk->privatekey)*8 <= kl); | 1870 | dh_dsa_export=(dh_dsa && EVP_PKEY_size(cpk->privatekey)*8 <= kl); |
1702 | cpk= &(c->pkeys[SSL_PKEY_ECC]); | 1871 | cpk= &(c->pkeys[SSL_PKEY_ECC]); |
1703 | have_ecc_cert= (cpk->x509 != NULL && cpk->privatekey != NULL); | 1872 | have_ecc_cert= (cpk->x509 != NULL && cpk->privatekey != NULL); |
1704 | mask=0; | 1873 | mask_k=0; |
1705 | emask=0; | 1874 | mask_a=0; |
1875 | emask_k=0; | ||
1876 | emask_a=0; | ||
1877 | |||
1878 | |||
1706 | 1879 | ||
1707 | #ifdef CIPHER_DEBUG | 1880 | #ifdef CIPHER_DEBUG |
1708 | printf("rt=%d rte=%d dht=%d re=%d ree=%d rs=%d ds=%d dhr=%d dhd=%d\n", | 1881 | printf("rt=%d rte=%d dht=%d ecdht=%d re=%d ree=%d rs=%d ds=%d dhr=%d dhd=%d\n", |
1709 | rsa_tmp,rsa_tmp_export,dh_tmp, | 1882 | rsa_tmp,rsa_tmp_export,dh_tmp,have_ecdh_tmp, |
1710 | rsa_enc,rsa_enc_export,rsa_sign,dsa_sign,dh_rsa,dh_dsa); | 1883 | rsa_enc,rsa_enc_export,rsa_sign,dsa_sign,dh_rsa,dh_dsa); |
1711 | #endif | 1884 | #endif |
1885 | |||
1886 | cpk = &(c->pkeys[SSL_PKEY_GOST01]); | ||
1887 | if (cpk->x509 != NULL && cpk->privatekey !=NULL) { | ||
1888 | mask_k |= SSL_kGOST; | ||
1889 | mask_a |= SSL_aGOST01; | ||
1890 | } | ||
1891 | cpk = &(c->pkeys[SSL_PKEY_GOST94]); | ||
1892 | if (cpk->x509 != NULL && cpk->privatekey !=NULL) { | ||
1893 | mask_k |= SSL_kGOST; | ||
1894 | mask_a |= SSL_aGOST94; | ||
1895 | } | ||
1712 | 1896 | ||
1713 | if (rsa_enc || (rsa_tmp && rsa_sign)) | 1897 | if (rsa_enc || (rsa_tmp && rsa_sign)) |
1714 | mask|=SSL_kRSA; | 1898 | mask_k|=SSL_kRSA; |
1715 | if (rsa_enc_export || (rsa_tmp_export && (rsa_sign || rsa_enc))) | 1899 | if (rsa_enc_export || (rsa_tmp_export && (rsa_sign || rsa_enc))) |
1716 | emask|=SSL_kRSA; | 1900 | emask_k|=SSL_kRSA; |
1717 | 1901 | ||
1718 | #if 0 | 1902 | #if 0 |
1719 | /* The match needs to be both kEDH and aRSA or aDSA, so don't worry */ | 1903 | /* The match needs to be both kEDH and aRSA or aDSA, so don't worry */ |
1720 | if ( (dh_tmp || dh_rsa || dh_dsa) && | 1904 | if ( (dh_tmp || dh_rsa || dh_dsa) && |
1721 | (rsa_enc || rsa_sign || dsa_sign)) | 1905 | (rsa_enc || rsa_sign || dsa_sign)) |
1722 | mask|=SSL_kEDH; | 1906 | mask_k|=SSL_kEDH; |
1723 | if ((dh_tmp_export || dh_rsa_export || dh_dsa_export) && | 1907 | if ((dh_tmp_export || dh_rsa_export || dh_dsa_export) && |
1724 | (rsa_enc || rsa_sign || dsa_sign)) | 1908 | (rsa_enc || rsa_sign || dsa_sign)) |
1725 | emask|=SSL_kEDH; | 1909 | emask_k|=SSL_kEDH; |
1726 | #endif | 1910 | #endif |
1727 | 1911 | ||
1728 | if (dh_tmp_export) | 1912 | if (dh_tmp_export) |
1729 | emask|=SSL_kEDH; | 1913 | emask_k|=SSL_kEDH; |
1730 | 1914 | ||
1731 | if (dh_tmp) | 1915 | if (dh_tmp) |
1732 | mask|=SSL_kEDH; | 1916 | mask_k|=SSL_kEDH; |
1733 | 1917 | ||
1734 | if (dh_rsa) mask|=SSL_kDHr; | 1918 | if (dh_rsa) mask_k|=SSL_kDHr; |
1735 | if (dh_rsa_export) emask|=SSL_kDHr; | 1919 | if (dh_rsa_export) emask_k|=SSL_kDHr; |
1736 | 1920 | ||
1737 | if (dh_dsa) mask|=SSL_kDHd; | 1921 | if (dh_dsa) mask_k|=SSL_kDHd; |
1738 | if (dh_dsa_export) emask|=SSL_kDHd; | 1922 | if (dh_dsa_export) emask_k|=SSL_kDHd; |
1739 | 1923 | ||
1740 | if (rsa_enc || rsa_sign) | 1924 | if (rsa_enc || rsa_sign) |
1741 | { | 1925 | { |
1742 | mask|=SSL_aRSA; | 1926 | mask_a|=SSL_aRSA; |
1743 | emask|=SSL_aRSA; | 1927 | emask_a|=SSL_aRSA; |
1744 | } | 1928 | } |
1745 | 1929 | ||
1746 | if (dsa_sign) | 1930 | if (dsa_sign) |
1747 | { | 1931 | { |
1748 | mask|=SSL_aDSS; | 1932 | mask_a|=SSL_aDSS; |
1749 | emask|=SSL_aDSS; | 1933 | emask_a|=SSL_aDSS; |
1750 | } | 1934 | } |
1751 | 1935 | ||
1752 | mask|=SSL_aNULL; | 1936 | mask_a|=SSL_aNULL; |
1753 | emask|=SSL_aNULL; | 1937 | emask_a|=SSL_aNULL; |
1754 | 1938 | ||
1755 | #ifndef OPENSSL_NO_KRB5 | 1939 | #ifndef OPENSSL_NO_KRB5 |
1756 | mask|=SSL_kKRB5|SSL_aKRB5; | 1940 | mask_k|=SSL_kKRB5; |
1757 | emask|=SSL_kKRB5|SSL_aKRB5; | 1941 | mask_a|=SSL_aKRB5; |
1942 | emask_k|=SSL_kKRB5; | ||
1943 | emask_a|=SSL_aKRB5; | ||
1758 | #endif | 1944 | #endif |
1759 | 1945 | ||
1760 | /* An ECC certificate may be usable for ECDH and/or | 1946 | /* An ECC certificate may be usable for ECDH and/or |
@@ -1762,7 +1948,7 @@ void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher) | |||
1762 | */ | 1948 | */ |
1763 | if (have_ecc_cert) | 1949 | if (have_ecc_cert) |
1764 | { | 1950 | { |
1765 | /* This call populates extension flags (ex_flags) */ | 1951 | /* This call populates extension flags (ex_flags) */ |
1766 | x = (c->pkeys[SSL_PKEY_ECC]).x509; | 1952 | x = (c->pkeys[SSL_PKEY_ECC]).x509; |
1767 | X509_check_purpose(x, -1, 0); | 1953 | X509_check_purpose(x, -1, 0); |
1768 | ecdh_ok = (x->ex_flags & EXFLAG_KUSAGE) ? | 1954 | ecdh_ok = (x->ex_flags & EXFLAG_KUSAGE) ? |
@@ -1770,7 +1956,7 @@ void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher) | |||
1770 | ecdsa_ok = (x->ex_flags & EXFLAG_KUSAGE) ? | 1956 | ecdsa_ok = (x->ex_flags & EXFLAG_KUSAGE) ? |
1771 | (x->ex_kusage & X509v3_KU_DIGITAL_SIGNATURE) : 1; | 1957 | (x->ex_kusage & X509v3_KU_DIGITAL_SIGNATURE) : 1; |
1772 | ecc_pkey = X509_get_pubkey(x); | 1958 | ecc_pkey = X509_get_pubkey(x); |
1773 | ecc_pkey_size = (ecc_pkey != NULL) ? | 1959 | ecc_pkey_size = (ecc_pkey != NULL) ? |
1774 | EVP_PKEY_bits(ecc_pkey) : 0; | 1960 | EVP_PKEY_bits(ecc_pkey) : 0; |
1775 | EVP_PKEY_free(ecc_pkey); | 1961 | EVP_PKEY_free(ecc_pkey); |
1776 | if ((x->sig_alg) && (x->sig_alg->algorithm)) | 1962 | if ((x->sig_alg) && (x->sig_alg->algorithm)) |
@@ -1778,27 +1964,41 @@ void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher) | |||
1778 | #ifndef OPENSSL_NO_ECDH | 1964 | #ifndef OPENSSL_NO_ECDH |
1779 | if (ecdh_ok) | 1965 | if (ecdh_ok) |
1780 | { | 1966 | { |
1781 | if ((signature_nid == NID_md5WithRSAEncryption) || | 1967 | const char *sig = OBJ_nid2ln(signature_nid); |
1782 | (signature_nid == NID_md4WithRSAEncryption) || | 1968 | if (sig == NULL) |
1783 | (signature_nid == NID_md2WithRSAEncryption)) | 1969 | { |
1970 | ERR_clear_error(); | ||
1971 | sig = "unknown"; | ||
1972 | } | ||
1973 | |||
1974 | if (strstr(sig, "WithRSA")) | ||
1784 | { | 1975 | { |
1785 | mask|=SSL_kECDH|SSL_aRSA; | 1976 | mask_k|=SSL_kECDHr; |
1977 | mask_a|=SSL_aECDH; | ||
1786 | if (ecc_pkey_size <= 163) | 1978 | if (ecc_pkey_size <= 163) |
1787 | emask|=SSL_kECDH|SSL_aRSA; | 1979 | { |
1980 | emask_k|=SSL_kECDHr; | ||
1981 | emask_a|=SSL_aECDH; | ||
1982 | } | ||
1788 | } | 1983 | } |
1984 | |||
1789 | if (signature_nid == NID_ecdsa_with_SHA1) | 1985 | if (signature_nid == NID_ecdsa_with_SHA1) |
1790 | { | 1986 | { |
1791 | mask|=SSL_kECDH|SSL_aECDSA; | 1987 | mask_k|=SSL_kECDHe; |
1988 | mask_a|=SSL_aECDH; | ||
1792 | if (ecc_pkey_size <= 163) | 1989 | if (ecc_pkey_size <= 163) |
1793 | emask|=SSL_kECDH|SSL_aECDSA; | 1990 | { |
1991 | emask_k|=SSL_kECDHe; | ||
1992 | emask_a|=SSL_aECDH; | ||
1993 | } | ||
1794 | } | 1994 | } |
1795 | } | 1995 | } |
1796 | #endif | 1996 | #endif |
1797 | #ifndef OPENSSL_NO_ECDSA | 1997 | #ifndef OPENSSL_NO_ECDSA |
1798 | if (ecdsa_ok) | 1998 | if (ecdsa_ok) |
1799 | { | 1999 | { |
1800 | mask|=SSL_aECDSA; | 2000 | mask_a|=SSL_aECDSA; |
1801 | emask|=SSL_aECDSA; | 2001 | emask_a|=SSL_aECDSA; |
1802 | } | 2002 | } |
1803 | #endif | 2003 | #endif |
1804 | } | 2004 | } |
@@ -1806,12 +2006,22 @@ void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher) | |||
1806 | #ifndef OPENSSL_NO_ECDH | 2006 | #ifndef OPENSSL_NO_ECDH |
1807 | if (have_ecdh_tmp) | 2007 | if (have_ecdh_tmp) |
1808 | { | 2008 | { |
1809 | mask|=SSL_kECDHE; | 2009 | mask_k|=SSL_kEECDH; |
1810 | emask|=SSL_kECDHE; | 2010 | emask_k|=SSL_kEECDH; |
1811 | } | 2011 | } |
1812 | #endif | 2012 | #endif |
1813 | c->mask=mask; | 2013 | |
1814 | c->export_mask=emask; | 2014 | #ifndef OPENSSL_NO_PSK |
2015 | mask_k |= SSL_kPSK; | ||
2016 | mask_a |= SSL_aPSK; | ||
2017 | emask_k |= SSL_kPSK; | ||
2018 | emask_a |= SSL_aPSK; | ||
2019 | #endif | ||
2020 | |||
2021 | c->mask_k=mask_k; | ||
2022 | c->mask_a=mask_a; | ||
2023 | c->export_mask_k=emask_k; | ||
2024 | c->export_mask_a=emask_a; | ||
1815 | c->valid=1; | 2025 | c->valid=1; |
1816 | } | 2026 | } |
1817 | 2027 | ||
@@ -1819,13 +2029,18 @@ void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher) | |||
1819 | #define ku_reject(x, usage) \ | 2029 | #define ku_reject(x, usage) \ |
1820 | (((x)->ex_flags & EXFLAG_KUSAGE) && !((x)->ex_kusage & (usage))) | 2030 | (((x)->ex_flags & EXFLAG_KUSAGE) && !((x)->ex_kusage & (usage))) |
1821 | 2031 | ||
1822 | int check_srvr_ecc_cert_and_alg(X509 *x, SSL_CIPHER *cs) | 2032 | #ifndef OPENSSL_NO_EC |
2033 | |||
2034 | int ssl_check_srvr_ecc_cert_and_alg(X509 *x, const SSL_CIPHER *cs) | ||
1823 | { | 2035 | { |
1824 | unsigned long alg = cs->algorithms; | 2036 | unsigned long alg_k, alg_a; |
1825 | EVP_PKEY *pkey = NULL; | 2037 | EVP_PKEY *pkey = NULL; |
1826 | int keysize = 0; | 2038 | int keysize = 0; |
1827 | int signature_nid = 0; | 2039 | int signature_nid = 0; |
1828 | 2040 | ||
2041 | alg_k = cs->algorithm_mkey; | ||
2042 | alg_a = cs->algorithm_auth; | ||
2043 | |||
1829 | if (SSL_C_IS_EXPORT(cs)) | 2044 | if (SSL_C_IS_EXPORT(cs)) |
1830 | { | 2045 | { |
1831 | /* ECDH key length in export ciphers must be <= 163 bits */ | 2046 | /* ECDH key length in export ciphers must be <= 163 bits */ |
@@ -1840,37 +2055,46 @@ int check_srvr_ecc_cert_and_alg(X509 *x, SSL_CIPHER *cs) | |||
1840 | X509_check_purpose(x, -1, 0); | 2055 | X509_check_purpose(x, -1, 0); |
1841 | if ((x->sig_alg) && (x->sig_alg->algorithm)) | 2056 | if ((x->sig_alg) && (x->sig_alg->algorithm)) |
1842 | signature_nid = OBJ_obj2nid(x->sig_alg->algorithm); | 2057 | signature_nid = OBJ_obj2nid(x->sig_alg->algorithm); |
1843 | if (alg & SSL_kECDH) | 2058 | if (alg_k & SSL_kECDHe || alg_k & SSL_kECDHr) |
1844 | { | 2059 | { |
1845 | /* key usage, if present, must allow key agreement */ | 2060 | /* key usage, if present, must allow key agreement */ |
1846 | if (ku_reject(x, X509v3_KU_KEY_AGREEMENT)) | 2061 | if (ku_reject(x, X509v3_KU_KEY_AGREEMENT)) |
1847 | { | 2062 | { |
2063 | SSLerr(SSL_F_SSL_CHECK_SRVR_ECC_CERT_AND_ALG, SSL_R_ECC_CERT_NOT_FOR_KEY_AGREEMENT); | ||
1848 | return 0; | 2064 | return 0; |
1849 | } | 2065 | } |
1850 | if (alg & SSL_aECDSA) | 2066 | if (alg_k & SSL_kECDHe) |
1851 | { | 2067 | { |
1852 | /* signature alg must be ECDSA */ | 2068 | /* signature alg must be ECDSA */ |
1853 | if (signature_nid != NID_ecdsa_with_SHA1) | 2069 | if (signature_nid != NID_ecdsa_with_SHA1) |
1854 | { | 2070 | { |
2071 | SSLerr(SSL_F_SSL_CHECK_SRVR_ECC_CERT_AND_ALG, SSL_R_ECC_CERT_SHOULD_HAVE_SHA1_SIGNATURE); | ||
1855 | return 0; | 2072 | return 0; |
1856 | } | 2073 | } |
1857 | } | 2074 | } |
1858 | if (alg & SSL_aRSA) | 2075 | if (alg_k & SSL_kECDHr) |
1859 | { | 2076 | { |
1860 | /* signature alg must be RSA */ | 2077 | /* signature alg must be RSA */ |
1861 | if ((signature_nid != NID_md5WithRSAEncryption) && | 2078 | |
1862 | (signature_nid != NID_md4WithRSAEncryption) && | 2079 | const char *sig = OBJ_nid2ln(signature_nid); |
1863 | (signature_nid != NID_md2WithRSAEncryption)) | 2080 | if (sig == NULL) |
1864 | { | 2081 | { |
2082 | ERR_clear_error(); | ||
2083 | sig = "unknown"; | ||
2084 | } | ||
2085 | if (strstr(sig, "WithRSA") == NULL) | ||
2086 | { | ||
2087 | SSLerr(SSL_F_SSL_CHECK_SRVR_ECC_CERT_AND_ALG, SSL_R_ECC_CERT_SHOULD_HAVE_RSA_SIGNATURE); | ||
1865 | return 0; | 2088 | return 0; |
1866 | } | 2089 | } |
1867 | } | 2090 | } |
1868 | } | 2091 | } |
1869 | else if (alg & SSL_aECDSA) | 2092 | if (alg_a & SSL_aECDSA) |
1870 | { | 2093 | { |
1871 | /* key usage, if present, must allow signing */ | 2094 | /* key usage, if present, must allow signing */ |
1872 | if (ku_reject(x, X509v3_KU_DIGITAL_SIGNATURE)) | 2095 | if (ku_reject(x, X509v3_KU_DIGITAL_SIGNATURE)) |
1873 | { | 2096 | { |
2097 | SSLerr(SSL_F_SSL_CHECK_SRVR_ECC_CERT_AND_ALG, SSL_R_ECC_CERT_NOT_FOR_SIGNING); | ||
1874 | return 0; | 2098 | return 0; |
1875 | } | 2099 | } |
1876 | } | 2100 | } |
@@ -1878,58 +2102,74 @@ int check_srvr_ecc_cert_and_alg(X509 *x, SSL_CIPHER *cs) | |||
1878 | return 1; /* all checks are ok */ | 2102 | return 1; /* all checks are ok */ |
1879 | } | 2103 | } |
1880 | 2104 | ||
2105 | #endif | ||
2106 | |||
1881 | /* THIS NEEDS CLEANING UP */ | 2107 | /* THIS NEEDS CLEANING UP */ |
1882 | X509 *ssl_get_server_send_cert(SSL *s) | 2108 | X509 *ssl_get_server_send_cert(SSL *s) |
1883 | { | 2109 | { |
1884 | unsigned long alg,mask,kalg; | 2110 | unsigned long alg_k,alg_a,mask_k,mask_a; |
1885 | CERT *c; | 2111 | CERT *c; |
1886 | int i,is_export; | 2112 | int i,is_export; |
1887 | 2113 | ||
1888 | c=s->cert; | 2114 | c=s->cert; |
1889 | ssl_set_cert_masks(c, s->s3->tmp.new_cipher); | 2115 | ssl_set_cert_masks(c, s->s3->tmp.new_cipher); |
1890 | alg=s->s3->tmp.new_cipher->algorithms; | ||
1891 | is_export=SSL_C_IS_EXPORT(s->s3->tmp.new_cipher); | 2116 | is_export=SSL_C_IS_EXPORT(s->s3->tmp.new_cipher); |
1892 | mask=is_export?c->export_mask:c->mask; | 2117 | if (is_export) |
1893 | kalg=alg&(SSL_MKEY_MASK|SSL_AUTH_MASK); | 2118 | { |
2119 | mask_k = c->export_mask_k; | ||
2120 | mask_a = c->export_mask_a; | ||
2121 | } | ||
2122 | else | ||
2123 | { | ||
2124 | mask_k = c->mask_k; | ||
2125 | mask_a = c->mask_a; | ||
2126 | } | ||
2127 | |||
2128 | alg_k = s->s3->tmp.new_cipher->algorithm_mkey; | ||
2129 | alg_a = s->s3->tmp.new_cipher->algorithm_auth; | ||
1894 | 2130 | ||
1895 | if (kalg & SSL_kECDH) | 2131 | if (alg_k & (SSL_kECDHr|SSL_kECDHe)) |
1896 | { | 2132 | { |
1897 | /* we don't need to look at SSL_kECDHE | 2133 | /* we don't need to look at SSL_kEECDH |
1898 | * since no certificate is needed for | 2134 | * since no certificate is needed for |
1899 | * anon ECDH and for authenticated | 2135 | * anon ECDH and for authenticated |
1900 | * ECDHE, the check for the auth | 2136 | * EECDH, the check for the auth |
1901 | * algorithm will set i correctly | 2137 | * algorithm will set i correctly |
1902 | * NOTE: For ECDH-RSA, we need an ECC | 2138 | * NOTE: For ECDH-RSA, we need an ECC |
1903 | * not an RSA cert but for ECDHE-RSA | 2139 | * not an RSA cert but for EECDH-RSA |
1904 | * we need an RSA cert. Placing the | 2140 | * we need an RSA cert. Placing the |
1905 | * checks for SSL_kECDH before RSA | 2141 | * checks for SSL_kECDH before RSA |
1906 | * checks ensures the correct cert is chosen. | 2142 | * checks ensures the correct cert is chosen. |
1907 | */ | 2143 | */ |
1908 | i=SSL_PKEY_ECC; | 2144 | i=SSL_PKEY_ECC; |
1909 | } | 2145 | } |
1910 | else if (kalg & SSL_aECDSA) | 2146 | else if (alg_a & SSL_aECDSA) |
1911 | { | 2147 | { |
1912 | i=SSL_PKEY_ECC; | 2148 | i=SSL_PKEY_ECC; |
1913 | } | 2149 | } |
1914 | else if (kalg & SSL_kDHr) | 2150 | else if (alg_k & SSL_kDHr) |
1915 | i=SSL_PKEY_DH_RSA; | 2151 | i=SSL_PKEY_DH_RSA; |
1916 | else if (kalg & SSL_kDHd) | 2152 | else if (alg_k & SSL_kDHd) |
1917 | i=SSL_PKEY_DH_DSA; | 2153 | i=SSL_PKEY_DH_DSA; |
1918 | else if (kalg & SSL_aDSS) | 2154 | else if (alg_a & SSL_aDSS) |
1919 | i=SSL_PKEY_DSA_SIGN; | 2155 | i=SSL_PKEY_DSA_SIGN; |
1920 | else if (kalg & SSL_aRSA) | 2156 | else if (alg_a & SSL_aRSA) |
1921 | { | 2157 | { |
1922 | if (c->pkeys[SSL_PKEY_RSA_ENC].x509 == NULL) | 2158 | if (c->pkeys[SSL_PKEY_RSA_ENC].x509 == NULL) |
1923 | i=SSL_PKEY_RSA_SIGN; | 2159 | i=SSL_PKEY_RSA_SIGN; |
1924 | else | 2160 | else |
1925 | i=SSL_PKEY_RSA_ENC; | 2161 | i=SSL_PKEY_RSA_ENC; |
1926 | } | 2162 | } |
1927 | else if (kalg & SSL_aKRB5) | 2163 | else if (alg_a & SSL_aKRB5) |
1928 | { | 2164 | { |
1929 | /* VRS something else here? */ | 2165 | /* VRS something else here? */ |
1930 | return(NULL); | 2166 | return(NULL); |
1931 | } | 2167 | } |
1932 | else /* if (kalg & SSL_aNULL) */ | 2168 | else if (alg_a & SSL_aGOST94) |
2169 | i=SSL_PKEY_GOST94; | ||
2170 | else if (alg_a & SSL_aGOST01) | ||
2171 | i=SSL_PKEY_GOST01; | ||
2172 | else /* if (alg_a & SSL_aNULL) */ | ||
1933 | { | 2173 | { |
1934 | SSLerr(SSL_F_SSL_GET_SERVER_SEND_CERT,ERR_R_INTERNAL_ERROR); | 2174 | SSLerr(SSL_F_SSL_GET_SERVER_SEND_CERT,ERR_R_INTERNAL_ERROR); |
1935 | return(NULL); | 2175 | return(NULL); |
@@ -1939,18 +2179,18 @@ X509 *ssl_get_server_send_cert(SSL *s) | |||
1939 | return(c->pkeys[i].x509); | 2179 | return(c->pkeys[i].x509); |
1940 | } | 2180 | } |
1941 | 2181 | ||
1942 | EVP_PKEY *ssl_get_sign_pkey(SSL *s,SSL_CIPHER *cipher) | 2182 | EVP_PKEY *ssl_get_sign_pkey(SSL *s,const SSL_CIPHER *cipher) |
1943 | { | 2183 | { |
1944 | unsigned long alg; | 2184 | unsigned long alg_a; |
1945 | CERT *c; | 2185 | CERT *c; |
1946 | 2186 | ||
1947 | alg=cipher->algorithms; | 2187 | alg_a = cipher->algorithm_auth; |
1948 | c=s->cert; | 2188 | c=s->cert; |
1949 | 2189 | ||
1950 | if ((alg & SSL_aDSS) && | 2190 | if ((alg_a & SSL_aDSS) && |
1951 | (c->pkeys[SSL_PKEY_DSA_SIGN].privatekey != NULL)) | 2191 | (c->pkeys[SSL_PKEY_DSA_SIGN].privatekey != NULL)) |
1952 | return(c->pkeys[SSL_PKEY_DSA_SIGN].privatekey); | 2192 | return(c->pkeys[SSL_PKEY_DSA_SIGN].privatekey); |
1953 | else if (alg & SSL_aRSA) | 2193 | else if (alg_a & SSL_aRSA) |
1954 | { | 2194 | { |
1955 | if (c->pkeys[SSL_PKEY_RSA_SIGN].privatekey != NULL) | 2195 | if (c->pkeys[SSL_PKEY_RSA_SIGN].privatekey != NULL) |
1956 | return(c->pkeys[SSL_PKEY_RSA_SIGN].privatekey); | 2196 | return(c->pkeys[SSL_PKEY_RSA_SIGN].privatekey); |
@@ -1959,10 +2199,10 @@ EVP_PKEY *ssl_get_sign_pkey(SSL *s,SSL_CIPHER *cipher) | |||
1959 | else | 2199 | else |
1960 | return(NULL); | 2200 | return(NULL); |
1961 | } | 2201 | } |
1962 | else if ((alg & SSL_aECDSA) && | 2202 | else if ((alg_a & SSL_aECDSA) && |
1963 | (c->pkeys[SSL_PKEY_ECC].privatekey != NULL)) | 2203 | (c->pkeys[SSL_PKEY_ECC].privatekey != NULL)) |
1964 | return(c->pkeys[SSL_PKEY_ECC].privatekey); | 2204 | return(c->pkeys[SSL_PKEY_ECC].privatekey); |
1965 | else /* if (alg & SSL_aNULL) */ | 2205 | else /* if (alg_a & SSL_aNULL) */ |
1966 | { | 2206 | { |
1967 | SSLerr(SSL_F_SSL_GET_SIGN_PKEY,ERR_R_INTERNAL_ERROR); | 2207 | SSLerr(SSL_F_SSL_GET_SIGN_PKEY,ERR_R_INTERNAL_ERROR); |
1968 | return(NULL); | 2208 | return(NULL); |
@@ -1977,14 +2217,14 @@ void ssl_update_cache(SSL *s,int mode) | |||
1977 | * and it would be rather hard to do anyway :-) */ | 2217 | * and it would be rather hard to do anyway :-) */ |
1978 | if (s->session->session_id_length == 0) return; | 2218 | if (s->session->session_id_length == 0) return; |
1979 | 2219 | ||
1980 | i=s->ctx->session_cache_mode; | 2220 | i=s->session_ctx->session_cache_mode; |
1981 | if ((i & mode) && (!s->hit) | 2221 | if ((i & mode) && (!s->hit) |
1982 | && ((i & SSL_SESS_CACHE_NO_INTERNAL_STORE) | 2222 | && ((i & SSL_SESS_CACHE_NO_INTERNAL_STORE) |
1983 | || SSL_CTX_add_session(s->ctx,s->session)) | 2223 | || SSL_CTX_add_session(s->session_ctx,s->session)) |
1984 | && (s->ctx->new_session_cb != NULL)) | 2224 | && (s->session_ctx->new_session_cb != NULL)) |
1985 | { | 2225 | { |
1986 | CRYPTO_add(&s->session->references,1,CRYPTO_LOCK_SSL_SESSION); | 2226 | CRYPTO_add(&s->session->references,1,CRYPTO_LOCK_SSL_SESSION); |
1987 | if (!s->ctx->new_session_cb(s,s->session)) | 2227 | if (!s->session_ctx->new_session_cb(s,s->session)) |
1988 | SSL_SESSION_free(s->session); | 2228 | SSL_SESSION_free(s->session); |
1989 | } | 2229 | } |
1990 | 2230 | ||
@@ -1993,20 +2233,20 @@ void ssl_update_cache(SSL *s,int mode) | |||
1993 | ((i & mode) == mode)) | 2233 | ((i & mode) == mode)) |
1994 | { | 2234 | { |
1995 | if ( (((mode & SSL_SESS_CACHE_CLIENT) | 2235 | if ( (((mode & SSL_SESS_CACHE_CLIENT) |
1996 | ?s->ctx->stats.sess_connect_good | 2236 | ?s->session_ctx->stats.sess_connect_good |
1997 | :s->ctx->stats.sess_accept_good) & 0xff) == 0xff) | 2237 | :s->session_ctx->stats.sess_accept_good) & 0xff) == 0xff) |
1998 | { | 2238 | { |
1999 | SSL_CTX_flush_sessions(s->ctx,(unsigned long)time(NULL)); | 2239 | SSL_CTX_flush_sessions(s->session_ctx,(unsigned long)time(NULL)); |
2000 | } | 2240 | } |
2001 | } | 2241 | } |
2002 | } | 2242 | } |
2003 | 2243 | ||
2004 | SSL_METHOD *SSL_get_ssl_method(SSL *s) | 2244 | const SSL_METHOD *SSL_get_ssl_method(SSL *s) |
2005 | { | 2245 | { |
2006 | return(s->method); | 2246 | return(s->method); |
2007 | } | 2247 | } |
2008 | 2248 | ||
2009 | int SSL_set_ssl_method(SSL *s,SSL_METHOD *meth) | 2249 | int SSL_set_ssl_method(SSL *s, const SSL_METHOD *meth) |
2010 | { | 2250 | { |
2011 | int conn= -1; | 2251 | int conn= -1; |
2012 | int ret=1; | 2252 | int ret=1; |
@@ -2149,6 +2389,8 @@ void SSL_set_accept_state(SSL *s) | |||
2149 | s->handshake_func=s->method->ssl_accept; | 2389 | s->handshake_func=s->method->ssl_accept; |
2150 | /* clear the current cipher */ | 2390 | /* clear the current cipher */ |
2151 | ssl_clear_cipher_ctx(s); | 2391 | ssl_clear_cipher_ctx(s); |
2392 | ssl_clear_hash_ctx(&s->read_hash); | ||
2393 | ssl_clear_hash_ctx(&s->write_hash); | ||
2152 | } | 2394 | } |
2153 | 2395 | ||
2154 | void SSL_set_connect_state(SSL *s) | 2396 | void SSL_set_connect_state(SSL *s) |
@@ -2159,6 +2401,8 @@ void SSL_set_connect_state(SSL *s) | |||
2159 | s->handshake_func=s->method->ssl_connect; | 2401 | s->handshake_func=s->method->ssl_connect; |
2160 | /* clear the current cipher */ | 2402 | /* clear the current cipher */ |
2161 | ssl_clear_cipher_ctx(s); | 2403 | ssl_clear_cipher_ctx(s); |
2404 | ssl_clear_hash_ctx(&s->read_hash); | ||
2405 | ssl_clear_hash_ctx(&s->write_hash); | ||
2162 | } | 2406 | } |
2163 | 2407 | ||
2164 | int ssl_undefined_function(SSL *s) | 2408 | int ssl_undefined_function(SSL *s) |
@@ -2203,7 +2447,7 @@ SSL *SSL_dup(SSL *s) | |||
2203 | X509_NAME *xn; | 2447 | X509_NAME *xn; |
2204 | SSL *ret; | 2448 | SSL *ret; |
2205 | int i; | 2449 | int i; |
2206 | 2450 | ||
2207 | if ((ret=SSL_new(SSL_get_SSL_CTX(s))) == NULL) | 2451 | if ((ret=SSL_new(SSL_get_SSL_CTX(s))) == NULL) |
2208 | return(NULL); | 2452 | return(NULL); |
2209 | 2453 | ||
@@ -2373,7 +2617,7 @@ EVP_PKEY *SSL_get_privatekey(SSL *s) | |||
2373 | return(NULL); | 2617 | return(NULL); |
2374 | } | 2618 | } |
2375 | 2619 | ||
2376 | SSL_CIPHER *SSL_get_current_cipher(const SSL *s) | 2620 | const SSL_CIPHER *SSL_get_current_cipher(const SSL *s) |
2377 | { | 2621 | { |
2378 | if ((s->session != NULL) && (s->session->cipher != NULL)) | 2622 | if ((s->session != NULL) && (s->session->cipher != NULL)) |
2379 | return(s->session->cipher); | 2623 | return(s->session->cipher); |
@@ -2451,7 +2695,7 @@ void ssl_free_wbio_buffer(SSL *s) | |||
2451 | s->wbio=BIO_pop(s->wbio); | 2695 | s->wbio=BIO_pop(s->wbio); |
2452 | #ifdef REF_CHECK /* not the usual REF_CHECK, but this avoids adding one more preprocessor symbol */ | 2696 | #ifdef REF_CHECK /* not the usual REF_CHECK, but this avoids adding one more preprocessor symbol */ |
2453 | assert(s->wbio != NULL); | 2697 | assert(s->wbio != NULL); |
2454 | #endif | 2698 | #endif |
2455 | } | 2699 | } |
2456 | BIO_free(s->bbio); | 2700 | BIO_free(s->bbio); |
2457 | s->bbio=NULL; | 2701 | s->bbio=NULL; |
@@ -2536,7 +2780,7 @@ void SSL_set_info_callback(SSL *ssl, | |||
2536 | 2780 | ||
2537 | /* One compiler (Diab DCC) doesn't like argument names in returned | 2781 | /* One compiler (Diab DCC) doesn't like argument names in returned |
2538 | function pointer. */ | 2782 | function pointer. */ |
2539 | void (*SSL_get_info_callback(const SSL *ssl))(const SSL * /*ssl*/,int /*type*/,int /*val*/) | 2783 | void (*SSL_get_info_callback(const SSL *ssl))(const SSL * /*ssl*/,int /*type*/,int /*val*/) |
2540 | { | 2784 | { |
2541 | return ssl->info_callback; | 2785 | return ssl->info_callback; |
2542 | } | 2786 | } |
@@ -2657,13 +2901,13 @@ RSA *cb(SSL *ssl,int is_export,int keylength) | |||
2657 | 2901 | ||
2658 | #ifndef OPENSSL_NO_DH | 2902 | #ifndef OPENSSL_NO_DH |
2659 | void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,DH *(*dh)(SSL *ssl,int is_export, | 2903 | void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,DH *(*dh)(SSL *ssl,int is_export, |
2660 | int keylength)) | 2904 | int keylength)) |
2661 | { | 2905 | { |
2662 | SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_DH_CB,(void (*)(void))dh); | 2906 | SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_DH_CB,(void (*)(void))dh); |
2663 | } | 2907 | } |
2664 | 2908 | ||
2665 | void SSL_set_tmp_dh_callback(SSL *ssl,DH *(*dh)(SSL *ssl,int is_export, | 2909 | void SSL_set_tmp_dh_callback(SSL *ssl,DH *(*dh)(SSL *ssl,int is_export, |
2666 | int keylength)) | 2910 | int keylength)) |
2667 | { | 2911 | { |
2668 | SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_DH_CB,(void (*)(void))dh); | 2912 | SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_DH_CB,(void (*)(void))dh); |
2669 | } | 2913 | } |
@@ -2671,18 +2915,109 @@ void SSL_set_tmp_dh_callback(SSL *ssl,DH *(*dh)(SSL *ssl,int is_export, | |||
2671 | 2915 | ||
2672 | #ifndef OPENSSL_NO_ECDH | 2916 | #ifndef OPENSSL_NO_ECDH |
2673 | void SSL_CTX_set_tmp_ecdh_callback(SSL_CTX *ctx,EC_KEY *(*ecdh)(SSL *ssl,int is_export, | 2917 | void SSL_CTX_set_tmp_ecdh_callback(SSL_CTX *ctx,EC_KEY *(*ecdh)(SSL *ssl,int is_export, |
2674 | int keylength)) | 2918 | int keylength)) |
2675 | { | 2919 | { |
2676 | SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_ECDH_CB,(void (*)(void))ecdh); | 2920 | SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_ECDH_CB,(void (*)(void))ecdh); |
2677 | } | 2921 | } |
2678 | 2922 | ||
2679 | void SSL_set_tmp_ecdh_callback(SSL *ssl,EC_KEY *(*ecdh)(SSL *ssl,int is_export, | 2923 | void SSL_set_tmp_ecdh_callback(SSL *ssl,EC_KEY *(*ecdh)(SSL *ssl,int is_export, |
2680 | int keylength)) | 2924 | int keylength)) |
2681 | { | 2925 | { |
2682 | SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_ECDH_CB,(void (*)(void))ecdh); | 2926 | SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_ECDH_CB,(void (*)(void))ecdh); |
2683 | } | 2927 | } |
2684 | #endif | 2928 | #endif |
2685 | 2929 | ||
2930 | #ifndef OPENSSL_NO_PSK | ||
2931 | int SSL_CTX_use_psk_identity_hint(SSL_CTX *ctx, const char *identity_hint) | ||
2932 | { | ||
2933 | if (identity_hint != NULL && strlen(identity_hint) > PSK_MAX_IDENTITY_LEN) | ||
2934 | { | ||
2935 | SSLerr(SSL_F_SSL_CTX_USE_PSK_IDENTITY_HINT, SSL_R_DATA_LENGTH_TOO_LONG); | ||
2936 | return 0; | ||
2937 | } | ||
2938 | if (ctx->psk_identity_hint != NULL) | ||
2939 | OPENSSL_free(ctx->psk_identity_hint); | ||
2940 | if (identity_hint != NULL) | ||
2941 | { | ||
2942 | ctx->psk_identity_hint = BUF_strdup(identity_hint); | ||
2943 | if (ctx->psk_identity_hint == NULL) | ||
2944 | return 0; | ||
2945 | } | ||
2946 | else | ||
2947 | ctx->psk_identity_hint = NULL; | ||
2948 | return 1; | ||
2949 | } | ||
2950 | |||
2951 | int SSL_use_psk_identity_hint(SSL *s, const char *identity_hint) | ||
2952 | { | ||
2953 | if (s == NULL) | ||
2954 | return 0; | ||
2955 | |||
2956 | if (s->session == NULL) | ||
2957 | return 1; /* session not created yet, ignored */ | ||
2958 | |||
2959 | if (identity_hint != NULL && strlen(identity_hint) > PSK_MAX_IDENTITY_LEN) | ||
2960 | { | ||
2961 | SSLerr(SSL_F_SSL_USE_PSK_IDENTITY_HINT, SSL_R_DATA_LENGTH_TOO_LONG); | ||
2962 | return 0; | ||
2963 | } | ||
2964 | if (s->session->psk_identity_hint != NULL) | ||
2965 | OPENSSL_free(s->session->psk_identity_hint); | ||
2966 | if (identity_hint != NULL) | ||
2967 | { | ||
2968 | s->session->psk_identity_hint = BUF_strdup(identity_hint); | ||
2969 | if (s->session->psk_identity_hint == NULL) | ||
2970 | return 0; | ||
2971 | } | ||
2972 | else | ||
2973 | s->session->psk_identity_hint = NULL; | ||
2974 | return 1; | ||
2975 | } | ||
2976 | |||
2977 | const char *SSL_get_psk_identity_hint(const SSL *s) | ||
2978 | { | ||
2979 | if (s == NULL || s->session == NULL) | ||
2980 | return NULL; | ||
2981 | return(s->session->psk_identity_hint); | ||
2982 | } | ||
2983 | |||
2984 | const char *SSL_get_psk_identity(const SSL *s) | ||
2985 | { | ||
2986 | if (s == NULL || s->session == NULL) | ||
2987 | return NULL; | ||
2988 | return(s->session->psk_identity); | ||
2989 | } | ||
2990 | |||
2991 | void SSL_set_psk_client_callback(SSL *s, | ||
2992 | unsigned int (*cb)(SSL *ssl, const char *hint, | ||
2993 | char *identity, unsigned int max_identity_len, unsigned char *psk, | ||
2994 | unsigned int max_psk_len)) | ||
2995 | { | ||
2996 | s->psk_client_callback = cb; | ||
2997 | } | ||
2998 | |||
2999 | void SSL_CTX_set_psk_client_callback(SSL_CTX *ctx, | ||
3000 | unsigned int (*cb)(SSL *ssl, const char *hint, | ||
3001 | char *identity, unsigned int max_identity_len, unsigned char *psk, | ||
3002 | unsigned int max_psk_len)) | ||
3003 | { | ||
3004 | ctx->psk_client_callback = cb; | ||
3005 | } | ||
3006 | |||
3007 | void SSL_set_psk_server_callback(SSL *s, | ||
3008 | unsigned int (*cb)(SSL *ssl, const char *identity, | ||
3009 | unsigned char *psk, unsigned int max_psk_len)) | ||
3010 | { | ||
3011 | s->psk_server_callback = cb; | ||
3012 | } | ||
3013 | |||
3014 | void SSL_CTX_set_psk_server_callback(SSL_CTX *ctx, | ||
3015 | unsigned int (*cb)(SSL *ssl, const char *identity, | ||
3016 | unsigned char *psk, unsigned int max_psk_len)) | ||
3017 | { | ||
3018 | ctx->psk_server_callback = cb; | ||
3019 | } | ||
3020 | #endif | ||
2686 | 3021 | ||
2687 | void SSL_CTX_set_msg_callback(SSL_CTX *ctx, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg)) | 3022 | void SSL_CTX_set_msg_callback(SSL_CTX *ctx, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg)) |
2688 | { | 3023 | { |
@@ -2693,7 +3028,25 @@ void SSL_set_msg_callback(SSL *ssl, void (*cb)(int write_p, int version, int con | |||
2693 | SSL_callback_ctrl(ssl, SSL_CTRL_SET_MSG_CALLBACK, (void (*)(void))cb); | 3028 | SSL_callback_ctrl(ssl, SSL_CTRL_SET_MSG_CALLBACK, (void (*)(void))cb); |
2694 | } | 3029 | } |
2695 | 3030 | ||
3031 | /* Allocates new EVP_MD_CTX and sets pointer to it into given pointer | ||
3032 | * vairable, freeing EVP_MD_CTX previously stored in that variable, if | ||
3033 | * any. If EVP_MD pointer is passed, initializes ctx with this md | ||
3034 | * Returns newly allocated ctx; | ||
3035 | */ | ||
3036 | |||
3037 | EVP_MD_CTX *ssl_replace_hash(EVP_MD_CTX **hash,const EVP_MD *md) | ||
3038 | { | ||
3039 | ssl_clear_hash_ctx(hash); | ||
3040 | *hash = EVP_MD_CTX_create(); | ||
3041 | if (md) EVP_DigestInit_ex(*hash,md,NULL); | ||
3042 | return *hash; | ||
3043 | } | ||
3044 | void ssl_clear_hash_ctx(EVP_MD_CTX **hash) | ||
3045 | { | ||
2696 | 3046 | ||
3047 | if (*hash) EVP_MD_CTX_destroy(*hash); | ||
3048 | *hash=NULL; | ||
3049 | } | ||
2697 | 3050 | ||
2698 | #if defined(_WINDLL) && defined(OPENSSL_SYS_WIN16) | 3051 | #if defined(_WINDLL) && defined(OPENSSL_SYS_WIN16) |
2699 | #include "../crypto/bio/bss_file.c" | 3052 | #include "../crypto/bio/bss_file.c" |
@@ -2701,3 +3054,6 @@ void SSL_set_msg_callback(SSL *ssl, void (*cb)(int write_p, int version, int con | |||
2701 | 3054 | ||
2702 | IMPLEMENT_STACK_OF(SSL_CIPHER) | 3055 | IMPLEMENT_STACK_OF(SSL_CIPHER) |
2703 | IMPLEMENT_STACK_OF(SSL_COMP) | 3056 | IMPLEMENT_STACK_OF(SSL_COMP) |
3057 | IMPLEMENT_OBJ_BSEARCH_GLOBAL_CMP_FN(SSL_CIPHER, SSL_CIPHER, | ||
3058 | ssl_cipher_id); | ||
3059 | |||