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

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

Issue 11275240: Update net/third_party/nss/ssl to NSS 3.14. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Upload before commit Created 8 years, 1 month 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.rc ('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 /* -*- 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 * ***** BEGIN LICENSE BLOCK ***** 5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 * The contents of this file are subject to the Mozilla Public License Version 8 /* $Id: ssl3con.c,v 1.192 2012/09/28 05:10:25 wtc%google.com Exp $ */
9 * 1.1 (the "License"); you may not use this file except in compliance with
10 * the License. You may obtain a copy of the License at
11 * http://www.mozilla.org/MPL/
12 *
13 * Software distributed under the License is distributed on an "AS IS" basis,
14 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
15 * for the specific language governing rights and limitations under the
16 * License.
17 *
18 * The Original Code is the Netscape security libraries.
19 *
20 * The Initial Developer of the Original Code is
21 * Netscape Communications Corporation.
22 * Portions created by the Initial Developer are Copyright (C) 1994-2000
23 * the Initial Developer. All Rights Reserved.
24 *
25 * Contributor(s):
26 * Dr Stephen Henson <stephen.henson@gemplus.com>
27 * Dr Vipul Gupta <vipul.gupta@sun.com> and
28 * Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
29 *
30 * Alternatively, the contents of this file may be used under the terms of
31 * either the GNU General Public License Version 2 or later (the "GPL"), or
32 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
33 * in which case the provisions of the GPL or the LGPL are applicable instead
34 * of those above. If you wish to allow use of your version of this file only
35 * under the terms of either the GPL or the LGPL, and not to allow others to
36 * use your version of this file under the terms of the MPL, indicate your
37 * decision by deleting the provisions above and replace them with the notice
38 * and other provisions required by the GPL or the LGPL. If you do not delete
39 * the provisions above, a recipient may use your version of this file under
40 * the terms of any one of the MPL, the GPL or the LGPL.
41 *
42 * ***** END LICENSE BLOCK ***** */
43 /* $Id: ssl3con.c,v 1.173 2012/03/18 00:31:19 wtc%google.com Exp $ */
44 9
45 /* TODO(ekr): Implement HelloVerifyRequest on server side. OK for now. */ 10 /* TODO(ekr): Implement HelloVerifyRequest on server side. OK for now. */
46 11
47 #include "cert.h" 12 #include "cert.h"
48 #include "ssl.h" 13 #include "ssl.h"
49 #include "cryptohi.h" /* for DSAU_ stuff */ 14 #include "cryptohi.h" /* for DSAU_ stuff */
50 #include "keyhi.h" 15 #include "keyhi.h"
51 #include "secder.h" 16 #include "secder.h"
52 #include "secitem.h" 17 #include "secitem.h"
53 18
54 #include "sslimpl.h" 19 #include "sslimpl.h"
55 #include "sslproto.h" 20 #include "sslproto.h"
56 #include "sslerr.h" 21 #include "sslerr.h"
57 #include "prtime.h" 22 #include "prtime.h"
58 #include "prinrval.h" 23 #include "prinrval.h"
59 #include "prerror.h" 24 #include "prerror.h"
60 #include "pratom.h" 25 #include "pratom.h"
61 #include "prthread.h" 26 #include "prthread.h"
62 27
63 #include "pk11func.h" 28 #include "pk11func.h"
64 #include "secmod.h" 29 #include "secmod.h"
30 #ifndef NO_PKCS11_BYPASS
65 #include "blapi.h" 31 #include "blapi.h"
32 #endif
66 33
67 #include <stdio.h> 34 #include <stdio.h>
68 #ifdef NSS_ENABLE_ZLIB 35 #ifdef NSS_ENABLE_ZLIB
69 #include "zlib.h" 36 #include "zlib.h"
70 #endif 37 #endif
71 38
72 /* DSA_SIGNATURE_LEN is deprecated and replaced by DSA1_SIGNATURE_LEN
73 * in NSS 3.14. Provide a backup definition when compiling against an
74 * older system NSS library.
75 */
76 #ifndef DSA1_SIGNATURE_LEN
77 #define DSA1_SIGNATURE_LEN 40 /* Bytes */
78 #endif
79
80 #ifndef PK11_SETATTRS 39 #ifndef PK11_SETATTRS
81 #define PK11_SETATTRS(x,id,v,l) (x)->type = (id); \ 40 #define PK11_SETATTRS(x,id,v,l) (x)->type = (id); \
82 (x)->pValue=(v); (x)->ulValueLen = (l); 41 (x)->pValue=(v); (x)->ulValueLen = (l);
83 #endif 42 #endif
84 43
85 static void ssl3_CleanupPeerCerts(sslSocket *ss); 44 static void ssl3_CleanupPeerCerts(sslSocket *ss);
86 static void ssl3_CopyPeerCertsFromSID(sslSocket *ss, sslSessionID *sid); 45 static void ssl3_CopyPeerCertsFromSID(sslSocket *ss, sslSessionID *sid);
87 static PK11SymKey *ssl3_GenerateRSAPMS(sslSocket *ss, ssl3CipherSpec *spec, 46 static PK11SymKey *ssl3_GenerateRSAPMS(sslSocket *ss, ssl3CipherSpec *spec,
88 PK11SlotInfo * serverKeySlot); 47 PK11SlotInfo * serverKeySlot);
89 static SECStatus ssl3_DeriveMasterSecret(sslSocket *ss, PK11SymKey *pms); 48 static SECStatus ssl3_DeriveMasterSecret(sslSocket *ss, PK11SymKey *pms);
(...skipping 15 matching lines...) Expand all
105 unsigned int l); 64 unsigned int l);
106 static SECStatus ssl3_FlushHandshakeMessages(sslSocket *ss, PRInt32 flags); 65 static SECStatus ssl3_FlushHandshakeMessages(sslSocket *ss, PRInt32 flags);
107 66
108 static SECStatus Null_Cipher(void *ctx, unsigned char *output, int *outputLen, 67 static SECStatus Null_Cipher(void *ctx, unsigned char *output, int *outputLen,
109 int maxOutputLen, const unsigned char *input, 68 int maxOutputLen, const unsigned char *input,
110 int inputLen); 69 int inputLen);
111 70
112 #define MAX_SEND_BUF_LENGTH 32000 /* watch for 16-bit integer overflow */ 71 #define MAX_SEND_BUF_LENGTH 32000 /* watch for 16-bit integer overflow */
113 #define MIN_SEND_BUF_LENGTH 4000 72 #define MIN_SEND_BUF_LENGTH 4000
114 73
115 #define MAX_CIPHER_SUITES 20
116
117 /* This list of SSL3 cipher suites is sorted in descending order of 74 /* This list of SSL3 cipher suites is sorted in descending order of
118 * precedence (desirability). It only includes cipher suites we implement. 75 * precedence (desirability). It only includes cipher suites we implement.
119 * This table is modified by SSL3_SetPolicy(). The ordering of cipher suites 76 * This table is modified by SSL3_SetPolicy(). The ordering of cipher suites
120 * in this table must match the ordering in SSL_ImplementedCiphers (sslenum.c) 77 * in this table must match the ordering in SSL_ImplementedCiphers (sslenum.c)
121 */ 78 */
122 static ssl3CipherSuiteCfg cipherSuites[ssl_V3_SUITES_IMPLEMENTED] = { 79 static ssl3CipherSuiteCfg cipherSuites[ssl_V3_SUITES_IMPLEMENTED] = {
123 /* cipher_suite policy enabled is_present*/ 80 /* cipher_suite policy enabled is_present*/
124 #ifdef NSS_ENABLE_ECC 81 #ifdef NSS_ENABLE_ECC
125 { TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 82 { TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
126 { TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 83 { TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
127 #endif /* NSS_ENABLE_ECC */ 84 #endif /* NSS_ENABLE_ECC */
128 { TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 85 { TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
129 { TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 86 { TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
130 { TLS_DHE_RSA_WITH_AES_256_CBC_SHA, » SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 87 { TLS_DHE_RSA_WITH_AES_256_CBC_SHA, » SSL_NOT_ALLOWED, PR_TRUE,PR_FALSE},
131 { TLS_DHE_DSS_WITH_AES_256_CBC_SHA, » SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 88 { TLS_DHE_DSS_WITH_AES_256_CBC_SHA, » SSL_NOT_ALLOWED, PR_TRUE,PR_FALSE},
132 #ifdef NSS_ENABLE_ECC 89 #ifdef NSS_ENABLE_ECC
133 { TLS_ECDH_RSA_WITH_AES_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 90 { TLS_ECDH_RSA_WITH_AES_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
134 { TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 91 { TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
135 #endif /* NSS_ENABLE_ECC */ 92 #endif /* NSS_ENABLE_ECC */
136 { TLS_RSA_WITH_CAMELLIA_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 93 { TLS_RSA_WITH_CAMELLIA_256_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
137 { TLS_RSA_WITH_AES_256_CBC_SHA, » SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 94 { TLS_RSA_WITH_AES_256_CBC_SHA, » SSL_NOT_ALLOWED, PR_TRUE,PR_FALSE},
138 95
139 #ifdef NSS_ENABLE_ECC 96 #ifdef NSS_ENABLE_ECC
140 { TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 97 { TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
141 { TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 98 { TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
142 { TLS_ECDHE_RSA_WITH_RC4_128_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 99 { TLS_ECDHE_RSA_WITH_RC4_128_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
143 { TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 100 { TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
144 #endif /* NSS_ENABLE_ECC */ 101 #endif /* NSS_ENABLE_ECC */
145 { TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 102 { TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
146 { TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 103 { TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
147 { TLS_DHE_DSS_WITH_RC4_128_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 104 { TLS_DHE_DSS_WITH_RC4_128_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
148 { TLS_DHE_RSA_WITH_AES_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 105 { TLS_DHE_RSA_WITH_AES_128_CBC_SHA, SSL_NOT_ALLOWED, PR_TRUE,PR_FALSE},
149 { TLS_DHE_DSS_WITH_AES_128_CBC_SHA, » SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 106 { TLS_DHE_DSS_WITH_AES_128_CBC_SHA, » SSL_NOT_ALLOWED, PR_TRUE,PR_FALSE},
150 #ifdef NSS_ENABLE_ECC 107 #ifdef NSS_ENABLE_ECC
151 { TLS_ECDH_RSA_WITH_RC4_128_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 108 { TLS_ECDH_RSA_WITH_RC4_128_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
152 { TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 109 { TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
153 { TLS_ECDH_ECDSA_WITH_RC4_128_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 110 { TLS_ECDH_ECDSA_WITH_RC4_128_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
154 { TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 111 { TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
155 #endif /* NSS_ENABLE_ECC */ 112 #endif /* NSS_ENABLE_ECC */
156 { TLS_RSA_WITH_SEED_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 113 { TLS_RSA_WITH_SEED_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
157 { TLS_RSA_WITH_CAMELLIA_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 114 { TLS_RSA_WITH_CAMELLIA_128_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
158 { SSL_RSA_WITH_RC4_128_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 115 { SSL_RSA_WITH_RC4_128_SHA, SSL_NOT_ALLOWED, PR_TRUE,PR_FALSE},
159 { SSL_RSA_WITH_RC4_128_MD5, SSL_NOT_ALLOWED, PR_TRUE, PR_FALSE}, 116 { SSL_RSA_WITH_RC4_128_MD5, SSL_NOT_ALLOWED, PR_TRUE, PR_FALSE},
160 { TLS_RSA_WITH_AES_128_CBC_SHA, » SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 117 { TLS_RSA_WITH_AES_128_CBC_SHA, » SSL_NOT_ALLOWED, PR_TRUE,PR_FALSE},
161 118
162 #ifdef NSS_ENABLE_ECC 119 #ifdef NSS_ENABLE_ECC
163 { TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 120 { TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
164 { TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 121 { TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
165 #endif /* NSS_ENABLE_ECC */ 122 #endif /* NSS_ENABLE_ECC */
166 { SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 123 { SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_NOT_ALLOWED, PR_TRUE,PR_FALSE},
167 { SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 124 { SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA, SSL_NOT_ALLOWED, PR_TRUE,PR_FALSE},
168 #ifdef NSS_ENABLE_ECC 125 #ifdef NSS_ENABLE_ECC
169 { TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 126 { TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
170 { TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 127 { TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
171 #endif /* NSS_ENABLE_ECC */ 128 #endif /* NSS_ENABLE_ECC */
172 { SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA, SSL_NOT_ALLOWED, PR_TRUE, PR_FALSE}, 129 { SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE, PR_FALSE},
173 { SSL_RSA_WITH_3DES_EDE_CBC_SHA, SSL_NOT_ALLOWED, PR_TRUE, PR_FALSE}, 130 { SSL_RSA_WITH_3DES_EDE_CBC_SHA, SSL_NOT_ALLOWED, PR_TRUE, PR_FALSE},
174 131
175 132
176 { SSL_DHE_RSA_WITH_DES_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 133 { SSL_DHE_RSA_WITH_DES_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
177 { SSL_DHE_DSS_WITH_DES_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 134 { SSL_DHE_DSS_WITH_DES_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
178 { SSL_RSA_FIPS_WITH_DES_CBC_SHA, SSL_NOT_ALLOWED, PR_TRUE, PR_FALSE}, 135 { SSL_RSA_FIPS_WITH_DES_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE, PR_FALSE},
179 { SSL_RSA_WITH_DES_CBC_SHA, SSL_NOT_ALLOWED, PR_TRUE, PR_FALSE}, 136 { SSL_RSA_WITH_DES_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE, PR_FALSE},
180 { TLS_RSA_EXPORT1024_WITH_RC4_56_SHA, SSL_NOT_ALLOWED, PR_TRUE, PR_FALSE}, 137 { TLS_RSA_EXPORT1024_WITH_RC4_56_SHA, SSL_NOT_ALLOWED, PR_FALSE, PR_FALSE},
181 { TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA, SSL_NOT_ALLOWED, PR_TRUE, PR_FALSE}, 138 { TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA, SSL_NOT_ALLOWED, PR_FALSE, PR_FALSE},
182 139
183 { SSL_RSA_EXPORT_WITH_RC4_40_MD5, SSL_NOT_ALLOWED, PR_TRUE, PR_FALSE}, 140 { SSL_RSA_EXPORT_WITH_RC4_40_MD5, SSL_NOT_ALLOWED, PR_FALSE, PR_FALSE},
184 { SSL_RSA_EXPORT_WITH_RC2_CBC_40_MD5, SSL_NOT_ALLOWED, PR_TRUE, PR_FALSE}, 141 { SSL_RSA_EXPORT_WITH_RC2_CBC_40_MD5, SSL_NOT_ALLOWED, PR_FALSE, PR_FALSE},
185 142
186 #ifdef NSS_ENABLE_ECC 143 #ifdef NSS_ENABLE_ECC
187 { TLS_ECDHE_ECDSA_WITH_NULL_SHA, SSL_NOT_ALLOWED, PR_FALSE, PR_FALSE}, 144 { TLS_ECDHE_ECDSA_WITH_NULL_SHA, SSL_NOT_ALLOWED, PR_FALSE, PR_FALSE},
188 { TLS_ECDHE_RSA_WITH_NULL_SHA, SSL_NOT_ALLOWED, PR_FALSE, PR_FALSE}, 145 { TLS_ECDHE_RSA_WITH_NULL_SHA, SSL_NOT_ALLOWED, PR_FALSE, PR_FALSE},
189 { TLS_ECDH_RSA_WITH_NULL_SHA, SSL_NOT_ALLOWED, PR_FALSE, PR_FALSE}, 146 { TLS_ECDH_RSA_WITH_NULL_SHA, SSL_NOT_ALLOWED, PR_FALSE, PR_FALSE},
190 { TLS_ECDH_ECDSA_WITH_NULL_SHA, SSL_NOT_ALLOWED, PR_FALSE, PR_FALSE}, 147 { TLS_ECDH_ECDSA_WITH_NULL_SHA, SSL_NOT_ALLOWED, PR_FALSE, PR_FALSE},
191 #endif /* NSS_ENABLE_ECC */ 148 #endif /* NSS_ENABLE_ECC */
192 { SSL_RSA_WITH_NULL_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 149 { SSL_RSA_WITH_NULL_SHA, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
193 { SSL_RSA_WITH_NULL_MD5, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE}, 150 { SSL_RSA_WITH_NULL_MD5, SSL_NOT_ALLOWED, PR_FALSE,PR_FALSE},
194 151
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 {SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA, 283 {SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA,
327 cipher_des40, mac_sha, kea_dh_dss_export}, 284 cipher_des40, mac_sha, kea_dh_dss_export},
328 {SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA, 285 {SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA,
329 cipher_des40, mac_sha, kea_dh_rsa_export}, 286 cipher_des40, mac_sha, kea_dh_rsa_export},
330 #endif 287 #endif
331 {SSL_DHE_RSA_WITH_DES_CBC_SHA, cipher_des, mac_sha, kea_dhe_rsa}, 288 {SSL_DHE_RSA_WITH_DES_CBC_SHA, cipher_des, mac_sha, kea_dhe_rsa},
332 {SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, 289 {SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA,
333 cipher_3des, mac_sha, kea_dhe_rsa}, 290 cipher_3des, mac_sha, kea_dhe_rsa},
334 #if 0 291 #if 0
335 {SSL_DH_ANON_EXPORT_RC4_40_MD5, cipher_rc4_40, mac_md5, kea_dh_anon_export}, 292 {SSL_DH_ANON_EXPORT_RC4_40_MD5, cipher_rc4_40, mac_md5, kea_dh_anon_export},
336 {SSL_DH_ANON_EXPORT_RC4_40_MD5, cipher_rc4, mac_md5, kea_dh_anon_export},
337 {SSL_DH_ANON_EXPORT_WITH_DES40_CBC_SHA, 293 {SSL_DH_ANON_EXPORT_WITH_DES40_CBC_SHA,
338 cipher_des40, mac_sha, kea_dh_anon_export}, 294 cipher_des40, mac_sha, kea_dh_anon_export},
339 {SSL_DH_ANON_DES_CBC_SHA, cipher_des, mac_sha, kea_dh_anon}, 295 {SSL_DH_ANON_DES_CBC_SHA, cipher_des, mac_sha, kea_dh_anon},
340 {SSL_DH_ANON_3DES_CBC_SHA, cipher_3des, mac_sha, kea_dh_anon}, 296 {SSL_DH_ANON_3DES_CBC_SHA, cipher_3des, mac_sha, kea_dh_anon},
341 #endif 297 #endif
342 298
343 299
344 /* New TLS cipher suites */ 300 /* New TLS cipher suites */
345 {TLS_RSA_WITH_AES_128_CBC_SHA, cipher_aes_128, mac_sha, kea_rsa}, 301 {TLS_RSA_WITH_AES_128_CBC_SHA, cipher_aes_128, mac_sha, kea_rsa},
346 {TLS_DHE_DSS_WITH_AES_128_CBC_SHA, cipher_aes_128, mac_sha, kea_dhe_dss}, 302 {TLS_DHE_DSS_WITH_AES_128_CBC_SHA, cipher_aes_128, mac_sha, kea_dhe_dss},
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 { 526 {
571 if ((sizeof *x) == sizeof(PRInt32)) { 527 if ((sizeof *x) == sizeof(PRInt32)) {
572 PR_ATOMIC_INCREMENT((PRInt32 *)x); 528 PR_ATOMIC_INCREMENT((PRInt32 *)x);
573 } else { 529 } else {
574 tooLong * tl = (tooLong *)x; 530 tooLong * tl = (tooLong *)x;
575 if (PR_ATOMIC_INCREMENT(&tl->low) == 0) 531 if (PR_ATOMIC_INCREMENT(&tl->low) == 0)
576 PR_ATOMIC_INCREMENT(&tl->high); 532 PR_ATOMIC_INCREMENT(&tl->high);
577 } 533 }
578 } 534 }
579 535
536 static PRBool
537 ssl3_CipherSuiteAllowedForVersion(ssl3CipherSuite cipherSuite,
538 SSL3ProtocolVersion version)
539 {
540 switch (cipherSuite) {
541 /* See RFC 4346 A.5. Export cipher suites must not be used in TLS 1.1 or
542 * later. This set of cipher suites is similar to, but different from, the
543 * set of cipher suites considered exportable by SSL_IsExportCipherSuite.
544 */
545 case SSL_RSA_EXPORT_WITH_RC4_40_MD5:
546 case SSL_RSA_EXPORT_WITH_RC2_CBC_40_MD5:
547 /* SSL_RSA_EXPORT_WITH_DES40_CBC_SHA: never implemented
548 * SSL_DH_DSS_EXPORT_WITH_DES40_CBC_SHA: never implemented
549 * SSL_DH_RSA_EXPORT_WITH_DES40_CBC_SHA: never implemented
550 * SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA: never implemented
551 * SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA: never implemented
552 * SSL_DH_ANON_EXPORT_WITH_RC4_40_MD5: never implemented
553 * SSL_DH_ANON_EXPORT_WITH_DES40_CBC_SHA: never implemented
554 */
555 return version <= SSL_LIBRARY_VERSION_TLS_1_0;
556 default:
557 return PR_TRUE;
558 }
559 }
560
580 /* return pointer to ssl3CipherSuiteDef for suite, or NULL */ 561 /* return pointer to ssl3CipherSuiteDef for suite, or NULL */
581 /* XXX This does a linear search. A binary search would be better. */ 562 /* XXX This does a linear search. A binary search would be better. */
582 static const ssl3CipherSuiteDef * 563 static const ssl3CipherSuiteDef *
583 ssl_LookupCipherSuiteDef(ssl3CipherSuite suite) 564 ssl_LookupCipherSuiteDef(ssl3CipherSuite suite)
584 { 565 {
585 int cipher_suite_def_len = 566 int cipher_suite_def_len =
586 sizeof(cipher_suite_defs) / sizeof(cipher_suite_defs[0]); 567 sizeof(cipher_suite_defs) / sizeof(cipher_suite_defs[0]);
587 int i; 568 int i;
588 569
589 for (i = 0; i < cipher_suite_def_len; i++) { 570 for (i = 0; i < cipher_suite_def_len; i++) {
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 894
914 switch (key->keyType) { 895 switch (key->keyType) {
915 case rsaKey: 896 case rsaKey:
916 hashItem.data = hash->md5; 897 hashItem.data = hash->md5;
917 hashItem.len = sizeof(SSL3Hashes); 898 hashItem.len = sizeof(SSL3Hashes);
918 break; 899 break;
919 case dsaKey: 900 case dsaKey:
920 hashItem.data = hash->sha; 901 hashItem.data = hash->sha;
921 hashItem.len = sizeof(hash->sha); 902 hashItem.len = sizeof(hash->sha);
922 /* Allow DER encoded DSA signatures in SSL 3.0 */ 903 /* Allow DER encoded DSA signatures in SSL 3.0 */
923 » if (isTLS || buf->len != DSA1_SIGNATURE_LEN) { 904 » if (isTLS || buf->len != SECKEY_SignatureLen(key)) {
924 signature = DSAU_DecodeDerSig(buf); 905 signature = DSAU_DecodeDerSig(buf);
925 if (!signature) { 906 if (!signature) {
926 PORT_SetError(SSL_ERROR_BAD_HANDSHAKE_HASH_VALUE); 907 PORT_SetError(SSL_ERROR_BAD_HANDSHAKE_HASH_VALUE);
927 return SECFailure; 908 return SECFailure;
928 } 909 }
929 buf = signature; 910 buf = signature;
930 } 911 }
931 break; 912 break;
932 913
933 #ifdef NSS_ENABLE_ECC 914 #ifdef NSS_ENABLE_ECC
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 /* Called from ssl3_ComputeExportRSAKeyHash 960 /* Called from ssl3_ComputeExportRSAKeyHash
980 * ssl3_ComputeDHKeyHash 961 * ssl3_ComputeDHKeyHash
981 * which are called from ssl3_HandleServerKeyExchange. 962 * which are called from ssl3_HandleServerKeyExchange.
982 */ 963 */
983 SECStatus 964 SECStatus
984 ssl3_ComputeCommonKeyHash(PRUint8 * hashBuf, unsigned int bufLen, 965 ssl3_ComputeCommonKeyHash(PRUint8 * hashBuf, unsigned int bufLen,
985 SSL3Hashes *hashes, PRBool bypassPKCS11) 966 SSL3Hashes *hashes, PRBool bypassPKCS11)
986 { 967 {
987 SECStatus rv = SECSuccess; 968 SECStatus rv = SECSuccess;
988 969
970 #ifndef NO_PKCS11_BYPASS
989 if (bypassPKCS11) { 971 if (bypassPKCS11) {
990 MD5_HashBuf (hashes->md5, hashBuf, bufLen); 972 MD5_HashBuf (hashes->md5, hashBuf, bufLen);
991 SHA1_HashBuf(hashes->sha, hashBuf, bufLen); 973 SHA1_HashBuf(hashes->sha, hashBuf, bufLen);
992 } else { 974 } else
975 #endif
976 {
993 rv = PK11_HashBuf(SEC_OID_MD5, hashes->md5, hashBuf, bufLen); 977 rv = PK11_HashBuf(SEC_OID_MD5, hashes->md5, hashBuf, bufLen);
994 if (rv != SECSuccess) { 978 if (rv != SECSuccess) {
995 ssl_MapLowLevelError(SSL_ERROR_MD5_DIGEST_FAILURE); 979 ssl_MapLowLevelError(SSL_ERROR_MD5_DIGEST_FAILURE);
996 rv = SECFailure; 980 rv = SECFailure;
997 goto done; 981 goto done;
998 } 982 }
999 983
1000 rv = PK11_HashBuf(SEC_OID_SHA1, hashes->sha, hashBuf, bufLen); 984 rv = PK11_HashBuf(SEC_OID_SHA1, hashes->sha, hashBuf, bufLen);
1001 if (rv != SECSuccess) { 985 if (rv != SECSuccess) {
1002 ssl_MapLowLevelError(SSL_ERROR_SHA_DIGEST_FAILURE); 986 ssl_MapLowLevelError(SSL_ERROR_SHA_DIGEST_FAILURE);
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
1403 #endif /* NSS_ENABLE_ZLIB */ 1387 #endif /* NSS_ENABLE_ZLIB */
1404 default: 1388 default:
1405 PORT_Assert(0); 1389 PORT_Assert(0);
1406 PORT_SetError(SEC_ERROR_LIBRARY_FAILURE); 1390 PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
1407 return SECFailure; 1391 return SECFailure;
1408 } 1392 }
1409 1393
1410 return SECSuccess; 1394 return SECSuccess;
1411 } 1395 }
1412 1396
1397 #ifndef NO_PKCS11_BYPASS
1413 /* Initialize encryption and MAC contexts for pending spec. 1398 /* Initialize encryption and MAC contexts for pending spec.
1414 * Master Secret already is derived in spec->msItem 1399 * Master Secret already is derived in spec->msItem
1415 * Caller holds Spec write lock. 1400 * Caller holds Spec write lock.
1416 */ 1401 */
1417 static SECStatus 1402 static SECStatus
1418 ssl3_InitPendingContextsBypass(sslSocket *ss) 1403 ssl3_InitPendingContextsBypass(sslSocket *ss)
1419 { 1404 {
1420 ssl3CipherSpec * pwSpec; 1405 ssl3CipherSpec * pwSpec;
1421 const ssl3BulkCipherDef *cipher_def; 1406 const ssl3BulkCipherDef *cipher_def;
1422 void * serverContext = NULL; 1407 void * serverContext = NULL;
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1569 pwSpec->decodeContext = (ss->sec.isServer) ? clientContext : serverContext; 1554 pwSpec->decodeContext = (ss->sec.isServer) ? clientContext : serverContext;
1570 1555
1571 ssl3_InitCompressionContext(pwSpec); 1556 ssl3_InitCompressionContext(pwSpec);
1572 1557
1573 success: 1558 success:
1574 return SECSuccess; 1559 return SECSuccess;
1575 1560
1576 bail_out: 1561 bail_out:
1577 return SECFailure; 1562 return SECFailure;
1578 } 1563 }
1564 #endif
1579 1565
1580 /* This function should probably be moved to pk11wrap and be named 1566 /* This function should probably be moved to pk11wrap and be named
1581 * PK11_ParamFromIVAndEffectiveKeyBits 1567 * PK11_ParamFromIVAndEffectiveKeyBits
1582 */ 1568 */
1583 static SECItem * 1569 static SECItem *
1584 ssl3_ParamFromIV(CK_MECHANISM_TYPE mtype, SECItem *iv, CK_ULONG ulEffectiveBits) 1570 ssl3_ParamFromIV(CK_MECHANISM_TYPE mtype, SECItem *iv, CK_ULONG ulEffectiveBits)
1585 { 1571 {
1586 SECItem * param = PK11_ParamFromIV(mtype, iv); 1572 SECItem * param = PK11_ParamFromIV(mtype, iv);
1587 if (param && param->data && param->len >= sizeof(CK_RC2_PARAMS)) { 1573 if (param && param->data && param->len >= sizeof(CK_RC2_PARAMS)) {
1588 switch (mtype) { 1574 switch (mtype) {
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
1768 1754
1769 pwSpec = ss->ssl3.pwSpec; 1755 pwSpec = ss->ssl3.pwSpec;
1770 cwSpec = ss->ssl3.cwSpec; 1756 cwSpec = ss->ssl3.cwSpec;
1771 1757
1772 if (pms || (!pwSpec->msItem.len && !pwSpec->master_secret)) { 1758 if (pms || (!pwSpec->msItem.len && !pwSpec->master_secret)) {
1773 rv = ssl3_DeriveMasterSecret(ss, pms); 1759 rv = ssl3_DeriveMasterSecret(ss, pms);
1774 if (rv != SECSuccess) { 1760 if (rv != SECSuccess) {
1775 goto done; /* err code set by ssl3_DeriveMasterSecret */ 1761 goto done; /* err code set by ssl3_DeriveMasterSecret */
1776 } 1762 }
1777 } 1763 }
1764 #ifndef NO_PKCS11_BYPASS
1778 if (ss->opt.bypassPKCS11 && pwSpec->msItem.len && pwSpec->msItem.data) { 1765 if (ss->opt.bypassPKCS11 && pwSpec->msItem.len && pwSpec->msItem.data) {
1779 /* Double Bypass succeeded in extracting the master_secret */ 1766 /* Double Bypass succeeded in extracting the master_secret */
1780 const ssl3KEADef * kea_def = ss->ssl3.hs.kea_def; 1767 const ssl3KEADef * kea_def = ss->ssl3.hs.kea_def;
1781 PRBool isTLS = (PRBool)(kea_def->tls_keygen || 1768 PRBool isTLS = (PRBool)(kea_def->tls_keygen ||
1782 (pwSpec->version > SSL_LIBRARY_VERSION_3_0)); 1769 (pwSpec->version > SSL_LIBRARY_VERSION_3_0));
1783 pwSpec->bypassCiphers = PR_TRUE; 1770 pwSpec->bypassCiphers = PR_TRUE;
1784 rv = ssl3_KeyAndMacDeriveBypass( pwSpec, 1771 rv = ssl3_KeyAndMacDeriveBypass( pwSpec,
1785 (const unsigned char *)&ss->ssl3.hs.client_random, 1772 (const unsigned char *)&ss->ssl3.hs.client_random,
1786 (const unsigned char *)&ss->ssl3.hs.server_random, 1773 (const unsigned char *)&ss->ssl3.hs.server_random,
1787 isTLS, 1774 isTLS,
1788 (PRBool)(kea_def->is_limited)); 1775 (PRBool)(kea_def->is_limited));
1789 if (rv == SECSuccess) { 1776 if (rv == SECSuccess) {
1790 rv = ssl3_InitPendingContextsBypass(ss); 1777 rv = ssl3_InitPendingContextsBypass(ss);
1791 } 1778 }
1792 } else if (pwSpec->master_secret) { 1779 } else
1780 #endif
1781 if (pwSpec->master_secret) {
1793 rv = ssl3_DeriveConnectionKeysPKCS11(ss); 1782 rv = ssl3_DeriveConnectionKeysPKCS11(ss);
1794 if (rv == SECSuccess) { 1783 if (rv == SECSuccess) {
1795 rv = ssl3_InitPendingContextsPKCS11(ss); 1784 rv = ssl3_InitPendingContextsPKCS11(ss);
1796 } 1785 }
1797 } else { 1786 } else {
1798 PORT_Assert(pwSpec->master_secret); 1787 PORT_Assert(pwSpec->master_secret);
1799 PORT_SetError(SEC_ERROR_LIBRARY_FAILURE); 1788 PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
1800 rv = SECFailure; 1789 rv = SECFailure;
1801 } 1790 }
1802 if (rv != SECSuccess) { 1791 if (rv != SECSuccess) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1868 SSL3ContentType type, 1857 SSL3ContentType type,
1869 SSL3ProtocolVersion version, 1858 SSL3ProtocolVersion version,
1870 SSL3SequenceNumber seq_num, 1859 SSL3SequenceNumber seq_num,
1871 const SSL3Opaque * input, 1860 const SSL3Opaque * input,
1872 int inputLength, 1861 int inputLength,
1873 unsigned char * outbuf, 1862 unsigned char * outbuf,
1874 unsigned int * outLength) 1863 unsigned int * outLength)
1875 { 1864 {
1876 const ssl3MACDef * mac_def; 1865 const ssl3MACDef * mac_def;
1877 SECStatus rv; 1866 SECStatus rv;
1867 #ifndef NO_PKCS11_BYPASS
1878 PRBool isTLS; 1868 PRBool isTLS;
1869 #endif
1879 unsigned int tempLen; 1870 unsigned int tempLen;
1880 unsigned char temp[MAX_MAC_LENGTH]; 1871 unsigned char temp[MAX_MAC_LENGTH];
1881 1872
1882 temp[0] = (unsigned char)(seq_num.high >> 24); 1873 temp[0] = (unsigned char)(seq_num.high >> 24);
1883 temp[1] = (unsigned char)(seq_num.high >> 16); 1874 temp[1] = (unsigned char)(seq_num.high >> 16);
1884 temp[2] = (unsigned char)(seq_num.high >> 8); 1875 temp[2] = (unsigned char)(seq_num.high >> 8);
1885 temp[3] = (unsigned char)(seq_num.high >> 0); 1876 temp[3] = (unsigned char)(seq_num.high >> 0);
1886 temp[4] = (unsigned char)(seq_num.low >> 24); 1877 temp[4] = (unsigned char)(seq_num.low >> 24);
1887 temp[5] = (unsigned char)(seq_num.low >> 16); 1878 temp[5] = (unsigned char)(seq_num.low >> 16);
1888 temp[6] = (unsigned char)(seq_num.low >> 8); 1879 temp[6] = (unsigned char)(seq_num.low >> 8);
1889 temp[7] = (unsigned char)(seq_num.low >> 0); 1880 temp[7] = (unsigned char)(seq_num.low >> 0);
1890 temp[8] = type; 1881 temp[8] = type;
1891 1882
1892 /* TLS MAC includes the record's version field, SSL's doesn't. 1883 /* TLS MAC includes the record's version field, SSL's doesn't.
1893 ** We decide which MAC defintiion to use based on the version of 1884 ** We decide which MAC defintiion to use based on the version of
1894 ** the protocol that was negotiated when the spec became current, 1885 ** the protocol that was negotiated when the spec became current,
1895 ** NOT based on the version value in the record itself. 1886 ** NOT based on the version value in the record itself.
1896 ** But, we use the record'v version value in the computation. 1887 ** But, we use the record'v version value in the computation.
1897 */ 1888 */
1898 if (spec->version <= SSL_LIBRARY_VERSION_3_0) { 1889 if (spec->version <= SSL_LIBRARY_VERSION_3_0) {
1899 temp[9] = MSB(inputLength); 1890 temp[9] = MSB(inputLength);
1900 temp[10] = LSB(inputLength); 1891 temp[10] = LSB(inputLength);
1901 tempLen = 11; 1892 tempLen = 11;
1893 #ifndef NO_PKCS11_BYPASS
1902 isTLS = PR_FALSE; 1894 isTLS = PR_FALSE;
1895 #endif
1903 } else { 1896 } else {
1904 /* New TLS hash includes version. */ 1897 /* New TLS hash includes version. */
1905 if (isDTLS) { 1898 if (isDTLS) {
1906 SSL3ProtocolVersion dtls_version; 1899 SSL3ProtocolVersion dtls_version;
1907 1900
1908 dtls_version = dtls_TLSVersionToDTLSVersion(version); 1901 dtls_version = dtls_TLSVersionToDTLSVersion(version);
1909 temp[9] = MSB(dtls_version); 1902 temp[9] = MSB(dtls_version);
1910 temp[10] = LSB(dtls_version); 1903 temp[10] = LSB(dtls_version);
1911 } else { 1904 } else {
1912 temp[9] = MSB(version); 1905 temp[9] = MSB(version);
1913 temp[10] = LSB(version); 1906 temp[10] = LSB(version);
1914 } 1907 }
1915 temp[11] = MSB(inputLength); 1908 temp[11] = MSB(inputLength);
1916 temp[12] = LSB(inputLength); 1909 temp[12] = LSB(inputLength);
1917 tempLen = 13; 1910 tempLen = 13;
1911 #ifndef NO_PKCS11_BYPASS
1918 isTLS = PR_TRUE; 1912 isTLS = PR_TRUE;
1913 #endif
1919 } 1914 }
1920 1915
1921 PRINT_BUF(95, (NULL, "frag hash1: temp", temp, tempLen)); 1916 PRINT_BUF(95, (NULL, "frag hash1: temp", temp, tempLen));
1922 PRINT_BUF(95, (NULL, "frag hash1: input", input, inputLength)); 1917 PRINT_BUF(95, (NULL, "frag hash1: input", input, inputLength));
1923 1918
1924 mac_def = spec->mac_def; 1919 mac_def = spec->mac_def;
1925 if (mac_def->mac == mac_null) { 1920 if (mac_def->mac == mac_null) {
1926 *outLength = 0; 1921 *outLength = 0;
1927 return SECSuccess; 1922 return SECSuccess;
1928 } 1923 }
1929 if (! spec->bypassCiphers) { 1924 #ifndef NO_PKCS11_BYPASS
1930 » PK11Context *mac_context = 1925 if (spec->bypassCiphers) {
1931 » (useServerMacKey ? spec->server.write_mac_context
1932 » : spec->client.write_mac_context);
1933 » rv = PK11_DigestBegin(mac_context);
1934 » rv |= PK11_DigestOp(mac_context, temp, tempLen);
1935 » rv |= PK11_DigestOp(mac_context, input, inputLength);
1936 » rv |= PK11_DigestFinal(mac_context, outbuf, outLength, spec->mac_size);
1937 } else {
1938 /* bypass version */ 1926 /* bypass version */
1939 const SECHashObject *hashObj = NULL; 1927 const SECHashObject *hashObj = NULL;
1940 unsigned int pad_bytes = 0; 1928 unsigned int pad_bytes = 0;
1941 PRUint64 write_mac_context[MAX_MAC_CONTEXT_LLONGS]; 1929 PRUint64 write_mac_context[MAX_MAC_CONTEXT_LLONGS];
1942 1930
1943 switch (mac_def->mac) { 1931 switch (mac_def->mac) {
1944 case ssl_mac_null: 1932 case ssl_mac_null:
1945 *outLength = 0; 1933 *outLength = 0;
1946 return SECSuccess; 1934 return SECSuccess;
1947 case ssl_mac_md5: 1935 case ssl_mac_md5:
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
2010 } 1998 }
2011 if (rv == SECSuccess) { 1999 if (rv == SECSuccess) {
2012 HMAC_Begin(cx); 2000 HMAC_Begin(cx);
2013 HMAC_Update(cx, temp, tempLen); 2001 HMAC_Update(cx, temp, tempLen);
2014 HMAC_Update(cx, input, inputLength); 2002 HMAC_Update(cx, input, inputLength);
2015 rv = HMAC_Finish(cx, outbuf, outLength, spec->mac_size); 2003 rv = HMAC_Finish(cx, outbuf, outLength, spec->mac_size);
2016 HMAC_Destroy(cx, PR_FALSE); 2004 HMAC_Destroy(cx, PR_FALSE);
2017 } 2005 }
2018 #undef cx 2006 #undef cx
2019 } 2007 }
2008 } else
2009 #endif
2010 {
2011 PK11Context *mac_context =
2012 (useServerMacKey ? spec->server.write_mac_context
2013 : spec->client.write_mac_context);
2014 rv = PK11_DigestBegin(mac_context);
2015 rv |= PK11_DigestOp(mac_context, temp, tempLen);
2016 rv |= PK11_DigestOp(mac_context, input, inputLength);
2017 rv |= PK11_DigestFinal(mac_context, outbuf, outLength, spec->mac_size);
2020 } 2018 }
2021 2019
2022 PORT_Assert(rv != SECSuccess || *outLength == (unsigned)spec->mac_size); 2020 PORT_Assert(rv != SECSuccess || *outLength == (unsigned)spec->mac_size);
2023 2021
2024 PRINT_BUF(95, (NULL, "frag hash2: result", outbuf, *outLength)); 2022 PRINT_BUF(95, (NULL, "frag hash2: result", outbuf, *outLength));
2025 2023
2026 if (rv != SECSuccess) { 2024 if (rv != SECSuccess) {
2027 rv = SECFailure; 2025 rv = SECFailure;
2028 ssl_MapLowLevelError(SSL_ERROR_MAC_COMPUTATION_FAILURE); 2026 ssl_MapLowLevelError(SSL_ERROR_MAC_COMPUTATION_FAILURE);
2029 } 2027 }
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after
2795 default: desc = bad_certificate; break; 2793 default: desc = bad_certificate; break;
2796 } 2794 }
2797 SSL_DBG(("%d: SSL3[%d]: peer certificate is no good: error=%d", 2795 SSL_DBG(("%d: SSL3[%d]: peer certificate is no good: error=%d",
2798 SSL_GETPID(), ss->fd, errCode)); 2796 SSL_GETPID(), ss->fd, errCode));
2799 2797
2800 (void) SSL3_SendAlert(ss, alert_fatal, desc); 2798 (void) SSL3_SendAlert(ss, alert_fatal, desc);
2801 } 2799 }
2802 2800
2803 2801
2804 /* 2802 /*
2805 * Send handshake_Failure alert. Set generic error number. 2803 * Send decode_error alert. Set generic error number.
2806 */ 2804 */
2807 SECStatus 2805 SECStatus
2808 ssl3_DecodeError(sslSocket *ss) 2806 ssl3_DecodeError(sslSocket *ss)
2809 { 2807 {
2810 (void)SSL3_SendAlert(ss, alert_fatal, 2808 (void)SSL3_SendAlert(ss, alert_fatal,
2811 ss->version > SSL_LIBRARY_VERSION_3_0 ? decode_error 2809 ss->version > SSL_LIBRARY_VERSION_3_0 ? decode_error
2812 : illegal_parameter); 2810 : illegal_parameter);
2813 PORT_SetError( ss->sec.isServer ? SSL_ERROR_BAD_CLIENT 2811 PORT_SetError( ss->sec.isServer ? SSL_ERROR_BAD_CLIENT
2814 : SSL_ERROR_BAD_SERVER ); 2812 : SSL_ERROR_BAD_SERVER );
2815 return SECFailure; 2813 return SECFailure;
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
3166 } 3164 }
3167 } 3165 }
3168 if (fpms) { 3166 if (fpms) {
3169 PK11_FreeSymKey(fpms); 3167 PK11_FreeSymKey(fpms);
3170 } 3168 }
3171 } 3169 }
3172 if (pwSpec->master_secret == NULL) { 3170 if (pwSpec->master_secret == NULL) {
3173 ssl_MapLowLevelError(SSL_ERROR_SESSION_KEY_GEN_FAILURE); 3171 ssl_MapLowLevelError(SSL_ERROR_SESSION_KEY_GEN_FAILURE);
3174 return rv; 3172 return rv;
3175 } 3173 }
3174 #ifndef NO_PKCS11_BYPASS
3176 if (ss->opt.bypassPKCS11) { 3175 if (ss->opt.bypassPKCS11) {
3177 SECItem * keydata; 3176 SECItem * keydata;
3178 /* In hope of doing a "double bypass", 3177 /* In hope of doing a "double bypass",
3179 * need to extract the master secret's value from the key object 3178 * need to extract the master secret's value from the key object
3180 * and store it raw in the sslSocket struct. 3179 * and store it raw in the sslSocket struct.
3181 */ 3180 */
3182 rv = PK11_ExtractKeyValue(pwSpec->master_secret); 3181 rv = PK11_ExtractKeyValue(pwSpec->master_secret);
3183 if (rv != SECSuccess) { 3182 if (rv != SECSuccess) {
3184 #if defined(NSS_SURVIVE_DOUBLE_BYPASS_FAILURE) 3183 #if defined(NSS_SURVIVE_DOUBLE_BYPASS_FAILURE)
3185 /* The double bypass failed. 3184 /* The double bypass failed.
(...skipping 15 matching lines...) Expand all
3201 keydata = PK11_GetKeyData(pwSpec->master_secret); 3200 keydata = PK11_GetKeyData(pwSpec->master_secret);
3202 if (keydata && keydata->len <= sizeof pwSpec->raw_master_secret) { 3201 if (keydata && keydata->len <= sizeof pwSpec->raw_master_secret) {
3203 memcpy(pwSpec->raw_master_secret, keydata->data, keydata->len); 3202 memcpy(pwSpec->raw_master_secret, keydata->data, keydata->len);
3204 pwSpec->msItem.data = pwSpec->raw_master_secret; 3203 pwSpec->msItem.data = pwSpec->raw_master_secret;
3205 pwSpec->msItem.len = keydata->len; 3204 pwSpec->msItem.len = keydata->len;
3206 } else { 3205 } else {
3207 PORT_SetError(SEC_ERROR_LIBRARY_FAILURE); 3206 PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
3208 return SECFailure; 3207 return SECFailure;
3209 } 3208 }
3210 } 3209 }
3210 #endif
3211 return SECSuccess; 3211 return SECSuccess;
3212 } 3212 }
3213 3213
3214 3214
3215 /* 3215 /*
3216 * Derive encryption and MAC Keys (and IVs) from master secret 3216 * Derive encryption and MAC Keys (and IVs) from master secret
3217 * Sets a useful error code when returning SECFailure. 3217 * Sets a useful error code when returning SECFailure.
3218 * 3218 *
3219 * Called only from ssl3_InitPendingCipherSpec(), 3219 * Called only from ssl3_InitPendingCipherSpec(),
3220 * which in turn is called from 3220 * which in turn is called from
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
3348 if (symKey) PK11_FreeSymKey(symKey); 3348 if (symKey) PK11_FreeSymKey(symKey);
3349 ssl_MapLowLevelError(SSL_ERROR_SESSION_KEY_GEN_FAILURE); 3349 ssl_MapLowLevelError(SSL_ERROR_SESSION_KEY_GEN_FAILURE);
3350 return SECFailure; 3350 return SECFailure;
3351 } 3351 }
3352 3352
3353 static SECStatus 3353 static SECStatus
3354 ssl3_RestartHandshakeHashes(sslSocket *ss) 3354 ssl3_RestartHandshakeHashes(sslSocket *ss)
3355 { 3355 {
3356 SECStatus rv = SECSuccess; 3356 SECStatus rv = SECSuccess;
3357 3357
3358 #ifndef NO_PKCS11_BYPASS
3358 if (ss->opt.bypassPKCS11) { 3359 if (ss->opt.bypassPKCS11) {
3359 ss->ssl3.hs.messages.len = 0; 3360 ss->ssl3.hs.messages.len = 0;
3360 MD5_Begin((MD5Context *)ss->ssl3.hs.md5_cx); 3361 MD5_Begin((MD5Context *)ss->ssl3.hs.md5_cx);
3361 SHA1_Begin((SHA1Context *)ss->ssl3.hs.sha_cx); 3362 SHA1_Begin((SHA1Context *)ss->ssl3.hs.sha_cx);
3362 } else { 3363 } else
3364 #endif
3365 {
3363 rv = PK11_DigestBegin(ss->ssl3.hs.md5); 3366 rv = PK11_DigestBegin(ss->ssl3.hs.md5);
3364 if (rv != SECSuccess) { 3367 if (rv != SECSuccess) {
3365 ssl_MapLowLevelError(SSL_ERROR_MD5_DIGEST_FAILURE); 3368 ssl_MapLowLevelError(SSL_ERROR_MD5_DIGEST_FAILURE);
3366 return rv; 3369 return rv;
3367 } 3370 }
3368 rv = PK11_DigestBegin(ss->ssl3.hs.sha); 3371 rv = PK11_DigestBegin(ss->ssl3.hs.sha);
3369 if (rv != SECSuccess) { 3372 if (rv != SECSuccess) {
3370 ssl_MapLowLevelError(SSL_ERROR_SHA_DIGEST_FAILURE); 3373 ssl_MapLowLevelError(SSL_ERROR_SHA_DIGEST_FAILURE);
3371 return rv; 3374 return rv;
3372 } 3375 }
3373 } 3376 }
3374 return rv; 3377 return rv;
3375 } 3378 }
3376 3379
3377 static SECStatus 3380 static SECStatus
3378 ssl3_NewHandshakeHashes(sslSocket *ss) 3381 ssl3_NewHandshakeHashes(sslSocket *ss)
3379 { 3382 {
3380 PK11Context *md5 = NULL; 3383 PK11Context *md5 = NULL;
3381 PK11Context *sha = NULL; 3384 PK11Context *sha = NULL;
3382 3385
3383 /* 3386 /*
3384 * note: We should probably lookup an SSL3 slot for these 3387 * note: We should probably lookup an SSL3 slot for these
3385 * handshake hashes in hopes that we wind up with the same slots 3388 * handshake hashes in hopes that we wind up with the same slots
3386 * that the master secret will wind up in ... 3389 * that the master secret will wind up in ...
3387 */ 3390 */
3388 SSL_TRC(30,("%d: SSL3[%d]: start handshake hashes", SSL_GETPID(), ss->fd)); 3391 SSL_TRC(30,("%d: SSL3[%d]: start handshake hashes", SSL_GETPID(), ss->fd));
3392 #ifndef NO_PKCS11_BYPASS
3389 if (ss->opt.bypassPKCS11) { 3393 if (ss->opt.bypassPKCS11) {
3390 PORT_Assert(!ss->ssl3.hs.messages.buf && !ss->ssl3.hs.messages.space); 3394 PORT_Assert(!ss->ssl3.hs.messages.buf && !ss->ssl3.hs.messages.space);
3391 ss->ssl3.hs.messages.buf = NULL; 3395 ss->ssl3.hs.messages.buf = NULL;
3392 ss->ssl3.hs.messages.space = 0; 3396 ss->ssl3.hs.messages.space = 0;
3393 } else { 3397 } else
3398 #endif
3399 {
3394 ss->ssl3.hs.md5 = md5 = PK11_CreateDigestContext(SEC_OID_MD5); 3400 ss->ssl3.hs.md5 = md5 = PK11_CreateDigestContext(SEC_OID_MD5);
3395 ss->ssl3.hs.sha = sha = PK11_CreateDigestContext(SEC_OID_SHA1); 3401 ss->ssl3.hs.sha = sha = PK11_CreateDigestContext(SEC_OID_SHA1);
3396 if (md5 == NULL) { 3402 if (md5 == NULL) {
3397 ssl_MapLowLevelError(SSL_ERROR_MD5_DIGEST_FAILURE); 3403 ssl_MapLowLevelError(SSL_ERROR_MD5_DIGEST_FAILURE);
3398 goto loser; 3404 goto loser;
3399 } 3405 }
3400 if (sha == NULL) { 3406 if (sha == NULL) {
3401 ssl_MapLowLevelError(SSL_ERROR_SHA_DIGEST_FAILURE); 3407 ssl_MapLowLevelError(SSL_ERROR_SHA_DIGEST_FAILURE);
3402 goto loser; 3408 goto loser;
3403 } 3409 }
(...skipping 27 matching lines...) Expand all
3431 static SECStatus 3437 static SECStatus
3432 ssl3_UpdateHandshakeHashes(sslSocket *ss, const unsigned char *b, 3438 ssl3_UpdateHandshakeHashes(sslSocket *ss, const unsigned char *b,
3433 unsigned int l) 3439 unsigned int l)
3434 { 3440 {
3435 SECStatus rv = SECSuccess; 3441 SECStatus rv = SECSuccess;
3436 3442
3437 PORT_Assert( ss->opt.noLocks || ssl_HaveSSL3HandshakeLock(ss) ); 3443 PORT_Assert( ss->opt.noLocks || ssl_HaveSSL3HandshakeLock(ss) );
3438 3444
3439 PRINT_BUF(90, (NULL, "MD5 & SHA handshake hash input:", b, l)); 3445 PRINT_BUF(90, (NULL, "MD5 & SHA handshake hash input:", b, l));
3440 3446
3447 #ifndef NO_PKCS11_BYPASS
3441 if (ss->opt.bypassPKCS11) { 3448 if (ss->opt.bypassPKCS11) {
3442 MD5_Update((MD5Context *)ss->ssl3.hs.md5_cx, b, l); 3449 MD5_Update((MD5Context *)ss->ssl3.hs.md5_cx, b, l);
3443 SHA1_Update((SHA1Context *)ss->ssl3.hs.sha_cx, b, l); 3450 SHA1_Update((SHA1Context *)ss->ssl3.hs.sha_cx, b, l);
3444 #if defined(NSS_SURVIVE_DOUBLE_BYPASS_FAILURE) 3451 #if defined(NSS_SURVIVE_DOUBLE_BYPASS_FAILURE)
3445 rv = sslBuffer_Append(&ss->ssl3.hs.messages, b, l); 3452 rv = sslBuffer_Append(&ss->ssl3.hs.messages, b, l);
3446 #endif 3453 #endif
3447 return rv; 3454 return rv;
3448 } 3455 }
3456 #endif
3449 rv = PK11_DigestOp(ss->ssl3.hs.md5, b, l); 3457 rv = PK11_DigestOp(ss->ssl3.hs.md5, b, l);
3450 if (rv != SECSuccess) { 3458 if (rv != SECSuccess) {
3451 ssl_MapLowLevelError(SSL_ERROR_MD5_DIGEST_FAILURE); 3459 ssl_MapLowLevelError(SSL_ERROR_MD5_DIGEST_FAILURE);
3452 return rv; 3460 return rv;
3453 } 3461 }
3454 rv = PK11_DigestOp(ss->ssl3.hs.sha, b, l); 3462 rv = PK11_DigestOp(ss->ssl3.hs.sha, b, l);
3455 if (rv != SECSuccess) { 3463 if (rv != SECSuccess) {
3456 ssl_MapLowLevelError(SSL_ERROR_SHA_DIGEST_FAILURE); 3464 ssl_MapLowLevelError(SSL_ERROR_SHA_DIGEST_FAILURE);
3457 return rv; 3465 return rv;
3458 } 3466 }
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
3732 PRUint32 sender) 3740 PRUint32 sender)
3733 { 3741 {
3734 SECStatus rv = SECSuccess; 3742 SECStatus rv = SECSuccess;
3735 PRBool isTLS = (PRBool)(spec->version > SSL_LIBRARY_VERSION_3_0); 3743 PRBool isTLS = (PRBool)(spec->version > SSL_LIBRARY_VERSION_3_0);
3736 unsigned int outLength; 3744 unsigned int outLength;
3737 SSL3Opaque md5_inner[MAX_MAC_LENGTH]; 3745 SSL3Opaque md5_inner[MAX_MAC_LENGTH];
3738 SSL3Opaque sha_inner[MAX_MAC_LENGTH]; 3746 SSL3Opaque sha_inner[MAX_MAC_LENGTH];
3739 3747
3740 PORT_Assert( ss->opt.noLocks || ssl_HaveSSL3HandshakeLock(ss) ); 3748 PORT_Assert( ss->opt.noLocks || ssl_HaveSSL3HandshakeLock(ss) );
3741 3749
3750 #ifndef NO_PKCS11_BYPASS
3742 if (ss->opt.bypassPKCS11) { 3751 if (ss->opt.bypassPKCS11) {
3743 /* compute them without PKCS11 */ 3752 /* compute them without PKCS11 */
3744 PRUint64 md5_cx[MAX_MAC_CONTEXT_LLONGS]; 3753 PRUint64 md5_cx[MAX_MAC_CONTEXT_LLONGS];
3745 PRUint64 sha_cx[MAX_MAC_CONTEXT_LLONGS]; 3754 PRUint64 sha_cx[MAX_MAC_CONTEXT_LLONGS];
3746 3755
3747 #define md5cx ((MD5Context *)md5_cx) 3756 #define md5cx ((MD5Context *)md5_cx)
3748 #define shacx ((SHA1Context *)sha_cx) 3757 #define shacx ((SHA1Context *)sha_cx)
3749 3758
3750 if (!spec->msItem.data) { 3759 if (!spec->msItem.data) {
3751 PORT_SetError(SSL_ERROR_RX_UNEXPECTED_HANDSHAKE); 3760 PORT_SetError(SSL_ERROR_RX_UNEXPECTED_HANDSHAKE);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
3814 SHA1_Update(shacx, mac_pad_2, mac_defs[mac_sha].pad_size); 3823 SHA1_Update(shacx, mac_pad_2, mac_defs[mac_sha].pad_size);
3815 SHA1_Update(shacx, sha_inner, SHA1_LENGTH); 3824 SHA1_Update(shacx, sha_inner, SHA1_LENGTH);
3816 } 3825 }
3817 SHA1_End(shacx, hashes->sha, &outLength, SHA1_LENGTH); 3826 SHA1_End(shacx, hashes->sha, &outLength, SHA1_LENGTH);
3818 3827
3819 PRINT_BUF(60, (NULL, "SHA outer: result", hashes->sha, SHA1_LENGTH)); 3828 PRINT_BUF(60, (NULL, "SHA outer: result", hashes->sha, SHA1_LENGTH));
3820 3829
3821 rv = SECSuccess; 3830 rv = SECSuccess;
3822 #undef md5cx 3831 #undef md5cx
3823 #undef shacx 3832 #undef shacx
3824 } else { 3833 } else
3834 #endif
3835 {
3825 /* compute hases with PKCS11 */ 3836 /* compute hases with PKCS11 */
3826 PK11Context * md5; 3837 PK11Context * md5;
3827 PK11Context * sha = NULL; 3838 PK11Context * sha = NULL;
3828 unsigned char *md5StateBuf = NULL; 3839 unsigned char *md5StateBuf = NULL;
3829 unsigned char *shaStateBuf = NULL; 3840 unsigned char *shaStateBuf = NULL;
3830 unsigned int md5StateLen, shaStateLen; 3841 unsigned int md5StateLen, shaStateLen;
3831 unsigned char md5StackBuf[256]; 3842 unsigned char md5StackBuf[256];
3832 unsigned char shaStackBuf[512]; 3843 unsigned char shaStackBuf[512];
3833 3844
3834 if (!spec->master_secret) { 3845 if (!spec->master_secret) {
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
4287 if (IS_DTLS(ss)) { 4298 if (IS_DTLS(ss)) {
4288 length += 1 + ss->ssl3.hs.cookieLen; 4299 length += 1 + ss->ssl3.hs.cookieLen;
4289 } 4300 }
4290 4301
4291 rv = ssl3_AppendHandshakeHeader(ss, client_hello, length); 4302 rv = ssl3_AppendHandshakeHeader(ss, client_hello, length);
4292 if (rv != SECSuccess) { 4303 if (rv != SECSuccess) {
4293 return rv; /* err set by ssl3_AppendHandshake* */ 4304 return rv; /* err set by ssl3_AppendHandshake* */
4294 } 4305 }
4295 4306
4296 if (ss->firstHsDone) { 4307 if (ss->firstHsDone) {
4297 » /* Work around the Windows SChannel bug described above. */ 4308 » /* The client hello version must stay unchanged to work around
4309 » * the Windows SChannel bug described above. */
4298 PORT_Assert(ss->version == ss->clientHelloVersion); 4310 PORT_Assert(ss->version == ss->clientHelloVersion);
4299 } 4311 }
4300 ss->clientHelloVersion = ss->version; 4312 ss->clientHelloVersion = ss->version;
4301 if (IS_DTLS(ss)) { 4313 if (IS_DTLS(ss)) {
4302 PRUint16 version; 4314 PRUint16 version;
4303 4315
4304 version = dtls_TLSVersionToDTLSVersion(ss->clientHelloVersion); 4316 version = dtls_TLSVersionToDTLSVersion(ss->clientHelloVersion);
4305 rv = ssl3_AppendHandshakeNumber(ss, version, 2); 4317 rv = ssl3_AppendHandshakeNumber(ss, version, 2);
4306 } else { 4318 } else {
4307 rv = ssl3_AppendHandshakeNumber(ss, ss->clientHelloVersion, 2); 4319 rv = ssl3_AppendHandshakeNumber(ss, ss->clientHelloVersion, 2);
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
4903 } 4915 }
4904 4916
4905 loser: 4917 loser:
4906 done: 4918 done:
4907 PZ_Unlock(symWrapKeysLock); 4919 PZ_Unlock(symWrapKeysLock);
4908 return unwrappedWrappingKey; 4920 return unwrappedWrappingKey;
4909 } 4921 }
4910 4922
4911 /* hexEncode hex encodes |length| bytes from |in| and writes it as |length*2| 4923 /* hexEncode hex encodes |length| bytes from |in| and writes it as |length*2|
4912 * bytes to |out|. */ 4924 * bytes to |out|. */
4913 static void hexEncode(char *out, const unsigned char *in, size_t length) { 4925 static void
4926 hexEncode(char *out, const unsigned char *in, unsigned int length)
4927 {
4914 static const char hextable[] = "0123456789abcdef"; 4928 static const char hextable[] = "0123456789abcdef";
4915 size_t i; 4929 unsigned int i;
4916 4930
4917 for (i = 0; i < length; i++) { 4931 for (i = 0; i < length; i++) {
4918 *(out++) = hextable[in[i] >> 4]; 4932 *(out++) = hextable[in[i] >> 4];
4919 *(out++) = hextable[in[i] & 15]; 4933 *(out++) = hextable[in[i] & 15];
4920 } 4934 }
4921 } 4935 }
4922 4936
4923 /* Called from ssl3_SendClientKeyExchange(). */ 4937 /* Called from ssl3_SendClientKeyExchange(). */
4924 /* Presently, this always uses PKCS11. There is no bypass for this. */ 4938 /* Presently, this always uses PKCS11. There is no bypass for this. */
4925 static SECStatus 4939 static SECStatus
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
5375 } 5389 }
5376 5390
5377 /* find selected cipher suite in our list. */ 5391 /* find selected cipher suite in our list. */
5378 temp = ssl3_ConsumeHandshakeNumber(ss, 2, &b, &length); 5392 temp = ssl3_ConsumeHandshakeNumber(ss, 2, &b, &length);
5379 if (temp < 0) { 5393 if (temp < 0) {
5380 goto loser; /* alert has been sent */ 5394 goto loser; /* alert has been sent */
5381 } 5395 }
5382 ssl3_config_match_init(ss); 5396 ssl3_config_match_init(ss);
5383 for (i = 0; i < ssl_V3_SUITES_IMPLEMENTED; i++) { 5397 for (i = 0; i < ssl_V3_SUITES_IMPLEMENTED; i++) {
5384 ssl3CipherSuiteCfg *suite = &ss->cipherSuites[i]; 5398 ssl3CipherSuiteCfg *suite = &ss->cipherSuites[i];
5385 » if ((temp == suite->cipher_suite) && 5399 » if (temp == suite->cipher_suite) {
5386 » (config_match(suite, ss->ssl3.policy, PR_TRUE))) { 5400 » if (!config_match(suite, ss->ssl3.policy, PR_TRUE)) {
5401 » » break;» /* failure */
5402 » }
5403 » if (!ssl3_CipherSuiteAllowedForVersion(suite->cipher_suite,
5404 » » » » » » ss->version)) {
5405 » » desc = handshake_failure;
5406 » » errCode = SSL_ERROR_CIPHER_DISALLOWED_FOR_VERSION;
5407 » » goto alert_loser;
5408 » }
5409 »
5387 suite_found = PR_TRUE; 5410 suite_found = PR_TRUE;
5388 break; /* success */ 5411 break; /* success */
5389 } 5412 }
5390 } 5413 }
5391 if (!suite_found) { 5414 if (!suite_found) {
5392 desc = handshake_failure; 5415 desc = handshake_failure;
5393 errCode = SSL_ERROR_NO_CYPHER_OVERLAP; 5416 errCode = SSL_ERROR_NO_CYPHER_OVERLAP;
5394 goto alert_loser; 5417 goto alert_loser;
5395 } 5418 }
5396 ss->ssl3.hs.cipher_suite = (ssl3CipherSuite)temp; 5419 ss->ssl3.hs.cipher_suite = (ssl3CipherSuite)temp;
5397 ss->ssl3.hs.suite_def = ssl_LookupCipherSuiteDef((ssl3CipherSuite)temp); 5420 ss->ssl3.hs.suite_def = ssl_LookupCipherSuiteDef((ssl3CipherSuite)temp);
5398 PORT_Assert(ss->ssl3.hs.suite_def); 5421 PORT_Assert(ss->ssl3.hs.suite_def);
5399 if (!ss->ssl3.hs.suite_def) { 5422 if (!ss->ssl3.hs.suite_def) {
5400 PORT_SetError(errCode = SEC_ERROR_LIBRARY_FAILURE); 5423 PORT_SetError(errCode = SEC_ERROR_LIBRARY_FAILURE);
5401 goto loser; /* we don't send alerts for our screw-ups. */ 5424 goto loser; /* we don't send alerts for our screw-ups. */
5402 } 5425 }
5403 5426
5404 /* find selected compression method in our list. */ 5427 /* find selected compression method in our list. */
5405 temp = ssl3_ConsumeHandshakeNumber(ss, 1, &b, &length); 5428 temp = ssl3_ConsumeHandshakeNumber(ss, 1, &b, &length);
5406 if (temp < 0) { 5429 if (temp < 0) {
5407 goto loser; /* alert has been sent */ 5430 goto loser; /* alert has been sent */
5408 } 5431 }
5409 suite_found = PR_FALSE; 5432 suite_found = PR_FALSE;
5410 for (i = 0; i < compressionMethodsCount; i++) { 5433 for (i = 0; i < compressionMethodsCount; i++) {
5411 » if (temp == compressions[i] && 5434 » if (temp == compressions[i]) {
5412 » compressionEnabled(ss, compressions[i])) { 5435 » if (!compressionEnabled(ss, compressions[i])) {
5436 » » break;» /* failure */
5437 » }
5413 suite_found = PR_TRUE; 5438 suite_found = PR_TRUE;
5414 break; /* success */ 5439 break; /* success */
5415 } 5440 }
5416 } 5441 }
5417 if (!suite_found) { 5442 if (!suite_found) {
5418 desc = handshake_failure; 5443 desc = handshake_failure;
5419 errCode = SSL_ERROR_NO_COMPRESSION_OVERLAP; 5444 errCode = SSL_ERROR_NO_COMPRESSION_OVERLAP;
5420 goto alert_loser; 5445 goto alert_loser;
5421 } 5446 }
5422 ss->ssl3.hs.compression = (SSLCompressionMethod)temp; 5447 ss->ssl3.hs.compression = (SSLCompressionMethod)temp;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
5487 /* 3 cases here: 5512 /* 3 cases here:
5488 * a) key is wrapped (implies using PKCS11) 5513 * a) key is wrapped (implies using PKCS11)
5489 * b) key is unwrapped, but we're still using PKCS11 5514 * b) key is unwrapped, but we're still using PKCS11
5490 * c) key is unwrapped, and we're bypassing PKCS11. 5515 * c) key is unwrapped, and we're bypassing PKCS11.
5491 */ 5516 */
5492 if (sid->u.ssl3.keys.msIsWrapped) { 5517 if (sid->u.ssl3.keys.msIsWrapped) {
5493 PK11SlotInfo *slot; 5518 PK11SlotInfo *slot;
5494 PK11SymKey * wrapKey; /* wrapping key */ 5519 PK11SymKey * wrapKey; /* wrapping key */
5495 CK_FLAGS keyFlags = 0; 5520 CK_FLAGS keyFlags = 0;
5496 5521
5522 #ifndef NO_PKCS11_BYPASS
5497 if (ss->opt.bypassPKCS11) { 5523 if (ss->opt.bypassPKCS11) {
5498 /* we cannot restart a non-bypass session in a 5524 /* we cannot restart a non-bypass session in a
5499 ** bypass socket. 5525 ** bypass socket.
5500 */ 5526 */
5501 break; 5527 break;
5502 } 5528 }
5529 #endif
5503 /* unwrap master secret with PKCS11 */ 5530 /* unwrap master secret with PKCS11 */
5504 slot = SECMOD_LookupSlot(sid->u.ssl3.masterModuleID, 5531 slot = SECMOD_LookupSlot(sid->u.ssl3.masterModuleID,
5505 sid->u.ssl3.masterSlotID); 5532 sid->u.ssl3.masterSlotID);
5506 if (slot == NULL) { 5533 if (slot == NULL) {
5507 break; /* not considered an error. */ 5534 break; /* not considered an error. */
5508 } 5535 }
5509 if (!PK11_IsPresent(slot)) { 5536 if (!PK11_IsPresent(slot)) {
5510 PK11_FreeSlot(slot); 5537 PK11_FreeSlot(slot);
5511 break; /* not considered an error. */ 5538 break; /* not considered an error. */
5512 } 5539 }
(...skipping 14 matching lines...) Expand all
5527 wrappedMS.len = sid->u.ssl3.keys.wrapped_master_secret_len; 5554 wrappedMS.len = sid->u.ssl3.keys.wrapped_master_secret_len;
5528 pwSpec->master_secret = 5555 pwSpec->master_secret =
5529 PK11_UnwrapSymKeyWithFlags(wrapKey, sid->u.ssl3.masterWrapMech, 5556 PK11_UnwrapSymKeyWithFlags(wrapKey, sid->u.ssl3.masterWrapMech,
5530 NULL, &wrappedMS, CKM_SSL3_MASTER_KEY_DERIVE, 5557 NULL, &wrappedMS, CKM_SSL3_MASTER_KEY_DERIVE,
5531 CKA_DERIVE, sizeof(SSL3MasterSecret), keyFlags); 5558 CKA_DERIVE, sizeof(SSL3MasterSecret), keyFlags);
5532 errCode = PORT_GetError(); 5559 errCode = PORT_GetError();
5533 PK11_FreeSymKey(wrapKey); 5560 PK11_FreeSymKey(wrapKey);
5534 if (pwSpec->master_secret == NULL) { 5561 if (pwSpec->master_secret == NULL) {
5535 break; /* errorCode set just after call to UnwrapSymKey. */ 5562 break; /* errorCode set just after call to UnwrapSymKey. */
5536 } 5563 }
5564 #ifndef NO_PKCS11_BYPASS
5537 } else if (ss->opt.bypassPKCS11) { 5565 } else if (ss->opt.bypassPKCS11) {
5538 /* MS is not wrapped */ 5566 /* MS is not wrapped */
5539 wrappedMS.data = sid->u.ssl3.keys.wrapped_master_secret; 5567 wrappedMS.data = sid->u.ssl3.keys.wrapped_master_secret;
5540 wrappedMS.len = sid->u.ssl3.keys.wrapped_master_secret_len; 5568 wrappedMS.len = sid->u.ssl3.keys.wrapped_master_secret_len;
5541 memcpy(pwSpec->raw_master_secret, wrappedMS.data, wrappedMS.len); 5569 memcpy(pwSpec->raw_master_secret, wrappedMS.data, wrappedMS.len);
5542 pwSpec->msItem.data = pwSpec->raw_master_secret; 5570 pwSpec->msItem.data = pwSpec->raw_master_secret;
5543 pwSpec->msItem.len = wrappedMS.len; 5571 pwSpec->msItem.len = wrappedMS.len;
5572 #endif
5544 } else { 5573 } else {
5545 /* We CAN restart a bypass session in a non-bypass socket. */ 5574 /* We CAN restart a bypass session in a non-bypass socket. */
5546 /* need to import the raw master secret to session object */ 5575 /* need to import the raw master secret to session object */
5547 PK11SlotInfo *slot = PK11_GetInternalSlot(); 5576 PK11SlotInfo *slot = PK11_GetInternalSlot();
5548 wrappedMS.data = sid->u.ssl3.keys.wrapped_master_secret; 5577 wrappedMS.data = sid->u.ssl3.keys.wrapped_master_secret;
5549 wrappedMS.len = sid->u.ssl3.keys.wrapped_master_secret_len; 5578 wrappedMS.len = sid->u.ssl3.keys.wrapped_master_secret_len;
5550 pwSpec->master_secret = 5579 pwSpec->master_secret =
5551 PK11_ImportSymKey(slot, CKM_SSL3_MASTER_KEY_DERIVE, 5580 PK11_ImportSymKey(slot, CKM_SSL3_MASTER_KEY_DERIVE,
5552 PK11_OriginUnwrap, CKA_ENCRYPT, 5581 PK11_OriginUnwrap, CKA_ENCRYPT,
5553 &wrappedMS, NULL); 5582 &wrappedMS, NULL);
(...skipping 17 matching lines...) Expand all
5571 ss->ssl3.hs.ws = wait_change_cipher; 5600 ss->ssl3.hs.ws = wait_change_cipher;
5572 5601
5573 ss->ssl3.hs.isResuming = PR_TRUE; 5602 ss->ssl3.hs.isResuming = PR_TRUE;
5574 5603
5575 /* copy the peer cert from the SID */ 5604 /* copy the peer cert from the SID */
5576 if (sid->peerCert != NULL) { 5605 if (sid->peerCert != NULL) {
5577 ss->sec.peerCert = CERT_DupCertificate(sid->peerCert); 5606 ss->sec.peerCert = CERT_DupCertificate(sid->peerCert);
5578 ssl3_CopyPeerCertsFromSID(ss, sid); 5607 ssl3_CopyPeerCertsFromSID(ss, sid);
5579 } 5608 }
5580 5609
5610
5581 /* NULL value for PMS signifies re-use of the old MS */ 5611 /* NULL value for PMS signifies re-use of the old MS */
5582 rv = ssl3_InitPendingCipherSpec(ss, NULL); 5612 rv = ssl3_InitPendingCipherSpec(ss, NULL);
5583 if (rv != SECSuccess) { 5613 if (rv != SECSuccess) {
5584 goto alert_loser; /* err code was set */ 5614 goto alert_loser; /* err code was set */
5585 } 5615 }
5586 goto winner; 5616 goto winner;
5587 } while (0); 5617 } while (0);
5588 5618
5589 if (sid_match) 5619 if (sid_match)
5590 SSL_AtomicIncrementLong(& ssl3stats.hsh_sid_cache_not_ok ); 5620 SSL_AtomicIncrementLong(& ssl3stats.hsh_sid_cache_not_ok );
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
5633 return SECSuccess; 5663 return SECSuccess;
5634 5664
5635 alert_loser: 5665 alert_loser:
5636 (void)SSL3_SendAlert(ss, alert_fatal, desc); 5666 (void)SSL3_SendAlert(ss, alert_fatal, desc);
5637 5667
5638 loser: 5668 loser:
5639 errCode = ssl_MapLowLevelError(errCode); 5669 errCode = ssl_MapLowLevelError(errCode);
5640 return SECFailure; 5670 return SECFailure;
5641 } 5671 }
5642 5672
5643 /* ssl3_BigIntGreaterThan1 returns true iff |mpint|, taken as an unsigned, 5673 /* ssl3_BigIntGreaterThanOne returns true iff |mpint|, taken as an unsigned,
5644 * big-endian integer is > 1 */ 5674 * big-endian integer is > 1 */
5645 static PRBool 5675 static PRBool
5646 ssl3_BigIntGreaterThan1(const SECItem* mpint) { 5676 ssl3_BigIntGreaterThanOne(const SECItem* mpint) {
5647 unsigned char firstNonZeroByte = 0; 5677 unsigned char firstNonZeroByte = 0;
5648 unsigned int i; 5678 unsigned int i;
5649 5679
5650 for (i = 0; i < mpint->len; i++) { 5680 for (i = 0; i < mpint->len; i++) {
5651 if (mpint->data[i]) { 5681 if (mpint->data[i]) {
5652 firstNonZeroByte = mpint->data[i]; 5682 firstNonZeroByte = mpint->data[i];
5653 break; 5683 break;
5654 } 5684 }
5655 } 5685 }
5656 5686
5657 if (firstNonZeroByte == 0) 5687 if (firstNonZeroByte == 0)
5658 return PR_FALSE; 5688 return PR_FALSE;
5659 if (firstNonZeroByte > 1) 5689 if (firstNonZeroByte > 1)
5660 return PR_TRUE; 5690 return PR_TRUE;
5661 5691
5662 // firstNonZeroByte == 1, therefore mpint > 1 iff the first non-zero byte 5692 /* firstNonZeroByte == 1, therefore mpint > 1 iff the first non-zero byte
5663 // is followed by another byte. 5693 * is followed by another byte. */
5664 return (i < mpint->len - 1); 5694 return (i < mpint->len - 1);
5665 } 5695 }
5666 5696
5667 /* Called from ssl3_HandleHandshakeMessage() when it has deciphered a complete 5697 /* Called from ssl3_HandleHandshakeMessage() when it has deciphered a complete
5668 * ssl3 ServerKeyExchange message. 5698 * ssl3 ServerKeyExchange message.
5669 * Caller must hold Handshake and RecvBuf locks. 5699 * Caller must hold Handshake and RecvBuf locks.
5670 */ 5700 */
5671 static SECStatus 5701 static SECStatus
5672 ssl3_HandleServerKeyExchange(sslSocket *ss, SSL3Opaque *b, PRUint32 length) 5702 ssl3_HandleServerKeyExchange(sslSocket *ss, SSL3Opaque *b, PRUint32 length)
5673 { 5703 {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
5788 goto loser; /* malformed. */ 5818 goto loser; /* malformed. */
5789 } 5819 }
5790 if (dh_p.len < 512/8) { 5820 if (dh_p.len < 512/8) {
5791 errCode = SSL_ERROR_WEAK_SERVER_EPHEMERAL_DH_KEY; 5821 errCode = SSL_ERROR_WEAK_SERVER_EPHEMERAL_DH_KEY;
5792 goto alert_loser; 5822 goto alert_loser;
5793 } 5823 }
5794 rv = ssl3_ConsumeHandshakeVariable(ss, &dh_g, 2, &b, &length); 5824 rv = ssl3_ConsumeHandshakeVariable(ss, &dh_g, 2, &b, &length);
5795 if (rv != SECSuccess) { 5825 if (rv != SECSuccess) {
5796 goto loser; /* malformed. */ 5826 goto loser; /* malformed. */
5797 } 5827 }
5798 » if (dh_g.len > dh_p.len || !ssl3_BigIntGreaterThan1(&dh_g)) 5828 » if (dh_g.len > dh_p.len || !ssl3_BigIntGreaterThanOne(&dh_g))
5799 goto alert_loser; 5829 goto alert_loser;
5800 rv = ssl3_ConsumeHandshakeVariable(ss, &dh_Ys, 2, &b, &length); 5830 rv = ssl3_ConsumeHandshakeVariable(ss, &dh_Ys, 2, &b, &length);
5801 if (rv != SECSuccess) { 5831 if (rv != SECSuccess) {
5802 goto loser; /* malformed. */ 5832 goto loser; /* malformed. */
5803 } 5833 }
5804 » if (dh_Ys.len > dh_p.len || !ssl3_BigIntGreaterThan1(&dh_Ys)) 5834 » if (dh_Ys.len > dh_p.len || !ssl3_BigIntGreaterThanOne(&dh_Ys))
5805 goto alert_loser; 5835 goto alert_loser;
5806 rv = ssl3_ConsumeHandshakeVariable(ss, &signature, 2, &b, &length); 5836 rv = ssl3_ConsumeHandshakeVariable(ss, &signature, 2, &b, &length);
5807 if (rv != SECSuccess) { 5837 if (rv != SECSuccess) {
5808 goto loser; /* malformed. */ 5838 goto loser; /* malformed. */
5809 } 5839 }
5810 if (length != 0) { 5840 if (length != 0) {
5811 if (isTLS) 5841 if (isTLS)
5812 desc = decode_error; 5842 desc = decode_error;
5813 goto alert_loser; /* malformed. */ 5843 goto alert_loser; /* malformed. */
5814 } 5844 }
(...skipping 1127 matching lines...) Expand 10 before | Expand all | Expand 10 after
6942 #ifndef PARANOID 6972 #ifndef PARANOID
6943 /* Look for a matching cipher suite. */ 6973 /* Look for a matching cipher suite. */
6944 j = ssl3_config_match_init(ss); 6974 j = ssl3_config_match_init(ss);
6945 if (j <= 0) { /* no ciphers are working/supported by PK11 */ 6975 if (j <= 0) { /* no ciphers are working/supported by PK11 */
6946 errCode = PORT_GetError(); /* error code is already set. */ 6976 errCode = PORT_GetError(); /* error code is already set. */
6947 goto alert_loser; 6977 goto alert_loser;
6948 } 6978 }
6949 #endif 6979 #endif
6950 6980
6951 /* Select a cipher suite. 6981 /* Select a cipher suite.
6982 **
6952 ** NOTE: This suite selection algorithm should be the same as the one in 6983 ** NOTE: This suite selection algorithm should be the same as the one in
6953 ** ssl3_HandleV2ClientHello(). 6984 ** ssl3_HandleV2ClientHello().
6985 **
6986 ** If TLS 1.0 is enabled, we could handle the case where the client
6987 ** offered TLS 1.1 but offered only export cipher suites by choosing TLS
6988 ** 1.0 and selecting one of those export cipher suites. However, a secure
6989 ** TLS 1.1 client should not have export cipher suites enabled at all,
6990 ** and a TLS 1.1 client should definitely not be offering *only* export
6991 ** cipher suites. Therefore, we refuse to negotiate export cipher suites
6992 ** with any client that indicates support for TLS 1.1 or higher when we
6993 ** (the server) have TLS 1.1 support enabled.
6954 */ 6994 */
6955 for (j = 0; j < ssl_V3_SUITES_IMPLEMENTED; j++) { 6995 for (j = 0; j < ssl_V3_SUITES_IMPLEMENTED; j++) {
6956 ssl3CipherSuiteCfg *suite = &ss->cipherSuites[j]; 6996 ssl3CipherSuiteCfg *suite = &ss->cipherSuites[j];
6957 » if (!config_match(suite, ss->ssl3.policy, PR_TRUE)) 6997 » if (!config_match(suite, ss->ssl3.policy, PR_TRUE) ||
6998 » !ssl3_CipherSuiteAllowedForVersion(suite->cipher_suite,
6999 » » » » » ss->version)) {
6958 continue; 7000 continue;
7001 }
6959 for (i = 0; i + 1 < suites.len; i += 2) { 7002 for (i = 0; i + 1 < suites.len; i += 2) {
6960 PRUint16 suite_i = (suites.data[i] << 8) | suites.data[i + 1]; 7003 PRUint16 suite_i = (suites.data[i] << 8) | suites.data[i + 1];
6961 if (suite_i == suite->cipher_suite) { 7004 if (suite_i == suite->cipher_suite) {
6962 ss->ssl3.hs.cipher_suite = suite->cipher_suite; 7005 ss->ssl3.hs.cipher_suite = suite->cipher_suite;
6963 ss->ssl3.hs.suite_def = 7006 ss->ssl3.hs.suite_def =
6964 ssl_LookupCipherSuiteDef(ss->ssl3.hs.cipher_suite); 7007 ssl_LookupCipherSuiteDef(ss->ssl3.hs.cipher_suite);
6965 goto suite_found; 7008 goto suite_found;
6966 } 7009 }
6967 } 7010 }
6968 } 7011 }
6969 errCode = SSL_ERROR_NO_CYPHER_OVERLAP; 7012 errCode = SSL_ERROR_NO_CYPHER_OVERLAP;
6970 goto alert_loser; 7013 goto alert_loser;
6971 7014
6972 suite_found: 7015 suite_found:
6973 /* Look for a matching compression algorithm. */ 7016 /* Look for a matching compression algorithm. */
6974 for (i = 0; i < comps.len; i++) { 7017 for (i = 0; i < comps.len; i++) {
7018 if (!compressionEnabled(ss, comps.data[i]))
7019 continue;
6975 for (j = 0; j < compressionMethodsCount; j++) { 7020 for (j = 0; j < compressionMethodsCount; j++) {
6976 » if (comps.data[i] == compressions[j] && 7021 » if (comps.data[i] == compressions[j]) {
6977 » » compressionEnabled(ss, compressions[j])) {
6978 ss->ssl3.hs.compression = 7022 ss->ssl3.hs.compression =
6979 (SSLCompressionMethod)compressions[j]; 7023 (SSLCompressionMethod)compressions[j];
6980 goto compression_found; 7024 goto compression_found;
6981 } 7025 }
6982 } 7026 }
6983 } 7027 }
6984 errCode = SSL_ERROR_NO_COMPRESSION_OVERLAP; 7028 errCode = SSL_ERROR_NO_COMPRESSION_OVERLAP;
6985 /* null compression must be supported */ 7029 /* null compression must be supported */
6986 goto alert_loser; 7030 goto alert_loser;
6987 7031
6988 compression_found: 7032 compression_found:
6989 suites.data = NULL; 7033 suites.data = NULL;
6990 comps.data = NULL; 7034 comps.data = NULL;
6991 7035
6992 ss->sec.send = ssl3_SendApplicationData; 7036 ss->sec.send = ssl3_SendApplicationData;
6993 7037
6994 /* If there are any failures while processing the old sid, 7038 /* If there are any failures while processing the old sid,
6995 * we don't consider them to be errors. Instead, We just behave 7039 * we don't consider them to be errors. Instead, We just behave
6996 * as if the client had sent us no sid to begin with, and make a new one. 7040 * as if the client had sent us no sid to begin with, and make a new one.
6997 */ 7041 */
6998 if (sid != NULL) do { 7042 if (sid != NULL) do {
6999 ssl3CipherSpec *pwSpec; 7043 ssl3CipherSpec *pwSpec;
7000 SECItem wrappedMS; /* wrapped key */ 7044 SECItem wrappedMS; /* wrapped key */
7001 7045
7002 if (sid->version != ss->version || 7046 if (sid->version != ss->version ||
7003 » sid->u.ssl3.cipherSuite != ss->ssl3.hs.cipher_suite) { 7047 » sid->u.ssl3.cipherSuite != ss->ssl3.hs.cipher_suite ||
7048 » sid->u.ssl3.compression != ss->ssl3.hs.compression) {
7004 break; /* not an error */ 7049 break; /* not an error */
7005 } 7050 }
7006 7051
7007 if (ss->sec.ci.sid) { 7052 if (ss->sec.ci.sid) {
7008 if (ss->sec.uncache) 7053 if (ss->sec.uncache)
7009 ss->sec.uncache(ss->sec.ci.sid); 7054 ss->sec.uncache(ss->sec.ci.sid);
7010 PORT_Assert(ss->sec.ci.sid != sid); /* should be impossible, but .. . */ 7055 PORT_Assert(ss->sec.ci.sid != sid); /* should be impossible, but .. . */
7011 if (ss->sec.ci.sid != sid) { 7056 if (ss->sec.ci.sid != sid) {
7012 ssl_FreeSID(ss->sec.ci.sid); 7057 ssl_FreeSID(ss->sec.ci.sid);
7013 } 7058 }
7014 ss->sec.ci.sid = NULL; 7059 ss->sec.ci.sid = NULL;
7015 } 7060 }
7016 /* we need to resurrect the master secret.... */ 7061 /* we need to resurrect the master secret.... */
7017 7062
7018 ssl_GetSpecWriteLock(ss); haveSpecWriteLock = PR_TRUE; 7063 ssl_GetSpecWriteLock(ss); haveSpecWriteLock = PR_TRUE;
7019 pwSpec = ss->ssl3.pwSpec; 7064 pwSpec = ss->ssl3.pwSpec;
7020 if (sid->u.ssl3.keys.msIsWrapped) { 7065 if (sid->u.ssl3.keys.msIsWrapped) {
7021 PK11SymKey * wrapKey; /* wrapping key */ 7066 PK11SymKey * wrapKey; /* wrapping key */
7022 CK_FLAGS keyFlags = 0; 7067 CK_FLAGS keyFlags = 0;
7068 #ifndef NO_PKCS11_BYPASS
7023 if (ss->opt.bypassPKCS11) { 7069 if (ss->opt.bypassPKCS11) {
7024 /* we cannot restart a non-bypass session in a 7070 /* we cannot restart a non-bypass session in a
7025 ** bypass socket. 7071 ** bypass socket.
7026 */ 7072 */
7027 break; 7073 break;
7028 } 7074 }
7075 #endif
7029 7076
7030 wrapKey = getWrappingKey(ss, NULL, sid->u.ssl3.exchKeyType, 7077 wrapKey = getWrappingKey(ss, NULL, sid->u.ssl3.exchKeyType,
7031 sid->u.ssl3.masterWrapMech, 7078 sid->u.ssl3.masterWrapMech,
7032 ss->pkcs11PinArg); 7079 ss->pkcs11PinArg);
7033 if (!wrapKey) { 7080 if (!wrapKey) {
7034 /* we have a SID cache entry, but no wrapping key for it??? */ 7081 /* we have a SID cache entry, but no wrapping key for it??? */
7035 break; 7082 break;
7036 } 7083 }
7037 7084
7038 if (ss->version > SSL_LIBRARY_VERSION_3_0) { /* isTLS */ 7085 if (ss->version > SSL_LIBRARY_VERSION_3_0) { /* isTLS */
7039 keyFlags = CKF_SIGN | CKF_VERIFY; 7086 keyFlags = CKF_SIGN | CKF_VERIFY;
7040 } 7087 }
7041 7088
7042 wrappedMS.data = sid->u.ssl3.keys.wrapped_master_secret; 7089 wrappedMS.data = sid->u.ssl3.keys.wrapped_master_secret;
7043 wrappedMS.len = sid->u.ssl3.keys.wrapped_master_secret_len; 7090 wrappedMS.len = sid->u.ssl3.keys.wrapped_master_secret_len;
7044 7091
7045 /* unwrap the master secret. */ 7092 /* unwrap the master secret. */
7046 pwSpec->master_secret = 7093 pwSpec->master_secret =
7047 PK11_UnwrapSymKeyWithFlags(wrapKey, sid->u.ssl3.masterWrapMech, 7094 PK11_UnwrapSymKeyWithFlags(wrapKey, sid->u.ssl3.masterWrapMech,
7048 NULL, &wrappedMS, CKM_SSL3_MASTER_KEY_DERIVE, 7095 NULL, &wrappedMS, CKM_SSL3_MASTER_KEY_DERIVE,
7049 CKA_DERIVE, sizeof(SSL3MasterSecret), keyFlags); 7096 CKA_DERIVE, sizeof(SSL3MasterSecret), keyFlags);
7050 PK11_FreeSymKey(wrapKey); 7097 PK11_FreeSymKey(wrapKey);
7051 if (pwSpec->master_secret == NULL) { 7098 if (pwSpec->master_secret == NULL) {
7052 break; /* not an error */ 7099 break; /* not an error */
7053 } 7100 }
7101 #ifndef NO_PKCS11_BYPASS
7054 } else if (ss->opt.bypassPKCS11) { 7102 } else if (ss->opt.bypassPKCS11) {
7055 wrappedMS.data = sid->u.ssl3.keys.wrapped_master_secret; 7103 wrappedMS.data = sid->u.ssl3.keys.wrapped_master_secret;
7056 wrappedMS.len = sid->u.ssl3.keys.wrapped_master_secret_len; 7104 wrappedMS.len = sid->u.ssl3.keys.wrapped_master_secret_len;
7057 memcpy(pwSpec->raw_master_secret, wrappedMS.data, wrappedMS.len); 7105 memcpy(pwSpec->raw_master_secret, wrappedMS.data, wrappedMS.len);
7058 pwSpec->msItem.data = pwSpec->raw_master_secret; 7106 pwSpec->msItem.data = pwSpec->raw_master_secret;
7059 pwSpec->msItem.len = wrappedMS.len; 7107 pwSpec->msItem.len = wrappedMS.len;
7108 #endif
7060 } else { 7109 } else {
7061 /* We CAN restart a bypass session in a non-bypass socket. */ 7110 /* We CAN restart a bypass session in a non-bypass socket. */
7062 /* need to import the raw master secret to session object */ 7111 /* need to import the raw master secret to session object */
7063 PK11SlotInfo * slot; 7112 PK11SlotInfo * slot;
7064 wrappedMS.data = sid->u.ssl3.keys.wrapped_master_secret; 7113 wrappedMS.data = sid->u.ssl3.keys.wrapped_master_secret;
7065 wrappedMS.len = sid->u.ssl3.keys.wrapped_master_secret_len; 7114 wrappedMS.len = sid->u.ssl3.keys.wrapped_master_secret_len;
7066 slot = PK11_GetInternalSlot(); 7115 slot = PK11_GetInternalSlot();
7067 pwSpec->master_secret = 7116 pwSpec->master_secret =
7068 PK11_ImportSymKey(slot, CKM_SSL3_MASTER_KEY_DERIVE, 7117 PK11_ImportSymKey(slot, CKM_SSL3_MASTER_KEY_DERIVE,
7069 PK11_OriginUnwrap, CKA_ENCRYPT, &wrappedMS, 7118 PK11_OriginUnwrap, CKA_ENCRYPT, &wrappedMS,
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
7453 /* Disable any ECC cipher suites for which we have no cert. */ 7502 /* Disable any ECC cipher suites for which we have no cert. */
7454 ssl3_FilterECCipherSuitesByServerCerts(ss); 7503 ssl3_FilterECCipherSuitesByServerCerts(ss);
7455 #endif 7504 #endif
7456 i = ssl3_config_match_init(ss); 7505 i = ssl3_config_match_init(ss);
7457 if (i <= 0) { 7506 if (i <= 0) {
7458 errCode = PORT_GetError(); /* error code is already set. */ 7507 errCode = PORT_GetError(); /* error code is already set. */
7459 goto alert_loser; 7508 goto alert_loser;
7460 } 7509 }
7461 7510
7462 /* Select a cipher suite. 7511 /* Select a cipher suite.
7512 **
7463 ** NOTE: This suite selection algorithm should be the same as the one in 7513 ** NOTE: This suite selection algorithm should be the same as the one in
7464 ** ssl3_HandleClientHello(). 7514 ** ssl3_HandleClientHello().
7515 **
7516 ** See the comments about export cipher suites in ssl3_HandleClientHello().
7465 */ 7517 */
7466 for (j = 0; j < ssl_V3_SUITES_IMPLEMENTED; j++) { 7518 for (j = 0; j < ssl_V3_SUITES_IMPLEMENTED; j++) {
7467 ssl3CipherSuiteCfg *suite = &ss->cipherSuites[j]; 7519 ssl3CipherSuiteCfg *suite = &ss->cipherSuites[j];
7468 » if (!config_match(suite, ss->ssl3.policy, PR_TRUE)) 7520 » if (!config_match(suite, ss->ssl3.policy, PR_TRUE) ||
7521 » !ssl3_CipherSuiteAllowedForVersion(suite->cipher_suite,
7522 » » » » » ss->version)) {
7469 continue; 7523 continue;
7524 }
7470 for (i = 0; i+2 < suite_length; i += 3) { 7525 for (i = 0; i+2 < suite_length; i += 3) {
7471 PRUint32 suite_i = (suites[i] << 16)|(suites[i+1] << 8)|suites[i+2]; 7526 PRUint32 suite_i = (suites[i] << 16)|(suites[i+1] << 8)|suites[i+2];
7472 if (suite_i == suite->cipher_suite) { 7527 if (suite_i == suite->cipher_suite) {
7473 ss->ssl3.hs.cipher_suite = suite->cipher_suite; 7528 ss->ssl3.hs.cipher_suite = suite->cipher_suite;
7474 ss->ssl3.hs.suite_def = 7529 ss->ssl3.hs.suite_def =
7475 ssl_LookupCipherSuiteDef(ss->ssl3.hs.cipher_suite); 7530 ssl_LookupCipherSuiteDef(ss->ssl3.hs.cipher_suite);
7476 goto suite_found; 7531 goto suite_found;
7477 } 7532 }
7478 } 7533 }
7479 } 7534 }
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
7785 ca_list = ss->ssl3.ca_list; 7840 ca_list = ss->ssl3.ca_list;
7786 if (!ca_list) { 7841 if (!ca_list) {
7787 ca_list = ssl3_server_ca_list; 7842 ca_list = ssl3_server_ca_list;
7788 } 7843 }
7789 7844
7790 if (ca_list != NULL) { 7845 if (ca_list != NULL) {
7791 names = ca_list->names; 7846 names = ca_list->names;
7792 nnames = ca_list->nnames; 7847 nnames = ca_list->nnames;
7793 } 7848 }
7794 7849
7795 /* There used to be a test here to require a CA, but there
7796 * are cases where you want to have no CAs offered. */
7797 for (i = 0, name = names; i < nnames; i++, name++) { 7850 for (i = 0, name = names; i < nnames; i++, name++) {
7798 calen += 2 + name->len; 7851 calen += 2 + name->len;
7799 } 7852 }
7800 7853
7801 certTypes = certificate_types; 7854 certTypes = certificate_types;
7802 certTypesLength = sizeof certificate_types; 7855 certTypesLength = sizeof certificate_types;
7803 7856
7804 length = 1 + certTypesLength + 2 + calen; 7857 length = 1 + certTypesLength + 2 + calen;
7805 7858
7806 rv = ssl3_AppendHandshakeHeader(ss, certificate_request, length); 7859 rv = ssl3_AppendHandshakeHeader(ss, certificate_request, length);
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
7992 * 8045 *
7993 * Called from ssl3_HandleClientKeyExchange 8046 * Called from ssl3_HandleClientKeyExchange
7994 */ 8047 */
7995 static SECStatus 8048 static SECStatus
7996 ssl3_HandleRSAClientKeyExchange(sslSocket *ss, 8049 ssl3_HandleRSAClientKeyExchange(sslSocket *ss,
7997 SSL3Opaque *b, 8050 SSL3Opaque *b,
7998 PRUint32 length, 8051 PRUint32 length,
7999 SECKEYPrivateKey *serverKey) 8052 SECKEYPrivateKey *serverKey)
8000 { 8053 {
8001 PK11SymKey * pms; 8054 PK11SymKey * pms;
8055 #ifndef NO_PKCS11_BYPASS
8002 unsigned char * cr = (unsigned char *)&ss->ssl3.hs.client_random; 8056 unsigned char * cr = (unsigned char *)&ss->ssl3.hs.client_random;
8003 unsigned char * sr = (unsigned char *)&ss->ssl3.hs.server_random; 8057 unsigned char * sr = (unsigned char *)&ss->ssl3.hs.server_random;
8004 ssl3CipherSpec * pwSpec = ss->ssl3.pwSpec; 8058 ssl3CipherSpec * pwSpec = ss->ssl3.pwSpec;
8005 unsigned int outLen = 0; 8059 unsigned int outLen = 0;
8060 #endif
8006 PRBool isTLS = PR_FALSE; 8061 PRBool isTLS = PR_FALSE;
8007 SECStatus rv; 8062 SECStatus rv;
8008 SECItem enc_pms; 8063 SECItem enc_pms;
8009 unsigned char rsaPmsBuf[SSL3_RSA_PMS_LENGTH]; 8064 unsigned char rsaPmsBuf[SSL3_RSA_PMS_LENGTH];
8010 SECItem pmsItem = {siBuffer, NULL, 0}; 8065 SECItem pmsItem = {siBuffer, NULL, 0};
8011 8066
8012 PORT_Assert( ss->opt.noLocks || ssl_HaveRecvBufLock(ss) ); 8067 PORT_Assert( ss->opt.noLocks || ssl_HaveRecvBufLock(ss) );
8013 PORT_Assert( ss->opt.noLocks || ssl_HaveSSL3HandshakeLock(ss) ); 8068 PORT_Assert( ss->opt.noLocks || ssl_HaveSSL3HandshakeLock(ss) );
8014 8069
8015 enc_pms.data = b; 8070 enc_pms.data = b;
8016 enc_pms.len = length; 8071 enc_pms.len = length;
8017 pmsItem.data = rsaPmsBuf; 8072 pmsItem.data = rsaPmsBuf;
8018 pmsItem.len = sizeof rsaPmsBuf; 8073 pmsItem.len = sizeof rsaPmsBuf;
8019 8074
8020 if (ss->ssl3.prSpec->version > SSL_LIBRARY_VERSION_3_0) { /* isTLS */ 8075 if (ss->ssl3.prSpec->version > SSL_LIBRARY_VERSION_3_0) { /* isTLS */
8021 PRInt32 kLen; 8076 PRInt32 kLen;
8022 kLen = ssl3_ConsumeHandshakeNumber(ss, 2, &enc_pms.data, &enc_pms.len); 8077 kLen = ssl3_ConsumeHandshakeNumber(ss, 2, &enc_pms.data, &enc_pms.len);
8023 if (kLen < 0) { 8078 if (kLen < 0) {
8024 PORT_SetError(SSL_ERROR_CLIENT_KEY_EXCHANGE_FAILURE); 8079 PORT_SetError(SSL_ERROR_CLIENT_KEY_EXCHANGE_FAILURE);
8025 return SECFailure; 8080 return SECFailure;
8026 } 8081 }
8027 if ((unsigned)kLen < enc_pms.len) { 8082 if ((unsigned)kLen < enc_pms.len) {
8028 enc_pms.len = kLen; 8083 enc_pms.len = kLen;
8029 } 8084 }
8030 isTLS = PR_TRUE; 8085 isTLS = PR_TRUE;
8031 } else { 8086 } else {
8032 isTLS = (PRBool)(ss->ssl3.hs.kea_def->tls_keygen != 0); 8087 isTLS = (PRBool)(ss->ssl3.hs.kea_def->tls_keygen != 0);
8033 } 8088 }
8034 8089
8090 #ifndef NO_PKCS11_BYPASS
8035 if (ss->opt.bypassPKCS11) { 8091 if (ss->opt.bypassPKCS11) {
8036 /* TRIPLE BYPASS, get PMS directly from RSA decryption. 8092 /* TRIPLE BYPASS, get PMS directly from RSA decryption.
8037 * Use PK11_PrivDecryptPKCS1 to decrypt the PMS to a buffer, 8093 * Use PK11_PrivDecryptPKCS1 to decrypt the PMS to a buffer,
8038 * then, check for version rollback attack, then 8094 * then, check for version rollback attack, then
8039 * do the equivalent of ssl3_DeriveMasterSecret, placing the MS in 8095 * do the equivalent of ssl3_DeriveMasterSecret, placing the MS in
8040 * pwSpec->msItem. Finally call ssl3_InitPendingCipherSpec with 8096 * pwSpec->msItem. Finally call ssl3_InitPendingCipherSpec with
8041 * ss and NULL, so that it will use the MS we've already derived here. 8097 * ss and NULL, so that it will use the MS we've already derived here.
8042 */ 8098 */
8043 8099
8044 rv = PK11_PrivDecryptPKCS1(serverKey, rsaPmsBuf, &outLen, 8100 rv = PK11_PrivDecryptPKCS1(serverKey, rsaPmsBuf, &outLen,
(...skipping 16 matching lines...) Expand all
8061 } 8117 }
8062 /* have PMS, build MS without PKCS11 */ 8118 /* have PMS, build MS without PKCS11 */
8063 rv = ssl3_MasterKeyDeriveBypass(pwSpec, cr, sr, &pmsItem, isTLS, 8119 rv = ssl3_MasterKeyDeriveBypass(pwSpec, cr, sr, &pmsItem, isTLS,
8064 PR_TRUE); 8120 PR_TRUE);
8065 if (rv != SECSuccess) { 8121 if (rv != SECSuccess) {
8066 pwSpec->msItem.data = pwSpec->raw_master_secret; 8122 pwSpec->msItem.data = pwSpec->raw_master_secret;
8067 pwSpec->msItem.len = SSL3_MASTER_SECRET_LENGTH; 8123 pwSpec->msItem.len = SSL3_MASTER_SECRET_LENGTH;
8068 PK11_GenerateRandom(pwSpec->msItem.data, pwSpec->msItem.len); 8124 PK11_GenerateRandom(pwSpec->msItem.data, pwSpec->msItem.len);
8069 } 8125 }
8070 rv = ssl3_InitPendingCipherSpec(ss, NULL); 8126 rv = ssl3_InitPendingCipherSpec(ss, NULL);
8071 } else { 8127 } else
8128 #endif
8129 {
8130 #ifndef NO_PKCS11_BYPASS
8072 double_bypass: 8131 double_bypass:
8132 #endif
8073 /* 8133 /*
8074 * unwrap pms out of the incoming buffer 8134 * unwrap pms out of the incoming buffer
8075 * Note: CKM_SSL3_MASTER_KEY_DERIVE is NOT the mechanism used to do 8135 * Note: CKM_SSL3_MASTER_KEY_DERIVE is NOT the mechanism used to do
8076 * the unwrap. Rather, it is the mechanism with which the 8136 * the unwrap. Rather, it is the mechanism with which the
8077 * unwrapped pms will be used. 8137 * unwrapped pms will be used.
8078 */ 8138 */
8079 pms = PK11_PubUnwrapSymKey(serverKey, &enc_pms, 8139 pms = PK11_PubUnwrapSymKey(serverKey, &enc_pms,
8080 CKM_SSL3_MASTER_KEY_DERIVE, CKA_DERIVE, 0); 8140 CKM_SSL3_MASTER_KEY_DERIVE, CKA_DERIVE, 0);
8081 if (pms != NULL) { 8141 if (pms != NULL) {
8082 PRINT_BUF(60, (ss, "decrypted premaster secret:", 8142 PRINT_BUF(60, (ss, "decrypted premaster secret:",
(...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after
8954 9014
8955 rv = PK11_DigestBegin(prf_context); 9015 rv = PK11_DigestBegin(prf_context);
8956 rv |= PK11_DigestOp(prf_context, (unsigned char *) label, labelLen); 9016 rv |= PK11_DigestOp(prf_context, (unsigned char *) label, labelLen);
8957 rv |= PK11_DigestOp(prf_context, val, valLen); 9017 rv |= PK11_DigestOp(prf_context, val, valLen);
8958 rv |= PK11_DigestFinal(prf_context, out, &retLen, outLen); 9018 rv |= PK11_DigestFinal(prf_context, out, &retLen, outLen);
8959 PORT_Assert(rv != SECSuccess || retLen == outLen); 9019 PORT_Assert(rv != SECSuccess || retLen == outLen);
8960 9020
8961 PK11_DestroyContext(prf_context, PR_TRUE); 9021 PK11_DestroyContext(prf_context, PR_TRUE);
8962 } else { 9022 } else {
8963 /* bypass PKCS11 */ 9023 /* bypass PKCS11 */
9024 #ifdef NO_PKCS11_BYPASS
9025 PORT_Assert(spec->master_secret);
9026 PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
9027 rv = SECFailure;
9028 #else
8964 SECItem inData = { siBuffer, }; 9029 SECItem inData = { siBuffer, };
8965 SECItem outData = { siBuffer, }; 9030 SECItem outData = { siBuffer, };
8966 PRBool isFIPS = PR_FALSE; 9031 PRBool isFIPS = PR_FALSE;
8967 9032
8968 inData.data = (unsigned char *) val; 9033 inData.data = (unsigned char *) val;
8969 inData.len = valLen; 9034 inData.len = valLen;
8970 outData.data = out; 9035 outData.data = out;
8971 outData.len = outLen; 9036 outData.len = outLen;
8972 rv = TLS_PRF(&spec->msItem, label, &inData, &outData, isFIPS); 9037 rv = TLS_PRF(&spec->msItem, label, &inData, &outData, isFIPS);
8973 PORT_Assert(rv != SECSuccess || outData.len == outLen); 9038 PORT_Assert(rv != SECSuccess || outData.len == outLen);
9039 #endif
8974 } 9040 }
8975 return rv; 9041 return rv;
8976 } 9042 }
8977 9043
8978 /* called from ssl3_HandleServerHelloDone 9044 /* called from ssl3_HandleServerHelloDone
8979 */ 9045 */
8980 static SECStatus 9046 static SECStatus
8981 ssl3_SendNextProto(sslSocket *ss) 9047 ssl3_SendNextProto(sslSocket *ss)
8982 { 9048 {
8983 SECStatus rv; 9049 SECStatus rv;
(...skipping 18 matching lines...) Expand all
9002 if (rv != SECSuccess) { 9068 if (rv != SECSuccess) {
9003 return rv; /* error code set by AppendHandshake */ 9069 return rv; /* error code set by AppendHandshake */
9004 } 9070 }
9005 rv = ssl3_AppendHandshakeVariable(ss, padding, padding_len, 1); 9071 rv = ssl3_AppendHandshakeVariable(ss, padding, padding_len, 1);
9006 if (rv != SECSuccess) { 9072 if (rv != SECSuccess) {
9007 return rv; /* error code set by AppendHandshake */ 9073 return rv; /* error code set by AppendHandshake */
9008 } 9074 }
9009 return rv; 9075 return rv;
9010 } 9076 }
9011 9077
9078 /* called from ssl3_SendFinished
9079 *
9080 * This function is simply a debugging aid and therefore does not return a
9081 * SECStatus. */
9082 static void
9083 ssl3_RecordKeyLog(sslSocket *ss)
9084 {
9085 sslSessionID *sid;
9086 SECStatus rv;
9087 SECItem *keyData;
9088 char buf[14 /* "CLIENT_RANDOM " */ +
9089 SSL3_RANDOM_LENGTH*2 /* client_random */ +
9090 1 /* " " */ +
9091 48*2 /* master secret */ +
9092 1 /* new line */];
9093 unsigned int j;
9094
9095 PORT_Assert( ss->opt.noLocks || ssl_HaveSSL3HandshakeLock(ss));
9096
9097 sid = ss->sec.ci.sid;
9098
9099 if (!ssl_keylog_iob)
9100 return;
9101
9102 rv = PK11_ExtractKeyValue(ss->ssl3.cwSpec->master_secret);
9103 if (rv != SECSuccess)
9104 return;
9105
9106 ssl_GetSpecReadLock(ss);
9107
9108 /* keyData does not need to be freed. */
9109 keyData = PK11_GetKeyData(ss->ssl3.cwSpec->master_secret);
9110 if (!keyData || !keyData->data || keyData->len != 48) {
9111 ssl_ReleaseSpecReadLock(ss);
9112 return;
9113 }
9114
9115 /* https://developer.mozilla.org/en/NSS_Key_Log_Format */
9116
9117 /* There could be multiple, concurrent writers to the
9118 * keylog, so we have to do everything in a single call to
9119 * fwrite. */
9120
9121 memcpy(buf, "CLIENT_RANDOM ", 14);
9122 j = 14;
9123 hexEncode(buf + j, ss->ssl3.hs.client_random.rand, SSL3_RANDOM_LENGTH);
9124 j += SSL3_RANDOM_LENGTH*2;
9125 buf[j++] = ' ';
9126 hexEncode(buf + j, keyData->data, 48);
9127 j += 48*2;
9128 buf[j++] = '\n';
9129
9130 PORT_Assert(j == sizeof(buf));
9131
9132 ssl_ReleaseSpecReadLock(ss);
9133
9134 if (fwrite(buf, sizeof(buf), 1, ssl_keylog_iob) != 1)
9135 return;
9136 fflush(ssl_keylog_iob);
9137 return;
9138 }
9139
9012 /* called from ssl3_SendClientSecondRound 9140 /* called from ssl3_SendClientSecondRound
9013 * ssl3_HandleFinished 9141 * ssl3_HandleFinished
9014 */ 9142 */
9015 static SECStatus 9143 static SECStatus
9016 ssl3_SendEncryptedExtensions(sslSocket *ss) 9144 ssl3_SendEncryptedExtensions(sslSocket *ss)
9017 { 9145 {
9018 static const char CHANNEL_ID_MAGIC[] = "TLS Channel ID signature"; 9146 static const char CHANNEL_ID_MAGIC[] = "TLS Channel ID signature";
9019 /* This is the ASN.1 prefix for a P-256 public key. Specifically it's: 9147 /* This is the ASN.1 prefix for a P-256 public key. Specifically it's:
9020 * SEQUENCE 9148 * SEQUENCE
9021 * SEQUENCE 9149 * SEQUENCE
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
9160 if (ss->ssl3.channelIDPub) 9288 if (ss->ssl3.channelIDPub)
9161 SECKEY_DestroyPublicKey(ss->ssl3.channelIDPub); 9289 SECKEY_DestroyPublicKey(ss->ssl3.channelIDPub);
9162 9290
9163 ss->handshake = ssl_GatherRecord1stHandshake; 9291 ss->handshake = ssl_GatherRecord1stHandshake;
9164 ss->ssl3.channelID = channelID; 9292 ss->ssl3.channelID = channelID;
9165 ss->ssl3.channelIDPub = channelIDPub; 9293 ss->ssl3.channelIDPub = channelIDPub;
9166 9294
9167 return SECSuccess; 9295 return SECSuccess;
9168 } 9296 }
9169 9297
9170 /* called from ssl3_SendFinished
9171 *
9172 * Caller must already hold the SpecReadLock. (wish we could assert that!).
9173 * This function is simply a debugging aid and therefore does not return a
9174 * SECStatus. */
9175 static void
9176 ssl3_RecordKeyLog(sslSocket *ss)
9177 {
9178 sslSessionID *sid;
9179 SECStatus rv;
9180 SECItem *keyData;
9181 char buf[14 /* "CLIENT_RANDOM " */ +
9182 SSL3_RANDOM_LENGTH*2 /* client_random */ +
9183 1 /* " " */ +
9184 48*2 /* master secret */ +
9185 1 /* new line */];
9186 unsigned int j;
9187
9188 PORT_Assert( ss->opt.noLocks || ssl_HaveSSL3HandshakeLock(ss));
9189
9190 sid = ss->sec.ci.sid;
9191
9192 if (!ssl_keylog_iob)
9193 return;
9194
9195 rv = PK11_ExtractKeyValue(ss->ssl3.cwSpec->master_secret);
9196 if (rv != SECSuccess)
9197 return;
9198
9199 ssl_GetSpecReadLock(ss);
9200
9201 /* keyData does not need to be freed. */
9202 keyData = PK11_GetKeyData(ss->ssl3.cwSpec->master_secret);
9203 if (!keyData || !keyData->data || keyData->len != 48) {
9204 ssl_ReleaseSpecReadLock(ss);
9205 return;
9206 }
9207
9208 /* https://developer.mozilla.org/en/NSS_Key_Log_Format */
9209
9210 /* There could be multiple, concurrent writers to the
9211 * keylog, so we have to do everything in a single call to
9212 * fwrite. */
9213
9214 memcpy(buf, "CLIENT_RANDOM ", 14);
9215 j = 14;
9216 hexEncode(buf + j, ss->ssl3.hs.client_random.rand, SSL3_RANDOM_LENGTH);
9217 j += SSL3_RANDOM_LENGTH*2;
9218 buf[j++] = ' ';
9219 hexEncode(buf + j, keyData->data, 48);
9220 j += 48*2;
9221 buf[j++] = '\n';
9222
9223 PORT_Assert(j == sizeof(buf));
9224
9225 ssl_ReleaseSpecReadLock(ss);
9226
9227 if (fwrite(buf, sizeof(buf), 1, ssl_keylog_iob) != 1)
9228 return;
9229 fflush(ssl_keylog_iob);
9230 return;
9231 }
9232
9233 /* called from ssl3_HandleServerHelloDone 9298 /* called from ssl3_HandleServerHelloDone
9234 * ssl3_HandleClientHello 9299 * ssl3_HandleClientHello
9235 * ssl3_HandleFinished 9300 * ssl3_HandleFinished
9236 */ 9301 */
9237 static SECStatus 9302 static SECStatus
9238 ssl3_SendFinished(sslSocket *ss, PRInt32 flags) 9303 ssl3_SendFinished(sslSocket *ss, PRInt32 flags)
9239 { 9304 {
9240 ssl3CipherSpec *cwSpec; 9305 ssl3CipherSpec *cwSpec;
9241 PRBool isTLS; 9306 PRBool isTLS;
9242 PRBool isServer = ss->sec.isServer; 9307 PRBool isServer = ss->sec.isServer;
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after
9928 buf->len -= ss->ssl3.hs.msg_len; 9993 buf->len -= ss->ssl3.hs.msg_len;
9929 ss->ssl3.hs.msg_len = 0; 9994 ss->ssl3.hs.msg_len = 0;
9930 ss->ssl3.hs.header_bytes = 0; 9995 ss->ssl3.hs.header_bytes = 0;
9931 if (rv != SECSuccess) { /* return if SECWouldBlock. */ 9996 if (rv != SECSuccess) { /* return if SECWouldBlock. */
9932 return rv; 9997 return rv;
9933 } 9998 }
9934 } else { 9999 } else {
9935 /* must be copied to msg_body and dealt with from there */ 10000 /* must be copied to msg_body and dealt with from there */
9936 unsigned int bytes; 10001 unsigned int bytes;
9937 10002
9938 » PORT_Assert(ss->ssl3.hs.msg_body.len <= ss->ssl3.hs.msg_len); 10003 » PORT_Assert(ss->ssl3.hs.msg_body.len < ss->ssl3.hs.msg_len);
9939 bytes = PR_MIN(buf->len, ss->ssl3.hs.msg_len - ss->ssl3.hs.msg_body. len); 10004 bytes = PR_MIN(buf->len, ss->ssl3.hs.msg_len - ss->ssl3.hs.msg_body. len);
9940 10005
9941 /* Grow the buffer if needed */ 10006 /* Grow the buffer if needed */
9942 rv = sslBuffer_Grow(&ss->ssl3.hs.msg_body, ss->ssl3.hs.msg_len); 10007 rv = sslBuffer_Grow(&ss->ssl3.hs.msg_body, ss->ssl3.hs.msg_len);
9943 if (rv != SECSuccess) { 10008 if (rv != SECSuccess) {
9944 /* sslBuffer_Grow has set a memory error code. */ 10009 /* sslBuffer_Grow has set a memory error code. */
9945 return SECFailure; 10010 return SECFailure;
9946 } 10011 }
9947 10012
9948 PORT_Memcpy(ss->ssl3.hs.msg_body.buf + ss->ssl3.hs.msg_body.len, 10013 PORT_Memcpy(ss->ssl3.hs.msg_body.buf + ss->ssl3.hs.msg_body.len,
9949 buf->buf, bytes); 10014 buf->buf, bytes);
9950 ss->ssl3.hs.msg_body.len += bytes; 10015 ss->ssl3.hs.msg_body.len += bytes;
9951 buf->buf += bytes; 10016 buf->buf += bytes;
9952 buf->len -= bytes; 10017 buf->len -= bytes;
9953 10018
9954 PORT_Assert(ss->ssl3.hs.msg_body.len <= ss->ssl3.hs.msg_len); 10019 PORT_Assert(ss->ssl3.hs.msg_body.len <= ss->ssl3.hs.msg_len);
9955 10020
9956 /* if we have a whole message, do it */ 10021 /* if we have a whole message, do it */
9957 if (ss->ssl3.hs.msg_body.len == ss->ssl3.hs.msg_len) { 10022 if (ss->ssl3.hs.msg_body.len == ss->ssl3.hs.msg_len) {
9958 rv = ssl3_HandleHandshakeMessage( 10023 rv = ssl3_HandleHandshakeMessage(
9959 ss, ss->ssl3.hs.msg_body.buf, ss->ssl3.hs.msg_len); 10024 ss, ss->ssl3.hs.msg_body.buf, ss->ssl3.hs.msg_len);
9960 » » /* 10025 » » if (rv == SECFailure) {
9961 » » * XXX This appears to be wrong. This error handling 10026 » » /* This test wants to fall through on either
9962 » » * should clean up after a SECWouldBlock return, like the 10027 » » * SECSuccess or SECWouldBlock.
9963 » » * error handling used 40 lines before/above this one, 10028 » » * ssl3_HandleHandshakeMessage MUST set error code.
9964 » » */ 10029 » » */
9965 » » if (rv != SECSuccess) {
9966 » » /* ssl3_HandleHandshakeMessage MUST set error code. */
9967 return rv; 10030 return rv;
9968 } 10031 }
9969 ss->ssl3.hs.msg_body.len = 0; 10032 ss->ssl3.hs.msg_body.len = 0;
9970 » » ss->ssl3.hs.msg_len = 0; 10033 » » ss->ssl3.hs.msg_len = 0;
9971 ss->ssl3.hs.header_bytes = 0; 10034 ss->ssl3.hs.header_bytes = 0;
10035 if (rv != SECSuccess) { /* return if SECWouldBlock. */
10036 return rv;
10037 }
9972 } else { 10038 } else {
9973 PORT_Assert(buf->len == 0); 10039 PORT_Assert(buf->len == 0);
9974 break; 10040 break;
9975 } 10041 }
9976 } 10042 }
9977 } /* end loop */ 10043 } /* end loop */
9978 10044
9979 origBuf->len = 0; /* So ssl3_GatherAppDataRecord will keep looping. */ 10045 origBuf->len = 0; /* So ssl3_GatherAppDataRecord will keep looping. */
9980 buf->buf = NULL; /* not a leak. */ 10046 buf->buf = NULL; /* not a leak. */
9981 return SECSuccess; 10047 return SECSuccess;
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
10450 #endif 10516 #endif
10451 ssl_ReleaseSpecWriteLock(ss); 10517 ssl_ReleaseSpecWriteLock(ss);
10452 10518
10453 PORT_Memset(&ss->xtnData, 0, sizeof(TLSExtensionData)); 10519 PORT_Memset(&ss->xtnData, 0, sizeof(TLSExtensionData));
10454 10520
10455 if (IS_DTLS(ss)) { 10521 if (IS_DTLS(ss)) {
10456 ss->ssl3.hs.sendMessageSeq = 0; 10522 ss->ssl3.hs.sendMessageSeq = 0;
10457 ss->ssl3.hs.recvMessageSeq = 0; 10523 ss->ssl3.hs.recvMessageSeq = 0;
10458 ss->ssl3.hs.rtTimeoutMs = INITIAL_DTLS_TIMEOUT_MS; 10524 ss->ssl3.hs.rtTimeoutMs = INITIAL_DTLS_TIMEOUT_MS;
10459 ss->ssl3.hs.rtRetries = 0; 10525 ss->ssl3.hs.rtRetries = 0;
10460
10461 /* Have to allocate this because ssl_FreeSocket relocates
10462 * this structure in DEBUG mode */
10463 if (!(ss->ssl3.hs.lastMessageFlight = PORT_New(PRCList)))
10464 return SECFailure;
10465 ss->ssl3.hs.recvdHighWater = -1; 10526 ss->ssl3.hs.recvdHighWater = -1;
10466 » PR_INIT_CLIST(ss->ssl3.hs.lastMessageFlight); 10527 » PR_INIT_CLIST(&ss->ssl3.hs.lastMessageFlight);
10467 dtls_SetMTU(ss, 0); /* Set the MTU to the highest plateau */ 10528 dtls_SetMTU(ss, 0); /* Set the MTU to the highest plateau */
10468 } 10529 }
10469 10530
10470 rv = ssl3_NewHandshakeHashes(ss); 10531 rv = ssl3_NewHandshakeHashes(ss);
10471 if (rv == SECSuccess) { 10532 if (rv == SECSuccess) {
10472 ss->ssl3.initialized = PR_TRUE; 10533 ss->ssl3.initialized = PR_TRUE;
10473 } 10534 }
10474 10535
10475 return rv; 10536 return rv;
10476 } 10537 }
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
10829 10890
10830 if (ss->ssl3.peerCertArena != NULL) 10891 if (ss->ssl3.peerCertArena != NULL)
10831 ssl3_CleanupPeerCerts(ss); 10892 ssl3_CleanupPeerCerts(ss);
10832 10893
10833 if (ss->ssl3.clientCertChain != NULL) { 10894 if (ss->ssl3.clientCertChain != NULL) {
10834 CERT_DestroyCertificateList(ss->ssl3.clientCertChain); 10895 CERT_DestroyCertificateList(ss->ssl3.clientCertChain);
10835 ss->ssl3.clientCertChain = NULL; 10896 ss->ssl3.clientCertChain = NULL;
10836 } 10897 }
10837 10898
10838 /* clean up handshake */ 10899 /* clean up handshake */
10900 #ifndef NO_PKCS11_BYPASS
10839 if (ss->opt.bypassPKCS11) { 10901 if (ss->opt.bypassPKCS11) {
10840 SHA1_DestroyContext((SHA1Context *)ss->ssl3.hs.sha_cx, PR_FALSE); 10902 SHA1_DestroyContext((SHA1Context *)ss->ssl3.hs.sha_cx, PR_FALSE);
10841 MD5_DestroyContext((MD5Context *)ss->ssl3.hs.md5_cx, PR_FALSE); 10903 MD5_DestroyContext((MD5Context *)ss->ssl3.hs.md5_cx, PR_FALSE);
10842 } 10904 }
10905 #endif
10843 if (ss->ssl3.hs.md5) { 10906 if (ss->ssl3.hs.md5) {
10844 PK11_DestroyContext(ss->ssl3.hs.md5,PR_TRUE); 10907 PK11_DestroyContext(ss->ssl3.hs.md5,PR_TRUE);
10845 } 10908 }
10846 if (ss->ssl3.hs.sha) { 10909 if (ss->ssl3.hs.sha) {
10847 PK11_DestroyContext(ss->ssl3.hs.sha,PR_TRUE); 10910 PK11_DestroyContext(ss->ssl3.hs.sha,PR_TRUE);
10848 } 10911 }
10849 if (ss->ssl3.hs.messages.buf) { 10912 if (ss->ssl3.hs.messages.buf) {
10850 PORT_Free(ss->ssl3.hs.messages.buf); 10913 PORT_Free(ss->ssl3.hs.messages.buf);
10851 ss->ssl3.hs.messages.buf = NULL; 10914 ss->ssl3.hs.messages.buf = NULL;
10852 ss->ssl3.hs.messages.len = 0; 10915 ss->ssl3.hs.messages.len = 0;
10853 ss->ssl3.hs.messages.space = 0; 10916 ss->ssl3.hs.messages.space = 0;
10854 } 10917 }
10855 if (ss->ssl3.hs.pending_cert_msg.data) { 10918 if (ss->ssl3.hs.pending_cert_msg.data) {
10856 SECITEM_FreeItem(&ss->ssl3.hs.pending_cert_msg, PR_FALSE); 10919 SECITEM_FreeItem(&ss->ssl3.hs.pending_cert_msg, PR_FALSE);
10857 } 10920 }
10858 if (ss->ssl3.hs.cert_status.data) { 10921 if (ss->ssl3.hs.cert_status.data) {
10859 SECITEM_FreeItem(&ss->ssl3.hs.cert_status, PR_FALSE); 10922 SECITEM_FreeItem(&ss->ssl3.hs.cert_status, PR_FALSE);
10860 } 10923 }
10861 10924
10862 /* free the SSL3Buffer (msg_body) */ 10925 /* free the SSL3Buffer (msg_body) */
10863 PORT_Free(ss->ssl3.hs.msg_body.buf); 10926 PORT_Free(ss->ssl3.hs.msg_body.buf);
10864 10927
10865 /* free up the CipherSpecs */ 10928 /* free up the CipherSpecs */
10866 ssl3_DestroyCipherSpec(&ss->ssl3.specs[0], PR_TRUE/*freeSrvName*/); 10929 ssl3_DestroyCipherSpec(&ss->ssl3.specs[0], PR_TRUE/*freeSrvName*/);
10867 ssl3_DestroyCipherSpec(&ss->ssl3.specs[1], PR_TRUE/*freeSrvName*/); 10930 ssl3_DestroyCipherSpec(&ss->ssl3.specs[1], PR_TRUE/*freeSrvName*/);
10868 10931
10869 /* Destroy the DTLS data */ 10932 /* Destroy the DTLS data */
10870 if (IS_DTLS(ss)) { 10933 if (IS_DTLS(ss)) {
10871 » if (ss->ssl3.hs.lastMessageFlight) { 10934 » dtls_FreeHandshakeMessages(&ss->ssl3.hs.lastMessageFlight);
10872 » dtls_FreeHandshakeMessages(ss->ssl3.hs.lastMessageFlight);
10873 » PORT_Free(ss->ssl3.hs.lastMessageFlight);
10874 » }
10875 if (ss->ssl3.hs.recvdFragments.buf) { 10935 if (ss->ssl3.hs.recvdFragments.buf) {
10876 PORT_Free(ss->ssl3.hs.recvdFragments.buf); 10936 PORT_Free(ss->ssl3.hs.recvdFragments.buf);
10877 } 10937 }
10878 } 10938 }
10879 10939
10880 ss->ssl3.initialized = PR_FALSE; 10940 ss->ssl3.initialized = PR_FALSE;
10881 10941
10882 SECITEM_FreeItem(&ss->ssl3.nextProto, PR_FALSE); 10942 SECITEM_FreeItem(&ss->ssl3.nextProto, PR_FALSE);
10883 } 10943 }
10884 10944
10885 /* End of ssl3con.c */ 10945 /* End of ssl3con.c */
OLDNEW
« no previous file with comments | « net/third_party/nss/ssl/ssl.rc ('k') | net/third_party/nss/ssl/ssl3ecc.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698