diff options
Diffstat (limited to 'src/lib/libssl/ssl_lib.c')
-rw-r--r-- | src/lib/libssl/ssl_lib.c | 641 |
1 files changed, 141 insertions, 500 deletions
diff --git a/src/lib/libssl/ssl_lib.c b/src/lib/libssl/ssl_lib.c index 3157f20eac..1a961a9e9e 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-2007 The OpenSSL Project. All rights reserved. | 61 | * Copyright (c) 1998-2001 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,32 +115,6 @@ | |||
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 | */ | ||
144 | 118 | ||
145 | #ifdef REF_CHECK | 119 | #ifdef REF_CHECK |
146 | # include <assert.h> | 120 | # include <assert.h> |
@@ -169,9 +143,9 @@ SSL3_ENC_METHOD ssl3_undef_enc_method={ | |||
169 | ssl_undefined_function, | 143 | ssl_undefined_function, |
170 | (int (*)(SSL *, unsigned char *, unsigned char *, int))ssl_undefined_function, | 144 | (int (*)(SSL *, unsigned char *, unsigned char *, int))ssl_undefined_function, |
171 | (int (*)(SSL*, int))ssl_undefined_function, | 145 | (int (*)(SSL*, int))ssl_undefined_function, |
172 | (int (*)(SSL *, const char*, int, unsigned char *))ssl_undefined_function, | 146 | (int (*)(SSL *, EVP_MD_CTX *, EVP_MD_CTX *, const char*, int, unsigned char *))ssl_undefined_function, |
173 | 0, /* finish_mac_length */ | 147 | 0, /* finish_mac_length */ |
174 | (int (*)(SSL *, int, unsigned char *))ssl_undefined_function, | 148 | (int (*)(SSL *, EVP_MD_CTX *, unsigned char *))ssl_undefined_function, |
175 | NULL, /* client_finished_label */ | 149 | NULL, /* client_finished_label */ |
176 | 0, /* client_finished_label_len */ | 150 | 0, /* client_finished_label_len */ |
177 | NULL, /* server_finished_label */ | 151 | NULL, /* server_finished_label */ |
@@ -230,8 +204,6 @@ int SSL_clear(SSL *s) | |||
230 | } | 204 | } |
231 | 205 | ||
232 | ssl_clear_cipher_ctx(s); | 206 | ssl_clear_cipher_ctx(s); |
233 | ssl_clear_hash_ctx(&s->read_hash); | ||
234 | ssl_clear_hash_ctx(&s->write_hash); | ||
235 | 207 | ||
236 | s->first_packet=0; | 208 | s->first_packet=0; |
237 | 209 | ||
@@ -252,15 +224,14 @@ int SSL_clear(SSL *s) | |||
252 | } | 224 | } |
253 | 225 | ||
254 | /** Used to change an SSL_CTXs default SSL method type */ | 226 | /** Used to change an SSL_CTXs default SSL method type */ |
255 | int SSL_CTX_set_ssl_version(SSL_CTX *ctx,const SSL_METHOD *meth) | 227 | int SSL_CTX_set_ssl_version(SSL_CTX *ctx,SSL_METHOD *meth) |
256 | { | 228 | { |
257 | STACK_OF(SSL_CIPHER) *sk; | 229 | STACK_OF(SSL_CIPHER) *sk; |
258 | 230 | ||
259 | ctx->method=meth; | 231 | ctx->method=meth; |
260 | 232 | ||
261 | sk=ssl_create_cipher_list(ctx->method,&(ctx->cipher_list), | 233 | sk=ssl_create_cipher_list(ctx->method,&(ctx->cipher_list), |
262 | &(ctx->cipher_list_by_id), | 234 | &(ctx->cipher_list_by_id),SSL_DEFAULT_CIPHER_LIST); |
263 | meth->version == SSL2_VERSION ? "SSLv2" : SSL_DEFAULT_CIPHER_LIST); | ||
264 | if ((sk == NULL) || (sk_SSL_CIPHER_num(sk) <= 0)) | 235 | if ((sk == NULL) || (sk_SSL_CIPHER_num(sk) <= 0)) |
265 | { | 236 | { |
266 | SSLerr(SSL_F_SSL_CTX_SET_SSL_VERSION,SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS); | 237 | SSLerr(SSL_F_SSL_CTX_SET_SSL_VERSION,SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS); |
@@ -337,7 +308,6 @@ SSL *SSL_new(SSL_CTX *ctx) | |||
337 | s->trust = ctx->trust; | 308 | s->trust = ctx->trust; |
338 | #endif | 309 | #endif |
339 | s->quiet_shutdown=ctx->quiet_shutdown; | 310 | s->quiet_shutdown=ctx->quiet_shutdown; |
340 | s->max_send_fragment = ctx->max_send_fragment; | ||
341 | 311 | ||
342 | CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX); | 312 | CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX); |
343 | s->ctx=ctx; | 313 | s->ctx=ctx; |
@@ -354,7 +324,6 @@ SSL *SSL_new(SSL_CTX *ctx) | |||
354 | CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX); | 324 | CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX); |
355 | s->initial_ctx=ctx; | 325 | s->initial_ctx=ctx; |
356 | #endif | 326 | #endif |
357 | |||
358 | s->verify_result=X509_V_OK; | 327 | s->verify_result=X509_V_OK; |
359 | 328 | ||
360 | s->method=ctx->method; | 329 | s->method=ctx->method; |
@@ -369,11 +338,6 @@ SSL *SSL_new(SSL_CTX *ctx) | |||
369 | 338 | ||
370 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data); | 339 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data); |
371 | 340 | ||
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 | |||
377 | return(s); | 341 | return(s); |
378 | err: | 342 | err: |
379 | if (s != NULL) | 343 | if (s != NULL) |
@@ -461,7 +425,7 @@ int SSL_has_matching_session_id(const SSL *ssl, const unsigned char *id, | |||
461 | } | 425 | } |
462 | 426 | ||
463 | CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX); | 427 | CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX); |
464 | p = lh_SSL_SESSION_retrieve(ssl->ctx->sessions, &r); | 428 | p = (SSL_SESSION *)lh_retrieve(ssl->ctx->sessions, &r); |
465 | CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX); | 429 | CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX); |
466 | return (p != NULL); | 430 | return (p != NULL); |
467 | } | 431 | } |
@@ -486,16 +450,6 @@ int SSL_set_trust(SSL *s, int trust) | |||
486 | return X509_VERIFY_PARAM_set_trust(s->param, trust); | 450 | return X509_VERIFY_PARAM_set_trust(s->param, trust); |
487 | } | 451 | } |
488 | 452 | ||
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 | |||
499 | void SSL_free(SSL *s) | 453 | void SSL_free(SSL *s) |
500 | { | 454 | { |
501 | int i; | 455 | int i; |
@@ -550,21 +504,15 @@ void SSL_free(SSL *s) | |||
550 | } | 504 | } |
551 | 505 | ||
552 | ssl_clear_cipher_ctx(s); | 506 | ssl_clear_cipher_ctx(s); |
553 | ssl_clear_hash_ctx(&s->read_hash); | ||
554 | ssl_clear_hash_ctx(&s->write_hash); | ||
555 | 507 | ||
556 | if (s->cert != NULL) ssl_cert_free(s->cert); | 508 | if (s->cert != NULL) ssl_cert_free(s->cert); |
557 | /* Free up if allocated */ | 509 | /* Free up if allocated */ |
558 | 510 | ||
511 | if (s->ctx) SSL_CTX_free(s->ctx); | ||
559 | #ifndef OPENSSL_NO_TLSEXT | 512 | #ifndef OPENSSL_NO_TLSEXT |
560 | if (s->tlsext_hostname) | 513 | if (s->tlsext_hostname) |
561 | OPENSSL_free(s->tlsext_hostname); | 514 | OPENSSL_free(s->tlsext_hostname); |
562 | if (s->initial_ctx) SSL_CTX_free(s->initial_ctx); | 515 | 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); | ||
568 | if (s->tlsext_ocsp_exts) | 516 | if (s->tlsext_ocsp_exts) |
569 | sk_X509_EXTENSION_pop_free(s->tlsext_ocsp_exts, | 517 | sk_X509_EXTENSION_pop_free(s->tlsext_ocsp_exts, |
570 | X509_EXTENSION_free); | 518 | X509_EXTENSION_free); |
@@ -573,14 +521,11 @@ void SSL_free(SSL *s) | |||
573 | if (s->tlsext_ocsp_resp) | 521 | if (s->tlsext_ocsp_resp) |
574 | OPENSSL_free(s->tlsext_ocsp_resp); | 522 | OPENSSL_free(s->tlsext_ocsp_resp); |
575 | #endif | 523 | #endif |
576 | |||
577 | if (s->client_CA != NULL) | 524 | if (s->client_CA != NULL) |
578 | sk_X509_NAME_pop_free(s->client_CA,X509_NAME_free); | 525 | sk_X509_NAME_pop_free(s->client_CA,X509_NAME_free); |
579 | 526 | ||
580 | if (s->method != NULL) s->method->ssl_free(s); | 527 | if (s->method != NULL) s->method->ssl_free(s); |
581 | 528 | ||
582 | if (s->ctx) SSL_CTX_free(s->ctx); | ||
583 | |||
584 | #ifndef OPENSSL_NO_KRB5 | 529 | #ifndef OPENSSL_NO_KRB5 |
585 | if (s->kssl_ctx != NULL) | 530 | if (s->kssl_ctx != NULL) |
586 | kssl_ctx_free(s->kssl_ctx); | 531 | kssl_ctx_free(s->kssl_ctx); |
@@ -898,7 +843,7 @@ int SSL_check_private_key(const SSL *ssl) | |||
898 | } | 843 | } |
899 | if (ssl->cert == NULL) | 844 | if (ssl->cert == NULL) |
900 | { | 845 | { |
901 | SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED); | 846 | SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED); |
902 | return 0; | 847 | return 0; |
903 | } | 848 | } |
904 | if (ssl->cert->key->x509 == NULL) | 849 | if (ssl->cert->key->x509 == NULL) |
@@ -1041,12 +986,8 @@ long SSL_ctrl(SSL *s,int cmd,long larg,void *parg) | |||
1041 | 986 | ||
1042 | case SSL_CTRL_OPTIONS: | 987 | case SSL_CTRL_OPTIONS: |
1043 | return(s->options|=larg); | 988 | return(s->options|=larg); |
1044 | case SSL_CTRL_CLEAR_OPTIONS: | ||
1045 | return(s->options&=~larg); | ||
1046 | case SSL_CTRL_MODE: | 989 | case SSL_CTRL_MODE: |
1047 | return(s->mode|=larg); | 990 | return(s->mode|=larg); |
1048 | case SSL_CTRL_CLEAR_MODE: | ||
1049 | return(s->mode &=~larg); | ||
1050 | case SSL_CTRL_GET_MAX_CERT_LIST: | 991 | case SSL_CTRL_GET_MAX_CERT_LIST: |
1051 | return(s->max_cert_list); | 992 | return(s->max_cert_list); |
1052 | case SSL_CTRL_SET_MAX_CERT_LIST: | 993 | case SSL_CTRL_SET_MAX_CERT_LIST: |
@@ -1054,22 +995,12 @@ long SSL_ctrl(SSL *s,int cmd,long larg,void *parg) | |||
1054 | s->max_cert_list=larg; | 995 | s->max_cert_list=larg; |
1055 | return(l); | 996 | return(l); |
1056 | case SSL_CTRL_SET_MTU: | 997 | case SSL_CTRL_SET_MTU: |
1057 | if (SSL_version(s) == DTLS1_VERSION || | 998 | if (SSL_version(s) == DTLS1_VERSION) |
1058 | SSL_version(s) == DTLS1_BAD_VER) | ||
1059 | { | 999 | { |
1060 | s->d1->mtu = larg; | 1000 | s->d1->mtu = larg; |
1061 | return larg; | 1001 | return larg; |
1062 | } | 1002 | } |
1063 | return 0; | 1003 | 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; | ||
1073 | default: | 1004 | default: |
1074 | return(s->method->ssl_ctrl(s,cmd,larg,parg)); | 1005 | return(s->method->ssl_ctrl(s,cmd,larg,parg)); |
1075 | } | 1006 | } |
@@ -1088,7 +1019,7 @@ long SSL_callback_ctrl(SSL *s, int cmd, void (*fp)(void)) | |||
1088 | } | 1019 | } |
1089 | } | 1020 | } |
1090 | 1021 | ||
1091 | LHASH_OF(SSL_SESSION) *SSL_CTX_sessions(SSL_CTX *ctx) | 1022 | struct lhash_st *SSL_CTX_sessions(SSL_CTX *ctx) |
1092 | { | 1023 | { |
1093 | return ctx->sessions; | 1024 | return ctx->sessions; |
1094 | } | 1025 | } |
@@ -1131,7 +1062,7 @@ long SSL_CTX_ctrl(SSL_CTX *ctx,int cmd,long larg,void *parg) | |||
1131 | return(ctx->session_cache_mode); | 1062 | return(ctx->session_cache_mode); |
1132 | 1063 | ||
1133 | case SSL_CTRL_SESS_NUMBER: | 1064 | case SSL_CTRL_SESS_NUMBER: |
1134 | return(lh_SSL_SESSION_num_items(ctx->sessions)); | 1065 | return(ctx->sessions->num_items); |
1135 | case SSL_CTRL_SESS_CONNECT: | 1066 | case SSL_CTRL_SESS_CONNECT: |
1136 | return(ctx->stats.sess_connect); | 1067 | return(ctx->stats.sess_connect); |
1137 | case SSL_CTRL_SESS_CONNECT_GOOD: | 1068 | case SSL_CTRL_SESS_CONNECT_GOOD: |
@@ -1156,17 +1087,8 @@ long SSL_CTX_ctrl(SSL_CTX *ctx,int cmd,long larg,void *parg) | |||
1156 | return(ctx->stats.sess_cache_full); | 1087 | return(ctx->stats.sess_cache_full); |
1157 | case SSL_CTRL_OPTIONS: | 1088 | case SSL_CTRL_OPTIONS: |
1158 | return(ctx->options|=larg); | 1089 | return(ctx->options|=larg); |
1159 | case SSL_CTRL_CLEAR_OPTIONS: | ||
1160 | return(ctx->options&=~larg); | ||
1161 | case SSL_CTRL_MODE: | 1090 | case SSL_CTRL_MODE: |
1162 | return(ctx->mode|=larg); | 1091 | 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; | ||
1170 | default: | 1092 | default: |
1171 | return(ctx->method->ssl_ctx_ctrl(ctx,cmd,larg,parg)); | 1093 | return(ctx->method->ssl_ctx_ctrl(ctx,cmd,larg,parg)); |
1172 | } | 1094 | } |
@@ -1271,8 +1193,8 @@ int SSL_CTX_set_cipher_list(SSL_CTX *ctx, const char *str) | |||
1271 | /* ssl_create_cipher_list may return an empty stack if it | 1193 | /* ssl_create_cipher_list may return an empty stack if it |
1272 | * was unable to find a cipher matching the given rule string | 1194 | * was unable to find a cipher matching the given rule string |
1273 | * (for example if the rule string specifies a cipher which | 1195 | * (for example if the rule string specifies a cipher which |
1274 | * has been disabled). This is not an error as far as | 1196 | * has been disabled). This is not an error as far as |
1275 | * ssl_create_cipher_list is concerned, and hence | 1197 | * ssl_create_cipher_list is concerned, and hence |
1276 | * ctx->cipher_list and ctx->cipher_list_by_id has been | 1198 | * ctx->cipher_list and ctx->cipher_list_by_id has been |
1277 | * updated. */ | 1199 | * updated. */ |
1278 | if (sk == NULL) | 1200 | if (sk == NULL) |
@@ -1306,47 +1228,44 @@ int SSL_set_cipher_list(SSL *s,const char *str) | |||
1306 | /* works well for SSLv2, not so good for SSLv3 */ | 1228 | /* works well for SSLv2, not so good for SSLv3 */ |
1307 | char *SSL_get_shared_ciphers(const SSL *s,char *buf,int len) | 1229 | char *SSL_get_shared_ciphers(const SSL *s,char *buf,int len) |
1308 | { | 1230 | { |
1309 | char *p; | 1231 | char *end; |
1310 | STACK_OF(SSL_CIPHER) *sk; | 1232 | STACK_OF(SSL_CIPHER) *sk; |
1311 | SSL_CIPHER *c; | 1233 | SSL_CIPHER *c; |
1234 | size_t curlen = 0; | ||
1312 | int i; | 1235 | int i; |
1313 | 1236 | ||
1314 | if ((s->session == NULL) || (s->session->ciphers == NULL) || | 1237 | if ((s->session == NULL) || (s->session->ciphers == NULL) || |
1315 | (len < 2)) | 1238 | (len < 2)) |
1316 | return(NULL); | 1239 | return(NULL); |
1317 | 1240 | ||
1318 | p=buf; | ||
1319 | sk=s->session->ciphers; | 1241 | sk=s->session->ciphers; |
1242 | buf[0] = '\0'; | ||
1320 | for (i=0; i<sk_SSL_CIPHER_num(sk); i++) | 1243 | for (i=0; i<sk_SSL_CIPHER_num(sk); i++) |
1321 | { | 1244 | { |
1322 | int n; | ||
1323 | |||
1324 | c=sk_SSL_CIPHER_value(sk,i); | 1245 | c=sk_SSL_CIPHER_value(sk,i); |
1325 | n=strlen(c->name); | 1246 | end = buf + curlen; |
1326 | if (n+1 > len) | 1247 | if (strlcat(buf, c->name, len) >= len || |
1248 | (curlen = strlcat(buf, ":", len)) >= len) | ||
1327 | { | 1249 | { |
1328 | if (p != buf) | 1250 | /* remove truncated cipher from list */ |
1329 | --p; | 1251 | *end = '\0'; |
1330 | *p='\0'; | 1252 | break; |
1331 | return buf; | ||
1332 | } | 1253 | } |
1333 | strcpy(p,c->name); | ||
1334 | p+=n; | ||
1335 | *(p++)=':'; | ||
1336 | len-=n+1; | ||
1337 | } | 1254 | } |
1338 | p[-1]='\0'; | 1255 | /* remove trailing colon */ |
1256 | if ((end = strrchr(buf, ':')) != NULL) | ||
1257 | *end = '\0'; | ||
1339 | return(buf); | 1258 | return(buf); |
1340 | } | 1259 | } |
1341 | 1260 | ||
1342 | int ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p, | 1261 | int ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p, |
1343 | int (*put_cb)(const SSL_CIPHER *, unsigned char *)) | 1262 | int (*put_cb)(const SSL_CIPHER *, unsigned char *)) |
1344 | { | 1263 | { |
1345 | int i,j=0; | 1264 | int i,j=0; |
1346 | SSL_CIPHER *c; | 1265 | SSL_CIPHER *c; |
1347 | unsigned char *q; | 1266 | unsigned char *q; |
1348 | #ifndef OPENSSL_NO_KRB5 | 1267 | #ifndef OPENSSL_NO_KRB5 |
1349 | int nokrb5 = !kssl_tgt_is_available(s->kssl_ctx); | 1268 | int nokrb5 = !kssl_tgt_is_available(s->kssl_ctx); |
1350 | #endif /* OPENSSL_NO_KRB5 */ | 1269 | #endif /* OPENSSL_NO_KRB5 */ |
1351 | 1270 | ||
1352 | if (sk == NULL) return(0); | 1271 | if (sk == NULL) return(0); |
@@ -1356,46 +1275,22 @@ int ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p, | |||
1356 | { | 1275 | { |
1357 | c=sk_SSL_CIPHER_value(sk,i); | 1276 | c=sk_SSL_CIPHER_value(sk,i); |
1358 | #ifndef OPENSSL_NO_KRB5 | 1277 | #ifndef OPENSSL_NO_KRB5 |
1359 | if (((c->algorithm_mkey & SSL_kKRB5) || (c->algorithm_auth & SSL_aKRB5)) && | 1278 | if ((c->algorithms & SSL_KRB5) && nokrb5) |
1360 | nokrb5) | 1279 | continue; |
1361 | continue; | 1280 | #endif /* OPENSSL_NO_KRB5 */ |
1362 | #endif /* OPENSSL_NO_KRB5 */ | 1281 | |
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 */ | ||
1369 | j = put_cb ? put_cb(c,p) : ssl_put_cipher_by_char(s,c,p); | 1282 | j = put_cb ? put_cb(c,p) : ssl_put_cipher_by_char(s,c,p); |
1370 | p+=j; | 1283 | p+=j; |
1371 | } | 1284 | } |
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 | |||
1388 | return(p-q); | 1285 | return(p-q); |
1389 | } | 1286 | } |
1390 | 1287 | ||
1391 | STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num, | 1288 | STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num, |
1392 | STACK_OF(SSL_CIPHER) **skp) | 1289 | STACK_OF(SSL_CIPHER) **skp) |
1393 | { | 1290 | { |
1394 | const SSL_CIPHER *c; | 1291 | SSL_CIPHER *c; |
1395 | STACK_OF(SSL_CIPHER) *sk; | 1292 | STACK_OF(SSL_CIPHER) *sk; |
1396 | int i,n; | 1293 | int i,n; |
1397 | if (s->s3) | ||
1398 | s->s3->send_connection_binding = 0; | ||
1399 | 1294 | ||
1400 | n=ssl_put_cipher_by_char(s,NULL,NULL); | 1295 | n=ssl_put_cipher_by_char(s,NULL,NULL); |
1401 | if ((num%n) != 0) | 1296 | if ((num%n) != 0) |
@@ -1413,26 +1308,6 @@ STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num, | |||
1413 | 1308 | ||
1414 | for (i=0; i<num; i+=n) | 1309 | for (i=0; i<num; i+=n) |
1415 | { | 1310 | { |
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 | |||
1436 | c=ssl_get_cipher_by_char(s,p); | 1311 | c=ssl_get_cipher_by_char(s,p); |
1437 | p+=n; | 1312 | p+=n; |
1438 | if (c != NULL) | 1313 | if (c != NULL) |
@@ -1454,7 +1329,6 @@ err: | |||
1454 | return(NULL); | 1329 | return(NULL); |
1455 | } | 1330 | } |
1456 | 1331 | ||
1457 | |||
1458 | #ifndef OPENSSL_NO_TLSEXT | 1332 | #ifndef OPENSSL_NO_TLSEXT |
1459 | /** return a servername extension value if provided in Client Hello, or NULL. | 1333 | /** return a servername extension value if provided in Client Hello, or NULL. |
1460 | * So far, only host_name types are defined (RFC 3546). | 1334 | * So far, only host_name types are defined (RFC 3546). |
@@ -1478,7 +1352,7 @@ int SSL_get_servername_type(const SSL *s) | |||
1478 | } | 1352 | } |
1479 | #endif | 1353 | #endif |
1480 | 1354 | ||
1481 | static unsigned long ssl_session_hash(const SSL_SESSION *a) | 1355 | unsigned long SSL_SESSION_hash(const SSL_SESSION *a) |
1482 | { | 1356 | { |
1483 | unsigned long l; | 1357 | unsigned long l; |
1484 | 1358 | ||
@@ -1495,7 +1369,7 @@ static unsigned long ssl_session_hash(const SSL_SESSION *a) | |||
1495 | * SSL_CTX_has_matching_session_id() is checked accordingly. It relies on being | 1369 | * SSL_CTX_has_matching_session_id() is checked accordingly. It relies on being |
1496 | * able to construct an SSL_SESSION that will collide with any existing session | 1370 | * able to construct an SSL_SESSION that will collide with any existing session |
1497 | * with a matching session ID. */ | 1371 | * with a matching session ID. */ |
1498 | static int ssl_session_cmp(const SSL_SESSION *a,const SSL_SESSION *b) | 1372 | int SSL_SESSION_cmp(const SSL_SESSION *a,const SSL_SESSION *b) |
1499 | { | 1373 | { |
1500 | if (a->ssl_version != b->ssl_version) | 1374 | if (a->ssl_version != b->ssl_version) |
1501 | return(1); | 1375 | return(1); |
@@ -1508,19 +1382,27 @@ static int ssl_session_cmp(const SSL_SESSION *a,const SSL_SESSION *b) | |||
1508 | * SSL_SESSION_hash and SSL_SESSION_cmp for void* types and casting each | 1382 | * SSL_SESSION_hash and SSL_SESSION_cmp for void* types and casting each |
1509 | * variable. The reason is that the functions aren't static, they're exposed via | 1383 | * variable. The reason is that the functions aren't static, they're exposed via |
1510 | * ssl.h. */ | 1384 | * ssl.h. */ |
1511 | static IMPLEMENT_LHASH_HASH_FN(ssl_session, SSL_SESSION) | 1385 | static IMPLEMENT_LHASH_HASH_FN(SSL_SESSION_hash, SSL_SESSION *) |
1512 | static IMPLEMENT_LHASH_COMP_FN(ssl_session, SSL_SESSION) | 1386 | static IMPLEMENT_LHASH_COMP_FN(SSL_SESSION_cmp, SSL_SESSION *) |
1513 | 1387 | ||
1514 | SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth) | 1388 | SSL_CTX *SSL_CTX_new(SSL_METHOD *meth) |
1515 | { | 1389 | { |
1516 | SSL_CTX *ret=NULL; | 1390 | SSL_CTX *ret=NULL; |
1517 | 1391 | ||
1518 | if (meth == NULL) | 1392 | if (meth == NULL) |
1519 | { | 1393 | { |
1520 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_NULL_SSL_METHOD_PASSED); | 1394 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_NULL_SSL_METHOD_PASSED); |
1521 | return(NULL); | 1395 | return(NULL); |
1522 | } | 1396 | } |
1523 | 1397 | ||
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 | |||
1524 | if (SSL_get_ex_data_X509_STORE_CTX_idx() < 0) | 1406 | if (SSL_get_ex_data_X509_STORE_CTX_idx() < 0) |
1525 | { | 1407 | { |
1526 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_X509_VERIFICATION_SETUP_PROBLEMS); | 1408 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_X509_VERIFICATION_SETUP_PROBLEMS); |
@@ -1583,14 +1465,15 @@ SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth) | |||
1583 | ret->app_gen_cookie_cb=0; | 1465 | ret->app_gen_cookie_cb=0; |
1584 | ret->app_verify_cookie_cb=0; | 1466 | ret->app_verify_cookie_cb=0; |
1585 | 1467 | ||
1586 | ret->sessions=lh_SSL_SESSION_new(); | 1468 | ret->sessions=lh_new(LHASH_HASH_FN(SSL_SESSION_hash), |
1469 | LHASH_COMP_FN(SSL_SESSION_cmp)); | ||
1587 | if (ret->sessions == NULL) goto err; | 1470 | if (ret->sessions == NULL) goto err; |
1588 | ret->cert_store=X509_STORE_new(); | 1471 | ret->cert_store=X509_STORE_new(); |
1589 | if (ret->cert_store == NULL) goto err; | 1472 | if (ret->cert_store == NULL) goto err; |
1590 | 1473 | ||
1591 | ssl_create_cipher_list(ret->method, | 1474 | ssl_create_cipher_list(ret->method, |
1592 | &ret->cipher_list,&ret->cipher_list_by_id, | 1475 | &ret->cipher_list,&ret->cipher_list_by_id, |
1593 | meth->version == SSL2_VERSION ? "SSLv2" : SSL_DEFAULT_CIPHER_LIST); | 1476 | SSL_DEFAULT_CIPHER_LIST); |
1594 | if (ret->cipher_list == NULL | 1477 | if (ret->cipher_list == NULL |
1595 | || sk_SSL_CIPHER_num(ret->cipher_list) <= 0) | 1478 | || sk_SSL_CIPHER_num(ret->cipher_list) <= 0) |
1596 | { | 1479 | { |
@@ -1626,8 +1509,6 @@ SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth) | |||
1626 | ret->extra_certs=NULL; | 1509 | ret->extra_certs=NULL; |
1627 | ret->comp_methods=SSL_COMP_get_compression_methods(); | 1510 | ret->comp_methods=SSL_COMP_get_compression_methods(); |
1628 | 1511 | ||
1629 | ret->max_send_fragment = SSL3_RT_MAX_PLAIN_LENGTH; | ||
1630 | |||
1631 | #ifndef OPENSSL_NO_TLSEXT | 1512 | #ifndef OPENSSL_NO_TLSEXT |
1632 | ret->tlsext_servername_callback = 0; | 1513 | ret->tlsext_servername_callback = 0; |
1633 | ret->tlsext_servername_arg = NULL; | 1514 | ret->tlsext_servername_arg = NULL; |
@@ -1641,29 +1522,7 @@ SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth) | |||
1641 | ret->tlsext_status_arg = NULL; | 1522 | ret->tlsext_status_arg = NULL; |
1642 | 1523 | ||
1643 | #endif | 1524 | #endif |
1644 | #ifndef OPENSSL_NO_PSK | 1525 | |
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 | ||
1667 | #ifndef OPENSSL_NO_ENGINE | 1526 | #ifndef OPENSSL_NO_ENGINE |
1668 | ret->client_cert_engine = NULL; | 1527 | ret->client_cert_engine = NULL; |
1669 | #ifdef OPENSSL_SSL_CLIENT_ENGINE_AUTO | 1528 | #ifdef OPENSSL_SSL_CLIENT_ENGINE_AUTO |
@@ -1684,10 +1543,6 @@ SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth) | |||
1684 | } | 1543 | } |
1685 | #endif | 1544 | #endif |
1686 | #endif | 1545 | #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; | ||
1691 | 1546 | ||
1692 | return(ret); | 1547 | return(ret); |
1693 | err: | 1548 | err: |
@@ -1702,20 +1557,6 @@ static void SSL_COMP_free(SSL_COMP *comp) | |||
1702 | { OPENSSL_free(comp); } | 1557 | { OPENSSL_free(comp); } |
1703 | #endif | 1558 | #endif |
1704 | 1559 | ||
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 | |||
1719 | void SSL_CTX_free(SSL_CTX *a) | 1560 | void SSL_CTX_free(SSL_CTX *a) |
1720 | { | 1561 | { |
1721 | int i; | 1562 | int i; |
@@ -1753,7 +1594,7 @@ void SSL_CTX_free(SSL_CTX *a) | |||
1753 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, a, &a->ex_data); | 1594 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, a, &a->ex_data); |
1754 | 1595 | ||
1755 | if (a->sessions != NULL) | 1596 | if (a->sessions != NULL) |
1756 | lh_SSL_SESSION_free(a->sessions); | 1597 | lh_free(a->sessions); |
1757 | 1598 | ||
1758 | if (a->cert_store != NULL) | 1599 | if (a->cert_store != NULL) |
1759 | X509_STORE_free(a->cert_store); | 1600 | X509_STORE_free(a->cert_store); |
@@ -1773,23 +1614,10 @@ void SSL_CTX_free(SSL_CTX *a) | |||
1773 | #else | 1614 | #else |
1774 | a->comp_methods = NULL; | 1615 | a->comp_methods = NULL; |
1775 | #endif | 1616 | #endif |
1776 | |||
1777 | #ifndef OPENSSL_NO_PSK | ||
1778 | if (a->psk_identity_hint) | ||
1779 | OPENSSL_free(a->psk_identity_hint); | ||
1780 | #endif | ||
1781 | #ifndef OPENSSL_NO_ENGINE | 1617 | #ifndef OPENSSL_NO_ENGINE |
1782 | if (a->client_cert_engine) | 1618 | if (a->client_cert_engine) |
1783 | ENGINE_finish(a->client_cert_engine); | 1619 | ENGINE_finish(a->client_cert_engine); |
1784 | #endif | 1620 | #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 | |||
1793 | OPENSSL_free(a); | 1621 | OPENSSL_free(a); |
1794 | } | 1622 | } |
1795 | 1623 | ||
@@ -1820,13 +1648,13 @@ void SSL_CTX_set_verify_depth(SSL_CTX *ctx,int depth) | |||
1820 | X509_VERIFY_PARAM_set_depth(ctx->param, depth); | 1648 | X509_VERIFY_PARAM_set_depth(ctx->param, depth); |
1821 | } | 1649 | } |
1822 | 1650 | ||
1823 | void ssl_set_cert_masks(CERT *c, const SSL_CIPHER *cipher) | 1651 | void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher) |
1824 | { | 1652 | { |
1825 | CERT_PKEY *cpk; | 1653 | CERT_PKEY *cpk; |
1826 | int rsa_enc,rsa_tmp,rsa_sign,dh_tmp,dh_rsa,dh_dsa,dsa_sign; | 1654 | int rsa_enc,rsa_tmp,rsa_sign,dh_tmp,dh_rsa,dh_dsa,dsa_sign; |
1827 | int rsa_enc_export,dh_rsa_export,dh_dsa_export; | 1655 | int rsa_enc_export,dh_rsa_export,dh_dsa_export; |
1828 | int rsa_tmp_export,dh_tmp_export,kl; | 1656 | int rsa_tmp_export,dh_tmp_export,kl; |
1829 | unsigned long mask_k,mask_a,emask_k,emask_a; | 1657 | unsigned long mask,emask; |
1830 | int have_ecc_cert, ecdh_ok, ecdsa_ok, ecc_pkey_size; | 1658 | int have_ecc_cert, ecdh_ok, ecdsa_ok, ecc_pkey_size; |
1831 | #ifndef OPENSSL_NO_ECDH | 1659 | #ifndef OPENSSL_NO_ECDH |
1832 | int have_ecdh_tmp; | 1660 | int have_ecdh_tmp; |
@@ -1873,77 +1701,60 @@ void ssl_set_cert_masks(CERT *c, const SSL_CIPHER *cipher) | |||
1873 | dh_dsa_export=(dh_dsa && EVP_PKEY_size(cpk->privatekey)*8 <= kl); | 1701 | dh_dsa_export=(dh_dsa && EVP_PKEY_size(cpk->privatekey)*8 <= kl); |
1874 | cpk= &(c->pkeys[SSL_PKEY_ECC]); | 1702 | cpk= &(c->pkeys[SSL_PKEY_ECC]); |
1875 | have_ecc_cert= (cpk->x509 != NULL && cpk->privatekey != NULL); | 1703 | have_ecc_cert= (cpk->x509 != NULL && cpk->privatekey != NULL); |
1876 | mask_k=0; | 1704 | mask=0; |
1877 | mask_a=0; | 1705 | emask=0; |
1878 | emask_k=0; | ||
1879 | emask_a=0; | ||
1880 | |||
1881 | |||
1882 | 1706 | ||
1883 | #ifdef CIPHER_DEBUG | 1707 | #ifdef CIPHER_DEBUG |
1884 | printf("rt=%d rte=%d dht=%d ecdht=%d re=%d ree=%d rs=%d ds=%d dhr=%d dhd=%d\n", | 1708 | printf("rt=%d rte=%d dht=%d re=%d ree=%d rs=%d ds=%d dhr=%d dhd=%d\n", |
1885 | rsa_tmp,rsa_tmp_export,dh_tmp,have_ecdh_tmp, | 1709 | rsa_tmp,rsa_tmp_export,dh_tmp, |
1886 | rsa_enc,rsa_enc_export,rsa_sign,dsa_sign,dh_rsa,dh_dsa); | 1710 | rsa_enc,rsa_enc_export,rsa_sign,dsa_sign,dh_rsa,dh_dsa); |
1887 | #endif | 1711 | #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 | } | ||
1899 | 1712 | ||
1900 | if (rsa_enc || (rsa_tmp && rsa_sign)) | 1713 | if (rsa_enc || (rsa_tmp && rsa_sign)) |
1901 | mask_k|=SSL_kRSA; | 1714 | mask|=SSL_kRSA; |
1902 | if (rsa_enc_export || (rsa_tmp_export && (rsa_sign || rsa_enc))) | 1715 | if (rsa_enc_export || (rsa_tmp_export && (rsa_sign || rsa_enc))) |
1903 | emask_k|=SSL_kRSA; | 1716 | emask|=SSL_kRSA; |
1904 | 1717 | ||
1905 | #if 0 | 1718 | #if 0 |
1906 | /* The match needs to be both kEDH and aRSA or aDSA, so don't worry */ | 1719 | /* The match needs to be both kEDH and aRSA or aDSA, so don't worry */ |
1907 | if ( (dh_tmp || dh_rsa || dh_dsa) && | 1720 | if ( (dh_tmp || dh_rsa || dh_dsa) && |
1908 | (rsa_enc || rsa_sign || dsa_sign)) | 1721 | (rsa_enc || rsa_sign || dsa_sign)) |
1909 | mask_k|=SSL_kEDH; | 1722 | mask|=SSL_kEDH; |
1910 | if ((dh_tmp_export || dh_rsa_export || dh_dsa_export) && | 1723 | if ((dh_tmp_export || dh_rsa_export || dh_dsa_export) && |
1911 | (rsa_enc || rsa_sign || dsa_sign)) | 1724 | (rsa_enc || rsa_sign || dsa_sign)) |
1912 | emask_k|=SSL_kEDH; | 1725 | emask|=SSL_kEDH; |
1913 | #endif | 1726 | #endif |
1914 | 1727 | ||
1915 | if (dh_tmp_export) | 1728 | if (dh_tmp_export) |
1916 | emask_k|=SSL_kEDH; | 1729 | emask|=SSL_kEDH; |
1917 | 1730 | ||
1918 | if (dh_tmp) | 1731 | if (dh_tmp) |
1919 | mask_k|=SSL_kEDH; | 1732 | mask|=SSL_kEDH; |
1920 | 1733 | ||
1921 | if (dh_rsa) mask_k|=SSL_kDHr; | 1734 | if (dh_rsa) mask|=SSL_kDHr; |
1922 | if (dh_rsa_export) emask_k|=SSL_kDHr; | 1735 | if (dh_rsa_export) emask|=SSL_kDHr; |
1923 | 1736 | ||
1924 | if (dh_dsa) mask_k|=SSL_kDHd; | 1737 | if (dh_dsa) mask|=SSL_kDHd; |
1925 | if (dh_dsa_export) emask_k|=SSL_kDHd; | 1738 | if (dh_dsa_export) emask|=SSL_kDHd; |
1926 | 1739 | ||
1927 | if (rsa_enc || rsa_sign) | 1740 | if (rsa_enc || rsa_sign) |
1928 | { | 1741 | { |
1929 | mask_a|=SSL_aRSA; | 1742 | mask|=SSL_aRSA; |
1930 | emask_a|=SSL_aRSA; | 1743 | emask|=SSL_aRSA; |
1931 | } | 1744 | } |
1932 | 1745 | ||
1933 | if (dsa_sign) | 1746 | if (dsa_sign) |
1934 | { | 1747 | { |
1935 | mask_a|=SSL_aDSS; | 1748 | mask|=SSL_aDSS; |
1936 | emask_a|=SSL_aDSS; | 1749 | emask|=SSL_aDSS; |
1937 | } | 1750 | } |
1938 | 1751 | ||
1939 | mask_a|=SSL_aNULL; | 1752 | mask|=SSL_aNULL; |
1940 | emask_a|=SSL_aNULL; | 1753 | emask|=SSL_aNULL; |
1941 | 1754 | ||
1942 | #ifndef OPENSSL_NO_KRB5 | 1755 | #ifndef OPENSSL_NO_KRB5 |
1943 | mask_k|=SSL_kKRB5; | 1756 | mask|=SSL_kKRB5|SSL_aKRB5; |
1944 | mask_a|=SSL_aKRB5; | 1757 | emask|=SSL_kKRB5|SSL_aKRB5; |
1945 | emask_k|=SSL_kKRB5; | ||
1946 | emask_a|=SSL_aKRB5; | ||
1947 | #endif | 1758 | #endif |
1948 | 1759 | ||
1949 | /* An ECC certificate may be usable for ECDH and/or | 1760 | /* An ECC certificate may be usable for ECDH and/or |
@@ -1951,7 +1762,7 @@ void ssl_set_cert_masks(CERT *c, const SSL_CIPHER *cipher) | |||
1951 | */ | 1762 | */ |
1952 | if (have_ecc_cert) | 1763 | if (have_ecc_cert) |
1953 | { | 1764 | { |
1954 | /* This call populates extension flags (ex_flags) */ | 1765 | /* This call populates extension flags (ex_flags) */ |
1955 | x = (c->pkeys[SSL_PKEY_ECC]).x509; | 1766 | x = (c->pkeys[SSL_PKEY_ECC]).x509; |
1956 | X509_check_purpose(x, -1, 0); | 1767 | X509_check_purpose(x, -1, 0); |
1957 | ecdh_ok = (x->ex_flags & EXFLAG_KUSAGE) ? | 1768 | ecdh_ok = (x->ex_flags & EXFLAG_KUSAGE) ? |
@@ -1959,7 +1770,7 @@ void ssl_set_cert_masks(CERT *c, const SSL_CIPHER *cipher) | |||
1959 | ecdsa_ok = (x->ex_flags & EXFLAG_KUSAGE) ? | 1770 | ecdsa_ok = (x->ex_flags & EXFLAG_KUSAGE) ? |
1960 | (x->ex_kusage & X509v3_KU_DIGITAL_SIGNATURE) : 1; | 1771 | (x->ex_kusage & X509v3_KU_DIGITAL_SIGNATURE) : 1; |
1961 | ecc_pkey = X509_get_pubkey(x); | 1772 | ecc_pkey = X509_get_pubkey(x); |
1962 | ecc_pkey_size = (ecc_pkey != NULL) ? | 1773 | ecc_pkey_size = (ecc_pkey != NULL) ? |
1963 | EVP_PKEY_bits(ecc_pkey) : 0; | 1774 | EVP_PKEY_bits(ecc_pkey) : 0; |
1964 | EVP_PKEY_free(ecc_pkey); | 1775 | EVP_PKEY_free(ecc_pkey); |
1965 | if ((x->sig_alg) && (x->sig_alg->algorithm)) | 1776 | if ((x->sig_alg) && (x->sig_alg->algorithm)) |
@@ -1967,41 +1778,27 @@ void ssl_set_cert_masks(CERT *c, const SSL_CIPHER *cipher) | |||
1967 | #ifndef OPENSSL_NO_ECDH | 1778 | #ifndef OPENSSL_NO_ECDH |
1968 | if (ecdh_ok) | 1779 | if (ecdh_ok) |
1969 | { | 1780 | { |
1970 | const char *sig = OBJ_nid2ln(signature_nid); | 1781 | if ((signature_nid == NID_md5WithRSAEncryption) || |
1971 | if (sig == NULL) | 1782 | (signature_nid == NID_md4WithRSAEncryption) || |
1972 | { | 1783 | (signature_nid == NID_md2WithRSAEncryption)) |
1973 | ERR_clear_error(); | ||
1974 | sig = "unknown"; | ||
1975 | } | ||
1976 | |||
1977 | if (strstr(sig, "WithRSA")) | ||
1978 | { | 1784 | { |
1979 | mask_k|=SSL_kECDHr; | 1785 | mask|=SSL_kECDH|SSL_aRSA; |
1980 | mask_a|=SSL_aECDH; | ||
1981 | if (ecc_pkey_size <= 163) | 1786 | if (ecc_pkey_size <= 163) |
1982 | { | 1787 | emask|=SSL_kECDH|SSL_aRSA; |
1983 | emask_k|=SSL_kECDHr; | ||
1984 | emask_a|=SSL_aECDH; | ||
1985 | } | ||
1986 | } | 1788 | } |
1987 | |||
1988 | if (signature_nid == NID_ecdsa_with_SHA1) | 1789 | if (signature_nid == NID_ecdsa_with_SHA1) |
1989 | { | 1790 | { |
1990 | mask_k|=SSL_kECDHe; | 1791 | mask|=SSL_kECDH|SSL_aECDSA; |
1991 | mask_a|=SSL_aECDH; | ||
1992 | if (ecc_pkey_size <= 163) | 1792 | if (ecc_pkey_size <= 163) |
1993 | { | 1793 | emask|=SSL_kECDH|SSL_aECDSA; |
1994 | emask_k|=SSL_kECDHe; | ||
1995 | emask_a|=SSL_aECDH; | ||
1996 | } | ||
1997 | } | 1794 | } |
1998 | } | 1795 | } |
1999 | #endif | 1796 | #endif |
2000 | #ifndef OPENSSL_NO_ECDSA | 1797 | #ifndef OPENSSL_NO_ECDSA |
2001 | if (ecdsa_ok) | 1798 | if (ecdsa_ok) |
2002 | { | 1799 | { |
2003 | mask_a|=SSL_aECDSA; | 1800 | mask|=SSL_aECDSA; |
2004 | emask_a|=SSL_aECDSA; | 1801 | emask|=SSL_aECDSA; |
2005 | } | 1802 | } |
2006 | #endif | 1803 | #endif |
2007 | } | 1804 | } |
@@ -2009,22 +1806,12 @@ void ssl_set_cert_masks(CERT *c, const SSL_CIPHER *cipher) | |||
2009 | #ifndef OPENSSL_NO_ECDH | 1806 | #ifndef OPENSSL_NO_ECDH |
2010 | if (have_ecdh_tmp) | 1807 | if (have_ecdh_tmp) |
2011 | { | 1808 | { |
2012 | mask_k|=SSL_kEECDH; | 1809 | mask|=SSL_kECDHE; |
2013 | emask_k|=SSL_kEECDH; | 1810 | emask|=SSL_kECDHE; |
2014 | } | 1811 | } |
2015 | #endif | 1812 | #endif |
2016 | 1813 | c->mask=mask; | |
2017 | #ifndef OPENSSL_NO_PSK | 1814 | c->export_mask=emask; |
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; | ||
2028 | c->valid=1; | 1815 | c->valid=1; |
2029 | } | 1816 | } |
2030 | 1817 | ||
@@ -2032,18 +1819,13 @@ void ssl_set_cert_masks(CERT *c, const SSL_CIPHER *cipher) | |||
2032 | #define ku_reject(x, usage) \ | 1819 | #define ku_reject(x, usage) \ |
2033 | (((x)->ex_flags & EXFLAG_KUSAGE) && !((x)->ex_kusage & (usage))) | 1820 | (((x)->ex_flags & EXFLAG_KUSAGE) && !((x)->ex_kusage & (usage))) |
2034 | 1821 | ||
2035 | #ifndef OPENSSL_NO_EC | 1822 | int check_srvr_ecc_cert_and_alg(X509 *x, SSL_CIPHER *cs) |
2036 | |||
2037 | int ssl_check_srvr_ecc_cert_and_alg(X509 *x, const SSL_CIPHER *cs) | ||
2038 | { | 1823 | { |
2039 | unsigned long alg_k, alg_a; | 1824 | unsigned long alg = cs->algorithms; |
2040 | EVP_PKEY *pkey = NULL; | 1825 | EVP_PKEY *pkey = NULL; |
2041 | int keysize = 0; | 1826 | int keysize = 0; |
2042 | int signature_nid = 0; | 1827 | int signature_nid = 0; |
2043 | 1828 | ||
2044 | alg_k = cs->algorithm_mkey; | ||
2045 | alg_a = cs->algorithm_auth; | ||
2046 | |||
2047 | if (SSL_C_IS_EXPORT(cs)) | 1829 | if (SSL_C_IS_EXPORT(cs)) |
2048 | { | 1830 | { |
2049 | /* ECDH key length in export ciphers must be <= 163 bits */ | 1831 | /* ECDH key length in export ciphers must be <= 163 bits */ |
@@ -2058,46 +1840,37 @@ int ssl_check_srvr_ecc_cert_and_alg(X509 *x, const SSL_CIPHER *cs) | |||
2058 | X509_check_purpose(x, -1, 0); | 1840 | X509_check_purpose(x, -1, 0); |
2059 | if ((x->sig_alg) && (x->sig_alg->algorithm)) | 1841 | if ((x->sig_alg) && (x->sig_alg->algorithm)) |
2060 | signature_nid = OBJ_obj2nid(x->sig_alg->algorithm); | 1842 | signature_nid = OBJ_obj2nid(x->sig_alg->algorithm); |
2061 | if (alg_k & SSL_kECDHe || alg_k & SSL_kECDHr) | 1843 | if (alg & SSL_kECDH) |
2062 | { | 1844 | { |
2063 | /* key usage, if present, must allow key agreement */ | 1845 | /* key usage, if present, must allow key agreement */ |
2064 | if (ku_reject(x, X509v3_KU_KEY_AGREEMENT)) | 1846 | if (ku_reject(x, X509v3_KU_KEY_AGREEMENT)) |
2065 | { | 1847 | { |
2066 | SSLerr(SSL_F_SSL_CHECK_SRVR_ECC_CERT_AND_ALG, SSL_R_ECC_CERT_NOT_FOR_KEY_AGREEMENT); | ||
2067 | return 0; | 1848 | return 0; |
2068 | } | 1849 | } |
2069 | if (alg_k & SSL_kECDHe) | 1850 | if (alg & SSL_aECDSA) |
2070 | { | 1851 | { |
2071 | /* signature alg must be ECDSA */ | 1852 | /* signature alg must be ECDSA */ |
2072 | if (signature_nid != NID_ecdsa_with_SHA1) | 1853 | if (signature_nid != NID_ecdsa_with_SHA1) |
2073 | { | 1854 | { |
2074 | SSLerr(SSL_F_SSL_CHECK_SRVR_ECC_CERT_AND_ALG, SSL_R_ECC_CERT_SHOULD_HAVE_SHA1_SIGNATURE); | ||
2075 | return 0; | 1855 | return 0; |
2076 | } | 1856 | } |
2077 | } | 1857 | } |
2078 | if (alg_k & SSL_kECDHr) | 1858 | if (alg & SSL_aRSA) |
2079 | { | 1859 | { |
2080 | /* signature alg must be RSA */ | 1860 | /* signature alg must be RSA */ |
2081 | 1861 | if ((signature_nid != NID_md5WithRSAEncryption) && | |
2082 | const char *sig = OBJ_nid2ln(signature_nid); | 1862 | (signature_nid != NID_md4WithRSAEncryption) && |
2083 | if (sig == NULL) | 1863 | (signature_nid != NID_md2WithRSAEncryption)) |
2084 | { | ||
2085 | ERR_clear_error(); | ||
2086 | sig = "unknown"; | ||
2087 | } | ||
2088 | if (strstr(sig, "WithRSA") == NULL) | ||
2089 | { | 1864 | { |
2090 | SSLerr(SSL_F_SSL_CHECK_SRVR_ECC_CERT_AND_ALG, SSL_R_ECC_CERT_SHOULD_HAVE_RSA_SIGNATURE); | ||
2091 | return 0; | 1865 | return 0; |
2092 | } | 1866 | } |
2093 | } | 1867 | } |
2094 | } | 1868 | } |
2095 | if (alg_a & SSL_aECDSA) | 1869 | else if (alg & SSL_aECDSA) |
2096 | { | 1870 | { |
2097 | /* key usage, if present, must allow signing */ | 1871 | /* key usage, if present, must allow signing */ |
2098 | if (ku_reject(x, X509v3_KU_DIGITAL_SIGNATURE)) | 1872 | if (ku_reject(x, X509v3_KU_DIGITAL_SIGNATURE)) |
2099 | { | 1873 | { |
2100 | SSLerr(SSL_F_SSL_CHECK_SRVR_ECC_CERT_AND_ALG, SSL_R_ECC_CERT_NOT_FOR_SIGNING); | ||
2101 | return 0; | 1874 | return 0; |
2102 | } | 1875 | } |
2103 | } | 1876 | } |
@@ -2105,74 +1878,58 @@ int ssl_check_srvr_ecc_cert_and_alg(X509 *x, const SSL_CIPHER *cs) | |||
2105 | return 1; /* all checks are ok */ | 1878 | return 1; /* all checks are ok */ |
2106 | } | 1879 | } |
2107 | 1880 | ||
2108 | #endif | ||
2109 | |||
2110 | /* THIS NEEDS CLEANING UP */ | 1881 | /* THIS NEEDS CLEANING UP */ |
2111 | X509 *ssl_get_server_send_cert(SSL *s) | 1882 | X509 *ssl_get_server_send_cert(SSL *s) |
2112 | { | 1883 | { |
2113 | unsigned long alg_k,alg_a,mask_k,mask_a; | 1884 | unsigned long alg,mask,kalg; |
2114 | CERT *c; | 1885 | CERT *c; |
2115 | int i,is_export; | 1886 | int i,is_export; |
2116 | 1887 | ||
2117 | c=s->cert; | 1888 | c=s->cert; |
2118 | ssl_set_cert_masks(c, s->s3->tmp.new_cipher); | 1889 | ssl_set_cert_masks(c, s->s3->tmp.new_cipher); |
1890 | alg=s->s3->tmp.new_cipher->algorithms; | ||
2119 | is_export=SSL_C_IS_EXPORT(s->s3->tmp.new_cipher); | 1891 | is_export=SSL_C_IS_EXPORT(s->s3->tmp.new_cipher); |
2120 | if (is_export) | 1892 | mask=is_export?c->export_mask:c->mask; |
2121 | { | 1893 | kalg=alg&(SSL_MKEY_MASK|SSL_AUTH_MASK); |
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; | ||
2133 | 1894 | ||
2134 | if (alg_k & (SSL_kECDHr|SSL_kECDHe)) | 1895 | if (kalg & SSL_kECDH) |
2135 | { | 1896 | { |
2136 | /* we don't need to look at SSL_kEECDH | 1897 | /* we don't need to look at SSL_kECDHE |
2137 | * since no certificate is needed for | 1898 | * since no certificate is needed for |
2138 | * anon ECDH and for authenticated | 1899 | * anon ECDH and for authenticated |
2139 | * EECDH, the check for the auth | 1900 | * ECDHE, the check for the auth |
2140 | * algorithm will set i correctly | 1901 | * algorithm will set i correctly |
2141 | * NOTE: For ECDH-RSA, we need an ECC | 1902 | * NOTE: For ECDH-RSA, we need an ECC |
2142 | * not an RSA cert but for EECDH-RSA | 1903 | * not an RSA cert but for ECDHE-RSA |
2143 | * we need an RSA cert. Placing the | 1904 | * we need an RSA cert. Placing the |
2144 | * checks for SSL_kECDH before RSA | 1905 | * checks for SSL_kECDH before RSA |
2145 | * checks ensures the correct cert is chosen. | 1906 | * checks ensures the correct cert is chosen. |
2146 | */ | 1907 | */ |
2147 | i=SSL_PKEY_ECC; | 1908 | i=SSL_PKEY_ECC; |
2148 | } | 1909 | } |
2149 | else if (alg_a & SSL_aECDSA) | 1910 | else if (kalg & SSL_aECDSA) |
2150 | { | 1911 | { |
2151 | i=SSL_PKEY_ECC; | 1912 | i=SSL_PKEY_ECC; |
2152 | } | 1913 | } |
2153 | else if (alg_k & SSL_kDHr) | 1914 | else if (kalg & SSL_kDHr) |
2154 | i=SSL_PKEY_DH_RSA; | 1915 | i=SSL_PKEY_DH_RSA; |
2155 | else if (alg_k & SSL_kDHd) | 1916 | else if (kalg & SSL_kDHd) |
2156 | i=SSL_PKEY_DH_DSA; | 1917 | i=SSL_PKEY_DH_DSA; |
2157 | else if (alg_a & SSL_aDSS) | 1918 | else if (kalg & SSL_aDSS) |
2158 | i=SSL_PKEY_DSA_SIGN; | 1919 | i=SSL_PKEY_DSA_SIGN; |
2159 | else if (alg_a & SSL_aRSA) | 1920 | else if (kalg & SSL_aRSA) |
2160 | { | 1921 | { |
2161 | if (c->pkeys[SSL_PKEY_RSA_ENC].x509 == NULL) | 1922 | if (c->pkeys[SSL_PKEY_RSA_ENC].x509 == NULL) |
2162 | i=SSL_PKEY_RSA_SIGN; | 1923 | i=SSL_PKEY_RSA_SIGN; |
2163 | else | 1924 | else |
2164 | i=SSL_PKEY_RSA_ENC; | 1925 | i=SSL_PKEY_RSA_ENC; |
2165 | } | 1926 | } |
2166 | else if (alg_a & SSL_aKRB5) | 1927 | else if (kalg & SSL_aKRB5) |
2167 | { | 1928 | { |
2168 | /* VRS something else here? */ | 1929 | /* VRS something else here? */ |
2169 | return(NULL); | 1930 | return(NULL); |
2170 | } | 1931 | } |
2171 | else if (alg_a & SSL_aGOST94) | 1932 | else /* if (kalg & SSL_aNULL) */ |
2172 | i=SSL_PKEY_GOST94; | ||
2173 | else if (alg_a & SSL_aGOST01) | ||
2174 | i=SSL_PKEY_GOST01; | ||
2175 | else /* if (alg_a & SSL_aNULL) */ | ||
2176 | { | 1933 | { |
2177 | SSLerr(SSL_F_SSL_GET_SERVER_SEND_CERT,ERR_R_INTERNAL_ERROR); | 1934 | SSLerr(SSL_F_SSL_GET_SERVER_SEND_CERT,ERR_R_INTERNAL_ERROR); |
2178 | return(NULL); | 1935 | return(NULL); |
@@ -2182,18 +1939,18 @@ X509 *ssl_get_server_send_cert(SSL *s) | |||
2182 | return(c->pkeys[i].x509); | 1939 | return(c->pkeys[i].x509); |
2183 | } | 1940 | } |
2184 | 1941 | ||
2185 | EVP_PKEY *ssl_get_sign_pkey(SSL *s,const SSL_CIPHER *cipher) | 1942 | EVP_PKEY *ssl_get_sign_pkey(SSL *s,SSL_CIPHER *cipher) |
2186 | { | 1943 | { |
2187 | unsigned long alg_a; | 1944 | unsigned long alg; |
2188 | CERT *c; | 1945 | CERT *c; |
2189 | 1946 | ||
2190 | alg_a = cipher->algorithm_auth; | 1947 | alg=cipher->algorithms; |
2191 | c=s->cert; | 1948 | c=s->cert; |
2192 | 1949 | ||
2193 | if ((alg_a & SSL_aDSS) && | 1950 | if ((alg & SSL_aDSS) && |
2194 | (c->pkeys[SSL_PKEY_DSA_SIGN].privatekey != NULL)) | 1951 | (c->pkeys[SSL_PKEY_DSA_SIGN].privatekey != NULL)) |
2195 | return(c->pkeys[SSL_PKEY_DSA_SIGN].privatekey); | 1952 | return(c->pkeys[SSL_PKEY_DSA_SIGN].privatekey); |
2196 | else if (alg_a & SSL_aRSA) | 1953 | else if (alg & SSL_aRSA) |
2197 | { | 1954 | { |
2198 | if (c->pkeys[SSL_PKEY_RSA_SIGN].privatekey != NULL) | 1955 | if (c->pkeys[SSL_PKEY_RSA_SIGN].privatekey != NULL) |
2199 | return(c->pkeys[SSL_PKEY_RSA_SIGN].privatekey); | 1956 | return(c->pkeys[SSL_PKEY_RSA_SIGN].privatekey); |
@@ -2202,10 +1959,10 @@ EVP_PKEY *ssl_get_sign_pkey(SSL *s,const SSL_CIPHER *cipher) | |||
2202 | else | 1959 | else |
2203 | return(NULL); | 1960 | return(NULL); |
2204 | } | 1961 | } |
2205 | else if ((alg_a & SSL_aECDSA) && | 1962 | else if ((alg & SSL_aECDSA) && |
2206 | (c->pkeys[SSL_PKEY_ECC].privatekey != NULL)) | 1963 | (c->pkeys[SSL_PKEY_ECC].privatekey != NULL)) |
2207 | return(c->pkeys[SSL_PKEY_ECC].privatekey); | 1964 | return(c->pkeys[SSL_PKEY_ECC].privatekey); |
2208 | else /* if (alg_a & SSL_aNULL) */ | 1965 | else /* if (alg & SSL_aNULL) */ |
2209 | { | 1966 | { |
2210 | SSLerr(SSL_F_SSL_GET_SIGN_PKEY,ERR_R_INTERNAL_ERROR); | 1967 | SSLerr(SSL_F_SSL_GET_SIGN_PKEY,ERR_R_INTERNAL_ERROR); |
2211 | return(NULL); | 1968 | return(NULL); |
@@ -2220,14 +1977,14 @@ void ssl_update_cache(SSL *s,int mode) | |||
2220 | * and it would be rather hard to do anyway :-) */ | 1977 | * and it would be rather hard to do anyway :-) */ |
2221 | if (s->session->session_id_length == 0) return; | 1978 | if (s->session->session_id_length == 0) return; |
2222 | 1979 | ||
2223 | i=s->session_ctx->session_cache_mode; | 1980 | i=s->ctx->session_cache_mode; |
2224 | if ((i & mode) && (!s->hit) | 1981 | if ((i & mode) && (!s->hit) |
2225 | && ((i & SSL_SESS_CACHE_NO_INTERNAL_STORE) | 1982 | && ((i & SSL_SESS_CACHE_NO_INTERNAL_STORE) |
2226 | || SSL_CTX_add_session(s->session_ctx,s->session)) | 1983 | || SSL_CTX_add_session(s->ctx,s->session)) |
2227 | && (s->session_ctx->new_session_cb != NULL)) | 1984 | && (s->ctx->new_session_cb != NULL)) |
2228 | { | 1985 | { |
2229 | CRYPTO_add(&s->session->references,1,CRYPTO_LOCK_SSL_SESSION); | 1986 | CRYPTO_add(&s->session->references,1,CRYPTO_LOCK_SSL_SESSION); |
2230 | if (!s->session_ctx->new_session_cb(s,s->session)) | 1987 | if (!s->ctx->new_session_cb(s,s->session)) |
2231 | SSL_SESSION_free(s->session); | 1988 | SSL_SESSION_free(s->session); |
2232 | } | 1989 | } |
2233 | 1990 | ||
@@ -2236,20 +1993,20 @@ void ssl_update_cache(SSL *s,int mode) | |||
2236 | ((i & mode) == mode)) | 1993 | ((i & mode) == mode)) |
2237 | { | 1994 | { |
2238 | if ( (((mode & SSL_SESS_CACHE_CLIENT) | 1995 | if ( (((mode & SSL_SESS_CACHE_CLIENT) |
2239 | ?s->session_ctx->stats.sess_connect_good | 1996 | ?s->ctx->stats.sess_connect_good |
2240 | :s->session_ctx->stats.sess_accept_good) & 0xff) == 0xff) | 1997 | :s->ctx->stats.sess_accept_good) & 0xff) == 0xff) |
2241 | { | 1998 | { |
2242 | SSL_CTX_flush_sessions(s->session_ctx,(unsigned long)time(NULL)); | 1999 | SSL_CTX_flush_sessions(s->ctx,(unsigned long)time(NULL)); |
2243 | } | 2000 | } |
2244 | } | 2001 | } |
2245 | } | 2002 | } |
2246 | 2003 | ||
2247 | const SSL_METHOD *SSL_get_ssl_method(SSL *s) | 2004 | SSL_METHOD *SSL_get_ssl_method(SSL *s) |
2248 | { | 2005 | { |
2249 | return(s->method); | 2006 | return(s->method); |
2250 | } | 2007 | } |
2251 | 2008 | ||
2252 | int SSL_set_ssl_method(SSL *s, const SSL_METHOD *meth) | 2009 | int SSL_set_ssl_method(SSL *s,SSL_METHOD *meth) |
2253 | { | 2010 | { |
2254 | int conn= -1; | 2011 | int conn= -1; |
2255 | int ret=1; | 2012 | int ret=1; |
@@ -2392,8 +2149,6 @@ void SSL_set_accept_state(SSL *s) | |||
2392 | s->handshake_func=s->method->ssl_accept; | 2149 | s->handshake_func=s->method->ssl_accept; |
2393 | /* clear the current cipher */ | 2150 | /* clear the current cipher */ |
2394 | ssl_clear_cipher_ctx(s); | 2151 | ssl_clear_cipher_ctx(s); |
2395 | ssl_clear_hash_ctx(&s->read_hash); | ||
2396 | ssl_clear_hash_ctx(&s->write_hash); | ||
2397 | } | 2152 | } |
2398 | 2153 | ||
2399 | void SSL_set_connect_state(SSL *s) | 2154 | void SSL_set_connect_state(SSL *s) |
@@ -2404,8 +2159,6 @@ void SSL_set_connect_state(SSL *s) | |||
2404 | s->handshake_func=s->method->ssl_connect; | 2159 | s->handshake_func=s->method->ssl_connect; |
2405 | /* clear the current cipher */ | 2160 | /* clear the current cipher */ |
2406 | ssl_clear_cipher_ctx(s); | 2161 | ssl_clear_cipher_ctx(s); |
2407 | ssl_clear_hash_ctx(&s->read_hash); | ||
2408 | ssl_clear_hash_ctx(&s->write_hash); | ||
2409 | } | 2162 | } |
2410 | 2163 | ||
2411 | int ssl_undefined_function(SSL *s) | 2164 | int ssl_undefined_function(SSL *s) |
@@ -2450,7 +2203,7 @@ SSL *SSL_dup(SSL *s) | |||
2450 | X509_NAME *xn; | 2203 | X509_NAME *xn; |
2451 | SSL *ret; | 2204 | SSL *ret; |
2452 | int i; | 2205 | int i; |
2453 | 2206 | ||
2454 | if ((ret=SSL_new(SSL_get_SSL_CTX(s))) == NULL) | 2207 | if ((ret=SSL_new(SSL_get_SSL_CTX(s))) == NULL) |
2455 | return(NULL); | 2208 | return(NULL); |
2456 | 2209 | ||
@@ -2620,7 +2373,7 @@ EVP_PKEY *SSL_get_privatekey(SSL *s) | |||
2620 | return(NULL); | 2373 | return(NULL); |
2621 | } | 2374 | } |
2622 | 2375 | ||
2623 | const SSL_CIPHER *SSL_get_current_cipher(const SSL *s) | 2376 | SSL_CIPHER *SSL_get_current_cipher(const SSL *s) |
2624 | { | 2377 | { |
2625 | if ((s->session != NULL) && (s->session->cipher != NULL)) | 2378 | if ((s->session != NULL) && (s->session->cipher != NULL)) |
2626 | return(s->session->cipher); | 2379 | return(s->session->cipher); |
@@ -2698,7 +2451,7 @@ void ssl_free_wbio_buffer(SSL *s) | |||
2698 | s->wbio=BIO_pop(s->wbio); | 2451 | s->wbio=BIO_pop(s->wbio); |
2699 | #ifdef REF_CHECK /* not the usual REF_CHECK, but this avoids adding one more preprocessor symbol */ | 2452 | #ifdef REF_CHECK /* not the usual REF_CHECK, but this avoids adding one more preprocessor symbol */ |
2700 | assert(s->wbio != NULL); | 2453 | assert(s->wbio != NULL); |
2701 | #endif | 2454 | #endif |
2702 | } | 2455 | } |
2703 | BIO_free(s->bbio); | 2456 | BIO_free(s->bbio); |
2704 | s->bbio=NULL; | 2457 | s->bbio=NULL; |
@@ -2783,7 +2536,7 @@ void SSL_set_info_callback(SSL *ssl, | |||
2783 | 2536 | ||
2784 | /* One compiler (Diab DCC) doesn't like argument names in returned | 2537 | /* One compiler (Diab DCC) doesn't like argument names in returned |
2785 | function pointer. */ | 2538 | function pointer. */ |
2786 | void (*SSL_get_info_callback(const SSL *ssl))(const SSL * /*ssl*/,int /*type*/,int /*val*/) | 2539 | void (*SSL_get_info_callback(const SSL *ssl))(const SSL * /*ssl*/,int /*type*/,int /*val*/) |
2787 | { | 2540 | { |
2788 | return ssl->info_callback; | 2541 | return ssl->info_callback; |
2789 | } | 2542 | } |
@@ -2904,13 +2657,13 @@ RSA *cb(SSL *ssl,int is_export,int keylength) | |||
2904 | 2657 | ||
2905 | #ifndef OPENSSL_NO_DH | 2658 | #ifndef OPENSSL_NO_DH |
2906 | void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,DH *(*dh)(SSL *ssl,int is_export, | 2659 | void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,DH *(*dh)(SSL *ssl,int is_export, |
2907 | int keylength)) | 2660 | int keylength)) |
2908 | { | 2661 | { |
2909 | SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_DH_CB,(void (*)(void))dh); | 2662 | SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_DH_CB,(void (*)(void))dh); |
2910 | } | 2663 | } |
2911 | 2664 | ||
2912 | void SSL_set_tmp_dh_callback(SSL *ssl,DH *(*dh)(SSL *ssl,int is_export, | 2665 | void SSL_set_tmp_dh_callback(SSL *ssl,DH *(*dh)(SSL *ssl,int is_export, |
2913 | int keylength)) | 2666 | int keylength)) |
2914 | { | 2667 | { |
2915 | SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_DH_CB,(void (*)(void))dh); | 2668 | SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_DH_CB,(void (*)(void))dh); |
2916 | } | 2669 | } |
@@ -2918,109 +2671,18 @@ void SSL_set_tmp_dh_callback(SSL *ssl,DH *(*dh)(SSL *ssl,int is_export, | |||
2918 | 2671 | ||
2919 | #ifndef OPENSSL_NO_ECDH | 2672 | #ifndef OPENSSL_NO_ECDH |
2920 | void SSL_CTX_set_tmp_ecdh_callback(SSL_CTX *ctx,EC_KEY *(*ecdh)(SSL *ssl,int is_export, | 2673 | void SSL_CTX_set_tmp_ecdh_callback(SSL_CTX *ctx,EC_KEY *(*ecdh)(SSL *ssl,int is_export, |
2921 | int keylength)) | 2674 | int keylength)) |
2922 | { | 2675 | { |
2923 | SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_ECDH_CB,(void (*)(void))ecdh); | 2676 | SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_ECDH_CB,(void (*)(void))ecdh); |
2924 | } | 2677 | } |
2925 | 2678 | ||
2926 | void SSL_set_tmp_ecdh_callback(SSL *ssl,EC_KEY *(*ecdh)(SSL *ssl,int is_export, | 2679 | void SSL_set_tmp_ecdh_callback(SSL *ssl,EC_KEY *(*ecdh)(SSL *ssl,int is_export, |
2927 | int keylength)) | 2680 | int keylength)) |
2928 | { | 2681 | { |
2929 | SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_ECDH_CB,(void (*)(void))ecdh); | 2682 | SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_ECDH_CB,(void (*)(void))ecdh); |
2930 | } | 2683 | } |
2931 | #endif | 2684 | #endif |
2932 | 2685 | ||
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 | ||
3024 | 2686 | ||
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)) | 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)) |
3026 | { | 2688 | { |
@@ -3031,25 +2693,7 @@ void SSL_set_msg_callback(SSL *ssl, void (*cb)(int write_p, int version, int con | |||
3031 | SSL_callback_ctrl(ssl, SSL_CTRL_SET_MSG_CALLBACK, (void (*)(void))cb); | 2693 | SSL_callback_ctrl(ssl, SSL_CTRL_SET_MSG_CALLBACK, (void (*)(void))cb); |
3032 | } | 2694 | } |
3033 | 2695 | ||
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 | { | ||
3049 | 2696 | ||
3050 | if (*hash) EVP_MD_CTX_destroy(*hash); | ||
3051 | *hash=NULL; | ||
3052 | } | ||
3053 | 2697 | ||
3054 | #if defined(_WINDLL) && defined(OPENSSL_SYS_WIN16) | 2698 | #if defined(_WINDLL) && defined(OPENSSL_SYS_WIN16) |
3055 | #include "../crypto/bio/bss_file.c" | 2699 | #include "../crypto/bio/bss_file.c" |
@@ -3057,6 +2701,3 @@ void ssl_clear_hash_ctx(EVP_MD_CTX **hash) | |||
3057 | 2701 | ||
3058 | IMPLEMENT_STACK_OF(SSL_CIPHER) | 2702 | IMPLEMENT_STACK_OF(SSL_CIPHER) |
3059 | IMPLEMENT_STACK_OF(SSL_COMP) | 2703 | IMPLEMENT_STACK_OF(SSL_COMP) |
3060 | IMPLEMENT_OBJ_BSEARCH_GLOBAL_CMP_FN(SSL_CIPHER, SSL_CIPHER, | ||
3061 | ssl_cipher_id); | ||
3062 | |||