diff options
author | djm <> | 2010-10-01 22:54:21 +0000 |
---|---|---|
committer | djm <> | 2010-10-01 22:54:21 +0000 |
commit | 829fd51d4f8dde4a7f3bf54754f3c1d1a502f5e2 (patch) | |
tree | e03b9f1bd051e844b971936729e9df549a209130 /src/lib/libssl/ssl_lib.c | |
parent | e6b755d2a53d3cac7a344dfdd6bf7c951cac754c (diff) | |
download | openbsd-829fd51d4f8dde4a7f3bf54754f3c1d1a502f5e2.tar.gz openbsd-829fd51d4f8dde4a7f3bf54754f3c1d1a502f5e2.tar.bz2 openbsd-829fd51d4f8dde4a7f3bf54754f3c1d1a502f5e2.zip |
import OpenSSL-1.0.0a
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 893abff1f4..3157f20eac 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) |
@@ -1262,13 +1340,13 @@ char *SSL_get_shared_ciphers(const SSL *s,char *buf,int len) | |||
1262 | } | 1340 | } |
1263 | 1341 | ||
1264 | int ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p, | 1342 | int ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p, |
1265 | int (*put_cb)(const SSL_CIPHER *, unsigned char *)) | 1343 | int (*put_cb)(const SSL_CIPHER *, unsigned char *)) |
1266 | { | 1344 | { |
1267 | int i,j=0; | 1345 | int i,j=0; |
1268 | SSL_CIPHER *c; | 1346 | SSL_CIPHER *c; |
1269 | unsigned char *q; | 1347 | unsigned char *q; |
1270 | #ifndef OPENSSL_NO_KRB5 | 1348 | #ifndef OPENSSL_NO_KRB5 |
1271 | int nokrb5 = !kssl_tgt_is_available(s->kssl_ctx); | 1349 | int nokrb5 = !kssl_tgt_is_available(s->kssl_ctx); |
1272 | #endif /* OPENSSL_NO_KRB5 */ | 1350 | #endif /* OPENSSL_NO_KRB5 */ |
1273 | 1351 | ||
1274 | if (sk == NULL) return(0); | 1352 | if (sk == NULL) return(0); |
@@ -1278,22 +1356,46 @@ int ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p, | |||
1278 | { | 1356 | { |
1279 | c=sk_SSL_CIPHER_value(sk,i); | 1357 | c=sk_SSL_CIPHER_value(sk,i); |
1280 | #ifndef OPENSSL_NO_KRB5 | 1358 | #ifndef OPENSSL_NO_KRB5 |
1281 | if ((c->algorithms & SSL_KRB5) && nokrb5) | 1359 | if (((c->algorithm_mkey & SSL_kKRB5) || (c->algorithm_auth & SSL_aKRB5)) && |
1282 | continue; | 1360 | nokrb5) |
1283 | #endif /* OPENSSL_NO_KRB5 */ | 1361 | continue; |
1284 | 1362 | #endif /* OPENSSL_NO_KRB5 */ | |
1363 | #ifndef OPENSSL_NO_PSK | ||
1364 | /* with PSK there must be client callback set */ | ||
1365 | if (((c->algorithm_mkey & SSL_kPSK) || (c->algorithm_auth & SSL_aPSK)) && | ||
1366 | s->psk_client_callback == NULL) | ||
1367 | continue; | ||
1368 | #endif /* OPENSSL_NO_PSK */ | ||
1285 | j = put_cb ? put_cb(c,p) : ssl_put_cipher_by_char(s,c,p); | 1369 | j = put_cb ? put_cb(c,p) : ssl_put_cipher_by_char(s,c,p); |
1286 | p+=j; | 1370 | p+=j; |
1287 | } | 1371 | } |
1372 | /* If p == q, no ciphers and caller indicates an error. Otherwise | ||
1373 | * add SCSV if not renegotiating. | ||
1374 | */ | ||
1375 | if (p != q && !s->new_session) | ||
1376 | { | ||
1377 | static SSL_CIPHER scsv = | ||
1378 | { | ||
1379 | 0, NULL, SSL3_CK_SCSV, 0, 0, 0, 0, 0, 0, 0, 0, 0 | ||
1380 | }; | ||
1381 | j = put_cb ? put_cb(&scsv,p) : ssl_put_cipher_by_char(s,&scsv,p); | ||
1382 | p+=j; | ||
1383 | #ifdef OPENSSL_RI_DEBUG | ||
1384 | fprintf(stderr, "SCSV sent by client\n"); | ||
1385 | #endif | ||
1386 | } | ||
1387 | |||
1288 | return(p-q); | 1388 | return(p-q); |
1289 | } | 1389 | } |
1290 | 1390 | ||
1291 | STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num, | 1391 | STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num, |
1292 | STACK_OF(SSL_CIPHER) **skp) | 1392 | STACK_OF(SSL_CIPHER) **skp) |
1293 | { | 1393 | { |
1294 | SSL_CIPHER *c; | 1394 | const SSL_CIPHER *c; |
1295 | STACK_OF(SSL_CIPHER) *sk; | 1395 | STACK_OF(SSL_CIPHER) *sk; |
1296 | int i,n; | 1396 | int i,n; |
1397 | if (s->s3) | ||
1398 | s->s3->send_connection_binding = 0; | ||
1297 | 1399 | ||
1298 | n=ssl_put_cipher_by_char(s,NULL,NULL); | 1400 | n=ssl_put_cipher_by_char(s,NULL,NULL); |
1299 | if ((num%n) != 0) | 1401 | if ((num%n) != 0) |
@@ -1311,6 +1413,26 @@ STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num, | |||
1311 | 1413 | ||
1312 | for (i=0; i<num; i+=n) | 1414 | for (i=0; i<num; i+=n) |
1313 | { | 1415 | { |
1416 | /* Check for SCSV */ | ||
1417 | if (s->s3 && (n != 3 || !p[0]) && | ||
1418 | (p[n-2] == ((SSL3_CK_SCSV >> 8) & 0xff)) && | ||
1419 | (p[n-1] == (SSL3_CK_SCSV & 0xff))) | ||
1420 | { | ||
1421 | /* SCSV fatal if renegotiating */ | ||
1422 | if (s->new_session) | ||
1423 | { | ||
1424 | SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,SSL_R_SCSV_RECEIVED_WHEN_RENEGOTIATING); | ||
1425 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE); | ||
1426 | goto err; | ||
1427 | } | ||
1428 | s->s3->send_connection_binding = 1; | ||
1429 | p += n; | ||
1430 | #ifdef OPENSSL_RI_DEBUG | ||
1431 | fprintf(stderr, "SCSV received by server\n"); | ||
1432 | #endif | ||
1433 | continue; | ||
1434 | } | ||
1435 | |||
1314 | c=ssl_get_cipher_by_char(s,p); | 1436 | c=ssl_get_cipher_by_char(s,p); |
1315 | p+=n; | 1437 | p+=n; |
1316 | if (c != NULL) | 1438 | if (c != NULL) |
@@ -1332,6 +1454,7 @@ err: | |||
1332 | return(NULL); | 1454 | return(NULL); |
1333 | } | 1455 | } |
1334 | 1456 | ||
1457 | |||
1335 | #ifndef OPENSSL_NO_TLSEXT | 1458 | #ifndef OPENSSL_NO_TLSEXT |
1336 | /** return a servername extension value if provided in Client Hello, or NULL. | 1459 | /** return a servername extension value if provided in Client Hello, or NULL. |
1337 | * So far, only host_name types are defined (RFC 3546). | 1460 | * So far, only host_name types are defined (RFC 3546). |
@@ -1355,7 +1478,7 @@ int SSL_get_servername_type(const SSL *s) | |||
1355 | } | 1478 | } |
1356 | #endif | 1479 | #endif |
1357 | 1480 | ||
1358 | unsigned long SSL_SESSION_hash(const SSL_SESSION *a) | 1481 | static unsigned long ssl_session_hash(const SSL_SESSION *a) |
1359 | { | 1482 | { |
1360 | unsigned long l; | 1483 | unsigned long l; |
1361 | 1484 | ||
@@ -1372,7 +1495,7 @@ unsigned long SSL_SESSION_hash(const SSL_SESSION *a) | |||
1372 | * SSL_CTX_has_matching_session_id() is checked accordingly. It relies on being | 1495 | * SSL_CTX_has_matching_session_id() is checked accordingly. It relies on being |
1373 | * able to construct an SSL_SESSION that will collide with any existing session | 1496 | * able to construct an SSL_SESSION that will collide with any existing session |
1374 | * with a matching session ID. */ | 1497 | * with a matching session ID. */ |
1375 | int SSL_SESSION_cmp(const SSL_SESSION *a,const SSL_SESSION *b) | 1498 | static int ssl_session_cmp(const SSL_SESSION *a,const SSL_SESSION *b) |
1376 | { | 1499 | { |
1377 | if (a->ssl_version != b->ssl_version) | 1500 | if (a->ssl_version != b->ssl_version) |
1378 | return(1); | 1501 | return(1); |
@@ -1385,27 +1508,19 @@ int SSL_SESSION_cmp(const SSL_SESSION *a,const SSL_SESSION *b) | |||
1385 | * SSL_SESSION_hash and SSL_SESSION_cmp for void* types and casting each | 1508 | * SSL_SESSION_hash and SSL_SESSION_cmp for void* types and casting each |
1386 | * variable. The reason is that the functions aren't static, they're exposed via | 1509 | * variable. The reason is that the functions aren't static, they're exposed via |
1387 | * ssl.h. */ | 1510 | * ssl.h. */ |
1388 | static IMPLEMENT_LHASH_HASH_FN(SSL_SESSION_hash, SSL_SESSION *) | 1511 | static IMPLEMENT_LHASH_HASH_FN(ssl_session, SSL_SESSION) |
1389 | static IMPLEMENT_LHASH_COMP_FN(SSL_SESSION_cmp, SSL_SESSION *) | 1512 | static IMPLEMENT_LHASH_COMP_FN(ssl_session, SSL_SESSION) |
1390 | 1513 | ||
1391 | SSL_CTX *SSL_CTX_new(SSL_METHOD *meth) | 1514 | SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth) |
1392 | { | 1515 | { |
1393 | SSL_CTX *ret=NULL; | 1516 | SSL_CTX *ret=NULL; |
1394 | 1517 | ||
1395 | if (meth == NULL) | 1518 | if (meth == NULL) |
1396 | { | 1519 | { |
1397 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_NULL_SSL_METHOD_PASSED); | 1520 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_NULL_SSL_METHOD_PASSED); |
1398 | return(NULL); | 1521 | return(NULL); |
1399 | } | 1522 | } |
1400 | 1523 | ||
1401 | #ifdef OPENSSL_FIPS | ||
1402 | if (FIPS_mode() && (meth->version < TLS1_VERSION)) | ||
1403 | { | ||
1404 | SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE); | ||
1405 | return NULL; | ||
1406 | } | ||
1407 | #endif | ||
1408 | |||
1409 | if (SSL_get_ex_data_X509_STORE_CTX_idx() < 0) | 1524 | if (SSL_get_ex_data_X509_STORE_CTX_idx() < 0) |
1410 | { | 1525 | { |
1411 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_X509_VERIFICATION_SETUP_PROBLEMS); | 1526 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_X509_VERIFICATION_SETUP_PROBLEMS); |
@@ -1468,15 +1583,14 @@ SSL_CTX *SSL_CTX_new(SSL_METHOD *meth) | |||
1468 | ret->app_gen_cookie_cb=0; | 1583 | ret->app_gen_cookie_cb=0; |
1469 | ret->app_verify_cookie_cb=0; | 1584 | ret->app_verify_cookie_cb=0; |
1470 | 1585 | ||
1471 | ret->sessions=lh_new(LHASH_HASH_FN(SSL_SESSION_hash), | 1586 | ret->sessions=lh_SSL_SESSION_new(); |
1472 | LHASH_COMP_FN(SSL_SESSION_cmp)); | ||
1473 | if (ret->sessions == NULL) goto err; | 1587 | if (ret->sessions == NULL) goto err; |
1474 | ret->cert_store=X509_STORE_new(); | 1588 | ret->cert_store=X509_STORE_new(); |
1475 | if (ret->cert_store == NULL) goto err; | 1589 | if (ret->cert_store == NULL) goto err; |
1476 | 1590 | ||
1477 | ssl_create_cipher_list(ret->method, | 1591 | ssl_create_cipher_list(ret->method, |
1478 | &ret->cipher_list,&ret->cipher_list_by_id, | 1592 | &ret->cipher_list,&ret->cipher_list_by_id, |
1479 | SSL_DEFAULT_CIPHER_LIST); | 1593 | meth->version == SSL2_VERSION ? "SSLv2" : SSL_DEFAULT_CIPHER_LIST); |
1480 | if (ret->cipher_list == NULL | 1594 | if (ret->cipher_list == NULL |
1481 | || sk_SSL_CIPHER_num(ret->cipher_list) <= 0) | 1595 | || sk_SSL_CIPHER_num(ret->cipher_list) <= 0) |
1482 | { | 1596 | { |
@@ -1512,6 +1626,8 @@ SSL_CTX *SSL_CTX_new(SSL_METHOD *meth) | |||
1512 | ret->extra_certs=NULL; | 1626 | ret->extra_certs=NULL; |
1513 | ret->comp_methods=SSL_COMP_get_compression_methods(); | 1627 | ret->comp_methods=SSL_COMP_get_compression_methods(); |
1514 | 1628 | ||
1629 | ret->max_send_fragment = SSL3_RT_MAX_PLAIN_LENGTH; | ||
1630 | |||
1515 | #ifndef OPENSSL_NO_TLSEXT | 1631 | #ifndef OPENSSL_NO_TLSEXT |
1516 | ret->tlsext_servername_callback = 0; | 1632 | ret->tlsext_servername_callback = 0; |
1517 | ret->tlsext_servername_arg = NULL; | 1633 | ret->tlsext_servername_arg = NULL; |
@@ -1525,7 +1641,29 @@ SSL_CTX *SSL_CTX_new(SSL_METHOD *meth) | |||
1525 | ret->tlsext_status_arg = NULL; | 1641 | ret->tlsext_status_arg = NULL; |
1526 | 1642 | ||
1527 | #endif | 1643 | #endif |
1528 | 1644 | #ifndef OPENSSL_NO_PSK | |
1645 | ret->psk_identity_hint=NULL; | ||
1646 | ret->psk_client_callback=NULL; | ||
1647 | ret->psk_server_callback=NULL; | ||
1648 | #endif | ||
1649 | #ifndef OPENSSL_NO_BUF_FREELISTS | ||
1650 | ret->freelist_max_len = SSL_MAX_BUF_FREELIST_LEN_DEFAULT; | ||
1651 | ret->rbuf_freelist = OPENSSL_malloc(sizeof(SSL3_BUF_FREELIST)); | ||
1652 | if (!ret->rbuf_freelist) | ||
1653 | goto err; | ||
1654 | ret->rbuf_freelist->chunklen = 0; | ||
1655 | ret->rbuf_freelist->len = 0; | ||
1656 | ret->rbuf_freelist->head = NULL; | ||
1657 | ret->wbuf_freelist = OPENSSL_malloc(sizeof(SSL3_BUF_FREELIST)); | ||
1658 | if (!ret->wbuf_freelist) | ||
1659 | { | ||
1660 | OPENSSL_free(ret->rbuf_freelist); | ||
1661 | goto err; | ||
1662 | } | ||
1663 | ret->wbuf_freelist->chunklen = 0; | ||
1664 | ret->wbuf_freelist->len = 0; | ||
1665 | ret->wbuf_freelist->head = NULL; | ||
1666 | #endif | ||
1529 | #ifndef OPENSSL_NO_ENGINE | 1667 | #ifndef OPENSSL_NO_ENGINE |
1530 | ret->client_cert_engine = NULL; | 1668 | ret->client_cert_engine = NULL; |
1531 | #ifdef OPENSSL_SSL_CLIENT_ENGINE_AUTO | 1669 | #ifdef OPENSSL_SSL_CLIENT_ENGINE_AUTO |
@@ -1546,6 +1684,10 @@ SSL_CTX *SSL_CTX_new(SSL_METHOD *meth) | |||
1546 | } | 1684 | } |
1547 | #endif | 1685 | #endif |
1548 | #endif | 1686 | #endif |
1687 | /* Default is to connect to non-RI servers. When RI is more widely | ||
1688 | * deployed might change this. | ||
1689 | */ | ||
1690 | ret->options |= SSL_OP_LEGACY_SERVER_CONNECT; | ||
1549 | 1691 | ||
1550 | return(ret); | 1692 | return(ret); |
1551 | err: | 1693 | err: |
@@ -1560,6 +1702,20 @@ static void SSL_COMP_free(SSL_COMP *comp) | |||
1560 | { OPENSSL_free(comp); } | 1702 | { OPENSSL_free(comp); } |
1561 | #endif | 1703 | #endif |
1562 | 1704 | ||
1705 | #ifndef OPENSSL_NO_BUF_FREELISTS | ||
1706 | static void | ||
1707 | ssl_buf_freelist_free(SSL3_BUF_FREELIST *list) | ||
1708 | { | ||
1709 | SSL3_BUF_FREELIST_ENTRY *ent, *next; | ||
1710 | for (ent = list->head; ent; ent = next) | ||
1711 | { | ||
1712 | next = ent->next; | ||
1713 | OPENSSL_free(ent); | ||
1714 | } | ||
1715 | OPENSSL_free(list); | ||
1716 | } | ||
1717 | #endif | ||
1718 | |||
1563 | void SSL_CTX_free(SSL_CTX *a) | 1719 | void SSL_CTX_free(SSL_CTX *a) |
1564 | { | 1720 | { |
1565 | int i; | 1721 | int i; |
@@ -1597,7 +1753,7 @@ void SSL_CTX_free(SSL_CTX *a) | |||
1597 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, a, &a->ex_data); | 1753 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, a, &a->ex_data); |
1598 | 1754 | ||
1599 | if (a->sessions != NULL) | 1755 | if (a->sessions != NULL) |
1600 | lh_free(a->sessions); | 1756 | lh_SSL_SESSION_free(a->sessions); |
1601 | 1757 | ||
1602 | if (a->cert_store != NULL) | 1758 | if (a->cert_store != NULL) |
1603 | X509_STORE_free(a->cert_store); | 1759 | X509_STORE_free(a->cert_store); |
@@ -1617,10 +1773,23 @@ void SSL_CTX_free(SSL_CTX *a) | |||
1617 | #else | 1773 | #else |
1618 | a->comp_methods = NULL; | 1774 | a->comp_methods = NULL; |
1619 | #endif | 1775 | #endif |
1776 | |||
1777 | #ifndef OPENSSL_NO_PSK | ||
1778 | if (a->psk_identity_hint) | ||
1779 | OPENSSL_free(a->psk_identity_hint); | ||
1780 | #endif | ||
1620 | #ifndef OPENSSL_NO_ENGINE | 1781 | #ifndef OPENSSL_NO_ENGINE |
1621 | if (a->client_cert_engine) | 1782 | if (a->client_cert_engine) |
1622 | ENGINE_finish(a->client_cert_engine); | 1783 | ENGINE_finish(a->client_cert_engine); |
1623 | #endif | 1784 | #endif |
1785 | |||
1786 | #ifndef OPENSSL_NO_BUF_FREELISTS | ||
1787 | if (a->wbuf_freelist) | ||
1788 | ssl_buf_freelist_free(a->wbuf_freelist); | ||
1789 | if (a->rbuf_freelist) | ||
1790 | ssl_buf_freelist_free(a->rbuf_freelist); | ||
1791 | #endif | ||
1792 | |||
1624 | OPENSSL_free(a); | 1793 | OPENSSL_free(a); |
1625 | } | 1794 | } |
1626 | 1795 | ||
@@ -1651,13 +1820,13 @@ void SSL_CTX_set_verify_depth(SSL_CTX *ctx,int depth) | |||
1651 | X509_VERIFY_PARAM_set_depth(ctx->param, depth); | 1820 | X509_VERIFY_PARAM_set_depth(ctx->param, depth); |
1652 | } | 1821 | } |
1653 | 1822 | ||
1654 | void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher) | 1823 | void ssl_set_cert_masks(CERT *c, const SSL_CIPHER *cipher) |
1655 | { | 1824 | { |
1656 | CERT_PKEY *cpk; | 1825 | CERT_PKEY *cpk; |
1657 | int rsa_enc,rsa_tmp,rsa_sign,dh_tmp,dh_rsa,dh_dsa,dsa_sign; | 1826 | int rsa_enc,rsa_tmp,rsa_sign,dh_tmp,dh_rsa,dh_dsa,dsa_sign; |
1658 | int rsa_enc_export,dh_rsa_export,dh_dsa_export; | 1827 | int rsa_enc_export,dh_rsa_export,dh_dsa_export; |
1659 | int rsa_tmp_export,dh_tmp_export,kl; | 1828 | int rsa_tmp_export,dh_tmp_export,kl; |
1660 | unsigned long mask,emask; | 1829 | unsigned long mask_k,mask_a,emask_k,emask_a; |
1661 | int have_ecc_cert, ecdh_ok, ecdsa_ok, ecc_pkey_size; | 1830 | int have_ecc_cert, ecdh_ok, ecdsa_ok, ecc_pkey_size; |
1662 | #ifndef OPENSSL_NO_ECDH | 1831 | #ifndef OPENSSL_NO_ECDH |
1663 | int have_ecdh_tmp; | 1832 | int have_ecdh_tmp; |
@@ -1704,60 +1873,77 @@ void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher) | |||
1704 | dh_dsa_export=(dh_dsa && EVP_PKEY_size(cpk->privatekey)*8 <= kl); | 1873 | dh_dsa_export=(dh_dsa && EVP_PKEY_size(cpk->privatekey)*8 <= kl); |
1705 | cpk= &(c->pkeys[SSL_PKEY_ECC]); | 1874 | cpk= &(c->pkeys[SSL_PKEY_ECC]); |
1706 | have_ecc_cert= (cpk->x509 != NULL && cpk->privatekey != NULL); | 1875 | have_ecc_cert= (cpk->x509 != NULL && cpk->privatekey != NULL); |
1707 | mask=0; | 1876 | mask_k=0; |
1708 | emask=0; | 1877 | mask_a=0; |
1878 | emask_k=0; | ||
1879 | emask_a=0; | ||
1880 | |||
1881 | |||
1709 | 1882 | ||
1710 | #ifdef CIPHER_DEBUG | 1883 | #ifdef CIPHER_DEBUG |
1711 | printf("rt=%d rte=%d dht=%d re=%d ree=%d rs=%d ds=%d dhr=%d dhd=%d\n", | 1884 | printf("rt=%d rte=%d dht=%d ecdht=%d re=%d ree=%d rs=%d ds=%d dhr=%d dhd=%d\n", |
1712 | rsa_tmp,rsa_tmp_export,dh_tmp, | 1885 | rsa_tmp,rsa_tmp_export,dh_tmp,have_ecdh_tmp, |
1713 | rsa_enc,rsa_enc_export,rsa_sign,dsa_sign,dh_rsa,dh_dsa); | 1886 | rsa_enc,rsa_enc_export,rsa_sign,dsa_sign,dh_rsa,dh_dsa); |
1714 | #endif | 1887 | #endif |
1888 | |||
1889 | cpk = &(c->pkeys[SSL_PKEY_GOST01]); | ||
1890 | if (cpk->x509 != NULL && cpk->privatekey !=NULL) { | ||
1891 | mask_k |= SSL_kGOST; | ||
1892 | mask_a |= SSL_aGOST01; | ||
1893 | } | ||
1894 | cpk = &(c->pkeys[SSL_PKEY_GOST94]); | ||
1895 | if (cpk->x509 != NULL && cpk->privatekey !=NULL) { | ||
1896 | mask_k |= SSL_kGOST; | ||
1897 | mask_a |= SSL_aGOST94; | ||
1898 | } | ||
1715 | 1899 | ||
1716 | if (rsa_enc || (rsa_tmp && rsa_sign)) | 1900 | if (rsa_enc || (rsa_tmp && rsa_sign)) |
1717 | mask|=SSL_kRSA; | 1901 | mask_k|=SSL_kRSA; |
1718 | if (rsa_enc_export || (rsa_tmp_export && (rsa_sign || rsa_enc))) | 1902 | if (rsa_enc_export || (rsa_tmp_export && (rsa_sign || rsa_enc))) |
1719 | emask|=SSL_kRSA; | 1903 | emask_k|=SSL_kRSA; |
1720 | 1904 | ||
1721 | #if 0 | 1905 | #if 0 |
1722 | /* The match needs to be both kEDH and aRSA or aDSA, so don't worry */ | 1906 | /* The match needs to be both kEDH and aRSA or aDSA, so don't worry */ |
1723 | if ( (dh_tmp || dh_rsa || dh_dsa) && | 1907 | if ( (dh_tmp || dh_rsa || dh_dsa) && |
1724 | (rsa_enc || rsa_sign || dsa_sign)) | 1908 | (rsa_enc || rsa_sign || dsa_sign)) |
1725 | mask|=SSL_kEDH; | 1909 | mask_k|=SSL_kEDH; |
1726 | if ((dh_tmp_export || dh_rsa_export || dh_dsa_export) && | 1910 | if ((dh_tmp_export || dh_rsa_export || dh_dsa_export) && |
1727 | (rsa_enc || rsa_sign || dsa_sign)) | 1911 | (rsa_enc || rsa_sign || dsa_sign)) |
1728 | emask|=SSL_kEDH; | 1912 | emask_k|=SSL_kEDH; |
1729 | #endif | 1913 | #endif |
1730 | 1914 | ||
1731 | if (dh_tmp_export) | 1915 | if (dh_tmp_export) |
1732 | emask|=SSL_kEDH; | 1916 | emask_k|=SSL_kEDH; |
1733 | 1917 | ||
1734 | if (dh_tmp) | 1918 | if (dh_tmp) |
1735 | mask|=SSL_kEDH; | 1919 | mask_k|=SSL_kEDH; |
1736 | 1920 | ||
1737 | if (dh_rsa) mask|=SSL_kDHr; | 1921 | if (dh_rsa) mask_k|=SSL_kDHr; |
1738 | if (dh_rsa_export) emask|=SSL_kDHr; | 1922 | if (dh_rsa_export) emask_k|=SSL_kDHr; |
1739 | 1923 | ||
1740 | if (dh_dsa) mask|=SSL_kDHd; | 1924 | if (dh_dsa) mask_k|=SSL_kDHd; |
1741 | if (dh_dsa_export) emask|=SSL_kDHd; | 1925 | if (dh_dsa_export) emask_k|=SSL_kDHd; |
1742 | 1926 | ||
1743 | if (rsa_enc || rsa_sign) | 1927 | if (rsa_enc || rsa_sign) |
1744 | { | 1928 | { |
1745 | mask|=SSL_aRSA; | 1929 | mask_a|=SSL_aRSA; |
1746 | emask|=SSL_aRSA; | 1930 | emask_a|=SSL_aRSA; |
1747 | } | 1931 | } |
1748 | 1932 | ||
1749 | if (dsa_sign) | 1933 | if (dsa_sign) |
1750 | { | 1934 | { |
1751 | mask|=SSL_aDSS; | 1935 | mask_a|=SSL_aDSS; |
1752 | emask|=SSL_aDSS; | 1936 | emask_a|=SSL_aDSS; |
1753 | } | 1937 | } |
1754 | 1938 | ||
1755 | mask|=SSL_aNULL; | 1939 | mask_a|=SSL_aNULL; |
1756 | emask|=SSL_aNULL; | 1940 | emask_a|=SSL_aNULL; |
1757 | 1941 | ||
1758 | #ifndef OPENSSL_NO_KRB5 | 1942 | #ifndef OPENSSL_NO_KRB5 |
1759 | mask|=SSL_kKRB5|SSL_aKRB5; | 1943 | mask_k|=SSL_kKRB5; |
1760 | emask|=SSL_kKRB5|SSL_aKRB5; | 1944 | mask_a|=SSL_aKRB5; |
1945 | emask_k|=SSL_kKRB5; | ||
1946 | emask_a|=SSL_aKRB5; | ||
1761 | #endif | 1947 | #endif |
1762 | 1948 | ||
1763 | /* An ECC certificate may be usable for ECDH and/or | 1949 | /* An ECC certificate may be usable for ECDH and/or |
@@ -1765,7 +1951,7 @@ void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher) | |||
1765 | */ | 1951 | */ |
1766 | if (have_ecc_cert) | 1952 | if (have_ecc_cert) |
1767 | { | 1953 | { |
1768 | /* This call populates extension flags (ex_flags) */ | 1954 | /* This call populates extension flags (ex_flags) */ |
1769 | x = (c->pkeys[SSL_PKEY_ECC]).x509; | 1955 | x = (c->pkeys[SSL_PKEY_ECC]).x509; |
1770 | X509_check_purpose(x, -1, 0); | 1956 | X509_check_purpose(x, -1, 0); |
1771 | ecdh_ok = (x->ex_flags & EXFLAG_KUSAGE) ? | 1957 | ecdh_ok = (x->ex_flags & EXFLAG_KUSAGE) ? |
@@ -1773,7 +1959,7 @@ void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher) | |||
1773 | ecdsa_ok = (x->ex_flags & EXFLAG_KUSAGE) ? | 1959 | ecdsa_ok = (x->ex_flags & EXFLAG_KUSAGE) ? |
1774 | (x->ex_kusage & X509v3_KU_DIGITAL_SIGNATURE) : 1; | 1960 | (x->ex_kusage & X509v3_KU_DIGITAL_SIGNATURE) : 1; |
1775 | ecc_pkey = X509_get_pubkey(x); | 1961 | ecc_pkey = X509_get_pubkey(x); |
1776 | ecc_pkey_size = (ecc_pkey != NULL) ? | 1962 | ecc_pkey_size = (ecc_pkey != NULL) ? |
1777 | EVP_PKEY_bits(ecc_pkey) : 0; | 1963 | EVP_PKEY_bits(ecc_pkey) : 0; |
1778 | EVP_PKEY_free(ecc_pkey); | 1964 | EVP_PKEY_free(ecc_pkey); |
1779 | if ((x->sig_alg) && (x->sig_alg->algorithm)) | 1965 | if ((x->sig_alg) && (x->sig_alg->algorithm)) |
@@ -1781,27 +1967,41 @@ void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher) | |||
1781 | #ifndef OPENSSL_NO_ECDH | 1967 | #ifndef OPENSSL_NO_ECDH |
1782 | if (ecdh_ok) | 1968 | if (ecdh_ok) |
1783 | { | 1969 | { |
1784 | if ((signature_nid == NID_md5WithRSAEncryption) || | 1970 | const char *sig = OBJ_nid2ln(signature_nid); |
1785 | (signature_nid == NID_md4WithRSAEncryption) || | 1971 | if (sig == NULL) |
1786 | (signature_nid == NID_md2WithRSAEncryption)) | 1972 | { |
1973 | ERR_clear_error(); | ||
1974 | sig = "unknown"; | ||
1975 | } | ||
1976 | |||
1977 | if (strstr(sig, "WithRSA")) | ||
1787 | { | 1978 | { |
1788 | mask|=SSL_kECDH|SSL_aRSA; | 1979 | mask_k|=SSL_kECDHr; |
1980 | mask_a|=SSL_aECDH; | ||
1789 | if (ecc_pkey_size <= 163) | 1981 | if (ecc_pkey_size <= 163) |
1790 | emask|=SSL_kECDH|SSL_aRSA; | 1982 | { |
1983 | emask_k|=SSL_kECDHr; | ||
1984 | emask_a|=SSL_aECDH; | ||
1985 | } | ||
1791 | } | 1986 | } |
1987 | |||
1792 | if (signature_nid == NID_ecdsa_with_SHA1) | 1988 | if (signature_nid == NID_ecdsa_with_SHA1) |
1793 | { | 1989 | { |
1794 | mask|=SSL_kECDH|SSL_aECDSA; | 1990 | mask_k|=SSL_kECDHe; |
1991 | mask_a|=SSL_aECDH; | ||
1795 | if (ecc_pkey_size <= 163) | 1992 | if (ecc_pkey_size <= 163) |
1796 | emask|=SSL_kECDH|SSL_aECDSA; | 1993 | { |
1994 | emask_k|=SSL_kECDHe; | ||
1995 | emask_a|=SSL_aECDH; | ||
1996 | } | ||
1797 | } | 1997 | } |
1798 | } | 1998 | } |
1799 | #endif | 1999 | #endif |
1800 | #ifndef OPENSSL_NO_ECDSA | 2000 | #ifndef OPENSSL_NO_ECDSA |
1801 | if (ecdsa_ok) | 2001 | if (ecdsa_ok) |
1802 | { | 2002 | { |
1803 | mask|=SSL_aECDSA; | 2003 | mask_a|=SSL_aECDSA; |
1804 | emask|=SSL_aECDSA; | 2004 | emask_a|=SSL_aECDSA; |
1805 | } | 2005 | } |
1806 | #endif | 2006 | #endif |
1807 | } | 2007 | } |
@@ -1809,12 +2009,22 @@ void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher) | |||
1809 | #ifndef OPENSSL_NO_ECDH | 2009 | #ifndef OPENSSL_NO_ECDH |
1810 | if (have_ecdh_tmp) | 2010 | if (have_ecdh_tmp) |
1811 | { | 2011 | { |
1812 | mask|=SSL_kECDHE; | 2012 | mask_k|=SSL_kEECDH; |
1813 | emask|=SSL_kECDHE; | 2013 | emask_k|=SSL_kEECDH; |
1814 | } | 2014 | } |
1815 | #endif | 2015 | #endif |
1816 | c->mask=mask; | 2016 | |
1817 | c->export_mask=emask; | 2017 | #ifndef OPENSSL_NO_PSK |
2018 | mask_k |= SSL_kPSK; | ||
2019 | mask_a |= SSL_aPSK; | ||
2020 | emask_k |= SSL_kPSK; | ||
2021 | emask_a |= SSL_aPSK; | ||
2022 | #endif | ||
2023 | |||
2024 | c->mask_k=mask_k; | ||
2025 | c->mask_a=mask_a; | ||
2026 | c->export_mask_k=emask_k; | ||
2027 | c->export_mask_a=emask_a; | ||
1818 | c->valid=1; | 2028 | c->valid=1; |
1819 | } | 2029 | } |
1820 | 2030 | ||
@@ -1822,13 +2032,18 @@ void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher) | |||
1822 | #define ku_reject(x, usage) \ | 2032 | #define ku_reject(x, usage) \ |
1823 | (((x)->ex_flags & EXFLAG_KUSAGE) && !((x)->ex_kusage & (usage))) | 2033 | (((x)->ex_flags & EXFLAG_KUSAGE) && !((x)->ex_kusage & (usage))) |
1824 | 2034 | ||
1825 | int check_srvr_ecc_cert_and_alg(X509 *x, SSL_CIPHER *cs) | 2035 | #ifndef OPENSSL_NO_EC |
2036 | |||
2037 | int ssl_check_srvr_ecc_cert_and_alg(X509 *x, const SSL_CIPHER *cs) | ||
1826 | { | 2038 | { |
1827 | unsigned long alg = cs->algorithms; | 2039 | unsigned long alg_k, alg_a; |
1828 | EVP_PKEY *pkey = NULL; | 2040 | EVP_PKEY *pkey = NULL; |
1829 | int keysize = 0; | 2041 | int keysize = 0; |
1830 | int signature_nid = 0; | 2042 | int signature_nid = 0; |
1831 | 2043 | ||
2044 | alg_k = cs->algorithm_mkey; | ||
2045 | alg_a = cs->algorithm_auth; | ||
2046 | |||
1832 | if (SSL_C_IS_EXPORT(cs)) | 2047 | if (SSL_C_IS_EXPORT(cs)) |
1833 | { | 2048 | { |
1834 | /* ECDH key length in export ciphers must be <= 163 bits */ | 2049 | /* ECDH key length in export ciphers must be <= 163 bits */ |
@@ -1843,37 +2058,46 @@ int check_srvr_ecc_cert_and_alg(X509 *x, SSL_CIPHER *cs) | |||
1843 | X509_check_purpose(x, -1, 0); | 2058 | X509_check_purpose(x, -1, 0); |
1844 | if ((x->sig_alg) && (x->sig_alg->algorithm)) | 2059 | if ((x->sig_alg) && (x->sig_alg->algorithm)) |
1845 | signature_nid = OBJ_obj2nid(x->sig_alg->algorithm); | 2060 | signature_nid = OBJ_obj2nid(x->sig_alg->algorithm); |
1846 | if (alg & SSL_kECDH) | 2061 | if (alg_k & SSL_kECDHe || alg_k & SSL_kECDHr) |
1847 | { | 2062 | { |
1848 | /* key usage, if present, must allow key agreement */ | 2063 | /* key usage, if present, must allow key agreement */ |
1849 | if (ku_reject(x, X509v3_KU_KEY_AGREEMENT)) | 2064 | if (ku_reject(x, X509v3_KU_KEY_AGREEMENT)) |
1850 | { | 2065 | { |
2066 | SSLerr(SSL_F_SSL_CHECK_SRVR_ECC_CERT_AND_ALG, SSL_R_ECC_CERT_NOT_FOR_KEY_AGREEMENT); | ||
1851 | return 0; | 2067 | return 0; |
1852 | } | 2068 | } |
1853 | if (alg & SSL_aECDSA) | 2069 | if (alg_k & SSL_kECDHe) |
1854 | { | 2070 | { |
1855 | /* signature alg must be ECDSA */ | 2071 | /* signature alg must be ECDSA */ |
1856 | if (signature_nid != NID_ecdsa_with_SHA1) | 2072 | if (signature_nid != NID_ecdsa_with_SHA1) |
1857 | { | 2073 | { |
2074 | SSLerr(SSL_F_SSL_CHECK_SRVR_ECC_CERT_AND_ALG, SSL_R_ECC_CERT_SHOULD_HAVE_SHA1_SIGNATURE); | ||
1858 | return 0; | 2075 | return 0; |
1859 | } | 2076 | } |
1860 | } | 2077 | } |
1861 | if (alg & SSL_aRSA) | 2078 | if (alg_k & SSL_kECDHr) |
1862 | { | 2079 | { |
1863 | /* signature alg must be RSA */ | 2080 | /* signature alg must be RSA */ |
1864 | if ((signature_nid != NID_md5WithRSAEncryption) && | 2081 | |
1865 | (signature_nid != NID_md4WithRSAEncryption) && | 2082 | const char *sig = OBJ_nid2ln(signature_nid); |
1866 | (signature_nid != NID_md2WithRSAEncryption)) | 2083 | if (sig == NULL) |
1867 | { | 2084 | { |
2085 | ERR_clear_error(); | ||
2086 | sig = "unknown"; | ||
2087 | } | ||
2088 | if (strstr(sig, "WithRSA") == NULL) | ||
2089 | { | ||
2090 | SSLerr(SSL_F_SSL_CHECK_SRVR_ECC_CERT_AND_ALG, SSL_R_ECC_CERT_SHOULD_HAVE_RSA_SIGNATURE); | ||
1868 | return 0; | 2091 | return 0; |
1869 | } | 2092 | } |
1870 | } | 2093 | } |
1871 | } | 2094 | } |
1872 | else if (alg & SSL_aECDSA) | 2095 | if (alg_a & SSL_aECDSA) |
1873 | { | 2096 | { |
1874 | /* key usage, if present, must allow signing */ | 2097 | /* key usage, if present, must allow signing */ |
1875 | if (ku_reject(x, X509v3_KU_DIGITAL_SIGNATURE)) | 2098 | if (ku_reject(x, X509v3_KU_DIGITAL_SIGNATURE)) |
1876 | { | 2099 | { |
2100 | SSLerr(SSL_F_SSL_CHECK_SRVR_ECC_CERT_AND_ALG, SSL_R_ECC_CERT_NOT_FOR_SIGNING); | ||
1877 | return 0; | 2101 | return 0; |
1878 | } | 2102 | } |
1879 | } | 2103 | } |
@@ -1881,58 +2105,74 @@ int check_srvr_ecc_cert_and_alg(X509 *x, SSL_CIPHER *cs) | |||
1881 | return 1; /* all checks are ok */ | 2105 | return 1; /* all checks are ok */ |
1882 | } | 2106 | } |
1883 | 2107 | ||
2108 | #endif | ||
2109 | |||
1884 | /* THIS NEEDS CLEANING UP */ | 2110 | /* THIS NEEDS CLEANING UP */ |
1885 | X509 *ssl_get_server_send_cert(SSL *s) | 2111 | X509 *ssl_get_server_send_cert(SSL *s) |
1886 | { | 2112 | { |
1887 | unsigned long alg,mask,kalg; | 2113 | unsigned long alg_k,alg_a,mask_k,mask_a; |
1888 | CERT *c; | 2114 | CERT *c; |
1889 | int i,is_export; | 2115 | int i,is_export; |
1890 | 2116 | ||
1891 | c=s->cert; | 2117 | c=s->cert; |
1892 | ssl_set_cert_masks(c, s->s3->tmp.new_cipher); | 2118 | ssl_set_cert_masks(c, s->s3->tmp.new_cipher); |
1893 | alg=s->s3->tmp.new_cipher->algorithms; | ||
1894 | is_export=SSL_C_IS_EXPORT(s->s3->tmp.new_cipher); | 2119 | is_export=SSL_C_IS_EXPORT(s->s3->tmp.new_cipher); |
1895 | mask=is_export?c->export_mask:c->mask; | 2120 | if (is_export) |
1896 | kalg=alg&(SSL_MKEY_MASK|SSL_AUTH_MASK); | 2121 | { |
2122 | mask_k = c->export_mask_k; | ||
2123 | mask_a = c->export_mask_a; | ||
2124 | } | ||
2125 | else | ||
2126 | { | ||
2127 | mask_k = c->mask_k; | ||
2128 | mask_a = c->mask_a; | ||
2129 | } | ||
2130 | |||
2131 | alg_k = s->s3->tmp.new_cipher->algorithm_mkey; | ||
2132 | alg_a = s->s3->tmp.new_cipher->algorithm_auth; | ||
1897 | 2133 | ||
1898 | if (kalg & SSL_kECDH) | 2134 | if (alg_k & (SSL_kECDHr|SSL_kECDHe)) |
1899 | { | 2135 | { |
1900 | /* we don't need to look at SSL_kECDHE | 2136 | /* we don't need to look at SSL_kEECDH |
1901 | * since no certificate is needed for | 2137 | * since no certificate is needed for |
1902 | * anon ECDH and for authenticated | 2138 | * anon ECDH and for authenticated |
1903 | * ECDHE, the check for the auth | 2139 | * EECDH, the check for the auth |
1904 | * algorithm will set i correctly | 2140 | * algorithm will set i correctly |
1905 | * NOTE: For ECDH-RSA, we need an ECC | 2141 | * NOTE: For ECDH-RSA, we need an ECC |
1906 | * not an RSA cert but for ECDHE-RSA | 2142 | * not an RSA cert but for EECDH-RSA |
1907 | * we need an RSA cert. Placing the | 2143 | * we need an RSA cert. Placing the |
1908 | * checks for SSL_kECDH before RSA | 2144 | * checks for SSL_kECDH before RSA |
1909 | * checks ensures the correct cert is chosen. | 2145 | * checks ensures the correct cert is chosen. |
1910 | */ | 2146 | */ |
1911 | i=SSL_PKEY_ECC; | 2147 | i=SSL_PKEY_ECC; |
1912 | } | 2148 | } |
1913 | else if (kalg & SSL_aECDSA) | 2149 | else if (alg_a & SSL_aECDSA) |
1914 | { | 2150 | { |
1915 | i=SSL_PKEY_ECC; | 2151 | i=SSL_PKEY_ECC; |
1916 | } | 2152 | } |
1917 | else if (kalg & SSL_kDHr) | 2153 | else if (alg_k & SSL_kDHr) |
1918 | i=SSL_PKEY_DH_RSA; | 2154 | i=SSL_PKEY_DH_RSA; |
1919 | else if (kalg & SSL_kDHd) | 2155 | else if (alg_k & SSL_kDHd) |
1920 | i=SSL_PKEY_DH_DSA; | 2156 | i=SSL_PKEY_DH_DSA; |
1921 | else if (kalg & SSL_aDSS) | 2157 | else if (alg_a & SSL_aDSS) |
1922 | i=SSL_PKEY_DSA_SIGN; | 2158 | i=SSL_PKEY_DSA_SIGN; |
1923 | else if (kalg & SSL_aRSA) | 2159 | else if (alg_a & SSL_aRSA) |
1924 | { | 2160 | { |
1925 | if (c->pkeys[SSL_PKEY_RSA_ENC].x509 == NULL) | 2161 | if (c->pkeys[SSL_PKEY_RSA_ENC].x509 == NULL) |
1926 | i=SSL_PKEY_RSA_SIGN; | 2162 | i=SSL_PKEY_RSA_SIGN; |
1927 | else | 2163 | else |
1928 | i=SSL_PKEY_RSA_ENC; | 2164 | i=SSL_PKEY_RSA_ENC; |
1929 | } | 2165 | } |
1930 | else if (kalg & SSL_aKRB5) | 2166 | else if (alg_a & SSL_aKRB5) |
1931 | { | 2167 | { |
1932 | /* VRS something else here? */ | 2168 | /* VRS something else here? */ |
1933 | return(NULL); | 2169 | return(NULL); |
1934 | } | 2170 | } |
1935 | else /* if (kalg & SSL_aNULL) */ | 2171 | else if (alg_a & SSL_aGOST94) |
2172 | i=SSL_PKEY_GOST94; | ||
2173 | else if (alg_a & SSL_aGOST01) | ||
2174 | i=SSL_PKEY_GOST01; | ||
2175 | else /* if (alg_a & SSL_aNULL) */ | ||
1936 | { | 2176 | { |
1937 | SSLerr(SSL_F_SSL_GET_SERVER_SEND_CERT,ERR_R_INTERNAL_ERROR); | 2177 | SSLerr(SSL_F_SSL_GET_SERVER_SEND_CERT,ERR_R_INTERNAL_ERROR); |
1938 | return(NULL); | 2178 | return(NULL); |
@@ -1942,18 +2182,18 @@ X509 *ssl_get_server_send_cert(SSL *s) | |||
1942 | return(c->pkeys[i].x509); | 2182 | return(c->pkeys[i].x509); |
1943 | } | 2183 | } |
1944 | 2184 | ||
1945 | EVP_PKEY *ssl_get_sign_pkey(SSL *s,SSL_CIPHER *cipher) | 2185 | EVP_PKEY *ssl_get_sign_pkey(SSL *s,const SSL_CIPHER *cipher) |
1946 | { | 2186 | { |
1947 | unsigned long alg; | 2187 | unsigned long alg_a; |
1948 | CERT *c; | 2188 | CERT *c; |
1949 | 2189 | ||
1950 | alg=cipher->algorithms; | 2190 | alg_a = cipher->algorithm_auth; |
1951 | c=s->cert; | 2191 | c=s->cert; |
1952 | 2192 | ||
1953 | if ((alg & SSL_aDSS) && | 2193 | if ((alg_a & SSL_aDSS) && |
1954 | (c->pkeys[SSL_PKEY_DSA_SIGN].privatekey != NULL)) | 2194 | (c->pkeys[SSL_PKEY_DSA_SIGN].privatekey != NULL)) |
1955 | return(c->pkeys[SSL_PKEY_DSA_SIGN].privatekey); | 2195 | return(c->pkeys[SSL_PKEY_DSA_SIGN].privatekey); |
1956 | else if (alg & SSL_aRSA) | 2196 | else if (alg_a & SSL_aRSA) |
1957 | { | 2197 | { |
1958 | if (c->pkeys[SSL_PKEY_RSA_SIGN].privatekey != NULL) | 2198 | if (c->pkeys[SSL_PKEY_RSA_SIGN].privatekey != NULL) |
1959 | return(c->pkeys[SSL_PKEY_RSA_SIGN].privatekey); | 2199 | return(c->pkeys[SSL_PKEY_RSA_SIGN].privatekey); |
@@ -1962,10 +2202,10 @@ EVP_PKEY *ssl_get_sign_pkey(SSL *s,SSL_CIPHER *cipher) | |||
1962 | else | 2202 | else |
1963 | return(NULL); | 2203 | return(NULL); |
1964 | } | 2204 | } |
1965 | else if ((alg & SSL_aECDSA) && | 2205 | else if ((alg_a & SSL_aECDSA) && |
1966 | (c->pkeys[SSL_PKEY_ECC].privatekey != NULL)) | 2206 | (c->pkeys[SSL_PKEY_ECC].privatekey != NULL)) |
1967 | return(c->pkeys[SSL_PKEY_ECC].privatekey); | 2207 | return(c->pkeys[SSL_PKEY_ECC].privatekey); |
1968 | else /* if (alg & SSL_aNULL) */ | 2208 | else /* if (alg_a & SSL_aNULL) */ |
1969 | { | 2209 | { |
1970 | SSLerr(SSL_F_SSL_GET_SIGN_PKEY,ERR_R_INTERNAL_ERROR); | 2210 | SSLerr(SSL_F_SSL_GET_SIGN_PKEY,ERR_R_INTERNAL_ERROR); |
1971 | return(NULL); | 2211 | return(NULL); |
@@ -1980,14 +2220,14 @@ void ssl_update_cache(SSL *s,int mode) | |||
1980 | * and it would be rather hard to do anyway :-) */ | 2220 | * and it would be rather hard to do anyway :-) */ |
1981 | if (s->session->session_id_length == 0) return; | 2221 | if (s->session->session_id_length == 0) return; |
1982 | 2222 | ||
1983 | i=s->ctx->session_cache_mode; | 2223 | i=s->session_ctx->session_cache_mode; |
1984 | if ((i & mode) && (!s->hit) | 2224 | if ((i & mode) && (!s->hit) |
1985 | && ((i & SSL_SESS_CACHE_NO_INTERNAL_STORE) | 2225 | && ((i & SSL_SESS_CACHE_NO_INTERNAL_STORE) |
1986 | || SSL_CTX_add_session(s->ctx,s->session)) | 2226 | || SSL_CTX_add_session(s->session_ctx,s->session)) |
1987 | && (s->ctx->new_session_cb != NULL)) | 2227 | && (s->session_ctx->new_session_cb != NULL)) |
1988 | { | 2228 | { |
1989 | CRYPTO_add(&s->session->references,1,CRYPTO_LOCK_SSL_SESSION); | 2229 | CRYPTO_add(&s->session->references,1,CRYPTO_LOCK_SSL_SESSION); |
1990 | if (!s->ctx->new_session_cb(s,s->session)) | 2230 | if (!s->session_ctx->new_session_cb(s,s->session)) |
1991 | SSL_SESSION_free(s->session); | 2231 | SSL_SESSION_free(s->session); |
1992 | } | 2232 | } |
1993 | 2233 | ||
@@ -1996,20 +2236,20 @@ void ssl_update_cache(SSL *s,int mode) | |||
1996 | ((i & mode) == mode)) | 2236 | ((i & mode) == mode)) |
1997 | { | 2237 | { |
1998 | if ( (((mode & SSL_SESS_CACHE_CLIENT) | 2238 | if ( (((mode & SSL_SESS_CACHE_CLIENT) |
1999 | ?s->ctx->stats.sess_connect_good | 2239 | ?s->session_ctx->stats.sess_connect_good |
2000 | :s->ctx->stats.sess_accept_good) & 0xff) == 0xff) | 2240 | :s->session_ctx->stats.sess_accept_good) & 0xff) == 0xff) |
2001 | { | 2241 | { |
2002 | SSL_CTX_flush_sessions(s->ctx,(unsigned long)time(NULL)); | 2242 | SSL_CTX_flush_sessions(s->session_ctx,(unsigned long)time(NULL)); |
2003 | } | 2243 | } |
2004 | } | 2244 | } |
2005 | } | 2245 | } |
2006 | 2246 | ||
2007 | SSL_METHOD *SSL_get_ssl_method(SSL *s) | 2247 | const SSL_METHOD *SSL_get_ssl_method(SSL *s) |
2008 | { | 2248 | { |
2009 | return(s->method); | 2249 | return(s->method); |
2010 | } | 2250 | } |
2011 | 2251 | ||
2012 | int SSL_set_ssl_method(SSL *s,SSL_METHOD *meth) | 2252 | int SSL_set_ssl_method(SSL *s, const SSL_METHOD *meth) |
2013 | { | 2253 | { |
2014 | int conn= -1; | 2254 | int conn= -1; |
2015 | int ret=1; | 2255 | int ret=1; |
@@ -2152,6 +2392,8 @@ void SSL_set_accept_state(SSL *s) | |||
2152 | s->handshake_func=s->method->ssl_accept; | 2392 | s->handshake_func=s->method->ssl_accept; |
2153 | /* clear the current cipher */ | 2393 | /* clear the current cipher */ |
2154 | ssl_clear_cipher_ctx(s); | 2394 | ssl_clear_cipher_ctx(s); |
2395 | ssl_clear_hash_ctx(&s->read_hash); | ||
2396 | ssl_clear_hash_ctx(&s->write_hash); | ||
2155 | } | 2397 | } |
2156 | 2398 | ||
2157 | void SSL_set_connect_state(SSL *s) | 2399 | void SSL_set_connect_state(SSL *s) |
@@ -2162,6 +2404,8 @@ void SSL_set_connect_state(SSL *s) | |||
2162 | s->handshake_func=s->method->ssl_connect; | 2404 | s->handshake_func=s->method->ssl_connect; |
2163 | /* clear the current cipher */ | 2405 | /* clear the current cipher */ |
2164 | ssl_clear_cipher_ctx(s); | 2406 | ssl_clear_cipher_ctx(s); |
2407 | ssl_clear_hash_ctx(&s->read_hash); | ||
2408 | ssl_clear_hash_ctx(&s->write_hash); | ||
2165 | } | 2409 | } |
2166 | 2410 | ||
2167 | int ssl_undefined_function(SSL *s) | 2411 | int ssl_undefined_function(SSL *s) |
@@ -2206,7 +2450,7 @@ SSL *SSL_dup(SSL *s) | |||
2206 | X509_NAME *xn; | 2450 | X509_NAME *xn; |
2207 | SSL *ret; | 2451 | SSL *ret; |
2208 | int i; | 2452 | int i; |
2209 | 2453 | ||
2210 | if ((ret=SSL_new(SSL_get_SSL_CTX(s))) == NULL) | 2454 | if ((ret=SSL_new(SSL_get_SSL_CTX(s))) == NULL) |
2211 | return(NULL); | 2455 | return(NULL); |
2212 | 2456 | ||
@@ -2376,7 +2620,7 @@ EVP_PKEY *SSL_get_privatekey(SSL *s) | |||
2376 | return(NULL); | 2620 | return(NULL); |
2377 | } | 2621 | } |
2378 | 2622 | ||
2379 | SSL_CIPHER *SSL_get_current_cipher(const SSL *s) | 2623 | const SSL_CIPHER *SSL_get_current_cipher(const SSL *s) |
2380 | { | 2624 | { |
2381 | if ((s->session != NULL) && (s->session->cipher != NULL)) | 2625 | if ((s->session != NULL) && (s->session->cipher != NULL)) |
2382 | return(s->session->cipher); | 2626 | return(s->session->cipher); |
@@ -2454,7 +2698,7 @@ void ssl_free_wbio_buffer(SSL *s) | |||
2454 | s->wbio=BIO_pop(s->wbio); | 2698 | s->wbio=BIO_pop(s->wbio); |
2455 | #ifdef REF_CHECK /* not the usual REF_CHECK, but this avoids adding one more preprocessor symbol */ | 2699 | #ifdef REF_CHECK /* not the usual REF_CHECK, but this avoids adding one more preprocessor symbol */ |
2456 | assert(s->wbio != NULL); | 2700 | assert(s->wbio != NULL); |
2457 | #endif | 2701 | #endif |
2458 | } | 2702 | } |
2459 | BIO_free(s->bbio); | 2703 | BIO_free(s->bbio); |
2460 | s->bbio=NULL; | 2704 | s->bbio=NULL; |
@@ -2539,7 +2783,7 @@ void SSL_set_info_callback(SSL *ssl, | |||
2539 | 2783 | ||
2540 | /* One compiler (Diab DCC) doesn't like argument names in returned | 2784 | /* One compiler (Diab DCC) doesn't like argument names in returned |
2541 | function pointer. */ | 2785 | function pointer. */ |
2542 | void (*SSL_get_info_callback(const SSL *ssl))(const SSL * /*ssl*/,int /*type*/,int /*val*/) | 2786 | void (*SSL_get_info_callback(const SSL *ssl))(const SSL * /*ssl*/,int /*type*/,int /*val*/) |
2543 | { | 2787 | { |
2544 | return ssl->info_callback; | 2788 | return ssl->info_callback; |
2545 | } | 2789 | } |
@@ -2660,13 +2904,13 @@ RSA *cb(SSL *ssl,int is_export,int keylength) | |||
2660 | 2904 | ||
2661 | #ifndef OPENSSL_NO_DH | 2905 | #ifndef OPENSSL_NO_DH |
2662 | void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,DH *(*dh)(SSL *ssl,int is_export, | 2906 | void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,DH *(*dh)(SSL *ssl,int is_export, |
2663 | int keylength)) | 2907 | int keylength)) |
2664 | { | 2908 | { |
2665 | SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_DH_CB,(void (*)(void))dh); | 2909 | SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_DH_CB,(void (*)(void))dh); |
2666 | } | 2910 | } |
2667 | 2911 | ||
2668 | void SSL_set_tmp_dh_callback(SSL *ssl,DH *(*dh)(SSL *ssl,int is_export, | 2912 | void SSL_set_tmp_dh_callback(SSL *ssl,DH *(*dh)(SSL *ssl,int is_export, |
2669 | int keylength)) | 2913 | int keylength)) |
2670 | { | 2914 | { |
2671 | SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_DH_CB,(void (*)(void))dh); | 2915 | SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_DH_CB,(void (*)(void))dh); |
2672 | } | 2916 | } |
@@ -2674,18 +2918,109 @@ void SSL_set_tmp_dh_callback(SSL *ssl,DH *(*dh)(SSL *ssl,int is_export, | |||
2674 | 2918 | ||
2675 | #ifndef OPENSSL_NO_ECDH | 2919 | #ifndef OPENSSL_NO_ECDH |
2676 | void SSL_CTX_set_tmp_ecdh_callback(SSL_CTX *ctx,EC_KEY *(*ecdh)(SSL *ssl,int is_export, | 2920 | void SSL_CTX_set_tmp_ecdh_callback(SSL_CTX *ctx,EC_KEY *(*ecdh)(SSL *ssl,int is_export, |
2677 | int keylength)) | 2921 | int keylength)) |
2678 | { | 2922 | { |
2679 | SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_ECDH_CB,(void (*)(void))ecdh); | 2923 | SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_ECDH_CB,(void (*)(void))ecdh); |
2680 | } | 2924 | } |
2681 | 2925 | ||
2682 | void SSL_set_tmp_ecdh_callback(SSL *ssl,EC_KEY *(*ecdh)(SSL *ssl,int is_export, | 2926 | void SSL_set_tmp_ecdh_callback(SSL *ssl,EC_KEY *(*ecdh)(SSL *ssl,int is_export, |
2683 | int keylength)) | 2927 | int keylength)) |
2684 | { | 2928 | { |
2685 | SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_ECDH_CB,(void (*)(void))ecdh); | 2929 | SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_ECDH_CB,(void (*)(void))ecdh); |
2686 | } | 2930 | } |
2687 | #endif | 2931 | #endif |
2688 | 2932 | ||
2933 | #ifndef OPENSSL_NO_PSK | ||
2934 | int SSL_CTX_use_psk_identity_hint(SSL_CTX *ctx, const char *identity_hint) | ||
2935 | { | ||
2936 | if (identity_hint != NULL && strlen(identity_hint) > PSK_MAX_IDENTITY_LEN) | ||
2937 | { | ||
2938 | SSLerr(SSL_F_SSL_CTX_USE_PSK_IDENTITY_HINT, SSL_R_DATA_LENGTH_TOO_LONG); | ||
2939 | return 0; | ||
2940 | } | ||
2941 | if (ctx->psk_identity_hint != NULL) | ||
2942 | OPENSSL_free(ctx->psk_identity_hint); | ||
2943 | if (identity_hint != NULL) | ||
2944 | { | ||
2945 | ctx->psk_identity_hint = BUF_strdup(identity_hint); | ||
2946 | if (ctx->psk_identity_hint == NULL) | ||
2947 | return 0; | ||
2948 | } | ||
2949 | else | ||
2950 | ctx->psk_identity_hint = NULL; | ||
2951 | return 1; | ||
2952 | } | ||
2953 | |||
2954 | int SSL_use_psk_identity_hint(SSL *s, const char *identity_hint) | ||
2955 | { | ||
2956 | if (s == NULL) | ||
2957 | return 0; | ||
2958 | |||
2959 | if (s->session == NULL) | ||
2960 | return 1; /* session not created yet, ignored */ | ||
2961 | |||
2962 | if (identity_hint != NULL && strlen(identity_hint) > PSK_MAX_IDENTITY_LEN) | ||
2963 | { | ||
2964 | SSLerr(SSL_F_SSL_USE_PSK_IDENTITY_HINT, SSL_R_DATA_LENGTH_TOO_LONG); | ||
2965 | return 0; | ||
2966 | } | ||
2967 | if (s->session->psk_identity_hint != NULL) | ||
2968 | OPENSSL_free(s->session->psk_identity_hint); | ||
2969 | if (identity_hint != NULL) | ||
2970 | { | ||
2971 | s->session->psk_identity_hint = BUF_strdup(identity_hint); | ||
2972 | if (s->session->psk_identity_hint == NULL) | ||
2973 | return 0; | ||
2974 | } | ||
2975 | else | ||
2976 | s->session->psk_identity_hint = NULL; | ||
2977 | return 1; | ||
2978 | } | ||
2979 | |||
2980 | const char *SSL_get_psk_identity_hint(const SSL *s) | ||
2981 | { | ||
2982 | if (s == NULL || s->session == NULL) | ||
2983 | return NULL; | ||
2984 | return(s->session->psk_identity_hint); | ||
2985 | } | ||
2986 | |||
2987 | const char *SSL_get_psk_identity(const SSL *s) | ||
2988 | { | ||
2989 | if (s == NULL || s->session == NULL) | ||
2990 | return NULL; | ||
2991 | return(s->session->psk_identity); | ||
2992 | } | ||
2993 | |||
2994 | void SSL_set_psk_client_callback(SSL *s, | ||
2995 | unsigned int (*cb)(SSL *ssl, const char *hint, | ||
2996 | char *identity, unsigned int max_identity_len, unsigned char *psk, | ||
2997 | unsigned int max_psk_len)) | ||
2998 | { | ||
2999 | s->psk_client_callback = cb; | ||
3000 | } | ||
3001 | |||
3002 | void SSL_CTX_set_psk_client_callback(SSL_CTX *ctx, | ||
3003 | unsigned int (*cb)(SSL *ssl, const char *hint, | ||
3004 | char *identity, unsigned int max_identity_len, unsigned char *psk, | ||
3005 | unsigned int max_psk_len)) | ||
3006 | { | ||
3007 | ctx->psk_client_callback = cb; | ||
3008 | } | ||
3009 | |||
3010 | void SSL_set_psk_server_callback(SSL *s, | ||
3011 | unsigned int (*cb)(SSL *ssl, const char *identity, | ||
3012 | unsigned char *psk, unsigned int max_psk_len)) | ||
3013 | { | ||
3014 | s->psk_server_callback = cb; | ||
3015 | } | ||
3016 | |||
3017 | void SSL_CTX_set_psk_server_callback(SSL_CTX *ctx, | ||
3018 | unsigned int (*cb)(SSL *ssl, const char *identity, | ||
3019 | unsigned char *psk, unsigned int max_psk_len)) | ||
3020 | { | ||
3021 | ctx->psk_server_callback = cb; | ||
3022 | } | ||
3023 | #endif | ||
2689 | 3024 | ||
2690 | 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)) | 3025 | 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)) |
2691 | { | 3026 | { |
@@ -2696,7 +3031,25 @@ void SSL_set_msg_callback(SSL *ssl, void (*cb)(int write_p, int version, int con | |||
2696 | SSL_callback_ctrl(ssl, SSL_CTRL_SET_MSG_CALLBACK, (void (*)(void))cb); | 3031 | SSL_callback_ctrl(ssl, SSL_CTRL_SET_MSG_CALLBACK, (void (*)(void))cb); |
2697 | } | 3032 | } |
2698 | 3033 | ||
3034 | /* Allocates new EVP_MD_CTX and sets pointer to it into given pointer | ||
3035 | * vairable, freeing EVP_MD_CTX previously stored in that variable, if | ||
3036 | * any. If EVP_MD pointer is passed, initializes ctx with this md | ||
3037 | * Returns newly allocated ctx; | ||
3038 | */ | ||
3039 | |||
3040 | EVP_MD_CTX *ssl_replace_hash(EVP_MD_CTX **hash,const EVP_MD *md) | ||
3041 | { | ||
3042 | ssl_clear_hash_ctx(hash); | ||
3043 | *hash = EVP_MD_CTX_create(); | ||
3044 | if (md) EVP_DigestInit_ex(*hash,md,NULL); | ||
3045 | return *hash; | ||
3046 | } | ||
3047 | void ssl_clear_hash_ctx(EVP_MD_CTX **hash) | ||
3048 | { | ||
2699 | 3049 | ||
3050 | if (*hash) EVP_MD_CTX_destroy(*hash); | ||
3051 | *hash=NULL; | ||
3052 | } | ||
2700 | 3053 | ||
2701 | #if defined(_WINDLL) && defined(OPENSSL_SYS_WIN16) | 3054 | #if defined(_WINDLL) && defined(OPENSSL_SYS_WIN16) |
2702 | #include "../crypto/bio/bss_file.c" | 3055 | #include "../crypto/bio/bss_file.c" |
@@ -2704,3 +3057,6 @@ void SSL_set_msg_callback(SSL *ssl, void (*cb)(int write_p, int version, int con | |||
2704 | 3057 | ||
2705 | IMPLEMENT_STACK_OF(SSL_CIPHER) | 3058 | IMPLEMENT_STACK_OF(SSL_CIPHER) |
2706 | IMPLEMENT_STACK_OF(SSL_COMP) | 3059 | IMPLEMENT_STACK_OF(SSL_COMP) |
3060 | IMPLEMENT_OBJ_BSEARCH_GLOBAL_CMP_FN(SSL_CIPHER, SSL_CIPHER, | ||
3061 | ssl_cipher_id); | ||
3062 | |||