Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(418)

Side by Side Diff: net/third_party/nss/ssl/ssl3con.c

Issue 6804032: Add TLS-SRP (RFC 5054) support Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: remove "httpsv" scheme, minor NSS/OpenSSL changes Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/third_party/nss/ssl/ssl.def ('k') | net/third_party/nss/ssl/ssl3ecc.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * SSL3 Protocol 2 * SSL3 Protocol
3 * 3 *
4 * ***** BEGIN LICENSE BLOCK ***** 4 * ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * 6 *
7 * The contents of this file are subject to the Mozilla Public License Version 7 * The contents of this file are subject to the Mozilla Public License Version
8 * 1.1 (the "License"); you may not use this file except in compliance with 8 * 1.1 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at 9 * the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/ 10 * http://www.mozilla.org/MPL/
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 { TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 111 { TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
112 { TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 112 { TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
113 { TLS_DHE_RSA_WITH_AES_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 113 { TLS_DHE_RSA_WITH_AES_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
114 { TLS_DHE_DSS_WITH_AES_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 114 { TLS_DHE_DSS_WITH_AES_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
115 #ifdef NSS_ENABLE_ECC 115 #ifdef NSS_ENABLE_ECC
116 { TLS_ECDH_RSA_WITH_AES_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 116 { TLS_ECDH_RSA_WITH_AES_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
117 { TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 117 { TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
118 #endif /* NSS_ENABLE_ECC */ 118 #endif /* NSS_ENABLE_ECC */
119 { TLS_RSA_WITH_CAMELLIA_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 119 { TLS_RSA_WITH_CAMELLIA_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
120 { TLS_RSA_WITH_AES_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 120 { TLS_RSA_WITH_AES_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
121 { TLS_SRP_SHA_WITH_AES_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
122 { TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
123 { TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
121 124
122 #ifdef NSS_ENABLE_ECC 125 #ifdef NSS_ENABLE_ECC
123 { TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 126 { TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
124 { TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 127 { TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
125 { TLS_ECDHE_RSA_WITH_RC4_128_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 128 { TLS_ECDHE_RSA_WITH_RC4_128_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
126 { TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 129 { TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
127 #endif /* NSS_ENABLE_ECC */ 130 #endif /* NSS_ENABLE_ECC */
128 { TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 131 { TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
129 { TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 132 { TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
130 { TLS_DHE_DSS_WITH_RC4_128_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 133 { TLS_DHE_DSS_WITH_RC4_128_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
131 { TLS_DHE_RSA_WITH_AES_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 134 { TLS_DHE_RSA_WITH_AES_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
132 { TLS_DHE_DSS_WITH_AES_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 135 { TLS_DHE_DSS_WITH_AES_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
133 #ifdef NSS_ENABLE_ECC 136 #ifdef NSS_ENABLE_ECC
134 { TLS_ECDH_RSA_WITH_RC4_128_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 137 { TLS_ECDH_RSA_WITH_RC4_128_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
135 { TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 138 { TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
136 { TLS_ECDH_ECDSA_WITH_RC4_128_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 139 { TLS_ECDH_ECDSA_WITH_RC4_128_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
137 { TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 140 { TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
138 #endif /* NSS_ENABLE_ECC */ 141 #endif /* NSS_ENABLE_ECC */
139 { TLS_RSA_WITH_SEED_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 142 { TLS_RSA_WITH_SEED_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
140 { TLS_RSA_WITH_CAMELLIA_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 143 { TLS_RSA_WITH_CAMELLIA_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
141 { SSL_RSA_WITH_RC4_128_MD5, SSL_NOT_ALLOWED, PR_TRUE, PR_FALSE}, 144 { SSL_RSA_WITH_RC4_128_MD5, SSL_NOT_ALLOWED, PR_TRUE, PR_FALSE},
142 { SSL_RSA_WITH_RC4_128_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 145 { SSL_RSA_WITH_RC4_128_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
143 { TLS_RSA_WITH_AES_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 146 { TLS_RSA_WITH_AES_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
147 { TLS_SRP_SHA_WITH_AES_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
148 { TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
149 { TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
144 150
145 #ifdef NSS_ENABLE_ECC 151 #ifdef NSS_ENABLE_ECC
146 { TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 152 { TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
147 { TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 153 { TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
148 #endif /* NSS_ENABLE_ECC */ 154 #endif /* NSS_ENABLE_ECC */
155 { TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
149 { SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 156 { SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
150 { SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 157 { SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
151 #ifdef NSS_ENABLE_ECC 158 #ifdef NSS_ENABLE_ECC
152 { TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 159 { TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
153 { TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 160 { TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
154 #endif /* NSS_ENABLE_ECC */ 161 #endif /* NSS_ENABLE_ECC */
155 { SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA, SSL_NOT_ALLOWED, PR_TRUE, PR_FALSE}, 162 { SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA, SSL_NOT_ALLOWED, PR_TRUE, PR_FALSE},
156 { SSL_RSA_WITH_3DES_EDE_CBC_SHA, SSL_NOT_ALLOWED, PR_TRUE, PR_FALSE}, 163 { SSL_RSA_WITH_3DES_EDE_CBC_SHA, SSL_NOT_ALLOWED, PR_TRUE, PR_FALSE},
164 { TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
165 { TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
157 166
158 167
159 { SSL_DHE_RSA_WITH_DES_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 168 { SSL_DHE_RSA_WITH_DES_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
160 { SSL_DHE_DSS_WITH_DES_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 169 { SSL_DHE_DSS_WITH_DES_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
161 { SSL_RSA_FIPS_WITH_DES_CBC_SHA, SSL_NOT_ALLOWED, PR_TRUE, PR_FALSE}, 170 { SSL_RSA_FIPS_WITH_DES_CBC_SHA, SSL_NOT_ALLOWED, PR_TRUE, PR_FALSE},
162 { SSL_RSA_WITH_DES_CBC_SHA, SSL_NOT_ALLOWED, PR_TRUE, PR_FALSE}, 171 { SSL_RSA_WITH_DES_CBC_SHA, SSL_NOT_ALLOWED, PR_TRUE, PR_FALSE},
163 { TLS_RSA_EXPORT1024_WITH_RC4_56_SHA, SSL_NOT_ALLOWED, PR_TRUE, PR_FALSE}, 172 { TLS_RSA_EXPORT1024_WITH_RC4_56_SHA, SSL_NOT_ALLOWED, PR_TRUE, PR_FALSE},
164 { TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA, SSL_NOT_ALLOWED, PR_TRUE, PR_FALSE}, 173 { TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA, SSL_NOT_ALLOWED, PR_TRUE, PR_FALSE},
165 174
166 { SSL_RSA_EXPORT_WITH_RC4_40_MD5, SSL_NOT_ALLOWED, PR_TRUE, PR_FALSE}, 175 { SSL_RSA_EXPORT_WITH_RC4_40_MD5, SSL_NOT_ALLOWED, PR_TRUE, PR_FALSE},
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 {kea_dh_dss_export, kt_dh, sign_dsa, PR_TRUE, 512, PR_FALSE}, 285 {kea_dh_dss_export, kt_dh, sign_dsa, PR_TRUE, 512, PR_FALSE},
277 {kea_dh_rsa, kt_dh, sign_rsa, PR_FALSE, 0, PR_FALSE}, 286 {kea_dh_rsa, kt_dh, sign_rsa, PR_FALSE, 0, PR_FALSE},
278 {kea_dh_rsa_export, kt_dh, sign_rsa, PR_TRUE, 512, PR_FALSE}, 287 {kea_dh_rsa_export, kt_dh, sign_rsa, PR_TRUE, 512, PR_FALSE},
279 {kea_dhe_dss, kt_dh, sign_dsa, PR_FALSE, 0, PR_FALSE}, 288 {kea_dhe_dss, kt_dh, sign_dsa, PR_FALSE, 0, PR_FALSE},
280 {kea_dhe_dss_export, kt_dh, sign_dsa, PR_TRUE, 512, PR_FALSE}, 289 {kea_dhe_dss_export, kt_dh, sign_dsa, PR_TRUE, 512, PR_FALSE},
281 {kea_dhe_rsa, kt_dh, sign_rsa, PR_FALSE, 0, PR_FALSE}, 290 {kea_dhe_rsa, kt_dh, sign_rsa, PR_FALSE, 0, PR_FALSE},
282 {kea_dhe_rsa_export, kt_dh, sign_rsa, PR_TRUE, 512, PR_FALSE}, 291 {kea_dhe_rsa_export, kt_dh, sign_rsa, PR_TRUE, 512, PR_FALSE},
283 {kea_dh_anon, kt_dh, sign_null, PR_FALSE, 0, PR_FALSE}, 292 {kea_dh_anon, kt_dh, sign_null, PR_FALSE, 0, PR_FALSE},
284 {kea_dh_anon_export, kt_dh, sign_null, PR_TRUE, 512, PR_FALSE}, 293 {kea_dh_anon_export, kt_dh, sign_null, PR_TRUE, 512, PR_FALSE},
285 {kea_rsa_fips, kt_rsa, sign_rsa, PR_FALSE, 0, PR_TRUE }, 294 {kea_rsa_fips, kt_rsa, sign_rsa, PR_FALSE, 0, PR_TRUE },
295 {kea_srp, kt_srp, sign_null, PR_FALSE, 0, PR_FALSE},
296 {kea_srp_rsa, kt_srp, sign_rsa, PR_FALSE, 0, PR_FALSE},
297 {kea_srp_dss, kt_srp, sign_dsa, PR_FALSE, 0, PR_FALSE},
286 #ifdef NSS_ENABLE_ECC 298 #ifdef NSS_ENABLE_ECC
287 {kea_ecdh_ecdsa, kt_ecdh, sign_ecdsa, PR_FALSE, 0, PR_FALSE}, 299 {kea_ecdh_ecdsa, kt_ecdh, sign_ecdsa, PR_FALSE, 0, PR_FALSE},
288 {kea_ecdhe_ecdsa, kt_ecdh, sign_ecdsa, PR_FALSE, 0, PR_FALSE}, 300 {kea_ecdhe_ecdsa, kt_ecdh, sign_ecdsa, PR_FALSE, 0, PR_FALSE},
289 {kea_ecdh_rsa, kt_ecdh, sign_rsa, PR_FALSE, 0, PR_FALSE}, 301 {kea_ecdh_rsa, kt_ecdh, sign_rsa, PR_FALSE, 0, PR_FALSE},
290 {kea_ecdhe_rsa, kt_ecdh, sign_rsa, PR_FALSE, 0, PR_FALSE}, 302 {kea_ecdhe_rsa, kt_ecdh, sign_rsa, PR_FALSE, 0, PR_FALSE},
291 {kea_ecdh_anon, kt_ecdh, sign_null, PR_FALSE, 0, PR_FALSE}, 303 {kea_ecdh_anon, kt_ecdh, sign_null, PR_FALSE, 0, PR_FALSE},
292 #endif /* NSS_ENABLE_ECC */ 304 #endif /* NSS_ENABLE_ECC */
293 }; 305 };
294 306
295 /* must use ssl_LookupCipherSuiteDef to access */ 307 /* must use ssl_LookupCipherSuiteDef to access */
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 {SSL_DH_ANON_EXPORT_RC4_40_MD5, cipher_rc4_40, mac_md5, kea_dh_anon_export}, 349 {SSL_DH_ANON_EXPORT_RC4_40_MD5, cipher_rc4_40, mac_md5, kea_dh_anon_export},
338 {SSL_DH_ANON_EXPORT_RC4_40_MD5, cipher_rc4, mac_md5, kea_dh_anon_export}, 350 {SSL_DH_ANON_EXPORT_RC4_40_MD5, cipher_rc4, mac_md5, kea_dh_anon_export},
339 {SSL_DH_ANON_EXPORT_WITH_DES40_CBC_SHA, 351 {SSL_DH_ANON_EXPORT_WITH_DES40_CBC_SHA,
340 cipher_des40, mac_sha, kea_dh_anon_export}, 352 cipher_des40, mac_sha, kea_dh_anon_export},
341 {SSL_DH_ANON_DES_CBC_SHA, cipher_des, mac_sha, kea_dh_anon}, 353 {SSL_DH_ANON_DES_CBC_SHA, cipher_des, mac_sha, kea_dh_anon},
342 {SSL_DH_ANON_3DES_CBC_SHA, cipher_3des, mac_sha, kea_dh_anon}, 354 {SSL_DH_ANON_3DES_CBC_SHA, cipher_3des, mac_sha, kea_dh_anon},
343 #endif 355 #endif
344 356
345 357
346 /* New TLS cipher suites */ 358 /* New TLS cipher suites */
359 {TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA, cipher_3des, mac_sha, kea_srp},
360 {TLS_SRP_SHA_WITH_AES_128_CBC_SHA, cipher_aes_128, mac_sha, kea_srp},
361 {TLS_SRP_SHA_WITH_AES_256_CBC_SHA, cipher_aes_256, mac_sha, kea_srp},
362 {TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA,
363 cipher_3des, mac_sha, kea_srp_rsa},
364 {TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA,
365 cipher_3des, mac_sha, kea_srp_dss},
366 {TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA,
367 cipher_aes_128, mac_sha, kea_srp_rsa},
368 {TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA,
369 cipher_aes_128, mac_sha, kea_srp_dss},
370 {TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA,
371 cipher_aes_256, mac_sha, kea_srp_rsa},
372 {TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA,
373 cipher_aes_256, mac_sha, kea_srp_dss},
347 {TLS_RSA_WITH_AES_128_CBC_SHA, cipher_aes_128, mac_sha, kea_rsa}, 374 {TLS_RSA_WITH_AES_128_CBC_SHA, cipher_aes_128, mac_sha, kea_rsa},
348 {TLS_DHE_DSS_WITH_AES_128_CBC_SHA, cipher_aes_128, mac_sha, kea_dhe_dss}, 375 {TLS_DHE_DSS_WITH_AES_128_CBC_SHA, cipher_aes_128, mac_sha, kea_dhe_dss},
349 {TLS_DHE_RSA_WITH_AES_128_CBC_SHA, cipher_aes_128, mac_sha, kea_dhe_rsa}, 376 {TLS_DHE_RSA_WITH_AES_128_CBC_SHA, cipher_aes_128, mac_sha, kea_dhe_rsa},
350 {TLS_RSA_WITH_AES_256_CBC_SHA, cipher_aes_256, mac_sha, kea_rsa}, 377 {TLS_RSA_WITH_AES_256_CBC_SHA, cipher_aes_256, mac_sha, kea_rsa},
351 {TLS_DHE_DSS_WITH_AES_256_CBC_SHA, cipher_aes_256, mac_sha, kea_dhe_dss}, 378 {TLS_DHE_DSS_WITH_AES_256_CBC_SHA, cipher_aes_256, mac_sha, kea_dhe_dss},
352 {TLS_DHE_RSA_WITH_AES_256_CBC_SHA, cipher_aes_256, mac_sha, kea_dhe_rsa}, 379 {TLS_DHE_RSA_WITH_AES_256_CBC_SHA, cipher_aes_256, mac_sha, kea_dhe_rsa},
353 #if 0 380 #if 0
354 {TLS_DH_DSS_WITH_AES_128_CBC_SHA, cipher_aes_128, mac_sha, kea_dh_dss}, 381 {TLS_DH_DSS_WITH_AES_128_CBC_SHA, cipher_aes_128, mac_sha, kea_dh_dss},
355 {TLS_DH_RSA_WITH_AES_128_CBC_SHA, cipher_aes_128, mac_sha, kea_dh_rsa}, 382 {TLS_DH_RSA_WITH_AES_128_CBC_SHA, cipher_aes_128, mac_sha, kea_dh_rsa},
356 {TLS_DH_ANON_WITH_AES_128_CBC_SHA, cipher_aes_128, mac_sha, kea_dh_anon}, 383 {TLS_DH_ANON_WITH_AES_128_CBC_SHA, cipher_aes_128, mac_sha, kea_dh_anon},
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 {TLS_ECDH_anon_WITH_AES_256_CBC_SHA, cipher_aes_256, mac_sha, kea_ecdh_anon }, 440 {TLS_ECDH_anon_WITH_AES_256_CBC_SHA, cipher_aes_256, mac_sha, kea_ecdh_anon },
414 #endif 441 #endif
415 #endif /* NSS_ENABLE_ECC */ 442 #endif /* NSS_ENABLE_ECC */
416 }; 443 };
417 444
418 static const CK_MECHANISM_TYPE kea_alg_defs[] = { 445 static const CK_MECHANISM_TYPE kea_alg_defs[] = {
419 0x80000000L, 446 0x80000000L,
420 CKM_RSA_PKCS, 447 CKM_RSA_PKCS,
421 CKM_DH_PKCS_DERIVE, 448 CKM_DH_PKCS_DERIVE,
422 CKM_KEA_KEY_DERIVE, 449 CKM_KEA_KEY_DERIVE,
423 CKM_ECDH1_DERIVE 450 CKM_ECDH1_DERIVE,
451 CKM_NSS_SRP_DERIVE
424 }; 452 };
425 453
426 typedef struct SSLCipher2MechStr { 454 typedef struct SSLCipher2MechStr {
427 SSLCipherAlgorithm calg; 455 SSLCipherAlgorithm calg;
428 CK_MECHANISM_TYPE cmech; 456 CK_MECHANISM_TYPE cmech;
429 } SSLCipher2Mech; 457 } SSLCipher2Mech;
430 458
431 /* indexed by type SSLCipherAlgorithm */ 459 /* indexed by type SSLCipherAlgorithm */
432 static const SSLCipher2Mech alg2Mech[] = { 460 static const SSLCipher2Mech alg2Mech[] = {
433 /* calg, cmech */ 461 /* calg, cmech */
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 * we could support both key exchange mechanisms 716 * we could support both key exchange mechanisms
689 * simultaneously. For now, both of them use 717 * simultaneously. For now, both of them use
690 * whatever is in the certificate slot for kt_ecdh 718 * whatever is in the certificate slot for kt_ecdh
691 */ 719 */
692 default: 720 default:
693 svrAuth = ss->serverCerts + exchKeyType; 721 svrAuth = ss->serverCerts + exchKeyType;
694 break; 722 break;
695 } 723 }
696 #endif /* NSS_ENABLE_ECC */ 724 #endif /* NSS_ENABLE_ECC */
697 725
726 /* XXX this should be merged with switch(kea) from above */
727 switch (cipher_def->key_exchange_alg) {
728 case kea_srp_rsa:
729 svrAuth = ss->serverCerts + kt_rsa;
730 break;
731 case kea_srp_dss:
732 svrAuth = ss->serverCerts + kt_null; /* don't ask me..*/
733 break;
734 default:
735 svrAuth = ss->serverCerts + exchKeyType;
736 break;
737 }
738
739
698 /* Mark the suites that are backed by real tokens, certs and keys */ 740 /* Mark the suites that are backed by real tokens, certs and keys */
699 suite->isPresent = (PRBool) 741 suite->isPresent = (PRBool)
700 (((exchKeyType == kt_null) || 742 (((exchKeyType == kt_null) ||
701 ((!isServer || (svrAuth->serverKeyPair && 743 ((!isServer || (svrAuth->serverKeyPair &&
702 svrAuth->SERVERKEY && 744 svrAuth->SERVERKEY &&
703 » » » » svrAuth->serverCertChain)) && 745 » » » » svrAuth->serverCertChain) ||
746 cipher_def->key_exchange_alg == kea_srp) &&
704 PK11_TokenExists(kea_alg_defs[exchKeyType]))) && 747 PK11_TokenExists(kea_alg_defs[exchKeyType]))) &&
705 ((cipher_alg == calg_null) || PK11_TokenExists(cipher_mech))); 748 ((cipher_alg == calg_null) || PK11_TokenExists(cipher_mech)));
706 if (suite->isPresent) 749 if (suite->isPresent)
707 ++numPresent; 750 ++numPresent;
708 } 751 }
709 } 752 }
710 PORT_Assert(numPresent > 0 || numEnabled == 0); 753 PORT_Assert(numPresent > 0 || numEnabled == 0);
711 if (numPresent <= 0) { 754 if (numPresent <= 0) {
712 PORT_SetError(SSL_ERROR_NO_CIPHERS_SUPPORTED); 755 PORT_SetError(SSL_ERROR_NO_CIPHERS_SUPPORTED);
713 } 756 }
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 1116
1074 PRINT_BUF(95, (NULL, "RSAkey hash: ", hashBuf, bufLen)); 1117 PRINT_BUF(95, (NULL, "RSAkey hash: ", hashBuf, bufLen));
1075 PRINT_BUF(95, (NULL, "RSAkey hash: MD5 result", hashes->md5, MD5_LENGTH)); 1118 PRINT_BUF(95, (NULL, "RSAkey hash: MD5 result", hashes->md5, MD5_LENGTH));
1076 PRINT_BUF(95, (NULL, "RSAkey hash: SHA1 result", hashes->sha, SHA1_LENGTH)); 1119 PRINT_BUF(95, (NULL, "RSAkey hash: SHA1 result", hashes->sha, SHA1_LENGTH));
1077 1120
1078 if (hashBuf != buf && hashBuf != NULL) 1121 if (hashBuf != buf && hashBuf != NULL)
1079 PORT_Free(hashBuf); 1122 PORT_Free(hashBuf);
1080 return rv; 1123 return rv;
1081 } 1124 }
1082 1125
1126 /* Caller must set hiLevel error code.
1127 * Called from ssl3_SendSRPServerKeyExchange */
1128 static SECStatus
1129 ssl3_ComputeSRPKeyHash(SECItem *N, SECItem *g, SECItem *s, SECItem *B,
1130 SSL3Random *client_rand, SSL3Random *server_rand,
1131 SSL3Hashes *hashes, PRBool bypassPKCS11)
1132 {
1133 PRUint8 * hashBuf;
1134 PRUint8 * pBuf;
1135 SECStatus rv = SECFailure;
1136 unsigned int bufLen;
1137
1138 bufLen = 2*SSL3_RANDOM_LENGTH + N->len + 2 + g->len + 2
1139 + s->len + 1 + B->len + 2;
1140
1141 hashBuf = PORT_Alloc(bufLen);
1142 if (!hashBuf) {
1143 return SECFailure;
1144 }
1145
1146 memcpy(hashBuf, client_rand, SSL3_RANDOM_LENGTH);
1147 pBuf = hashBuf + SSL3_RANDOM_LENGTH;
1148 memcpy(pBuf, server_rand, SSL3_RANDOM_LENGTH);
1149 pBuf += SSL3_RANDOM_LENGTH;
1150 pBuf[0] = (PRUint8)(N->len >> 8);
1151 pBuf[1] = (PRUint8)(N->len);
1152 pBuf+=2;
1153 memcpy(pBuf, N->data, N->len);
1154 pBuf += N->len;
1155 pBuf[0] = (PRUint8)(g->len >> 8);
1156 pBuf[1] = (PRUint8)(g->len);
1157 pBuf+=2;
1158 memcpy(pBuf, g->data, g->len);
1159 pBuf += g->len;
1160 pBuf[0] = (PRUint8)(s->len);
1161 pBuf+=1;
1162 memcpy(pBuf, s->data, s->len);
1163 pBuf += s->len;
1164 pBuf[0] = (PRUint8)(B->len >> 8);
1165 pBuf[1] = (PRUint8)(B->len);
1166 pBuf+=2;
1167 memcpy(pBuf, B->data, B->len);
1168 pBuf += B->len;
1169
1170 rv = ssl3_ComputeCommonKeyHash(hashBuf, bufLen, hashes, bypassPKCS11);
1171
1172 if (hashBuf)
1173 PORT_Free(hashBuf);
1174 return rv;
1175 }
1176
1083 /* Caller must set hiLevel error code. */ 1177 /* Caller must set hiLevel error code. */
1084 /* Called from ssl3_HandleServerKeyExchange. */ 1178 /* Called from ssl3_HandleServerKeyExchange. */
1085 static SECStatus 1179 static SECStatus
1086 ssl3_ComputeDHKeyHash(SECItem dh_p, SECItem dh_g, SECItem dh_Ys, 1180 ssl3_ComputeDHKeyHash(SECItem dh_p, SECItem dh_g, SECItem dh_Ys,
1087 SSL3Random *client_rand, SSL3Random *server_rand, 1181 SSL3Random *client_rand, SSL3Random *server_rand,
1088 SSL3Hashes *hashes, PRBool bypassPKCS11) 1182 SSL3Hashes *hashes, PRBool bypassPKCS11)
1089 { 1183 {
1090 PRUint8 * hashBuf; 1184 PRUint8 * hashBuf;
1091 PRUint8 * pBuf; 1185 PRUint8 * pBuf;
1092 SECStatus rv = SECSuccess; 1186 SECStatus rv = SECSuccess;
(...skipping 1563 matching lines...) Expand 10 before | Expand all | Expand 10 after
2656 case unsupported_extension: 2750 case unsupported_extension:
2657 error = SSL_ERROR_UNSUPPORTED_EXTENSION_ALERT; break; 2751 error = SSL_ERROR_UNSUPPORTED_EXTENSION_ALERT; break;
2658 case certificate_unobtainable: 2752 case certificate_unobtainable:
2659 error = SSL_ERROR_CERTIFICATE_UNOBTAINABLE_ALERT; break; 2753 error = SSL_ERROR_CERTIFICATE_UNOBTAINABLE_ALERT; break;
2660 case unrecognized_name: 2754 case unrecognized_name:
2661 error = SSL_ERROR_UNRECOGNIZED_NAME_ALERT; break; 2755 error = SSL_ERROR_UNRECOGNIZED_NAME_ALERT; break;
2662 case bad_certificate_status_response: 2756 case bad_certificate_status_response:
2663 error = SSL_ERROR_BAD_CERT_STATUS_RESPONSE_ALERT; break; 2757 error = SSL_ERROR_BAD_CERT_STATUS_RESPONSE_ALERT; break;
2664 case bad_certificate_hash_value: 2758 case bad_certificate_hash_value:
2665 error = SSL_ERROR_BAD_CERT_HASH_VALUE_ALERT; break; 2759 error = SSL_ERROR_BAD_CERT_HASH_VALUE_ALERT; break;
2760 case unknown_psk_identity:
2761 error = SSL_ERROR_UNKNOWN_PSK_IDENTITY_ALERT; break;
2666 default: error = SSL_ERROR_RX_UNKNOWN_ALERT; break; 2762 default: error = SSL_ERROR_RX_UNKNOWN_ALERT; break;
2667 } 2763 }
2668 if (level == alert_fatal) { 2764 if (level == alert_fatal) {
2669 ss->sec.uncache(ss->sec.ci.sid); 2765 ss->sec.uncache(ss->sec.ci.sid);
2670 if ((ss->ssl3.hs.ws == wait_server_hello) && 2766 if ((ss->ssl3.hs.ws == wait_server_hello) &&
2671 (desc == handshake_failure)) { 2767 (desc == handshake_failure)) {
2672 /* XXX This is a hack. We're assuming that any handshake failure 2768 /* XXX This is a hack. We're assuming that any handshake failure
2673 * XXX on the client hello is a failure to match ciphers. 2769 * XXX on the client hello is a failure to match ciphers.
2674 */ 2770 */
2675 error = SSL_ERROR_NO_CYPHER_OVERLAP; 2771 error = SSL_ERROR_NO_CYPHER_OVERLAP;
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
2821 unsigned char * cr = (unsigned char *)&ss->ssl3.hs.client_random; 2917 unsigned char * cr = (unsigned char *)&ss->ssl3.hs.client_random;
2822 unsigned char * sr = (unsigned char *)&ss->ssl3.hs.server_random; 2918 unsigned char * sr = (unsigned char *)&ss->ssl3.hs.server_random;
2823 PRBool isTLS = (PRBool)(kea_def->tls_keygen || 2919 PRBool isTLS = (PRBool)(kea_def->tls_keygen ||
2824 (pwSpec->version > SSL_LIBRARY_VERSION_3_0)); 2920 (pwSpec->version > SSL_LIBRARY_VERSION_3_0));
2825 /* 2921 /*
2826 * Whenever isDH is true, we need to use CKM_TLS_MASTER_KEY_DERIVE_DH 2922 * Whenever isDH is true, we need to use CKM_TLS_MASTER_KEY_DERIVE_DH
2827 * which, unlike CKM_TLS_MASTER_KEY_DERIVE, converts arbitrary size 2923 * which, unlike CKM_TLS_MASTER_KEY_DERIVE, converts arbitrary size
2828 * data into a 48-byte value. 2924 * data into a 48-byte value.
2829 */ 2925 */
2830 PRBool isDH = (PRBool) ((ss->ssl3.hs.kea_def->exchKeyType == kt_dh) || 2926 PRBool isDH = (PRBool) ((ss->ssl3.hs.kea_def->exchKeyType == kt_dh) ||
2831 » (ss->ssl3.hs.kea_def->exchKeyType == kt_ecdh)); 2927 » (ss->ssl3.hs.kea_def->exchKeyType == kt_ecdh) ||
2928 (ss->ssl3.hs.kea_def->exchKeyType == kt_srp));
2832 SECStatus rv = SECFailure; 2929 SECStatus rv = SECFailure;
2833 CK_MECHANISM_TYPE master_derive; 2930 CK_MECHANISM_TYPE master_derive;
2834 CK_MECHANISM_TYPE key_derive; 2931 CK_MECHANISM_TYPE key_derive;
2835 SECItem params; 2932 SECItem params;
2836 CK_FLAGS keyFlags; 2933 CK_FLAGS keyFlags;
2837 CK_VERSION pms_version; 2934 CK_VERSION pms_version;
2838 CK_SSL3_MASTER_KEY_DERIVE_PARAMS master_params; 2935 CK_SSL3_MASTER_KEY_DERIVE_PARAMS master_params;
2839 2936
2840 PORT_Assert( ss->opt.noLocks || ssl_HaveSSL3HandshakeLock(ss)); 2937 PORT_Assert( ss->opt.noLocks || ssl_HaveSSL3HandshakeLock(ss));
2841 PORT_Assert( ss->opt.noLocks || ssl_HaveSpecWriteLock(ss)); 2938 PORT_Assert( ss->opt.noLocks || ssl_HaveSpecWriteLock(ss));
(...skipping 1884 matching lines...) Expand 10 before | Expand all | Expand 10 after
4726 4823
4727 4824
4728 loser: 4825 loser:
4729 4826
4730 if(pms) PK11_FreeSymKey(pms); 4827 if(pms) PK11_FreeSymKey(pms);
4731 if(privKey) SECKEY_DestroyPrivateKey(privKey); 4828 if(privKey) SECKEY_DestroyPrivateKey(privKey);
4732 if(pubKey) SECKEY_DestroyPublicKey(pubKey); 4829 if(pubKey) SECKEY_DestroyPublicKey(pubKey);
4733 return rv; 4830 return rv;
4734 } 4831 }
4735 4832
4736 4833 /* Read srp values from datastream and verify the signature
4737 4834 * if requiried by cipher. Save parameters to ss->sec.peerKey.
4835 *
4836 * called from ssl3_HandleServerKeyExchange
4837 */
4838 static SECStatus
4839 ssl3_HandleSRPServerKeyExchange(sslSocket *ss, SSL3Opaque *b,
4840 PRUint32 length) {
4841
4842 SECItem signature = {siBuffer, NULL, 0};
4843 PRArenaPool *arena = NULL;
4844 SECKEYPublicKey *peerKey = NULL;
4845 SECStatus rv;
4846 SSL3Hashes hashes;
4847 » SECItem srp_N, srp_g, srp_s, srp_ppub;
4848 int errCode;
4849
4850 rv = ssl3_ConsumeHandshakeVariable(ss, &srp_N, 2, &b, &length);
4851 if (rv != SECSuccess) {
4852 » goto loser;»» /* malformed. */
4853 » }
4854 rv = ssl3_ConsumeHandshakeVariable(ss, &srp_g, 2, &b, &length);
4855 if (rv != SECSuccess) {
4856 » goto loser;»» /* malformed. */
4857 » }
4858 rv = ssl3_ConsumeHandshakeVariable(ss, &srp_s, 1, &b, &length);
4859 if (rv != SECSuccess) {
4860 » goto loser;»» /* malformed. */
4861 » }
4862 rv = ssl3_ConsumeHandshakeVariable(ss, &srp_ppub, 2, &b, &length);
4863 if (rv != SECSuccess) {
4864 » goto loser;»» /* malformed. */
4865 » }
4866
4867 if (ss->ssl3.hs.kea_def->kea != kea_srp) { /* there MUST be a signature */
4868 rv = ssl3_ConsumeHandshakeVariable(ss, &signature, 2, &b, &length);
4869 if (rv != SECSuccess) {
4870 goto loser;» » /* malformed. */
4871 }
4872 rv = ssl3_ComputeSRPKeyHash(&srp_N, &srp_g, &srp_s, &srp_ppub,
4873 &ss->ssl3.hs.client_random,
4874 » » » &ss->ssl3.hs.server_random,
4875 » » » &hashes, ss->opt.bypassPKCS11);
4876 if (rv != SECSuccess) {
4877 » errCode = ssl_MapLowLevelError(SSL_ERROR_SERVER_KEY_EXCHANGE_FAILURE );
4878 » goto alert_loser;
4879 » }
4880 rv = ssl3_VerifySignedHashes(&hashes, ss->sec.peerCert, &signature,
4881 » » » PR_TRUE, ss->pkcs11P inArg);
4882 » if (rv != SECSuccess) {
4883 » errCode = ssl_MapLowLevelError(SSL_ERROR_SERVER_KEY_EXCHANGE_FAILURE );
4884 » goto alert_loser;
4885 }
4886 }
4887
4888 /* all ok, save and return */
4889 arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE);
4890 » if (arena == NULL) {
4891 return SECFailure;
4892 » }
4893 ss->sec.peerKey = peerKey = PORT_ArenaZNew(arena, SECKEYPublicKey);
4894 if (peerKey == NULL) {
4895 return SECFailure;
4896 » }
4897 » peerKey->arena = arena;
4898 » peerKey->keyType = srpKey;
4899 » peerKey->pkcs11Slot = NULL;
4900 » peerKey->pkcs11ID = CK_INVALID_HANDLE;
4901
4902 » if (SECITEM_CopyItem(arena, &peerKey->u.srp.N, &srp_N) ||
4903 » SECITEM_CopyItem(arena, &peerKey->u.srp.g, &srp_g) ||
4904 » SECITEM_CopyItem(arena, &peerKey->u.srp.s, &srp_s) ||
4905 » SECITEM_CopyItem(arena, &peerKey->u.srp.ppub, &srp_ppub)) {
4906 return SECFailure;
4907 }
4908 return SECSuccess;
4909
4910 alert_loser:
4911 (void)SSL3_SendAlert(ss, alert_fatal, illegal_parameter);
4912 loser:
4913 PORT_SetError(errCode);
4914 return SECFailure;
4915 }
4916
4917 /* Calculate ClientKeyExchange and Pre-Master-Secret via SRP_GenKeys(),
4918 * then send ClientKeyExchange and derive SSL master key
4919 *
4920 * called from ssl3_SendClientKeyExchange()
4921 */
4922 static SECStatus
4923 ssl3_SendSRPClientKeyExchange(sslSocket *ss, SECKEYPublicKey * pubKey) {
4924
4925 SECKEYSRPParams *srpParam;
4926 SECStatus rv;
4927
4928 PORT_Assert( ss->opt.noLocks || ssl_HaveSSL3HandshakeLock(ss) );
4929 PORT_Assert( ss->opt.noLocks || ssl_HaveXmitBufLock(ss));
4930
4931 srpParam = PORT_ZAlloc(sizeof(SECKEYSRPParams));
4932 if (!srpParam) {
4933 ssl_MapLowLevelError(SSL_ERROR_SERVER_KEY_EXCHANGE_FAILURE);
4934 goto loser;
4935 }
4936
4937 /* PW-Callback overrides SSL_SetUserLogin. If both fail to
4938 * provide a password, the token must know it or fail. */
4939 if (ss->getUserPasswd) {
4940 if (!ss->sec.userPasswd)
4941 ss->sec.userPasswd = SECITEM_AllocItem(NULL,NULL,0);
4942 SECITEM_FreeItem(ss->sec.userPasswd, PR_FALSE);
4943 ss->getUserPasswd(ss->fd, ss->sec.userPasswd, ss->getUserPasswdArg);
4944 }
4945 if (ss->sec.userPasswd) {
4946 srpParam->secret.data = ss->sec.userPasswd->data;
4947 srpParam->secret.len = ss->sec.userPasswd->len;
4948 ss->sec.userPasswd = NULL;
4949 }
4950
4951 /* calculate client key pair and PMS, then send key exchange data */
4952 if (ss->opt.bypassPKCS11) {
4953 SECItem pms = {0, NULL, 0};
4954 SRPPrivateKey *prvKey;
4955 SRPKeyPairParams keyPairParam;
4956 keyPairParam.N.data = pubKey->u.srp.N.data;
4957 keyPairParam.N.len = pubKey->u.srp.N.len;
4958 keyPairParam.g.data = pubKey->u.srp.g.data;
4959 keyPairParam.g.len = pubKey->u.srp.g.len;
4960 keyPairParam.secret.data = srpParam->secret.data;
4961 keyPairParam.secret.len = srpParam->secret.len;
4962
4963 rv = SRP_NewClientKeyPair(&prvKey, &keyPairParam);
4964 if (rv != SECSuccess) goto loser; /* err set by SRP_ClientDerive */
4965
4966 SRPDeriveParams deriveParam;
4967 deriveParam.N.data = pubKey->u.srp.N.data;
4968 deriveParam.N.len = pubKey->u.srp.N.len;
4969 deriveParam.g.data = pubKey->u.srp.g.data;
4970 deriveParam.g.len = pubKey->u.srp.g.len;
4971 deriveParam.s.data = pubKey->u.srp.s.data;
4972 deriveParam.s.len = pubKey->u.srp.s.len;
4973 deriveParam.u.data = ss->sec.userName->data;
4974 deriveParam.u.len = ss->sec.userName->len;
4975 deriveParam.ppub.data= pubKey->u.srp.ppub.data;
4976 deriveParam.ppub.len = pubKey->u.srp.ppub.len;
4977
4978
4979 if (SECSuccess != SRP_ClientDerive(prvKey, &deriveParam, &pms)) {
4980 goto derive_fail;
4981 }
4982
4983 /* client key exchange data */
4984 rv = ssl3_AppendHandshakeHeader(ss, client_key_exchange,
4985 prvKey->pubKey.len + 2);
4986 if (rv != SECSuccess) goto loser; /* err set by ssl3_AppendHandshake* */
4987 rv = ssl3_AppendHandshakeVariable(ss, prvKey->pubKey.data,
4988 prvKey->pubKey.len, 2);
4989 if (rv != SECSuccess) goto loser; /* err set by ssl3_AppendHandshake* */
4990
4991 /* init pending cipher spec*/
4992 rv = ssl3_MasterKeyDeriveBypass(ss->ssl3.pwSpec,
4993 (unsigned char *)&ss->ssl3.hs.client_random,
4994 (unsigned char *)&ss->ssl3.hs.server_random,
4995 &pms, PR_TRUE, PR_FALSE);
4996 if (rv != SECSuccess) {
4997 ss->ssl3.pwSpec->msItem.data = ss->ssl3.pwSpec->raw_master_secret;
4998 ss->ssl3.pwSpec->msItem.len = SSL3_MASTER_SECRET_LENGTH;
4999 PK11_GenerateRandom(ss->ssl3.pwSpec->msItem.data,
5000 SSL3_MASTER_SECRET_LENGTH);
5001 }
5002 rv = ssl3_InitPendingCipherSpec(ss, NULL);
5003
5004 SECITEM_FreeItem(&pms, PR_FALSE);
5005 PORT_FreeArena(prvKey->arena, PR_TRUE);
5006 } else { /* PK11 path */
5007 PK11SymKey *pms = NULL;
5008 SECKEYPrivateKey *prvKey = NULL;
5009 SECKEYPublicKey *newPub = NULL;
5010
5011 srpParam->N.data = pubKey->u.srp.N.data;
5012 srpParam->N.len = pubKey->u.srp.N.len;
5013 srpParam->g.data = pubKey->u.srp.g.data;
5014 srpParam->g.len = pubKey->u.srp.g.len;
5015 srpParam->s.data = pubKey->u.srp.s.data;
5016 srpParam->s.len = pubKey->u.srp.s.len;
5017 srpParam->u.data = ss->sec.userName->data;
5018 srpParam->u.len = ss->sec.userName->len;
5019
5020 /* The token handles (missing) info supplied in srpParam
5021 * The template not actually involved in key generation,
5022 * but it's important in the server key exchange */
5023
5024 prvKey = SECKEY_CreateSRPPrivateKey(srpParam, &newPub, PR_FALSE, NULL);
5025 if (!prvKey) {
5026 » ssl_MapLowLevelError(SEC_ERROR_KEYGEN_FAIL);
5027 » rv = SECFailure;
5028 » goto loser;
5029 }
5030 SECITEM_CopyItem(newPub->arena, &newPub->u.srp.ppub, &pubKey->u.srp.ppub );
5031
5032 /* Now all data is in newPub and prvKey, compute pms with them */
5033 pms = PK11_PubDerive(prvKey, newPub, PR_FALSE, NULL, NULL,
5034 » » » CKM_NSS_SRP_DERIVE, CKM_TLS_MASTER_KEY_DERIVE, CKF_D ERIVE, 0, NULL);
5035
5036 if (!pms) {
5037 goto derive_fail;
5038 }
5039
5040 /* init pending cipher spec*/
5041 rv = ssl3_InitPendingCipherSpec(ss, pms);
5042
5043
5044 /* client key exchange data */
5045 rv = ssl3_AppendHandshakeHeader(ss, client_key_exchange,
5046 newPub->u.srp.pub.len + 2);
5047 if (rv != SECSuccess) goto loser; /* err set by ssl3_AppendHandshake* */
5048 rv = ssl3_AppendHandshakeVariable(ss, newPub->u.srp.pub.data,
5049 newPub->u.srp.pub.len, 2);
5050 if (rv != SECSuccess) goto loser; /* err set by ssl3_AppendHandshake* */
5051
5052 if (pms) PK11_FreeSymKey(pms);
5053 SECKEY_DestroyPublicKey(newPub);
5054 } /* end of PK11 path */
5055
5056 loser:
5057 SECITEM_ZfreeItem(ss->sec.userPasswd, PR_TRUE);
5058 PORT_Free(srpParam);
5059 /* caller frees pubKey */
5060 return rv;
5061 derive_fail:
5062 if (PORT_GetError() == SEC_ERROR_SRP_UNSUPPORTED_GROUP)
5063 SSL3_SendAlert(ss, alert_fatal, insufficient_security);
5064 if (PORT_GetError() == SEC_ERROR_SRP_ILLEGAL_PARAMETER)
5065 SSL3_SendAlert(ss, alert_fatal, illegal_parameter);
5066 return SECFailure;
5067 }
4738 5068
4739 5069
4740 /* Called from ssl3_HandleServerHelloDone(). */ 5070 /* Called from ssl3_HandleServerHelloDone(). */
4741 SECStatus 5071 SECStatus
4742 ssl3_SendClientKeyExchange(sslSocket *ss) 5072 ssl3_SendClientKeyExchange(sslSocket *ss)
4743 { 5073 {
4744 SECKEYPublicKey * serverKey = NULL; 5074 SECKEYPublicKey * serverKey = NULL;
4745 SECStatus rv = SECFailure; 5075 SECStatus rv = SECFailure;
4746 PRBool isTLS; 5076 PRBool isTLS;
4747 5077
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
4787 5117
4788 case kt_dh: 5118 case kt_dh:
4789 rv = sendDHClientKeyExchange(ss, serverKey); 5119 rv = sendDHClientKeyExchange(ss, serverKey);
4790 break; 5120 break;
4791 5121
4792 #ifdef NSS_ENABLE_ECC 5122 #ifdef NSS_ENABLE_ECC
4793 case kt_ecdh: 5123 case kt_ecdh:
4794 rv = ssl3_SendECDHClientKeyExchange(ss, serverKey); 5124 rv = ssl3_SendECDHClientKeyExchange(ss, serverKey);
4795 break; 5125 break;
4796 #endif /* NSS_ENABLE_ECC */ 5126 #endif /* NSS_ENABLE_ECC */
4797 5127 case kt_srp:
5128 » rv = ssl3_SendSRPClientKeyExchange(ss, serverKey);
5129 » break;
4798 default: 5130 default:
4799 /* got an unknown or unsupported Key Exchange Algorithm. */ 5131 /* got an unknown or unsupported Key Exchange Algorithm. */
4800 SEND_ALERT 5132 SEND_ALERT
4801 PORT_SetError(SEC_ERROR_UNSUPPORTED_KEYALG); 5133 PORT_SetError(SEC_ERROR_UNSUPPORTED_KEYALG);
4802 break; 5134 break;
4803 } 5135 }
4804 5136
4805 SSL_TRC(3, ("%d: SSL3[%d]: DONE sending client_key_exchange", 5137 SSL_TRC(3, ("%d: SSL3[%d]: DONE sending client_key_exchange",
4806 SSL_GETPID(), ss->fd)); 5138 SSL_GETPID(), ss->fd));
4807 5139
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
5277 SSL_GETPID(), ss->fd)); 5609 SSL_GETPID(), ss->fd));
5278 PORT_Assert( ss->opt.noLocks || ssl_HaveRecvBufLock(ss) ); 5610 PORT_Assert( ss->opt.noLocks || ssl_HaveRecvBufLock(ss) );
5279 PORT_Assert( ss->opt.noLocks || ssl_HaveSSL3HandshakeLock(ss) ); 5611 PORT_Assert( ss->opt.noLocks || ssl_HaveSSL3HandshakeLock(ss) );
5280 5612
5281 if (ss->ssl3.hs.ws != wait_server_key && 5613 if (ss->ssl3.hs.ws != wait_server_key &&
5282 ss->ssl3.hs.ws != wait_server_cert) { 5614 ss->ssl3.hs.ws != wait_server_cert) {
5283 errCode = SSL_ERROR_RX_UNEXPECTED_SERVER_KEY_EXCH; 5615 errCode = SSL_ERROR_RX_UNEXPECTED_SERVER_KEY_EXCH;
5284 desc = unexpected_message; 5616 desc = unexpected_message;
5285 goto alert_loser; 5617 goto alert_loser;
5286 } 5618 }
5287 if (ss->sec.peerCert == NULL) { 5619 if (ss->sec.peerCert == NULL &&
5620 » ss->ssl3.hs.suite_def->key_exchange_alg != kea_srp) {
5288 errCode = SSL_ERROR_RX_UNEXPECTED_SERVER_KEY_EXCH; 5621 errCode = SSL_ERROR_RX_UNEXPECTED_SERVER_KEY_EXCH;
5289 desc = unexpected_message; 5622 desc = unexpected_message;
5290 goto alert_loser; 5623 goto alert_loser;
5291 } 5624 }
5292 5625
5293 isTLS = (PRBool)(ss->ssl3.prSpec->version > SSL_LIBRARY_VERSION_3_0); 5626 isTLS = (PRBool)(ss->ssl3.prSpec->version > SSL_LIBRARY_VERSION_3_0);
5294 5627
5295 switch (ss->ssl3.hs.kea_def->exchKeyType) { 5628 switch (ss->ssl3.hs.kea_def->exchKeyType) {
5296 5629
5297 case kt_rsa: { 5630 case kt_rsa: {
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
5466 ss->sec.peerKey = peerKey; 5799 ss->sec.peerKey = peerKey;
5467 ss->ssl3.hs.ws = wait_cert_request; 5800 ss->ssl3.hs.ws = wait_cert_request;
5468 return SECSuccess; 5801 return SECSuccess;
5469 } 5802 }
5470 5803
5471 #ifdef NSS_ENABLE_ECC 5804 #ifdef NSS_ENABLE_ECC
5472 case kt_ecdh: 5805 case kt_ecdh:
5473 rv = ssl3_HandleECDHServerKeyExchange(ss, b, length); 5806 rv = ssl3_HandleECDHServerKeyExchange(ss, b, length);
5474 return rv; 5807 return rv;
5475 #endif /* NSS_ENABLE_ECC */ 5808 #endif /* NSS_ENABLE_ECC */
5809 case kt_srp:
5810 rv = ssl3_HandleSRPServerKeyExchange(ss, b, length);
5811 if (rv != SECSuccess) {
5812 errCode = ssl_MapLowLevelError(SSL_ERROR_SERVER_KEY_EXCHANGE_FAILURE );
5813 goto alert_loser;
5814 }
5815 return rv;
5476 5816
5477 default: 5817 default:
5478 desc = handshake_failure; 5818 desc = handshake_failure;
5479 errCode = SEC_ERROR_UNSUPPORTED_KEYALG; 5819 errCode = SEC_ERROR_UNSUPPORTED_KEYALG;
5480 break; /* goto alert_loser; */ 5820 break; /* goto alert_loser; */
5481 } 5821 }
5482 5822
5483 alert_loser: 5823 alert_loser:
5484 (void)SSL3_SendAlert(ss, alert_fatal, desc); 5824 (void)SSL3_SendAlert(ss, alert_fatal, desc);
5485 loser: 5825 loser:
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
6027 SSL_TRC(3, ("%d: SSL3[%d]: begin send server_hello sequence", 6367 SSL_TRC(3, ("%d: SSL3[%d]: begin send server_hello sequence",
6028 SSL_GETPID(), ss->fd)); 6368 SSL_GETPID(), ss->fd));
6029 6369
6030 PORT_Assert( ss->opt.noLocks || ssl_HaveSSL3HandshakeLock(ss) ); 6370 PORT_Assert( ss->opt.noLocks || ssl_HaveSSL3HandshakeLock(ss) );
6031 PORT_Assert( ss->opt.noLocks || ssl_HaveXmitBufLock(ss) ); 6371 PORT_Assert( ss->opt.noLocks || ssl_HaveXmitBufLock(ss) );
6032 6372
6033 rv = ssl3_SendServerHello(ss); 6373 rv = ssl3_SendServerHello(ss);
6034 if (rv != SECSuccess) { 6374 if (rv != SECSuccess) {
6035 return rv; /* err code is set. */ 6375 return rv; /* err code is set. */
6036 } 6376 }
6037 rv = ssl3_SendCertificate(ss);
6038 if (rv != SECSuccess) {
6039 return rv; /* error code is set. */
6040 }
6041 /* We have to do this after the call to ssl3_SendServerHello, 6377 /* We have to do this after the call to ssl3_SendServerHello,
6042 * because kea_def is set up by ssl3_SendServerHello(). 6378 * because kea_def is set up by ssl3_SendServerHello().
6043 */ 6379 */
6044 kea_def = ss->ssl3.hs.kea_def; 6380 kea_def = ss->ssl3.hs.kea_def;
6045 ss->ssl3.hs.usedStepDownKey = PR_FALSE; 6381 ss->ssl3.hs.usedStepDownKey = PR_FALSE;
6046 6382
6383
6384 if (kea_def->kea != kea_srp) { /* SRP auth only */
6385 rv = ssl3_SendCertificate(ss);
6386 if (rv != SECSuccess) {
6387 return rv; /* error code is set. */
6388 }
6389 }
6390
6047 if (kea_def->is_limited && kea_def->exchKeyType == kt_rsa) { 6391 if (kea_def->is_limited && kea_def->exchKeyType == kt_rsa) {
6048 /* see if we can legally use the key in the cert. */ 6392 /* see if we can legally use the key in the cert. */
6049 int keyLen; /* bytes */ 6393 int keyLen; /* bytes */
6050 6394
6051 keyLen = PK11_GetPrivateModulusLen( 6395 keyLen = PK11_GetPrivateModulusLen(
6052 ss->serverCerts[kea_def->exchKeyType].SERVERKEY); 6396 ss->serverCerts[kea_def->exchKeyType].SERVERKEY);
6053 6397
6054 if (keyLen > 0 && 6398 if (keyLen > 0 &&
6055 keyLen * BPB <= kea_def->key_size_limit ) { 6399 keyLen * BPB <= kea_def->key_size_limit ) {
6056 /* XXX AND cert is not signing only!! */ 6400 /* XXX AND cert is not signing only!! */
(...skipping 11 matching lines...) Expand all
6068 #endif 6412 #endif
6069 } 6413 }
6070 #ifdef NSS_ENABLE_ECC 6414 #ifdef NSS_ENABLE_ECC
6071 } else if ((kea_def->kea == kea_ecdhe_rsa) || 6415 } else if ((kea_def->kea == kea_ecdhe_rsa) ||
6072 (kea_def->kea == kea_ecdhe_ecdsa)) { 6416 (kea_def->kea == kea_ecdhe_ecdsa)) {
6073 rv = ssl3_SendServerKeyExchange(ss); 6417 rv = ssl3_SendServerKeyExchange(ss);
6074 if (rv != SECSuccess) { 6418 if (rv != SECSuccess) {
6075 return rv; /* err code was set. */ 6419 return rv; /* err code was set. */
6076 } 6420 }
6077 #endif /* NSS_ENABLE_ECC */ 6421 #endif /* NSS_ENABLE_ECC */
6422 } else if ( kea_def->exchKeyType == kt_srp ) {
6423 rv = ssl3_SendServerKeyExchange(ss);
6424 if (rv != SECSuccess) {
6425 return rv; /* err code was set. */
6426 }
6078 } 6427 }
6079 6428
6080 if (ss->opt.requestCertificate) { 6429 if (ss->opt.requestCertificate) {
6081 rv = ssl3_SendCertificateRequest(ss); 6430 rv = ssl3_SendCertificateRequest(ss);
6082 if (rv != SECSuccess) { 6431 if (rv != SECSuccess) {
6083 return rv; /* err code is set. */ 6432 return rv; /* err code is set. */
6084 } 6433 }
6085 } 6434 }
6086 rv = ssl3_SendServerHelloDone(ss); 6435 rv = ssl3_SendServerHelloDone(ss);
6087 if (rv != SECSuccess) { 6436 if (rv != SECSuccess) {
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after
7092 } 7441 }
7093 } 7442 }
7094 rv = ssl3_SetupPendingCipherSpec(ss); 7443 rv = ssl3_SetupPendingCipherSpec(ss);
7095 if (rv != SECSuccess) { 7444 if (rv != SECSuccess) {
7096 return rv; /* err set by ssl3_SetupPendingCipherSpec */ 7445 return rv; /* err set by ssl3_SetupPendingCipherSpec */
7097 } 7446 }
7098 7447
7099 return SECSuccess; 7448 return SECSuccess;
7100 } 7449 }
7101 7450
7451 /* ssl3_SendSRPServerKeyExchange()
7452 * called by ssl3_SendServerKeyExchange()
7453 *
7454 * - make sure we got a userid in the srp client hello extension
7455 * - retrieve verifier and parameters for the user via callback func
7456 * - if user nonexistant, CB makes something up if it wants to
7457 * - continue by creating and sending the SRP key exchange data:
7458 *
7459 * N, g, s, v = <read from password file>
7460 * b = random()
7461 * k = SHA1(N | PAD(g))
7462 * B = k*v + g^b % N
7463 * send (N,g,s,B)
7464 *
7465 * save values b,v,N for calculation of pms in ssl3_HandleSRPClientKeyExchange
7466 */
7467
7468 SECStatus
7469 ssl3_SendSRPServerKeyExchange(sslSocket *ss) {
7470
7471 int bytes = 0;
7472 const ssl3KEADef *kea_def = ss->ssl3.hs.kea_def;
7473 SECItem signed_hash = {siBuffer, NULL, 0};
7474 SECStatus rv = SECFailure;
7475 SECKEYSRPPublicKey *srp = NULL;
7476 SECKEYPublicKey *pubKey = NULL;
7477 SECKEYPrivateKey *prvKey = NULL;
7478 SECKEYSRPParams *srpParams;
7479 SSL3Hashes hashes;
7480
7481 /* send error if no userid was supplied in Client Hello */
7482 if (!ss->sec.userName || !ss->sec.userName->data)
7483 goto unknown_id;
7484
7485 /* Ask application for SRP parameters for specified username.
7486 * Information provided via callback overrides data set on token.
7487 * If no params provided, the token must supply them or fail.
7488 * Callback may fail for nonexistant user.
7489 */
7490
7491 srpParams = PORT_ZAlloc(sizeof(SECKEYSRPParams));
7492 if (!srpParams) goto no_memory;
7493
7494 srpParams->u.data = ss->sec.userName->data;
7495 srpParams->u.len = ss->sec.userName->len;
7496
7497 if (ss->getSRPParams) {
7498 rv = ss->getSRPParams(ss->fd, srpParams, ss->getSRPParamsArg);
7499 if (rv != SECSuccess) {
7500 SECITEM_FreeItem(&srpParams->N, PR_FALSE);
7501 SECITEM_FreeItem(&srpParams->g, PR_FALSE);
7502 SECITEM_FreeItem(&srpParams->s, PR_FALSE);
7503 SECITEM_ZfreeItem(&srpParams->secret, PR_FALSE);
7504 PORT_Free(srpParams);
7505 goto unknown_id;
7506 }
7507 }
7508
7509 /* create SRP server key pair */
7510 if (ss->opt.bypassPKCS11) {
7511 /* srpParams, keyPairParams are temporary. pubKey and prvKey have
7512 * own arenas and are saved for ssl3_HandleSRPClientKeyExchange */
7513 SRPPrivateKey *srpPrv;
7514 SRPKeyPairParams keyPairParams;
7515
7516 PRArenaPool *arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE);
7517 if (!arena) goto no_memory;
7518
7519 keyPairParams.N.data = srpParams->N.data;
7520 keyPairParams.N.len = srpParams->N.len;
7521 keyPairParams.g.data = srpParams->g.data;
7522 keyPairParams.g.len = srpParams->g.len;
7523 keyPairParams.secret.data = srpParams->secret.data;
7524 keyPairParams.secret.len = srpParams->secret.len;
7525
7526 rv = SRP_NewServerKeyPair(&srpPrv, &keyPairParams);
7527 if (rv != SECSuccess) {
7528 ssl_MapLowLevelError(SEC_ERROR_KEYGEN_FAIL);
7529 return rv;
7530 }
7531 prvKey = (SECKEYPrivateKey *)srpPrv;
7532
7533 /* create pubKey from temporary stuff */
7534 pubKey = PORT_ArenaZAlloc(arena, sizeof(SECKEYPublicKey));
7535 if (!pubKey) goto no_memory;
7536 pubKey->arena = arena;
7537 srp = &pubKey->u.srp;
7538
7539 SECITEM_CopyItem(arena, &srp->N, &srpParams->N);
7540 SECITEM_CopyItem(arena, &srp->g, &srpParams->g);
7541 SECITEM_CopyItem(arena, &srp->s, &srpParams->s);
7542 SECITEM_CopyItem(arena, &srp->u, &srpParams->u);
7543 SECITEM_CopyItem(arena, &srp->pub, &srpPrv->pubKey);
7544
7545 } else {
7546
7547 /* input: srpParams, output: prvKey = b,B,v, pubKey = N,g,s,u,B */
7548 prvKey = SECKEY_CreateSRPPrivateKey(srpParams, &pubKey, PR_TRUE, NULL);
7549 if (!prvKey) {
7550 ssl_MapLowLevelError(SEC_ERROR_KEYGEN_FAIL);
7551 rv = SECFailure;
7552 goto cleanup;
7553 }
7554 srp = &pubKey->u.srp;
7555 }
7556
7557 /* send N,g,s,B as ServerKeyExchange to Client */
7558 /* optionally include signature for additional DSS/RSA auth */
7559
7560 if (kea_def->kea != kea_srp) { /* we need a RSA/DSA signature */
7561 rv = ssl3_ComputeSRPKeyHash(&srp->N, &srp->g, &srp->s, &srp->pub,
7562 &ss->ssl3.hs.client _random,
7563 &ss->ssl3.hs.server _random,
7564 &hashes, ss->opt.by passPKCS11);
7565 if (rv != SECSuccess) {
7566 ssl_MapLowLevelError(SSL_ERROR_SERVER_KEY_EXCHANGE_FAILURE);
7567 goto loser;
7568 }
7569 /* look if we have a certificate for selected algo */
7570 if (kea_def->kea == kea_srp_rsa)
7571 bytes = kt_rsa;
7572 else
7573 bytes = kt_null;
7574
7575 if (!(&ss->serverCerts[bytes])) {
7576 /* ciphersuite signing algo does not match supplied certificate */
7577 PORT_SetError(SSL_ERROR_CERT_KEA_MISMATCH);
7578 return SECFailure;
7579 }
7580 rv = ssl3_SignHashes(&hashes, ss->serverCerts[bytes].SERVERKEY,
7581 &signed_hash, PR_TRUE);
7582 bytes = 2 + signed_hash.len;
7583 }
7584
7585 bytes += srp->N.len + srp->g.len + srp->s.len + srp->pub.len + 7;
7586
7587 rv = ssl3_AppendHandshakeHeader(ss, server_key_exchange, bytes);
7588 if (rv != SECSuccess)
7589 return rv; /* err set by AppendHandshake. */
7590
7591 rv = ssl3_AppendHandshakeVariable(ss, srp->N.data, srp->N.len, 2);
7592 if (rv != SECSuccess)
7593 return rv; /* err set by AppendHandshake. */
7594
7595 rv = ssl3_AppendHandshakeVariable(ss, srp->g.data, srp->g.len, 2);
7596 if (rv != SECSuccess)
7597 return rv; /* err set by AppendHandshake. */
7598
7599 rv = ssl3_AppendHandshakeVariable(ss, srp->s.data, srp->s.len, 1);
7600 if (rv != SECSuccess)
7601 return rv; /* err set by AppendHandshake. */
7602
7603 rv = ssl3_AppendHandshakeVariable(ss, srp->pub.data, srp->pub.len, 2);
7604 if (rv != SECSuccess)
7605 return rv; /* err set by AppendHandshake. */
7606
7607 if (kea_def->kea != kea_srp) {
7608 rv = ssl3_AppendHandshakeVariable(ss, signed_hash.data,
7609 signed_hash.len, 2);
7610 if (rv != SECSuccess) {
7611 return rv; /* err set by AppendHandshake. */
7612 }
7613 SECITEM_FreeItem(&signed_hash, PR_FALSE);
7614 }
7615
7616 /* save prvKey / pubKey for use in HandleSRPClientExchange
7617 * XXX in bypassPK11, prvKey is no PK11 object and must be casted */
7618 ssl3KeyPair *srpPair = ssl3_NewKeyPair(prvKey, pubKey);
7619 ss->serverCerts[kt_srp].serverKeyPair = srpPair;
7620
7621 cleanup:
7622 SECITEM_FreeItem(&srpParams->N, PR_FALSE);
7623 SECITEM_FreeItem(&srpParams->g, PR_FALSE);
7624 SECITEM_FreeItem(&srpParams->s, PR_FALSE);
7625 SECITEM_ZfreeItem(&srpParams->secret, PR_FALSE);
7626 if (srpParams) PORT_Free(srpParams);
7627 return rv;
7628 loser:
7629 PORT_SetError(SSL_ERROR_INTERNAL_ERROR_ALERT);
7630 (void)SSL3_SendAlert(ss, alert_fatal, internal_error);
7631 return SECFailure;
7632 unknown_id:
7633 PORT_SetError(SSL_ERROR_UNKNOWN_PSK_IDENTITY_ALERT);
7634 (void)SSL3_SendAlert(ss, alert_fatal, unknown_psk_identity);
7635 return SECFailure;
7636 no_memory:
7637 ssl_MapLowLevelError(SSL_ERROR_SERVER_KEY_EXCHANGE_FAILURE);
7638 return SECFailure;
7639 }
7102 7640
7103 static SECStatus 7641 static SECStatus
7104 ssl3_SendServerKeyExchange(sslSocket *ss) 7642 ssl3_SendServerKeyExchange(sslSocket *ss)
7105 { 7643 {
7106 const ssl3KEADef * kea_def = ss->ssl3.hs.kea_def; 7644 const ssl3KEADef * kea_def = ss->ssl3.hs.kea_def;
7107 SECStatus rv = SECFailure; 7645 SECStatus rv = SECFailure;
7108 int length; 7646 int length;
7109 PRBool isTLS; 7647 PRBool isTLS;
7110 SECItem signed_hash = {siBuffer, NULL, 0}; 7648 SECItem signed_hash = {siBuffer, NULL, 0};
7111 SSL3Hashes hashes; 7649 SSL3Hashes hashes;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
7176 } 7714 }
7177 PORT_Free(signed_hash.data); 7715 PORT_Free(signed_hash.data);
7178 return SECSuccess; 7716 return SECSuccess;
7179 7717
7180 #ifdef NSS_ENABLE_ECC 7718 #ifdef NSS_ENABLE_ECC
7181 case kt_ecdh: { 7719 case kt_ecdh: {
7182 rv = ssl3_SendECDHServerKeyExchange(ss); 7720 rv = ssl3_SendECDHServerKeyExchange(ss);
7183 return rv; 7721 return rv;
7184 } 7722 }
7185 #endif /* NSS_ENABLE_ECC */ 7723 #endif /* NSS_ENABLE_ECC */
7186 7724 case kt_srp:
7725 rv = ssl3_SendSRPServerKeyExchange(ss);
7726 » return rv;
7187 case kt_dh: 7727 case kt_dh:
7188 case kt_null: 7728 case kt_null:
7189 default: 7729 default:
7190 PORT_SetError(SEC_ERROR_UNSUPPORTED_KEYALG); 7730 PORT_SetError(SEC_ERROR_UNSUPPORTED_KEYALG);
7191 break; 7731 break;
7192 } 7732 }
7193 loser: 7733 loser:
7194 if (signed_hash.data != NULL) 7734 if (signed_hash.data != NULL)
7195 PORT_Free(signed_hash.data); 7735 PORT_Free(signed_hash.data);
7196 return SECFailure; 7736 return SECFailure;
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
7529 PK11_FreeSymKey(pms); 8069 PK11_FreeSymKey(pms);
7530 } 8070 }
7531 8071
7532 if (rv != SECSuccess) { 8072 if (rv != SECSuccess) {
7533 SEND_ALERT 8073 SEND_ALERT
7534 return SECFailure; /* error code set by ssl3_InitPendingCipherSpec */ 8074 return SECFailure; /* error code set by ssl3_InitPendingCipherSpec */
7535 } 8075 }
7536 return SECSuccess; 8076 return SECSuccess;
7537 } 8077 }
7538 8078
8079 /*
8080 * extract SRP value A from ClientKeyExchange
8081 * calculate pre-master-secret and init cipher specs
8082 *
8083 * called by ssl3_HandleClientKeyExchange
8084 */
8085 SECStatus
8086 ssl3_HandleSRPClientKeyExchange(sslSocket *ss, SSL3Opaque *b,
8087 PRUint32 length) {
8088
8089 SECItem ppub; /* peers public key ('A') */
8090 sslServerCerts sc;
8091 SECStatus rv = SECFailure;
8092 SECKEYPublicKey *pubKey = NULL;
8093
8094
8095 PORT_Assert( ss->opt.noLocks || ssl_HaveRecvBufLock(ss) );
8096 PORT_Assert( ss->opt.noLocks || ssl_HaveSSL3HandshakeLock(ss) );
8097
8098 rv = ssl3_ConsumeHandshakeVariable(ss, &ppub, 2, &b, &length);
8099 if (rv != SECSuccess) {
8100 PORT_SetError(SSL_ERROR_CLIENT_KEY_EXCHANGE_FAILURE);
8101 return SECFailure;
8102 }
8103
8104 sc = ss->serverCerts[kt_srp];
8105 pubKey = sc.serverKeyPair->pubKey;
8106
8107 SECITEM_CopyItem(pubKey->arena, &pubKey->u.srp.ppub, &ppub);
8108
8109 if (ss->opt.bypassPKCS11) {
8110 SRPPrivateKey *prvKey = NULL;
8111 SECItem pms = { 0, NULL, 0 };
8112 SRPDeriveParams param;
8113
8114 prvKey = (SRPPrivateKey *)sc.serverKeyPair->privKey;
8115
8116 param.N.data = pubKey->u.srp.N.data;
8117 param.N.len = pubKey->u.srp.N.len;
8118 param.g.data = pubKey->u.srp.g.data;
8119 param.g.len = pubKey->u.srp.g.len;
8120 param.ppub.data = pubKey->u.srp.ppub.data;
8121 param.ppub.len = pubKey->u.srp.ppub.len;
8122
8123 if (SECSuccess != SRP_ServerDerive(prvKey, &param, &pms))
8124 goto derive_fail;
8125
8126 ssl_GetSpecWriteLock(ss);
8127 /* create MS out of MS, bypassing PKCS11 */
8128 rv = ssl3_MasterKeyDeriveBypass(ss->ssl3.pwSpec,
8129 (unsigned char *)&ss->ssl3.hs.client_random,
8130 (unsigned char *)&ss->ssl3.hs.server_random,
8131 &pms, PR_TRUE, PR_FALSE);
8132 if (rv != SECSuccess) {
8133 ss->ssl3.pwSpec->msItem.data = ss->ssl3.pwSpec->raw_master_secret;
8134 ss->ssl3.pwSpec->msItem.len = SSL3_MASTER_SECRET_LENGTH;
8135 PK11_GenerateRandom(ss->ssl3.pwSpec->msItem.data, ss->ssl3.pwSpec->m sItem.len);
8136 }
8137
8138 rv = ssl3_InitPendingCipherSpec(ss, NULL);
8139
8140 SECITEM_ZfreeItem(&pms, PR_FALSE);
8141 PORT_FreeArena(prvKey->arena, PR_TRUE); /* XXX FreeArena does not zeroiz e! */
8142 sc.serverKeyPair->privKey = NULL;
8143
8144 } else {
8145 SECKEYPrivateKey *prvKey = NULL;
8146 PK11SymKey *pms = NULL; /* pre-master secret */
8147
8148 prvKey = sc.serverKeyPair->privKey;
8149
8150 /* Calculate PMS based on clntKey and public params */
8151 pms = PK11_PubDerive(prvKey, pubKey, PR_TRUE, NULL, NULL,
8152 CKM_NSS_SRP_DERIVE, CKM_TLS_MASTER_KEY_DERIVE, CKF_D ERIVE, 0, NULL);
8153
8154 if (!pms) {
8155 goto derive_fail;
8156 }
8157
8158 ssl_GetSpecWriteLock(ss);
8159 /* derive master secret from pms */
8160 rv = ssl3_InitPendingCipherSpec(ss, pms);
8161 ssl_ReleaseSpecWriteLock(ss);
8162
8163 PK11_FreeSymKey(pms);
8164 /*SECKEY_DestroyPrivateKey(prvKey);*/
8165 }
8166
8167 return rv;
8168 derive_fail:
8169 if (PORT_GetError() == SEC_ERROR_SRP_ILLEGAL_PARAMETER)
8170 SSL3_SendAlert(ss, alert_fatal, illegal_parameter);
8171 return rv;
8172 }
8173
7539 8174
7540 /* Called from ssl3_HandleHandshakeMessage() when it has deciphered a complete 8175 /* Called from ssl3_HandleHandshakeMessage() when it has deciphered a complete
7541 * ssl3 ClientKeyExchange message from the remote client 8176 * ssl3 ClientKeyExchange message from the remote client
7542 * Caller must hold Handshake and RecvBuf locks. 8177 * Caller must hold Handshake and RecvBuf locks.
7543 */ 8178 */
7544 static SECStatus 8179 static SECStatus
7545 ssl3_HandleClientKeyExchange(sslSocket *ss, SSL3Opaque *b, PRUint32 length) 8180 ssl3_HandleClientKeyExchange(sslSocket *ss, SSL3Opaque *b, PRUint32 length)
7546 { 8181 {
7547 SECKEYPrivateKey *serverKey = NULL; 8182 SECKEYPrivateKey *serverKey = NULL;
7548 SECStatus rv; 8183 SECStatus rv;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
7601 { 8236 {
7602 sslServerCerts * sc = ss->serverCerts + kea_def->exchKeyType; 8237 sslServerCerts * sc = ss->serverCerts + kea_def->exchKeyType;
7603 serverKeyPair = sc->serverKeyPair; 8238 serverKeyPair = sc->serverKeyPair;
7604 ss->sec.keaKeyBits = sc->serverKeyBits; 8239 ss->sec.keaKeyBits = sc->serverKeyBits;
7605 } 8240 }
7606 8241
7607 if (serverKeyPair) { 8242 if (serverKeyPair) {
7608 serverKey = serverKeyPair->privKey; 8243 serverKey = serverKeyPair->privKey;
7609 } 8244 }
7610 8245
7611 if (serverKey == NULL) { 8246 /* XXX hack, figure out this serverKey thing..*/
8247 if (serverKey == NULL && kea_def->exchKeyType != kt_srp) {
7612 SEND_ALERT 8248 SEND_ALERT
7613 PORT_SetError(SSL_ERROR_NO_SERVER_KEY_FOR_ALG); 8249 PORT_SetError(SSL_ERROR_NO_SERVER_KEY_FOR_ALG);
7614 return SECFailure; 8250 return SECFailure;
7615 } 8251 }
7616 8252
7617 ss->sec.keaType = kea_def->exchKeyType; 8253 ss->sec.keaType = kea_def->exchKeyType;
7618 8254
7619 switch (kea_def->exchKeyType) { 8255 switch (kea_def->exchKeyType) {
7620 case kt_rsa: 8256 case kt_rsa:
7621 rv = ssl3_HandleRSAClientKeyExchange(ss, b, length, serverKey); 8257 rv = ssl3_HandleRSAClientKeyExchange(ss, b, length, serverKey);
(...skipping 20 matching lines...) Expand all
7642 PORT_SetError(SSL_ERROR_EXTRACT_PUBLIC_KEY_FAILURE); 8278 PORT_SetError(SSL_ERROR_EXTRACT_PUBLIC_KEY_FAILURE);
7643 return SECFailure; 8279 return SECFailure;
7644 } 8280 }
7645 rv = ssl3_HandleECDHClientKeyExchange(ss, b, length, 8281 rv = ssl3_HandleECDHClientKeyExchange(ss, b, length,
7646 serverPubKey, serverKey); 8282 serverPubKey, serverKey);
7647 if (rv != SECSuccess) { 8283 if (rv != SECSuccess) {
7648 return SECFailure; /* error code set */ 8284 return SECFailure; /* error code set */
7649 } 8285 }
7650 break; 8286 break;
7651 #endif /* NSS_ENABLE_ECC */ 8287 #endif /* NSS_ENABLE_ECC */
7652 8288 case kt_srp:
8289 rv = ssl3_HandleSRPClientKeyExchange(ss, b, length);
8290 » if (rv != SECSuccess) {
8291 » return SECFailure;» /* error code set */
8292 » }
8293 break;
7653 default: 8294 default:
7654 (void) ssl3_HandshakeFailure(ss); 8295 (void) ssl3_HandshakeFailure(ss);
7655 PORT_SetError(SEC_ERROR_UNSUPPORTED_KEYALG); 8296 PORT_SetError(SEC_ERROR_UNSUPPORTED_KEYALG);
7656 return SECFailure; 8297 return SECFailure;
7657 } 8298 }
7658 ss->ssl3.hs.ws = ss->sec.peerCert ? wait_cert_verify : wait_change_cipher; 8299 ss->ssl3.hs.ws = ss->sec.peerCert ? wait_cert_verify : wait_change_cipher;
7659 return SECSuccess; 8300 return SECSuccess;
7660 8301
7661 } 8302 }
7662 8303
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
7816 8457
7817 /* XXX SSLKEAType isn't really a good choice for 8458 /* XXX SSLKEAType isn't really a good choice for
7818 * indexing certificates (it breaks when we deal 8459 * indexing certificates (it breaks when we deal
7819 * with (EC)DHE-* cipher suites. This hack ensures 8460 * with (EC)DHE-* cipher suites. This hack ensures
7820 * the RSA cert is picked for (EC)DHE-RSA. 8461 * the RSA cert is picked for (EC)DHE-RSA.
7821 * Revisit this when we add server side support 8462 * Revisit this when we add server side support
7822 * for ECDHE-ECDSA or client-side authentication 8463 * for ECDHE-ECDSA or client-side authentication
7823 * using EC certificates. 8464 * using EC certificates.
7824 */ 8465 */
7825 if ((ss->ssl3.hs.kea_def->kea == kea_ecdhe_rsa) || 8466 if ((ss->ssl3.hs.kea_def->kea == kea_ecdhe_rsa) ||
7826 » (ss->ssl3.hs.kea_def->kea == kea_dhe_rsa)) { 8467 » (ss->ssl3.hs.kea_def->kea == kea_dhe_rsa) ||
8468 » (ss->ssl3.hs.kea_def->kea == kea_srp_rsa)) {
7827 certIndex = kt_rsa; 8469 certIndex = kt_rsa;
8470 } else if
8471 (ss->ssl3.hs.kea_def->kea == kea_srp_dss) {
8472 certIndex = kt_null;
7828 } else { 8473 } else {
7829 certIndex = ss->ssl3.hs.kea_def->exchKeyType; 8474 certIndex = ss->ssl3.hs.kea_def->exchKeyType;
7830 } 8475 }
7831 sc = ss->serverCerts + certIndex; 8476 sc = ss->serverCerts + certIndex;
7832 certChain = sc->serverCertChain; 8477 certChain = sc->serverCertChain;
7833 ss->sec.authKeyBits = sc->serverKeyBits; 8478 ss->sec.authKeyBits = sc->serverKeyBits;
7834 ss->sec.authAlgorithm = ss->ssl3.hs.kea_def->signKeyType; 8479 ss->sec.authAlgorithm = ss->ssl3.hs.kea_def->signKeyType;
7835 ss->sec.localCert = CERT_DupCertificate(sc->serverCert); 8480 ss->sec.localCert = CERT_DupCertificate(sc->serverCert);
7836 } else { 8481 } else {
7837 certChain = ss->ssl3.clientCertChain; 8482 certChain = ss->ssl3.clientCertChain;
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
8237 if (ss->sec.isServer) { 8882 if (ss->sec.isServer) {
8238 ss->ssl3.hs.ws = wait_client_key; 8883 ss->ssl3.hs.ws = wait_client_key;
8239 } else { 8884 } else {
8240 ss->ssl3.hs.ws = wait_cert_request; /* disallow server_key_exchange */ 8885 ss->ssl3.hs.ws = wait_cert_request; /* disallow server_key_exchange */
8241 if (ss->ssl3.hs.kea_def->is_limited || 8886 if (ss->ssl3.hs.kea_def->is_limited ||
8242 /* XXX OR server cert is signing only. */ 8887 /* XXX OR server cert is signing only. */
8243 #ifdef NSS_ENABLE_ECC 8888 #ifdef NSS_ENABLE_ECC
8244 ss->ssl3.hs.kea_def->kea == kea_ecdhe_ecdsa || 8889 ss->ssl3.hs.kea_def->kea == kea_ecdhe_ecdsa ||
8245 ss->ssl3.hs.kea_def->kea == kea_ecdhe_rsa || 8890 ss->ssl3.hs.kea_def->kea == kea_ecdhe_rsa ||
8246 #endif /* NSS_ENABLE_ECC */ 8891 #endif /* NSS_ENABLE_ECC */
8247 » ss->ssl3.hs.kea_def->exchKeyType == kt_dh) { 8892 » ss->ssl3.hs.kea_def->exchKeyType == kt_dh ||
8893 » ss->ssl3.hs.kea_def->kea == kea_srp_dss ||
8894 » ss->ssl3.hs.kea_def->kea == kea_srp_rsa) {
8248 ss->ssl3.hs.ws = wait_server_key; /* allow server_key_exchange */ 8895 ss->ssl3.hs.ws = wait_server_key; /* allow server_key_exchange */
8249 } 8896 }
8250 } 8897 }
8251 8898
8252 /* rv must normally be equal to SECSuccess here. If we called 8899 /* rv must normally be equal to SECSuccess here. If we called
8253 * handleBadCert, it can also be SECWouldBlock. 8900 * handleBadCert, it can also be SECWouldBlock.
8254 */ 8901 */
8255 return rv; 8902 return rv;
8256 8903
8257 ambiguous_err: 8904 ambiguous_err:
(...skipping 1629 matching lines...) Expand 10 before | Expand all | Expand 10 after
9887 10534
9888 ss->ssl3.initialized = PR_FALSE; 10535 ss->ssl3.initialized = PR_FALSE;
9889 10536
9890 if (ss->ssl3.nextProto.data) { 10537 if (ss->ssl3.nextProto.data) {
9891 PORT_Free(ss->ssl3.nextProto.data); 10538 PORT_Free(ss->ssl3.nextProto.data);
9892 ss->ssl3.nextProto.data = NULL; 10539 ss->ssl3.nextProto.data = NULL;
9893 } 10540 }
9894 } 10541 }
9895 10542
9896 /* End of ssl3con.c */ 10543 /* End of ssl3con.c */
OLDNEW
« no previous file with comments | « net/third_party/nss/ssl/ssl.def ('k') | net/third_party/nss/ssl/ssl3ecc.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698