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

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

Issue 21696002: Implement the AES GCM cipher suites for TLS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fix a grammatical error in a comment Created 7 years, 4 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 | « no previous file | net/third_party/nss/ssl/ssl3ecc.c » ('j') | net/third_party/nss/ssl/sslenum.c » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* 2 /*
3 * SSL3 Protocol 3 * SSL3 Protocol
4 * 4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public 5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 8
9 /* TODO(ekr): Implement HelloVerifyRequest on server side. OK for now. */ 9 /* TODO(ekr): Implement HelloVerifyRequest on server side. OK for now. */
10 10
(...skipping 26 matching lines...) Expand all
37 #define CKM_NSS_TLS_PRF_GENERAL_SHA256 (CKM_NSS + 21) 37 #define CKM_NSS_TLS_PRF_GENERAL_SHA256 (CKM_NSS + 21)
38 #define CKM_NSS_TLS_MASTER_KEY_DERIVE_SHA256 (CKM_NSS + 22) 38 #define CKM_NSS_TLS_MASTER_KEY_DERIVE_SHA256 (CKM_NSS + 22)
39 #define CKM_NSS_TLS_KEY_AND_MAC_DERIVE_SHA256 (CKM_NSS + 23) 39 #define CKM_NSS_TLS_KEY_AND_MAC_DERIVE_SHA256 (CKM_NSS + 23)
40 #define CKM_NSS_TLS_MASTER_KEY_DERIVE_DH_SHA256 (CKM_NSS + 24) 40 #define CKM_NSS_TLS_MASTER_KEY_DERIVE_DH_SHA256 (CKM_NSS + 24)
41 #endif 41 #endif
42 42
43 #include <stdio.h> 43 #include <stdio.h>
44 #ifdef NSS_ENABLE_ZLIB 44 #ifdef NSS_ENABLE_ZLIB
45 #include "zlib.h" 45 #include "zlib.h"
46 #endif 46 #endif
47 #ifdef LINUX
48 #include <dlfcn.h>
49 #endif
47 50
48 #ifndef PK11_SETATTRS 51 #ifndef PK11_SETATTRS
49 #define PK11_SETATTRS(x,id,v,l) (x)->type = (id); \ 52 #define PK11_SETATTRS(x,id,v,l) (x)->type = (id); \
50 (x)->pValue=(v); (x)->ulValueLen = (l); 53 (x)->pValue=(v); (x)->ulValueLen = (l);
51 #endif 54 #endif
52 55
53 static SECStatus ssl3_AuthCertificate(sslSocket *ss); 56 static SECStatus ssl3_AuthCertificate(sslSocket *ss);
54 static void ssl3_CleanupPeerCerts(sslSocket *ss); 57 static void ssl3_CleanupPeerCerts(sslSocket *ss);
55 static void ssl3_CopyPeerCertsFromSID(sslSocket *ss, sslSessionID *sid); 58 static void ssl3_CopyPeerCertsFromSID(sslSocket *ss, sslSessionID *sid);
56 static PK11SymKey *ssl3_GenerateRSAPMS(sslSocket *ss, ssl3CipherSpec *spec, 59 static PK11SymKey *ssl3_GenerateRSAPMS(sslSocket *ss, ssl3CipherSpec *spec,
(...skipping 25 matching lines...) Expand all
82 #define MAX_SEND_BUF_LENGTH 32000 /* watch for 16-bit integer overflow */ 85 #define MAX_SEND_BUF_LENGTH 32000 /* watch for 16-bit integer overflow */
83 #define MIN_SEND_BUF_LENGTH 4000 86 #define MIN_SEND_BUF_LENGTH 4000
84 87
85 /* This list of SSL3 cipher suites is sorted in descending order of 88 /* This list of SSL3 cipher suites is sorted in descending order of
86 * precedence (desirability). It only includes cipher suites we implement. 89 * precedence (desirability). It only includes cipher suites we implement.
87 * This table is modified by SSL3_SetPolicy(). The ordering of cipher suites 90 * This table is modified by SSL3_SetPolicy(). The ordering of cipher suites
88 * in this table must match the ordering in SSL_ImplementedCiphers (sslenum.c) 91 * in this table must match the ordering in SSL_ImplementedCiphers (sslenum.c)
89 */ 92 */
90 static ssl3CipherSuiteCfg cipherSuites[ssl_V3_SUITES_IMPLEMENTED] = { 93 static ssl3CipherSuiteCfg cipherSuites[ssl_V3_SUITES_IMPLEMENTED] = {
91 /* cipher_suite policy enabled is_present*/ 94 /* cipher_suite policy enabled is_present*/
95 { TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, SSL_NOT_ALLOWED, PR_TRUE,PR_FALSE},
wtc 2013/08/10 01:22:59 I added TLS_DHE_RSA_WITH_AES_128_GCM_SHA256.
Ryan Sleevi 2013/08/13 21:05:45 Do we really want DHE_RSA over the ECDHE case? I
wtc 2013/08/14 01:57:02 Done.
96 { TLS_RSA_WITH_AES_128_GCM_SHA256, SSL_NOT_ALLOWED, PR_TRUE,PR_FALSE},
92 #ifdef NSS_ENABLE_ECC 97 #ifdef NSS_ENABLE_ECC
98 { TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,SSL_NOT_ALLOWED, PR_TRUE,PR_FALSE},
99 { TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, SSL_NOT_ALLOWED, PR_TRUE,PR_FALSE},
93 { TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 100 { TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
94 { TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 101 { TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
95 #endif /* NSS_ENABLE_ECC */ 102 #endif /* NSS_ENABLE_ECC */
96 { TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 103 { TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
97 { TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 104 { TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
98 { TLS_DHE_RSA_WITH_AES_256_CBC_SHA, SSL_NOT_ALLOWED, PR_TRUE,PR_FALSE}, 105 { TLS_DHE_RSA_WITH_AES_256_CBC_SHA, SSL_NOT_ALLOWED, PR_TRUE,PR_FALSE},
99 { TLS_DHE_RSA_WITH_AES_256_CBC_SHA256, SSL_NOT_ALLOWED, PR_TRUE,PR_FALSE}, 106 { TLS_DHE_RSA_WITH_AES_256_CBC_SHA256, SSL_NOT_ALLOWED, PR_TRUE,PR_FALSE},
100 { TLS_DHE_DSS_WITH_AES_256_CBC_SHA, SSL_NOT_ALLOWED, PR_TRUE,PR_FALSE}, 107 { TLS_DHE_DSS_WITH_AES_256_CBC_SHA, SSL_NOT_ALLOWED, PR_TRUE,PR_FALSE},
101 #ifdef NSS_ENABLE_ECC 108 #ifdef NSS_ENABLE_ECC
102 { TLS_ECDH_RSA_WITH_AES_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 109 { TLS_ECDH_RSA_WITH_AES_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 233
227 234
228 /* This global item is used only in servers. It is is initialized by 235 /* This global item is used only in servers. It is is initialized by
229 ** SSL_ConfigSecureServer(), and is used in ssl3_SendCertificateRequest(). 236 ** SSL_ConfigSecureServer(), and is used in ssl3_SendCertificateRequest().
230 */ 237 */
231 CERTDistNames *ssl3_server_ca_list = NULL; 238 CERTDistNames *ssl3_server_ca_list = NULL;
232 static SSL3Statistics ssl3stats; 239 static SSL3Statistics ssl3stats;
233 240
234 /* indexed by SSL3BulkCipher */ 241 /* indexed by SSL3BulkCipher */
235 static const ssl3BulkCipherDef bulk_cipher_defs[] = { 242 static const ssl3BulkCipherDef bulk_cipher_defs[] = {
236 /* cipher calg keySz secretSz type ivSz BlkSz keygen */ 243 /* |--------- Lengths --------| */
237 {cipher_null, calg_null, 0, 0, type_stream, 0, 0, kg_null}, 244 /* cipher calg k s type i b t n */
238 {cipher_rc4, calg_rc4, 16, 16, type_stream, 0, 0, kg_strong}, 245 /* e e v l a o */
239 {cipher_rc4_40, calg_rc4, 16, 5, type_stream, 0, 0, kg_export}, 246 /* y c | o g n */
240 {cipher_rc4_56, calg_rc4, 16, 7, type_stream, 0, 0, kg_export}, 247 /* | r | c | c */
241 {cipher_rc2, calg_rc2, 16, 16, type_block, 8, 8, kg_strong}, 248 /* | e | k | e */
242 {cipher_rc2_40, calg_rc2, 16, 5, type_block, 8, 8, kg_export}, 249 /* | t | | | | */
243 {cipher_des, calg_des, 8, 8, type_block, 8, 8, kg_strong}, 250 {cipher_null, calg_null, 0, 0, type_stream, 0, 0, 0, 0},
244 {cipher_3des, calg_3des, 24, 24, type_block, 8, 8, kg_strong}, 251 {cipher_rc4, calg_rc4, 16,16, type_stream, 0, 0, 0, 0},
245 {cipher_des40, calg_des, 8, 5, type_block, 8, 8, kg_export}, 252 {cipher_rc4_40, calg_rc4, 16, 5, type_stream, 0, 0, 0, 0},
246 {cipher_idea, calg_idea, 16, 16, type_block, 8, 8, kg_strong}, 253 {cipher_rc4_56, calg_rc4, 16, 7, type_stream, 0, 0, 0, 0},
247 {cipher_aes_128, calg_aes, 16, 16, type_block, 16,16, kg_strong}, 254 {cipher_rc2, calg_rc2, 16,16, type_block, 8, 8, 0, 0},
248 {cipher_aes_256, calg_aes, 32, 32, type_block, 16,16, kg_strong}, 255 {cipher_rc2_40, calg_rc2, 16, 5, type_block, 8, 8, 0, 0},
249 {cipher_camellia_128, calg_camellia,16, 16, type_block, 16,16, kg_strong}, 256 {cipher_des, calg_des, 8, 8, type_block, 8, 8, 0, 0},
250 {cipher_camellia_256, calg_camellia,32, 32, type_block, 16,16, kg_strong}, 257 {cipher_3des, calg_3des, 24,24, type_block, 8, 8, 0, 0},
251 {cipher_seed, calg_seed, 16, 16, type_block, 16,16, kg_strong}, 258 {cipher_des40, calg_des, 8, 5, type_block, 8, 8, 0, 0},
252 {cipher_missing, calg_null, 0, 0, type_stream, 0, 0, kg_null}, 259 {cipher_idea, calg_idea, 16,16, type_block, 8, 8, 0, 0},
260 {cipher_aes_128, calg_aes, 16,16, type_block, 16,16, 0, 0},
261 {cipher_aes_256, calg_aes, 32,32, type_block, 16,16, 0, 0},
262 {cipher_camellia_128, calg_camellia, 16,16, type_block, 16,16, 0, 0},
263 {cipher_camellia_256, calg_camellia, 32,32, type_block, 16,16, 0, 0},
264 {cipher_seed, calg_seed, 16,16, type_block, 16,16, 0, 0},
265 {cipher_aes_128_gcm, calg_aes_gcm, 16,16, type_aead, 4, 0,16, 8},
wtc 2013/08/10 01:22:59 I renamed calg_aes_128_gcm to calg_aes_gcm because
266 {cipher_missing, calg_null, 0, 0, type_stream, 0, 0, 0, 0},
253 }; 267 };
254 268
255 static const ssl3KEADef kea_defs[] = 269 static const ssl3KEADef kea_defs[] =
256 { /* indexed by SSL3KeyExchangeAlgorithm */ 270 { /* indexed by SSL3KeyExchangeAlgorithm */
257 /* kea exchKeyType signKeyType is_limited limit tls_keygen */ 271 /* kea exchKeyType signKeyType is_limited limit tls_keygen */
258 {kea_null, kt_null, sign_null, PR_FALSE, 0, PR_FALSE}, 272 {kea_null, kt_null, sign_null, PR_FALSE, 0, PR_FALSE},
259 {kea_rsa, kt_rsa, sign_rsa, PR_FALSE, 0, PR_FALSE}, 273 {kea_rsa, kt_rsa, sign_rsa, PR_FALSE, 0, PR_FALSE},
260 {kea_rsa_export, kt_rsa, sign_rsa, PR_TRUE, 512, PR_FALSE}, 274 {kea_rsa_export, kt_rsa, sign_rsa, PR_TRUE, 512, PR_FALSE},
261 {kea_rsa_export_1024,kt_rsa, sign_rsa, PR_TRUE, 1024, PR_FALSE}, 275 {kea_rsa_export_1024,kt_rsa, sign_rsa, PR_TRUE, 1024, PR_FALSE},
262 {kea_dh_dss, kt_dh, sign_dsa, PR_FALSE, 0, PR_FALSE}, 276 {kea_dh_dss, kt_dh, sign_dsa, PR_FALSE, 0, PR_FALSE},
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 cipher_camellia_256, mac_sha, kea_dhe_rsa}, 378 cipher_camellia_256, mac_sha, kea_dhe_rsa},
365 379
366 {TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA, 380 {TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA,
367 cipher_des, mac_sha,kea_rsa_export_1024}, 381 cipher_des, mac_sha,kea_rsa_export_1024},
368 {TLS_RSA_EXPORT1024_WITH_RC4_56_SHA, 382 {TLS_RSA_EXPORT1024_WITH_RC4_56_SHA,
369 cipher_rc4_56, mac_sha,kea_rsa_export_1024}, 383 cipher_rc4_56, mac_sha,kea_rsa_export_1024},
370 384
371 {SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA, cipher_3des, mac_sha, kea_rsa_fips}, 385 {SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA, cipher_3des, mac_sha, kea_rsa_fips},
372 {SSL_RSA_FIPS_WITH_DES_CBC_SHA, cipher_des, mac_sha, kea_rsa_fips}, 386 {SSL_RSA_FIPS_WITH_DES_CBC_SHA, cipher_des, mac_sha, kea_rsa_fips},
373 387
388 {TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, cipher_aes_128_gcm, mac_null, kea_dhe_ rsa},
389 {TLS_RSA_WITH_AES_128_GCM_SHA256, cipher_aes_128_gcm, mac_null, kea_rsa},
390 {TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, cipher_aes_128_gcm, mac_null, kea_ec dhe_rsa},
391 {TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, cipher_aes_128_gcm, mac_null, kea_ ecdhe_ecdsa},
392
374 #ifdef NSS_ENABLE_ECC 393 #ifdef NSS_ENABLE_ECC
375 {TLS_ECDH_ECDSA_WITH_NULL_SHA, cipher_null, mac_sha, kea_ecdh_ecdsa}, 394 {TLS_ECDH_ECDSA_WITH_NULL_SHA, cipher_null, mac_sha, kea_ecdh_ecdsa},
376 {TLS_ECDH_ECDSA_WITH_RC4_128_SHA, cipher_rc4, mac_sha, kea_ecdh_ecdsa}, 395 {TLS_ECDH_ECDSA_WITH_RC4_128_SHA, cipher_rc4, mac_sha, kea_ecdh_ecdsa},
377 {TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, cipher_3des, mac_sha, kea_ecdh_ecdsa} , 396 {TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, cipher_3des, mac_sha, kea_ecdh_ecdsa} ,
378 {TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, cipher_aes_128, mac_sha, kea_ecdh_ecds a}, 397 {TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, cipher_aes_128, mac_sha, kea_ecdh_ecds a},
379 {TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA, cipher_aes_256, mac_sha, kea_ecdh_ecds a}, 398 {TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA, cipher_aes_256, mac_sha, kea_ecdh_ecds a},
380 399
381 {TLS_ECDHE_ECDSA_WITH_NULL_SHA, cipher_null, mac_sha, kea_ecdhe_ecdsa }, 400 {TLS_ECDHE_ECDSA_WITH_NULL_SHA, cipher_null, mac_sha, kea_ecdhe_ecdsa },
382 {TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, cipher_rc4, mac_sha, kea_ecdhe_ecdsa }, 401 {TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, cipher_rc4, mac_sha, kea_ecdhe_ecdsa },
383 {TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, cipher_3des, mac_sha, kea_ecdhe_ecds a}, 402 {TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, cipher_3des, mac_sha, kea_ecdhe_ecds a},
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 { calg_null , (CK_MECHANISM_TYPE)0x80000000L }, 446 { calg_null , (CK_MECHANISM_TYPE)0x80000000L },
428 { calg_rc4 , CKM_RC4 }, 447 { calg_rc4 , CKM_RC4 },
429 { calg_rc2 , CKM_RC2_CBC }, 448 { calg_rc2 , CKM_RC2_CBC },
430 { calg_des , CKM_DES_CBC }, 449 { calg_des , CKM_DES_CBC },
431 { calg_3des , CKM_DES3_CBC }, 450 { calg_3des , CKM_DES3_CBC },
432 { calg_idea , CKM_IDEA_CBC }, 451 { calg_idea , CKM_IDEA_CBC },
433 { calg_fortezza , CKM_SKIPJACK_CBC64 }, 452 { calg_fortezza , CKM_SKIPJACK_CBC64 },
434 { calg_aes , CKM_AES_CBC }, 453 { calg_aes , CKM_AES_CBC },
435 { calg_camellia , CKM_CAMELLIA_CBC }, 454 { calg_camellia , CKM_CAMELLIA_CBC },
436 { calg_seed , CKM_SEED_CBC }, 455 { calg_seed , CKM_SEED_CBC },
456 { calg_aes_gcm , CKM_AES_GCM },
437 /* { calg_init , (CK_MECHANISM_TYPE)0x7fffffffL } */ 457 /* { calg_init , (CK_MECHANISM_TYPE)0x7fffffffL } */
438 }; 458 };
439 459
440 #define mmech_null (CK_MECHANISM_TYPE)0x80000000L 460 #define mmech_null (CK_MECHANISM_TYPE)0x80000000L
441 #define mmech_md5 CKM_SSL3_MD5_MAC 461 #define mmech_md5 CKM_SSL3_MD5_MAC
442 #define mmech_sha CKM_SSL3_SHA1_MAC 462 #define mmech_sha CKM_SSL3_SHA1_MAC
443 #define mmech_md5_hmac CKM_MD5_HMAC 463 #define mmech_md5_hmac CKM_MD5_HMAC
444 #define mmech_sha_hmac CKM_SHA_1_HMAC 464 #define mmech_sha_hmac CKM_SHA_1_HMAC
445 #define mmech_sha256_hmac CKM_SHA256_HMAC 465 #define mmech_sha256_hmac CKM_SHA256_HMAC
446 466
(...skipping 18 matching lines...) Expand all
465 "RC2-CBC-40", 485 "RC2-CBC-40",
466 "DES-CBC", 486 "DES-CBC",
467 "3DES-EDE-CBC", 487 "3DES-EDE-CBC",
468 "DES-CBC-40", 488 "DES-CBC-40",
469 "IDEA-CBC", 489 "IDEA-CBC",
470 "AES-128", 490 "AES-128",
471 "AES-256", 491 "AES-256",
472 "Camellia-128", 492 "Camellia-128",
473 "Camellia-256", 493 "Camellia-256",
474 "SEED-CBC", 494 "SEED-CBC",
495 "AES-128-GCM",
475 "missing" 496 "missing"
476 }; 497 };
477 498
478 #ifdef NSS_ENABLE_ECC 499 #ifdef NSS_ENABLE_ECC
479 /* The ECCWrappedKeyInfo structure defines how various pieces of 500 /* The ECCWrappedKeyInfo structure defines how various pieces of
480 * information are laid out within wrappedSymmetricWrappingkey 501 * information are laid out within wrappedSymmetricWrappingkey
481 * for ECDH key exchange. Since wrappedSymmetricWrappingkey is 502 * for ECDH key exchange. Since wrappedSymmetricWrappingkey is
482 * a 512-byte buffer (see sslimpl.h), the variable length field 503 * a 512-byte buffer (see sslimpl.h), the variable length field
483 * in ECCWrappedKeyInfo can be at most (512 - 8) = 504 bytes. 504 * in ECCWrappedKeyInfo can be at most (512 - 8) = 504 bytes.
484 * 505 *
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 * SSL_DH_RSA_EXPORT_WITH_DES40_CBC_SHA: never implemented 612 * SSL_DH_RSA_EXPORT_WITH_DES40_CBC_SHA: never implemented
592 * SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA: never implemented 613 * SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA: never implemented
593 * SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA: never implemented 614 * SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA: never implemented
594 * SSL_DH_ANON_EXPORT_WITH_RC4_40_MD5: never implemented 615 * SSL_DH_ANON_EXPORT_WITH_RC4_40_MD5: never implemented
595 * SSL_DH_ANON_EXPORT_WITH_DES40_CBC_SHA: never implemented 616 * SSL_DH_ANON_EXPORT_WITH_DES40_CBC_SHA: never implemented
596 */ 617 */
597 return version <= SSL_LIBRARY_VERSION_TLS_1_0; 618 return version <= SSL_LIBRARY_VERSION_TLS_1_0;
598 case TLS_DHE_RSA_WITH_AES_256_CBC_SHA256: 619 case TLS_DHE_RSA_WITH_AES_256_CBC_SHA256:
599 case TLS_RSA_WITH_AES_256_CBC_SHA256: 620 case TLS_RSA_WITH_AES_256_CBC_SHA256:
600 case TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256: 621 case TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256:
622 case TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256:
601 case TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256: 623 case TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256:
624 case TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:
602 case TLS_DHE_RSA_WITH_AES_128_CBC_SHA256: 625 case TLS_DHE_RSA_WITH_AES_128_CBC_SHA256:
626 case TLS_DHE_RSA_WITH_AES_128_GCM_SHA256:
603 case TLS_RSA_WITH_AES_128_CBC_SHA256: 627 case TLS_RSA_WITH_AES_128_CBC_SHA256:
628 case TLS_RSA_WITH_AES_128_GCM_SHA256:
604 case TLS_RSA_WITH_NULL_SHA256: 629 case TLS_RSA_WITH_NULL_SHA256:
605 return version >= SSL_LIBRARY_VERSION_TLS_1_2; 630 return version >= SSL_LIBRARY_VERSION_TLS_1_2;
606 default: 631 default:
607 return PR_TRUE; 632 return PR_TRUE;
608 } 633 }
609 } 634 }
610 635
611 /* return pointer to ssl3CipherSuiteDef for suite, or NULL */ 636 /* return pointer to ssl3CipherSuiteDef for suite, or NULL */
612 /* XXX This does a linear search. A binary search would be better. */ 637 /* XXX This does a linear search. A binary search would be better. */
613 static const ssl3CipherSuiteDef * 638 static const ssl3CipherSuiteDef *
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after
1353 if (IS_DTLS(ss)) { 1378 if (IS_DTLS(ss)) {
1354 /* Double-check that we did not pick an RC4 suite */ 1379 /* Double-check that we did not pick an RC4 suite */
1355 PORT_Assert((suite_def->bulk_cipher_alg != cipher_rc4) && 1380 PORT_Assert((suite_def->bulk_cipher_alg != cipher_rc4) &&
1356 (suite_def->bulk_cipher_alg != cipher_rc4_40) && 1381 (suite_def->bulk_cipher_alg != cipher_rc4_40) &&
1357 (suite_def->bulk_cipher_alg != cipher_rc4_56)); 1382 (suite_def->bulk_cipher_alg != cipher_rc4_56));
1358 } 1383 }
1359 1384
1360 cipher = suite_def->bulk_cipher_alg; 1385 cipher = suite_def->bulk_cipher_alg;
1361 kea = suite_def->key_exchange_alg; 1386 kea = suite_def->key_exchange_alg;
1362 mac = suite_def->mac_alg; 1387 mac = suite_def->mac_alg;
1363 if (mac <= ssl_mac_sha && isTLS) 1388 if (mac <= ssl_mac_sha && mac != ssl_mac_null && isTLS)
1364 mac += 2; 1389 mac += 2;
1365 1390
1366 ss->ssl3.hs.suite_def = suite_def; 1391 ss->ssl3.hs.suite_def = suite_def;
1367 ss->ssl3.hs.kea_def = &kea_defs[kea]; 1392 ss->ssl3.hs.kea_def = &kea_defs[kea];
1368 PORT_Assert(ss->ssl3.hs.kea_def->kea == kea); 1393 PORT_Assert(ss->ssl3.hs.kea_def->kea == kea);
1369 1394
1370 pwSpec->cipher_def = &bulk_cipher_defs[cipher]; 1395 pwSpec->cipher_def = &bulk_cipher_defs[cipher];
1371 PORT_Assert(pwSpec->cipher_def->cipher == cipher); 1396 PORT_Assert(pwSpec->cipher_def->cipher == cipher);
1372 1397
1373 pwSpec->mac_def = &mac_defs[mac]; 1398 pwSpec->mac_def = &mac_defs[mac];
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
1547 ssl3CipherSpec * pwSpec; 1572 ssl3CipherSpec * pwSpec;
1548 const ssl3BulkCipherDef *cipher_def; 1573 const ssl3BulkCipherDef *cipher_def;
1549 void * serverContext = NULL; 1574 void * serverContext = NULL;
1550 void * clientContext = NULL; 1575 void * clientContext = NULL;
1551 BLapiInitContextFunc initFn = (BLapiInitContextFunc)NULL; 1576 BLapiInitContextFunc initFn = (BLapiInitContextFunc)NULL;
1552 int mode = 0; 1577 int mode = 0;
1553 unsigned int optArg1 = 0; 1578 unsigned int optArg1 = 0;
1554 unsigned int optArg2 = 0; 1579 unsigned int optArg2 = 0;
1555 PRBool server_encrypts = ss->sec.isServer; 1580 PRBool server_encrypts = ss->sec.isServer;
1556 SSLCipherAlgorithm calg; 1581 SSLCipherAlgorithm calg;
1557 SSLCompressionMethod compression_method;
1558 SECStatus rv; 1582 SECStatus rv;
1559 1583
1560 PORT_Assert(ss->opt.noLocks || ssl_HaveSSL3HandshakeLock(ss)); 1584 PORT_Assert(ss->opt.noLocks || ssl_HaveSSL3HandshakeLock(ss));
1561 PORT_Assert(ss->opt.noLocks || ssl_HaveSpecWriteLock(ss)); 1585 PORT_Assert(ss->opt.noLocks || ssl_HaveSpecWriteLock(ss));
1562 PORT_Assert(ss->ssl3.prSpec == ss->ssl3.pwSpec); 1586 PORT_Assert(ss->ssl3.prSpec == ss->ssl3.pwSpec);
1563 1587
1564 pwSpec = ss->ssl3.pwSpec; 1588 pwSpec = ss->ssl3.pwSpec;
1565 cipher_def = pwSpec->cipher_def; 1589 cipher_def = pwSpec->cipher_def;
1566 1590
1567 calg = cipher_def->calg; 1591 calg = cipher_def->calg;
1568 compression_method = pwSpec->compression_method;
1569 1592
1570 serverContext = pwSpec->server.cipher_context; 1593 serverContext = pwSpec->server.cipher_context;
1571 clientContext = pwSpec->client.cipher_context; 1594 clientContext = pwSpec->client.cipher_context;
1572 1595
1573 switch (calg) { 1596 switch (calg) {
1574 case ssl_calg_null: 1597 case ssl_calg_null:
1575 pwSpec->encode = Null_Cipher; 1598 pwSpec->encode = Null_Cipher;
1576 pwSpec->decode = Null_Cipher; 1599 pwSpec->decode = Null_Cipher;
1577 pwSpec->destroy = NULL; 1600 pwSpec->destroy = NULL;
1578 goto success; 1601 goto success;
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1714 case CKM_RC2_MAC: 1737 case CKM_RC2_MAC:
1715 case CKM_RC2_MAC_GENERAL: 1738 case CKM_RC2_MAC_GENERAL:
1716 case CKM_RC2_CBC_PAD: 1739 case CKM_RC2_CBC_PAD:
1717 *(CK_RC2_PARAMS *)param->data = ulEffectiveBits; 1740 *(CK_RC2_PARAMS *)param->data = ulEffectiveBits;
1718 default: break; 1741 default: break;
1719 } 1742 }
1720 } 1743 }
1721 return param; 1744 return param;
1722 } 1745 }
1723 1746
1747 /* ssl3_BuildRecordPseudoHeader writes the TLS pseudo-header (the data which
1748 * is included in the MAC) to |out| and returns its length. */
1749 static unsigned int
1750 ssl3_BuildRecordPseudoHeader(unsigned char *out,
1751 SSL3SequenceNumber seq_num,
1752 SSL3ContentType type,
1753 PRBool includesVersion,
1754 SSL3ProtocolVersion version,
1755 PRBool isDTLS,
1756 int length)
1757 {
1758 out[0] = (unsigned char)(seq_num.high >> 24);
1759 out[1] = (unsigned char)(seq_num.high >> 16);
1760 out[2] = (unsigned char)(seq_num.high >> 8);
1761 out[3] = (unsigned char)(seq_num.high >> 0);
1762 out[4] = (unsigned char)(seq_num.low >> 24);
1763 out[5] = (unsigned char)(seq_num.low >> 16);
1764 out[6] = (unsigned char)(seq_num.low >> 8);
1765 out[7] = (unsigned char)(seq_num.low >> 0);
1766 out[8] = type;
1767
1768 /* SSL3 MAC doesn't include the record's version field. */
1769 if (!includesVersion) {
1770 out[9] = MSB(length);
1771 out[10] = LSB(length);
1772 return 11;
1773 }
1774
1775 /* TLS MAC and AEAD additional data include version. */
1776 if (isDTLS) {
1777 SSL3ProtocolVersion dtls_version;
1778
1779 dtls_version = dtls_TLSVersionToDTLSVersion(version);
1780 out[9] = MSB(dtls_version);
1781 out[10] = LSB(dtls_version);
1782 } else {
1783 out[9] = MSB(version);
1784 out[10] = LSB(version);
1785 }
1786 out[11] = MSB(length);
1787 out[12] = LSB(length);
1788 return 13;
1789 }
1790
1791 typedef SECStatus (*PK11CryptFcn)(
1792 PK11SymKey *symKey, CK_MECHANISM_TYPE mechanism, SECItem *param,
1793 unsigned char *out, unsigned int *outLen, unsigned int maxLen,
1794 const unsigned char *in, unsigned int inLen);
1795
1796 static PK11CryptFcn pk11_encrypt = NULL;
1797 static PK11CryptFcn pk11_decrypt = NULL;
1798
1799 static PRCallOnceType resolvePK11CryptOnce;
1800
1801 static PRStatus
1802 ssl3_ResolvePK11CryptFunctions(void)
1803 {
1804 #ifdef LINUX
1805 /* On Linux we use the system NSS libraries. Look up the PK11_Encrypt and
1806 * PK11_Decrypt functions at run time. */
1807 void *handle = dlopen(NULL, RTLD_LAZY);
1808 if (!handle) {
1809 PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
1810 return PR_FAILURE;
1811 }
1812 pk11_encrypt = (PK11CryptFcn)dlsym(handle, "PK11_Encrypt");
1813 pk11_decrypt = (PK11CryptFcn)dlsym(handle, "PK11_Decrypt");
1814 dlclose(handle);
1815 return PR_SUCCESS;
1816 #else
1817 /* On other platforms we use our own copy of NSS. PK11_Encrypt and
1818 * PK11_Decrypt are known to be available. */
1819 pk11_encrypt = PK11_Encrypt;
1820 pk11_decrypt = PK11_Decrypt;
1821 return PR_SUCCESS;
1822 #endif
1823 }
1824
1825 /*
1826 * In NSS 3.15, PK11_Encrypt and PK11_Decrypt were added to provide access
1827 * to the AES GCM implementation in the NSS softoken. So the presence of
1828 * these two functions implies the NSS version supports AES GCM.
1829 */
1830 static PRBool
1831 ssl3_HasGCMSupport(void)
1832 {
1833 (void)PR_CallOnce(&resolvePK11CryptOnce, ssl3_ResolvePK11CryptFunctions);
1834 return pk11_encrypt != NULL;
1835 }
1836
1837 /* On this socket, disable the GCM cipher suites */
1838 SECStatus
1839 ssl3_DisableGCMSuites(sslSocket * ss)
1840 {
1841 unsigned int i;
1842
1843 for (i = 0; i < PR_ARRAY_SIZE(cipher_suite_defs); i++) {
1844 const ssl3CipherSuiteDef *cipher_def = &cipher_suite_defs[i];
1845 if (cipher_def->bulk_cipher_alg == cipher_aes_128_gcm) {
1846 SECStatus rv = ssl3_CipherPrefSet(ss, cipher_def->cipher_suite,
1847 PR_FALSE);
1848 PORT_Assert(rv == SECSuccess); /* else is coding error */
1849 }
1850 }
1851 return SECSuccess;
1852 }
1853
1854 static SECStatus
1855 ssl3_AESGCM(ssl3KeyMaterial *keys,
1856 PRBool doDecrypt,
1857 unsigned char *out,
1858 int *outlen,
1859 int maxout,
1860 const unsigned char *in,
1861 int inlen,
wtc 2013/08/10 01:22:59 I removed the explicitNonce input. For decrypt, t
1862 SSL3ContentType type,
1863 SSL3ProtocolVersion version,
1864 SSL3SequenceNumber seq_num)
1865 {
1866 SECItem param;
1867 SECStatus rv = SECFailure;
1868 unsigned char nonce[12];
1869 unsigned char additionalData[13];
1870 unsigned int additionalDataLen;
1871 unsigned int uOutLen;
1872 CK_GCM_PARAMS gcmParams;
1873
1874 static const int tagSize = 16;
1875 static const int explicitNonceLen = 8;
1876 PR_STATIC_ASSERT(sizeof(seq_num) == explicitNonceLen);
1877
1878 /* See https://tools.ietf.org/html/rfc5288#section-3 for details of how the
1879 * nonce is formed. */
1880 memcpy(nonce, keys->write_iv, 4);
1881 if (doDecrypt) {
1882 if (inlen < explicitNonceLen) {
1883 PORT_SetError(SEC_ERROR_INPUT_LEN);
1884 return SECFailure;
1885 }
1886 memcpy(nonce + 4, in, explicitNonceLen);
1887 in += explicitNonceLen;
1888 inlen -= explicitNonceLen;
1889 *outlen = 0;
1890 } else {
1891 if (maxout < explicitNonceLen) {
1892 PORT_SetError(SEC_ERROR_INPUT_LEN);
1893 return SECFailure;
1894 }
1895 /* Use the 64-bit sequence number as the explicit nonce. */
1896 memcpy(nonce + 4, &seq_num, explicitNonceLen);
agl 2013/08/13 12:17:12 This is coping directly out of the SSL3SequenceNum
wtc 2013/08/14 01:57:02 Done.
1897 memcpy(out, &seq_num, explicitNonceLen);
1898 out += explicitNonceLen;
1899 maxout -= explicitNonceLen;
1900 *outlen = explicitNonceLen;
1901 }
1902
1903 /* See https://tools.ietf.org/html/rfc5246#section-6.2.3.3 for the
1904 * definition of the AEAD additional data. */
1905 additionalDataLen = ssl3_BuildRecordPseudoHeader(
1906 additionalData, seq_num, type, PR_TRUE /* includes version */,
1907 version, PR_FALSE /* not DTLS */,
1908 inlen - (doDecrypt ? tagSize : 0));
1909 PORT_Assert(additionalDataLen <= sizeof(additionalData));
1910
1911 param.type = siBuffer;
1912 param.data = (unsigned char *) &gcmParams;
1913 param.len = sizeof(gcmParams);
1914 gcmParams.pIv = nonce;
1915 gcmParams.ulIvLen = sizeof(nonce);
1916 gcmParams.pAAD = additionalData;
1917 gcmParams.ulAADLen = additionalDataLen;
1918 gcmParams.ulTagBits = tagSize * 8;
1919
1920 if (doDecrypt) {
1921 rv = pk11_decrypt(keys->write_key, CKM_AES_GCM, &param, out, &uOutLen,
1922 maxout, in, inlen);
1923 } else {
1924 rv = pk11_encrypt(keys->write_key, CKM_AES_GCM, &param, out, &uOutLen,
1925 maxout, in, inlen);
1926 }
1927 *outlen += (int) uOutLen;
1928
1929 return rv;
1930 }
1931
1724 /* Initialize encryption and MAC contexts for pending spec. 1932 /* Initialize encryption and MAC contexts for pending spec.
1725 * Master Secret already is derived. 1933 * Master Secret already is derived.
1726 * Caller holds Spec write lock. 1934 * Caller holds Spec write lock.
1727 */ 1935 */
1728 static SECStatus 1936 static SECStatus
1729 ssl3_InitPendingContextsPKCS11(sslSocket *ss) 1937 ssl3_InitPendingContextsPKCS11(sslSocket *ss)
1730 { 1938 {
1731 ssl3CipherSpec * pwSpec; 1939 ssl3CipherSpec * pwSpec;
1732 const ssl3BulkCipherDef *cipher_def; 1940 const ssl3BulkCipherDef *cipher_def;
1733 PK11Context * serverContext = NULL; 1941 PK11Context * serverContext = NULL;
1734 PK11Context * clientContext = NULL; 1942 PK11Context * clientContext = NULL;
1735 SECItem * param; 1943 SECItem * param;
1736 CK_MECHANISM_TYPE mechanism; 1944 CK_MECHANISM_TYPE mechanism;
1737 CK_MECHANISM_TYPE mac_mech; 1945 CK_MECHANISM_TYPE mac_mech;
1738 CK_ULONG macLength; 1946 CK_ULONG macLength;
1739 CK_ULONG effKeyBits; 1947 CK_ULONG effKeyBits;
1740 SECItem iv; 1948 SECItem iv;
1741 SECItem mac_param; 1949 SECItem mac_param;
1742 SSLCipherAlgorithm calg; 1950 SSLCipherAlgorithm calg;
1743 1951
1744 PORT_Assert( ss->opt.noLocks || ssl_HaveSSL3HandshakeLock(ss)); 1952 PORT_Assert( ss->opt.noLocks || ssl_HaveSSL3HandshakeLock(ss));
1745 PORT_Assert( ss->opt.noLocks || ssl_HaveSpecWriteLock(ss)); 1953 PORT_Assert( ss->opt.noLocks || ssl_HaveSpecWriteLock(ss));
1746 PORT_Assert(ss->ssl3.prSpec == ss->ssl3.pwSpec); 1954 PORT_Assert(ss->ssl3.prSpec == ss->ssl3.pwSpec);
1747 1955
1748 pwSpec = ss->ssl3.pwSpec; 1956 pwSpec = ss->ssl3.pwSpec;
1749 cipher_def = pwSpec->cipher_def; 1957 cipher_def = pwSpec->cipher_def;
1750 macLength = pwSpec->mac_size; 1958 macLength = pwSpec->mac_size;
1959 calg = cipher_def->calg;
1960 PORT_Assert(alg2Mech[calg].calg == calg);
1961
1962 pwSpec->client.write_mac_context = NULL;
1963 pwSpec->server.write_mac_context = NULL;
1964
1965 if (calg == calg_aes_gcm) {
1966 pwSpec->encode = NULL;
1967 pwSpec->decode = NULL;
1968 pwSpec->destroy = NULL;
1969 pwSpec->encodeContext = NULL;
1970 pwSpec->decodeContext = NULL;
1971 pwSpec->aead = ssl3_AESGCM;
1972 return SECSuccess;
1973 }
1751 1974
1752 /* 1975 /*
1753 ** Now setup the MAC contexts, 1976 ** Now setup the MAC contexts,
1754 ** crypto contexts are setup below. 1977 ** crypto contexts are setup below.
1755 */ 1978 */
1756 1979
1757 pwSpec->client.write_mac_context = NULL;
1758 pwSpec->server.write_mac_context = NULL;
1759 mac_mech = pwSpec->mac_def->mmech; 1980 mac_mech = pwSpec->mac_def->mmech;
1760 mac_param.data = (unsigned char *)&macLength; 1981 mac_param.data = (unsigned char *)&macLength;
1761 mac_param.len = sizeof(macLength); 1982 mac_param.len = sizeof(macLength);
1762 mac_param.type = 0; 1983 mac_param.type = 0;
1763 1984
1764 pwSpec->client.write_mac_context = PK11_CreateContextBySymKey( 1985 pwSpec->client.write_mac_context = PK11_CreateContextBySymKey(
1765 mac_mech, CKA_SIGN, pwSpec->client.write_mac_key, &mac_param); 1986 mac_mech, CKA_SIGN, pwSpec->client.write_mac_key, &mac_param);
1766 if (pwSpec->client.write_mac_context == NULL) { 1987 if (pwSpec->client.write_mac_context == NULL) {
1767 ssl_MapLowLevelError(SSL_ERROR_SYM_KEY_CONTEXT_FAILURE); 1988 ssl_MapLowLevelError(SSL_ERROR_SYM_KEY_CONTEXT_FAILURE);
1768 goto fail; 1989 goto fail;
1769 } 1990 }
1770 pwSpec->server.write_mac_context = PK11_CreateContextBySymKey( 1991 pwSpec->server.write_mac_context = PK11_CreateContextBySymKey(
1771 mac_mech, CKA_SIGN, pwSpec->server.write_mac_key, &mac_param); 1992 mac_mech, CKA_SIGN, pwSpec->server.write_mac_key, &mac_param);
1772 if (pwSpec->server.write_mac_context == NULL) { 1993 if (pwSpec->server.write_mac_context == NULL) {
1773 ssl_MapLowLevelError(SSL_ERROR_SYM_KEY_CONTEXT_FAILURE); 1994 ssl_MapLowLevelError(SSL_ERROR_SYM_KEY_CONTEXT_FAILURE);
1774 goto fail; 1995 goto fail;
1775 } 1996 }
1776 1997
1777 /* 1998 /*
1778 ** Now setup the crypto contexts. 1999 ** Now setup the crypto contexts.
1779 */ 2000 */
1780 2001
1781 calg = cipher_def->calg;
1782 PORT_Assert(alg2Mech[calg].calg == calg);
1783
1784 if (calg == calg_null) { 2002 if (calg == calg_null) {
1785 pwSpec->encode = Null_Cipher; 2003 pwSpec->encode = Null_Cipher;
1786 pwSpec->decode = Null_Cipher; 2004 pwSpec->decode = Null_Cipher;
1787 pwSpec->destroy = NULL; 2005 pwSpec->destroy = NULL;
1788 return SECSuccess; 2006 return SECSuccess;
1789 } 2007 }
1790 mechanism = alg2Mech[calg].cmech; 2008 mechanism = alg2Mech[calg].cmech;
1791 effKeyBits = cipher_def->key_size * BPB; 2009 effKeyBits = cipher_def->key_size * BPB;
1792 2010
1793 /* 2011 /*
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1992 SSL3ContentType type, 2210 SSL3ContentType type,
1993 SSL3ProtocolVersion version, 2211 SSL3ProtocolVersion version,
1994 SSL3SequenceNumber seq_num, 2212 SSL3SequenceNumber seq_num,
1995 const SSL3Opaque * input, 2213 const SSL3Opaque * input,
1996 int inputLength, 2214 int inputLength,
1997 unsigned char * outbuf, 2215 unsigned char * outbuf,
1998 unsigned int * outLength) 2216 unsigned int * outLength)
1999 { 2217 {
2000 const ssl3MACDef * mac_def; 2218 const ssl3MACDef * mac_def;
2001 SECStatus rv; 2219 SECStatus rv;
2002 #ifndef NO_PKCS11_BYPASS
2003 PRBool isTLS; 2220 PRBool isTLS;
2004 #endif
2005 unsigned int tempLen; 2221 unsigned int tempLen;
2006 unsigned char temp[MAX_MAC_LENGTH]; 2222 unsigned char temp[MAX_MAC_LENGTH];
2007 2223
2008 temp[0] = (unsigned char)(seq_num.high >> 24);
2009 temp[1] = (unsigned char)(seq_num.high >> 16);
2010 temp[2] = (unsigned char)(seq_num.high >> 8);
2011 temp[3] = (unsigned char)(seq_num.high >> 0);
2012 temp[4] = (unsigned char)(seq_num.low >> 24);
2013 temp[5] = (unsigned char)(seq_num.low >> 16);
2014 temp[6] = (unsigned char)(seq_num.low >> 8);
2015 temp[7] = (unsigned char)(seq_num.low >> 0);
2016 temp[8] = type;
2017
2018 /* TLS MAC includes the record's version field, SSL's doesn't. 2224 /* TLS MAC includes the record's version field, SSL's doesn't.
2019 ** We decide which MAC defintiion to use based on the version of 2225 ** We decide which MAC defintiion to use based on the version of
2020 ** the protocol that was negotiated when the spec became current, 2226 ** the protocol that was negotiated when the spec became current,
2021 ** NOT based on the version value in the record itself. 2227 ** NOT based on the version value in the record itself.
2022 ** But, we use the record'v version value in the computation. 2228 ** But, we use the record'v version value in the computation.
agl 2013/08/13 12:17:12 This relocated comment contains a typo ("record'v"
wtc 2013/08/14 01:57:02 Done.
2023 */ 2229 */
2024 if (spec->version <= SSL_LIBRARY_VERSION_3_0) { 2230 isTLS = spec->version > SSL_LIBRARY_VERSION_3_0;
2025 » temp[9] = MSB(inputLength); 2231 tempLen = ssl3_BuildRecordPseudoHeader(temp, seq_num, type, isTLS,
2026 » temp[10] = LSB(inputLength); 2232 » » » » » version, isDTLS, inputLength);
2027 » tempLen = 11; 2233 PORT_Assert(tempLen <= sizeof(temp));
2028 #ifndef NO_PKCS11_BYPASS
2029 » isTLS = PR_FALSE;
2030 #endif
2031 } else {
2032 » /* New TLS hash includes version. */
2033 » if (isDTLS) {
2034 » SSL3ProtocolVersion dtls_version;
2035
2036 » dtls_version = dtls_TLSVersionToDTLSVersion(version);
2037 » temp[9] = MSB(dtls_version);
2038 » temp[10] = LSB(dtls_version);
2039 } else {
2040 » temp[9] = MSB(version);
2041 » temp[10] = LSB(version);
2042 }
2043 » temp[11] = MSB(inputLength);
2044 » temp[12] = LSB(inputLength);
2045 » tempLen = 13;
2046 #ifndef NO_PKCS11_BYPASS
2047 » isTLS = PR_TRUE;
2048 #endif
2049 }
2050 2234
2051 PRINT_BUF(95, (NULL, "frag hash1: temp", temp, tempLen)); 2235 PRINT_BUF(95, (NULL, "frag hash1: temp", temp, tempLen));
2052 PRINT_BUF(95, (NULL, "frag hash1: input", input, inputLength)); 2236 PRINT_BUF(95, (NULL, "frag hash1: input", input, inputLength));
2053 2237
2054 mac_def = spec->mac_def; 2238 mac_def = spec->mac_def;
2055 if (mac_def->mac == mac_null) { 2239 if (mac_def->mac == mac_null) {
2056 *outLength = 0; 2240 *outLength = 0;
2057 return SECSuccess; 2241 return SECSuccess;
2058 } 2242 }
2059 #ifndef NO_PKCS11_BYPASS 2243 #ifndef NO_PKCS11_BYPASS
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
2163 rv = SECFailure; 2347 rv = SECFailure;
2164 ssl_MapLowLevelError(SSL_ERROR_MAC_COMPUTATION_FAILURE); 2348 ssl_MapLowLevelError(SSL_ERROR_MAC_COMPUTATION_FAILURE);
2165 } 2349 }
2166 return rv; 2350 return rv;
2167 } 2351 }
2168 2352
2169 /* This is a bodge to allow this code to be compiled against older NSS headers 2353 /* This is a bodge to allow this code to be compiled against older NSS headers
2170 * that don't contain the CBC constant-time changes. */ 2354 * that don't contain the CBC constant-time changes. */
2171 #ifndef CKM_NSS_HMAC_CONSTANT_TIME 2355 #ifndef CKM_NSS_HMAC_CONSTANT_TIME
2172 #define CKM_NSS_HMAC_CONSTANT_TIME (CKM_NSS + 19) 2356 #define CKM_NSS_HMAC_CONSTANT_TIME (CKM_NSS + 19)
2173 #define CKM_NSS_SSL3_MAC_CONSTANT_TIME (CKM_NSS + 20) 2357 #define CKM_NSS_SSL3_MAC_CONSTANT_TIME (CKM_NSS + 20)
Ryan Sleevi 2013/08/13 21:34:46 We can remove this in a follow-up patch, now that
wtc 2013/08/14 22:05:42 Done. Added a TODO to README.chromium to remove cb
2174 2358
2175 typedef struct CK_NSS_MAC_CONSTANT_TIME_PARAMS { 2359 typedef struct CK_NSS_MAC_CONSTANT_TIME_PARAMS {
2176 CK_MECHANISM_TYPE macAlg; /* in */ 2360 CK_MECHANISM_TYPE macAlg; /* in */
2177 CK_ULONG ulBodyTotalLen; /* in */ 2361 CK_ULONG ulBodyTotalLen; /* in */
2178 CK_BYTE * pHeader; /* in */ 2362 CK_BYTE * pHeader; /* in */
2179 CK_ULONG ulHeaderLen; /* in */ 2363 CK_ULONG ulHeaderLen; /* in */
2180 } CK_NSS_MAC_CONSTANT_TIME_PARAMS; 2364 } CK_NSS_MAC_CONSTANT_TIME_PARAMS;
2181 #endif 2365 #endif
2182 2366
2183 /* Called from: ssl3_HandleRecord() 2367 /* Called from: ssl3_HandleRecord()
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
2383 rv = cwSpec->compressor( 2567 rv = cwSpec->compressor(
2384 cwSpec->compressContext, 2568 cwSpec->compressContext,
2385 wrBuf->buf + headerLen + ivLen, &outlen, 2569 wrBuf->buf + headerLen + ivLen, &outlen,
2386 wrBuf->space - headerLen - ivLen, pIn, contentLen); 2570 wrBuf->space - headerLen - ivLen, pIn, contentLen);
2387 if (rv != SECSuccess) 2571 if (rv != SECSuccess)
2388 return rv; 2572 return rv;
2389 pIn = wrBuf->buf + headerLen + ivLen; 2573 pIn = wrBuf->buf + headerLen + ivLen;
2390 contentLen = outlen; 2574 contentLen = outlen;
2391 } 2575 }
2392 2576
2393 /* 2577 if (cipher_def->type == type_aead) {
2394 * Add the MAC 2578 » const int nonceLen = cipher_def->explicit_nonce_size;
agl 2013/08/13 12:17:12 The explicit nonce size in the cipher_def is now o
wtc 2013/08/14 01:57:02 cipher_def->explicit_nonce_size is also used in th
2395 */ 2579 » const int tagLen = cipher_def->tag_size;
2396 rv = ssl3_ComputeRecordMAC( cwSpec, isServer, isDTLS,
2397 » type, cwSpec->version, cwSpec->write_seq_num, pIn, contentLen,
2398 » wrBuf->buf + headerLen + ivLen + contentLen, &macLen);
2399 if (rv != SECSuccess) {
2400 » ssl_MapLowLevelError(SSL_ERROR_MAC_COMPUTATION_FAILURE);
2401 » return SECFailure;
2402 }
2403 p1Len = contentLen;
2404 p2Len = macLen;
2405 fragLen = contentLen + macLen;» /* needs to be encrypted */
2406 PORT_Assert(fragLen <= MAX_FRAGMENT_LENGTH + 1024);
2407 2580
2408 /* 2581 » if (headerLen + nonceLen + contentLen + tagLen > wrBuf->space) {
2409 * Pad the text (if we're doing a block cipher) 2582 » PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
2410 * then Encrypt it 2583 » return SECFailure;
2411 */ 2584 » }
2412 if (cipher_def->type == type_block) {
2413 » unsigned char * pBuf;
2414 » int padding_length;
2415 » int i;
2416 2585
2417 » oddLen = contentLen % cipher_def->block_size; 2586 » cipherBytes = contentLen;
2418 » /* Assume blockSize is a power of two */ 2587 » rv = cwSpec->aead(
2419 » padding_length = cipher_def->block_size - 1 - 2588 » » isServer ? &cwSpec->server : &cwSpec->client,
2420 » » » ((fragLen) & (cipher_def->block_size - 1)); 2589 » » PR_FALSE, /* do encrypt */
2421 » fragLen += padding_length + 1; 2590 » » wrBuf->buf + headerLen, /* output */
2422 » PORT_Assert((fragLen % cipher_def->block_size) == 0); 2591 » » &cipherBytes, /* out len */
2423 2592 » » wrBuf->space - headerLen, /* max out */
2424 » /* Pad according to TLS rules (also acceptable to SSL3). */ 2593 » » pIn, contentLen, /* input */
2425 » pBuf = &wrBuf->buf[headerLen + ivLen + fragLen - 1]; 2594 » » type, cwSpec->version, cwSpec->write_seq_num);
2426 » for (i = padding_length + 1; i > 0; --i) { 2595 » if (rv != SECSuccess) {
2427 » *pBuf-- = padding_length;
2428 » }
2429 » /* now, if contentLen is not a multiple of block size, fix it */
2430 » p2Len = fragLen - p1Len;
2431 }
2432 if (p1Len < 256) {
2433 » oddLen = p1Len;
2434 » p1Len = 0;
2435 } else {
2436 » p1Len -= oddLen;
2437 }
2438 if (oddLen) {
2439 » p2Len += oddLen;
2440 » PORT_Assert( (cipher_def->block_size < 2) || \
2441 » » (p2Len % cipher_def->block_size) == 0);
2442 » memmove(wrBuf->buf + headerLen + ivLen + p1Len, pIn + p1Len, oddLen);
2443 }
2444 if (p1Len > 0) {
2445 » int cipherBytesPart1 = -1;
2446 » rv = cwSpec->encode( cwSpec->encodeContext,
2447 » wrBuf->buf + headerLen + ivLen, /* output */
2448 » &cipherBytesPart1, /* actual outlen */
2449 » p1Len, /* max outlen */
2450 » pIn, p1Len); /* input, and inputlen */
2451 » PORT_Assert(rv == SECSuccess && cipherBytesPart1 == (int) p1Len);
2452 » if (rv != SECSuccess || cipherBytesPart1 != (int) p1Len) {
2453 PORT_SetError(SSL_ERROR_ENCRYPTION_FAILURE); 2596 PORT_SetError(SSL_ERROR_ENCRYPTION_FAILURE);
2454 return SECFailure; 2597 return SECFailure;
2455 } 2598 }
2456 » cipherBytes += cipherBytesPart1; 2599 } else {
2457 } 2600 » /*
2458 if (p2Len > 0) { 2601 » * Add the MAC
2459 » int cipherBytesPart2 = -1; 2602 » */
2460 » rv = cwSpec->encode( cwSpec->encodeContext, 2603 » rv = ssl3_ComputeRecordMAC( cwSpec, isServer, isDTLS,
2461 » wrBuf->buf + headerLen + ivLen + p1Len, 2604 » type, cwSpec->version, cwSpec->write_seq_num, pIn, contentLen,
2462 » &cipherBytesPart2, /* output and actual outLen */ 2605 » wrBuf->buf + headerLen + ivLen + contentLen, &macLen);
2463 » p2Len, /* max outlen */ 2606 » if (rv != SECSuccess) {
2464 » wrBuf->buf + headerLen + ivLen + p1Len, 2607 » ssl_MapLowLevelError(SSL_ERROR_MAC_COMPUTATION_FAILURE);
2465 » p2Len); /* input and inputLen*/
2466 » PORT_Assert(rv == SECSuccess && cipherBytesPart2 == (int) p2Len);
2467 » if (rv != SECSuccess || cipherBytesPart2 != (int) p2Len) {
2468 » PORT_SetError(SSL_ERROR_ENCRYPTION_FAILURE);
2469 return SECFailure; 2608 return SECFailure;
2470 } 2609 }
2471 » cipherBytes += cipherBytesPart2; 2610 » p1Len = contentLen;
2472 }» 2611 » p2Len = macLen;
2612 » fragLen = contentLen + macLen;» /* needs to be encrypted */
2613 » PORT_Assert(fragLen <= MAX_FRAGMENT_LENGTH + 1024);
2614
2615 » /*
2616 » * Pad the text (if we're doing a block cipher)
2617 » * then Encrypt it
2618 » */
2619 » if (cipher_def->type == type_block) {
2620 » unsigned char * pBuf;
2621 » int padding_length;
2622 » int i;
2623
2624 » oddLen = contentLen % cipher_def->block_size;
2625 » /* Assume blockSize is a power of two */
2626 » padding_length = cipher_def->block_size - 1 -
2627 » » » ((fragLen) & (cipher_def->block_size - 1));
2628 » fragLen += padding_length + 1;
2629 » PORT_Assert((fragLen % cipher_def->block_size) == 0);
2630
2631 » /* Pad according to TLS rules (also acceptable to SSL3). */
2632 » pBuf = &wrBuf->buf[headerLen + ivLen + fragLen - 1];
2633 » for (i = padding_length + 1; i > 0; --i) {
2634 » » *pBuf-- = padding_length;
2635 » }
2636 » /* now, if contentLen is not a multiple of block size, fix it */
2637 » p2Len = fragLen - p1Len;
2638 » }
2639 » if (p1Len < 256) {
2640 » oddLen = p1Len;
2641 » p1Len = 0;
2642 » } else {
2643 » p1Len -= oddLen;
2644 » }
2645 » if (oddLen) {
2646 » p2Len += oddLen;
2647 » PORT_Assert( (cipher_def->block_size < 2) || \
2648 » » » (p2Len % cipher_def->block_size) == 0);
2649 » memmove(wrBuf->buf + headerLen + ivLen + p1Len, pIn + p1Len,
2650 » » oddLen);
2651 » }
2652 » if (p1Len > 0) {
2653 » int cipherBytesPart1 = -1;
2654 » rv = cwSpec->encode( cwSpec->encodeContext,
2655 » » wrBuf->buf + headerLen + ivLen, /* output */
2656 » » &cipherBytesPart1, /* actual outlen */
2657 » » p1Len, /* max outlen */
2658 » » pIn, p1Len); /* input, and inputlen */
2659 » PORT_Assert(rv == SECSuccess && cipherBytesPart1 == (int) p1Len);
2660 » if (rv != SECSuccess || cipherBytesPart1 != (int) p1Len) {
2661 » » PORT_SetError(SSL_ERROR_ENCRYPTION_FAILURE);
2662 » » return SECFailure;
2663 » }
2664 » cipherBytes += cipherBytesPart1;
2665 » }
2666 » if (p2Len > 0) {
2667 » int cipherBytesPart2 = -1;
2668 » rv = cwSpec->encode( cwSpec->encodeContext,
2669 » » wrBuf->buf + headerLen + ivLen + p1Len,
2670 » » &cipherBytesPart2, /* output and actual outLen */
2671 » » p2Len, /* max outlen */
2672 » » wrBuf->buf + headerLen + ivLen + p1Len,
2673 » » p2Len); /* input and inputLen*/
2674 » PORT_Assert(rv == SECSuccess && cipherBytesPart2 == (int) p2Len);
2675 » if (rv != SECSuccess || cipherBytesPart2 != (int) p2Len) {
2676 » » PORT_SetError(SSL_ERROR_ENCRYPTION_FAILURE);
2677 » » return SECFailure;
2678 » }
2679 » cipherBytes += cipherBytesPart2;
2680 » }
2681 }
2682
2473 PORT_Assert(cipherBytes <= MAX_FRAGMENT_LENGTH + 1024); 2683 PORT_Assert(cipherBytes <= MAX_FRAGMENT_LENGTH + 1024);
2474 2684
2475 wrBuf->len = cipherBytes + headerLen; 2685 wrBuf->len = cipherBytes + headerLen;
2476 wrBuf->buf[0] = type; 2686 wrBuf->buf[0] = type;
2477 if (isDTLS) { 2687 if (isDTLS) {
2478 SSL3ProtocolVersion version; 2688 SSL3ProtocolVersion version;
2479 2689
2480 version = dtls_TLSVersionToDTLSVersion(cwSpec->version); 2690 version = dtls_TLSVersionToDTLSVersion(cwSpec->version);
2481 wrBuf->buf[1] = MSB(version); 2691 wrBuf->buf[1] = MSB(version);
2482 wrBuf->buf[2] = LSB(version); 2692 wrBuf->buf[2] = LSB(version);
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
3005 ssl_ReleaseSSL3HandshakeLock(ss); 3215 ssl_ReleaseSSL3HandshakeLock(ss);
3006 return rv; /* error set by ssl3_FlushHandshake or ssl3_SendRecord */ 3216 return rv; /* error set by ssl3_FlushHandshake or ssl3_SendRecord */
3007 } 3217 }
3008 3218
3009 /* 3219 /*
3010 * Send illegal_parameter alert. Set generic error number. 3220 * Send illegal_parameter alert. Set generic error number.
3011 */ 3221 */
3012 static SECStatus 3222 static SECStatus
3013 ssl3_IllegalParameter(sslSocket *ss) 3223 ssl3_IllegalParameter(sslSocket *ss)
3014 { 3224 {
3015 PRBool isTLS;
3016
3017 isTLS = (PRBool)(ss->ssl3.pwSpec->version > SSL_LIBRARY_VERSION_3_0);
3018 (void)SSL3_SendAlert(ss, alert_fatal, illegal_parameter); 3225 (void)SSL3_SendAlert(ss, alert_fatal, illegal_parameter);
3019 PORT_SetError(ss->sec.isServer ? SSL_ERROR_BAD_CLIENT 3226 PORT_SetError(ss->sec.isServer ? SSL_ERROR_BAD_CLIENT
3020 : SSL_ERROR_BAD_SERVER ); 3227 : SSL_ERROR_BAD_SERVER );
3021 return SECFailure; 3228 return SECFailure;
3022 } 3229 }
3023 3230
3024 /* 3231 /*
3025 * Send handshake_Failure alert. Set generic error number. 3232 * Send handshake_Failure alert. Set generic error number.
3026 */ 3233 */
3027 static SECStatus 3234 static SECStatus
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
3531 key_material_params.ulIVSizeInBits = cipher_def->iv_size * BPB; 3738 key_material_params.ulIVSizeInBits = cipher_def->iv_size * BPB;
3532 if (cipher_def->type == type_block && 3739 if (cipher_def->type == type_block &&
3533 pwSpec->version >= SSL_LIBRARY_VERSION_TLS_1_1) { 3740 pwSpec->version >= SSL_LIBRARY_VERSION_TLS_1_1) {
3534 /* Block ciphers in >= TLS 1.1 use a per-record, explicit IV. */ 3741 /* Block ciphers in >= TLS 1.1 use a per-record, explicit IV. */
3535 key_material_params.ulIVSizeInBits = 0; 3742 key_material_params.ulIVSizeInBits = 0;
3536 memset(pwSpec->client.write_iv, 0, cipher_def->iv_size); 3743 memset(pwSpec->client.write_iv, 0, cipher_def->iv_size);
3537 memset(pwSpec->server.write_iv, 0, cipher_def->iv_size); 3744 memset(pwSpec->server.write_iv, 0, cipher_def->iv_size);
3538 } 3745 }
3539 3746
3540 key_material_params.bIsExport = (CK_BBOOL)(kea_def->is_limited); 3747 key_material_params.bIsExport = (CK_BBOOL)(kea_def->is_limited);
3541 /* was: (CK_BBOOL)(cipher_def->keygen_mode != kg_strong); */
3542 3748
3543 key_material_params.RandomInfo.pClientRandom = cr; 3749 key_material_params.RandomInfo.pClientRandom = cr;
3544 key_material_params.RandomInfo.ulClientRandomLen = SSL3_RANDOM_LENGTH; 3750 key_material_params.RandomInfo.ulClientRandomLen = SSL3_RANDOM_LENGTH;
3545 key_material_params.RandomInfo.pServerRandom = sr; 3751 key_material_params.RandomInfo.pServerRandom = sr;
3546 key_material_params.RandomInfo.ulServerRandomLen = SSL3_RANDOM_LENGTH; 3752 key_material_params.RandomInfo.ulServerRandomLen = SSL3_RANDOM_LENGTH;
3547 key_material_params.pReturnedKeyMaterial = &returnedKeys; 3753 key_material_params.pReturnedKeyMaterial = &returnedKeys;
3548 3754
3549 returnedKeys.pIVClient = pwSpec->client.write_iv; 3755 returnedKeys.pIVClient = pwSpec->client.write_iv;
3550 returnedKeys.pIVServer = pwSpec->server.write_iv; 3756 returnedKeys.pIVServer = pwSpec->server.write_iv;
3551 keySize = cipher_def->key_size; 3757 keySize = cipher_def->key_size;
(...skipping 1271 matching lines...) Expand 10 before | Expand all | Expand 10 after
4823 if (!total_exten_len || !isTLS) { 5029 if (!total_exten_len || !isTLS) {
4824 /* not sending the elliptic_curves and ec_point_formats extensions */ 5030 /* not sending the elliptic_curves and ec_point_formats extensions */
4825 ssl3_DisableECCSuites(ss, NULL); /* disable all ECC suites */ 5031 ssl3_DisableECCSuites(ss, NULL); /* disable all ECC suites */
4826 } 5032 }
4827 #endif 5033 #endif
4828 5034
4829 if (IS_DTLS(ss)) { 5035 if (IS_DTLS(ss)) {
4830 ssl3_DisableNonDTLSSuites(ss); 5036 ssl3_DisableNonDTLSSuites(ss);
4831 } 5037 }
4832 5038
5039 if (!ssl3_HasGCMSupport()) {
5040 ssl3_DisableGCMSuites(ss);
5041 }
5042
4833 /* how many suites are permitted by policy and user preference? */ 5043 /* how many suites are permitted by policy and user preference? */
4834 num_suites = count_cipher_suites(ss, ss->ssl3.policy, PR_TRUE); 5044 num_suites = count_cipher_suites(ss, ss->ssl3.policy, PR_TRUE);
4835 if (!num_suites) 5045 if (!num_suites)
4836 return SECFailure; /* count_cipher_suites has set error code. */ 5046 return SECFailure; /* count_cipher_suites has set error code. */
4837 if (ss->ssl3.hs.sendingSCSV) { 5047 if (ss->ssl3.hs.sendingSCSV) {
4838 ++num_suites; /* make room for SCSV */ 5048 ++num_suites; /* make room for SCSV */
4839 } 5049 }
4840 5050
4841 /* count compression methods */ 5051 /* count compression methods */
4842 numCompressionMethods = 0; 5052 numCompressionMethods = 0;
(...skipping 5096 matching lines...) Expand 10 before | Expand all | Expand 10 after
9939 return rv; 10149 return rv;
9940 } 10150 }
9941 10151
9942 /* called from ssl3_SendFinished 10152 /* called from ssl3_SendFinished
9943 * 10153 *
9944 * This function is simply a debugging aid and therefore does not return a 10154 * This function is simply a debugging aid and therefore does not return a
9945 * SECStatus. */ 10155 * SECStatus. */
9946 static void 10156 static void
9947 ssl3_RecordKeyLog(sslSocket *ss) 10157 ssl3_RecordKeyLog(sslSocket *ss)
9948 { 10158 {
9949 sslSessionID *sid;
9950 SECStatus rv; 10159 SECStatus rv;
9951 SECItem *keyData; 10160 SECItem *keyData;
9952 char buf[14 /* "CLIENT_RANDOM " */ + 10161 char buf[14 /* "CLIENT_RANDOM " */ +
9953 SSL3_RANDOM_LENGTH*2 /* client_random */ + 10162 SSL3_RANDOM_LENGTH*2 /* client_random */ +
9954 1 /* " " */ + 10163 1 /* " " */ +
9955 48*2 /* master secret */ + 10164 48*2 /* master secret */ +
9956 1 /* new line */]; 10165 1 /* new line */];
9957 unsigned int j; 10166 unsigned int j;
9958 10167
9959 PORT_Assert( ss->opt.noLocks || ssl_HaveSSL3HandshakeLock(ss)); 10168 PORT_Assert( ss->opt.noLocks || ssl_HaveSSL3HandshakeLock(ss));
9960 10169
9961 sid = ss->sec.ci.sid;
9962
9963 if (!ssl_keylog_iob) 10170 if (!ssl_keylog_iob)
9964 return; 10171 return;
9965 10172
9966 rv = PK11_ExtractKeyValue(ss->ssl3.cwSpec->master_secret); 10173 rv = PK11_ExtractKeyValue(ss->ssl3.cwSpec->master_secret);
9967 if (rv != SECSuccess) 10174 if (rv != SECSuccess)
9968 return; 10175 return;
9969 10176
9970 ssl_GetSpecReadLock(ss); 10177 ssl_GetSpecReadLock(ss);
9971 10178
9972 /* keyData does not need to be freed. */ 10179 /* keyData does not need to be freed. */
(...skipping 1191 matching lines...) Expand 10 before | Expand all | Expand 10 after
11164 11371
11165 good = ~0U; 11372 good = ~0U;
11166 minLength = crSpec->mac_size; 11373 minLength = crSpec->mac_size;
11167 if (cipher_def->type == type_block) { 11374 if (cipher_def->type == type_block) {
11168 /* CBC records have a padding length byte at the end. */ 11375 /* CBC records have a padding length byte at the end. */
11169 minLength++; 11376 minLength++;
11170 if (crSpec->version >= SSL_LIBRARY_VERSION_TLS_1_1) { 11377 if (crSpec->version >= SSL_LIBRARY_VERSION_TLS_1_1) {
11171 /* With >= TLS 1.1, CBC records have an explicit IV. */ 11378 /* With >= TLS 1.1, CBC records have an explicit IV. */
11172 minLength += cipher_def->iv_size; 11379 minLength += cipher_def->iv_size;
11173 } 11380 }
11381 } else if (cipher_def->type == type_aead) {
11382 minLength = cipher_def->explicit_nonce_size + cipher_def->tag_size;
11174 } 11383 }
11175 11384
11176 /* We can perform this test in variable time because the record's total 11385 /* We can perform this test in variable time because the record's total
11177 * length and the ciphersuite are both public knowledge. */ 11386 * length and the ciphersuite are both public knowledge. */
11178 if (cText->buf->len < minLength) { 11387 if (cText->buf->len < minLength) {
11179 goto decrypt_loser; 11388 » goto decrypt_loser;
11180 } 11389 }
11181 11390
11182 if (cipher_def->type == type_block && 11391 if (cipher_def->type == type_block &&
11183 crSpec->version >= SSL_LIBRARY_VERSION_TLS_1_1) { 11392 crSpec->version >= SSL_LIBRARY_VERSION_TLS_1_1) {
11184 /* Consume the per-record explicit IV. RFC 4346 Section 6.2.3.2 states 11393 /* Consume the per-record explicit IV. RFC 4346 Section 6.2.3.2 states
11185 * "The receiver decrypts the entire GenericBlockCipher structure and 11394 * "The receiver decrypts the entire GenericBlockCipher structure and
11186 * then discards the first cipher block corresponding to the IV 11395 * then discards the first cipher block corresponding to the IV
11187 * component." Instead, we decrypt the first cipher block and then 11396 * component." Instead, we decrypt the first cipher block and then
11188 * discard it before decrypting the rest. 11397 * discard it before decrypting the rest.
11189 */ 11398 */
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
11237 11446
11238 isTLS = (PRBool)(crSpec->version > SSL_LIBRARY_VERSION_3_0); 11447 isTLS = (PRBool)(crSpec->version > SSL_LIBRARY_VERSION_3_0);
11239 11448
11240 if (isTLS && cText->buf->len - ivLen > (MAX_FRAGMENT_LENGTH + 2048)) { 11449 if (isTLS && cText->buf->len - ivLen > (MAX_FRAGMENT_LENGTH + 2048)) {
11241 ssl_ReleaseSpecReadLock(ss); 11450 ssl_ReleaseSpecReadLock(ss);
11242 SSL3_SendAlert(ss, alert_fatal, record_overflow); 11451 SSL3_SendAlert(ss, alert_fatal, record_overflow);
11243 PORT_SetError(SSL_ERROR_RX_RECORD_TOO_LONG); 11452 PORT_SetError(SSL_ERROR_RX_RECORD_TOO_LONG);
11244 return SECFailure; 11453 return SECFailure;
11245 } 11454 }
11246 11455
11247 if (cipher_def->type == type_block && 11456 rType = cText->type;
11248 » ((cText->buf->len - ivLen) % cipher_def->block_size) != 0) { 11457 if (cipher_def->type == type_aead) {
11249 » goto decrypt_loser; 11458 » rv = crSpec->aead(
11250 } 11459 » » ss->sec.isServer ? &crSpec->client : &crSpec->server,
11460 » » PR_TRUE, /* do decrypt */
11461 » » plaintext->buf, /* out */
11462 » » (int*) &plaintext->len, /* outlen */
11463 » » plaintext->space, /* maxout */
11464 » » cText->buf->buf, /* in */
11465 » » cText->buf->len, /* inlen */
11466 » » rType, /* record type */
11467 » » cText->version,
wtc 2013/08/10 01:22:59 Note: we still need to pass a "PRBool isDTLS" argu
11468 » » IS_DTLS(ss) ? cText->seq_num : crSpec->read_seq_num);
11469 » if (rv != SECSuccess) {
11470 » good = 0;
11471 » }
11472 } else {
11473 » if (cipher_def->type == type_block &&
11474 » ((cText->buf->len - ivLen) % cipher_def->block_size) != 0) {
11475 » goto decrypt_loser;
11476 » }
11251 11477
11252 /* decrypt from cText buf to plaintext. */ 11478 » /* decrypt from cText buf to plaintext. */
11253 rv = crSpec->decode( 11479 » rv = crSpec->decode(
11254 » crSpec->decodeContext, plaintext->buf, (int *)&plaintext->len, 11480 » crSpec->decodeContext, plaintext->buf, (int *)&plaintext->len,
11255 » plaintext->space, cText->buf->buf + ivLen, cText->buf->len - ivLen); 11481 » plaintext->space, cText->buf->buf + ivLen, cText->buf->len - ivLen);
11256 if (rv != SECSuccess) { 11482 » if (rv != SECSuccess) {
11257 » goto decrypt_loser; 11483 » goto decrypt_loser;
11258 } 11484 » }
11259 11485
11260 PRINT_BUF(80, (ss, "cleartext:", plaintext->buf, plaintext->len)); 11486 » PRINT_BUF(80, (ss, "cleartext:", plaintext->buf, plaintext->len));
11261 11487
11262 originalLen = plaintext->len; 11488 » originalLen = plaintext->len;
11263 11489
11264 /* If it's a block cipher, check and strip the padding. */ 11490 » /* If it's a block cipher, check and strip the padding. */
11265 if (cipher_def->type == type_block) { 11491 » if (cipher_def->type == type_block) {
11266 » const unsigned int blockSize = cipher_def->block_size; 11492 » const unsigned int blockSize = cipher_def->block_size;
11267 » const unsigned int macSize = crSpec->mac_size; 11493 » const unsigned int macSize = crSpec->mac_size;
11268 11494
11269 » if (crSpec->version <= SSL_LIBRARY_VERSION_3_0) { 11495 » if (crSpec->version <= SSL_LIBRARY_VERSION_3_0) {
11270 » good &= SECStatusToMask(ssl_RemoveSSLv3CBCPadding( 11496 » » good &= SECStatusToMask(ssl_RemoveSSLv3CBCPadding(
11271 » » » plaintext, blockSize, macSize)); 11497 » » » plaintext, blockSize, macSize));
11498 » } else {
11499 » » good &= SECStatusToMask(ssl_RemoveTLSCBCPadding(
11500 » » » plaintext, macSize));
11501 » }
11502 » }
11503
11504 » /* compute the MAC */
11505 » if (cipher_def->type == type_block) {
11506 » rv = ssl3_ComputeRecordMACConstantTime(
11507 » » crSpec, (PRBool)(!ss->sec.isServer),
11508 » » IS_DTLS(ss), rType, cText->version,
11509 » » IS_DTLS(ss) ? cText->seq_num : crSpec->read_seq_num,
11510 » » plaintext->buf, plaintext->len, originalLen,
11511 » » hash, &hashBytes);
11512
11513 » ssl_CBCExtractMAC(plaintext, originalLen, givenHashBuf,
11514 » » » crSpec->mac_size);
11515 » givenHash = givenHashBuf;
11516
11517 » /* plaintext->len will always have enough space to remove the MAC
11518 » * because in ssl_Remove{SSLv3|TLS}CBCPadding we only adjust
11519 » * plaintext->len if the result has enough space for the MAC and we
11520 » * tested the unadjusted size against minLength, above. */
11521 » plaintext->len -= crSpec->mac_size;
11272 } else { 11522 } else {
11273 » good &= SECStatusToMask(ssl_RemoveTLSCBCPadding( 11523 » /* This is safe because we checked the minLength above. */
11274 » » » plaintext, macSize)); 11524 » plaintext->len -= crSpec->mac_size;
11525
11526 » rv = ssl3_ComputeRecordMAC(
11527 » » crSpec, (PRBool)(!ss->sec.isServer),
11528 » » IS_DTLS(ss), rType, cText->version,
11529 » » IS_DTLS(ss) ? cText->seq_num : crSpec->read_seq_num,
11530 » » plaintext->buf, plaintext->len,
11531 » » hash, &hashBytes);
11532
11533 » /* We can read the MAC directly from the record because its location
11534 » * is public when a stream cipher is used. */
11535 » givenHash = plaintext->buf + plaintext->len;
11536 » }
11537
11538 » good &= SECStatusToMask(rv);
11539
11540 » if (hashBytes != (unsigned)crSpec->mac_size ||
11541 » NSS_SecureMemcmp(givenHash, hash, crSpec->mac_size) != 0) {
11542 » /* We're allowed to leak whether or not the MAC check was correct */
11543 » good = 0;
11275 } 11544 }
11276 } 11545 }
11277 11546
11278 /* compute the MAC */
11279 rType = cText->type;
11280 if (cipher_def->type == type_block) {
11281 rv = ssl3_ComputeRecordMACConstantTime(
11282 crSpec, (PRBool)(!ss->sec.isServer),
11283 IS_DTLS(ss), rType, cText->version,
11284 IS_DTLS(ss) ? cText->seq_num : crSpec->read_seq_num,
11285 plaintext->buf, plaintext->len, originalLen,
11286 hash, &hashBytes);
11287
11288 ssl_CBCExtractMAC(plaintext, originalLen, givenHashBuf,
11289 crSpec->mac_size);
11290 givenHash = givenHashBuf;
11291
11292 /* plaintext->len will always have enough space to remove the MAC
11293 * because in ssl_Remove{SSLv3|TLS}CBCPadding we only adjust
11294 * plaintext->len if the result has enough space for the MAC and we
11295 * tested the unadjusted size against minLength, above. */
11296 plaintext->len -= crSpec->mac_size;
11297 } else {
11298 /* This is safe because we checked the minLength above. */
11299 plaintext->len -= crSpec->mac_size;
11300
11301 rv = ssl3_ComputeRecordMAC(
11302 crSpec, (PRBool)(!ss->sec.isServer),
11303 IS_DTLS(ss), rType, cText->version,
11304 IS_DTLS(ss) ? cText->seq_num : crSpec->read_seq_num,
11305 plaintext->buf, plaintext->len,
11306 hash, &hashBytes);
11307
11308 /* We can read the MAC directly from the record because its location is
11309 * public when a stream cipher is used. */
11310 givenHash = plaintext->buf + plaintext->len;
11311 }
11312
11313 good &= SECStatusToMask(rv);
11314
11315 if (hashBytes != (unsigned)crSpec->mac_size ||
11316 NSS_SecureMemcmp(givenHash, hash, crSpec->mac_size) != 0) {
11317 /* We're allowed to leak whether or not the MAC check was correct */
11318 good = 0;
11319 }
11320
11321 if (good == 0) { 11547 if (good == 0) {
11322 decrypt_loser: 11548 decrypt_loser:
11323 /* must not hold spec lock when calling SSL3_SendAlert. */ 11549 /* must not hold spec lock when calling SSL3_SendAlert. */
11324 ssl_ReleaseSpecReadLock(ss); 11550 ssl_ReleaseSpecReadLock(ss);
11325 11551
11326 SSL_DBG(("%d: SSL3[%d]: decryption failed", SSL_GETPID(), ss->fd)); 11552 SSL_DBG(("%d: SSL3[%d]: decryption failed", SSL_GETPID(), ss->fd));
11327 11553
11328 if (!IS_DTLS(ss)) { 11554 if (!IS_DTLS(ss)) {
11329 SSL3_SendAlert(ss, alert_fatal, bad_record_mac); 11555 SSL3_SendAlert(ss, alert_fatal, bad_record_mac);
11330 /* always log mac error, in case attacker can read server logs. */ 11556 /* always log mac error, in case attacker can read server logs. */
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after
11970 PORT_Free(ss->ssl3.hs.recvdFragments.buf); 12196 PORT_Free(ss->ssl3.hs.recvdFragments.buf);
11971 } 12197 }
11972 } 12198 }
11973 12199
11974 ss->ssl3.initialized = PR_FALSE; 12200 ss->ssl3.initialized = PR_FALSE;
11975 12201
11976 SECITEM_FreeItem(&ss->ssl3.nextProto, PR_FALSE); 12202 SECITEM_FreeItem(&ss->ssl3.nextProto, PR_FALSE);
11977 } 12203 }
11978 12204
11979 /* End of ssl3con.c */ 12205 /* End of ssl3con.c */
OLDNEW
« no previous file with comments | « no previous file | net/third_party/nss/ssl/ssl3ecc.c » ('j') | net/third_party/nss/ssl/sslenum.c » ('J')

Powered by Google App Engine
This is Rietveld 408576698