OLD | NEW |
| (Empty) |
1 From fb2d182ed92f38bd9c1134bb929f095ea6d3e752 Mon Sep 17 00:00:00 2001 | |
2 From: Adam Langley <agl@chromium.org> | |
3 Date: Mon, 3 Oct 2011 12:23:29 -0400 | |
4 Subject: [PATCH] cbcrandomiv.patch | |
5 | |
6 --- | |
7 mozilla/security/nss/lib/ssl/ssl3con.c | 97 +++++++++++++++++++++++--------- | |
8 1 files changed, 70 insertions(+), 27 deletions(-) | |
9 | |
10 diff --git a/mozilla/security/nss/lib/ssl/ssl3con.c b/mozilla/security/nss/lib/s
sl/ssl3con.c | |
11 index dd99962..d561307 100644 | |
12 --- a/mozilla/security/nss/lib/ssl/ssl3con.c | |
13 +++ b/mozilla/security/nss/lib/ssl/ssl3con.c | |
14 @@ -2039,24 +2039,24 @@ ssl3_ClientAuthTokenPresent(sslSessionID *sid) { | |
15 return isPresent; | |
16 } | |
17 | |
18 +/* Caller must hold the spec read lock. wrBuf is sometimes, but not always, | |
19 + * ss->sec.writeBuf. | |
20 + */ | |
21 static SECStatus | |
22 -ssl3_CompressMACEncryptRecord(sslSocket * ss, | |
23 +ssl3_CompressMACEncryptRecord(ssl3CipherSpec * cwSpec, | |
24 + PRBool isServer, | |
25 SSL3ContentType type, | |
26 const SSL3Opaque * pIn, | |
27 - PRUint32 contentLen) | |
28 + PRUint32 contentLen, | |
29 + sslBuffer * wrBuf) | |
30 { | |
31 - ssl3CipherSpec * cwSpec; | |
32 const ssl3BulkCipherDef * cipher_def; | |
33 - sslBuffer * wrBuf = &ss->sec.writeBuf; | |
34 SECStatus rv; | |
35 PRUint32 macLen = 0; | |
36 PRUint32 fragLen; | |
37 PRUint32 p1Len, p2Len, oddLen = 0; | |
38 PRInt32 cipherBytes = 0; | |
39 | |
40 - ssl_GetSpecReadLock(ss); /********************************/ | |
41 - | |
42 - cwSpec = ss->ssl3.cwSpec; | |
43 cipher_def = cwSpec->cipher_def; | |
44 | |
45 if (cwSpec->compressor) { | |
46 @@ -2073,12 +2073,12 @@ ssl3_CompressMACEncryptRecord(sslSocket * ss, | |
47 /* | |
48 * Add the MAC | |
49 */ | |
50 - rv = ssl3_ComputeRecordMAC( cwSpec, (PRBool)(ss->sec.isServer), | |
51 + rv = ssl3_ComputeRecordMAC( cwSpec, isServer, | |
52 type, cwSpec->version, cwSpec->write_seq_num, pIn, contentLen, | |
53 wrBuf->buf + contentLen + SSL3_RECORD_HEADER_LENGTH, &macLen); | |
54 if (rv != SECSuccess) { | |
55 ssl_MapLowLevelError(SSL_ERROR_MAC_COMPUTATION_FAILURE); | |
56 - goto spec_locked_loser; | |
57 + return SECFailure; | |
58 } | |
59 p1Len = contentLen; | |
60 p2Len = macLen; | |
61 @@ -2131,7 +2131,7 @@ ssl3_CompressMACEncryptRecord(sslSocket * ss, | |
62 PORT_Assert(rv == SECSuccess && cipherBytes == p1Len); | |
63 if (rv != SECSuccess || cipherBytes != p1Len) { | |
64 PORT_SetError(SSL_ERROR_ENCRYPTION_FAILURE); | |
65 - goto spec_locked_loser; | |
66 + return SECFailure; | |
67 } | |
68 } | |
69 if (p2Len > 0) { | |
70 @@ -2145,7 +2145,7 @@ ssl3_CompressMACEncryptRecord(sslSocket * ss, | |
71 PORT_Assert(rv == SECSuccess && cipherBytesPart2 == p2Len); | |
72 if (rv != SECSuccess || cipherBytesPart2 != p2Len) { | |
73 PORT_SetError(SSL_ERROR_ENCRYPTION_FAILURE); | |
74 - goto spec_locked_loser; | |
75 + return SECFailure; | |
76 } | |
77 cipherBytes += cipherBytesPart2; | |
78 } | |
79 @@ -2160,13 +2160,7 @@ ssl3_CompressMACEncryptRecord(sslSocket * ss, | |
80 wrBuf->buf[3] = MSB(cipherBytes); | |
81 wrBuf->buf[4] = LSB(cipherBytes); | |
82 | |
83 - ssl_ReleaseSpecReadLock(ss); /************************************/ | |
84 - | |
85 return SECSuccess; | |
86 - | |
87 -spec_locked_loser: | |
88 - ssl_ReleaseSpecReadLock(ss); | |
89 - return SECFailure; | |
90 } | |
91 | |
92 /* Process the plain text before sending it. | |
93 @@ -2227,20 +2221,71 @@ ssl3_SendRecord( sslSocket * ss, | |
94 | |
95 while (nIn > 0) { | |
96 PRUint32 contentLen = PR_MIN(nIn, MAX_FRAGMENT_LENGTH); | |
97 + unsigned int spaceNeeded; | |
98 + unsigned int numRecords; | |
99 + | |
100 + ssl_GetSpecReadLock(ss); /********************************/ | |
101 + | |
102 + if (nIn > 1 && | |
103 + ss->opt.enableFalseStart && | |
104 + ss->ssl3.cwSpec->version <= SSL_LIBRARY_VERSION_3_1_TLS && | |
105 + type == content_application_data && | |
106 + ss->ssl3.cwSpec->cipher_def->type == type_block /* CBC mode */) { | |
107 + /* We will split the first byte of the record into its own record, | |
108 + * as explained in the documentation for SSL_CBC_RANDOM_IV in ssl.h | |
109 + */ | |
110 + numRecords = 2; | |
111 + } else { | |
112 + numRecords = 1; | |
113 + } | |
114 | |
115 - if (wrBuf->space < contentLen + SSL3_BUFFER_FUDGE) { | |
116 - PRInt32 newSpace = PR_MAX(wrBuf->space * 2, contentLen); | |
117 - newSpace = PR_MIN(newSpace, MAX_FRAGMENT_LENGTH); | |
118 - newSpace += SSL3_BUFFER_FUDGE; | |
119 - rv = sslBuffer_Grow(wrBuf, newSpace); | |
120 + spaceNeeded = contentLen + (numRecords * SSL3_BUFFER_FUDGE); | |
121 + if (spaceNeeded > wrBuf->space) { | |
122 + rv = sslBuffer_Grow(wrBuf, spaceNeeded); | |
123 if (rv != SECSuccess) { | |
124 SSL_DBG(("%d: SSL3[%d]: SendRecord, tried to get %d bytes", | |
125 - SSL_GETPID(), ss->fd, newSpace)); | |
126 - return SECFailure; /* sslBuffer_Grow set a memory error code. */ | |
127 + SSL_GETPID(), ss->fd, spaceNeeded)); | |
128 + goto spec_locked_loser; /* sslBuffer_Grow set a memory error cod
e. */ | |
129 + } | |
130 + } | |
131 + | |
132 + if (numRecords == 2) { | |
133 + sslBuffer secondRecord; | |
134 + | |
135 + rv = ssl3_CompressMACEncryptRecord(ss->ssl3.cwSpec, | |
136 + ss->sec.isServer, type, pIn, 1, | |
137 + wrBuf); | |
138 + if (rv != SECSuccess) | |
139 + goto spec_locked_loser; | |
140 + | |
141 + PRINT_BUF(50, (ss, "send (encrypted) record data [1/2]:", | |
142 + wrBuf->buf, wrBuf->len)); | |
143 + | |
144 + secondRecord.buf = wrBuf->buf + wrBuf->len; | |
145 + secondRecord.len = 0; | |
146 + secondRecord.space = wrBuf->space - wrBuf->len; | |
147 + | |
148 + rv = ssl3_CompressMACEncryptRecord(ss->ssl3.cwSpec, | |
149 + ss->sec.isServer, type, pIn + 1, | |
150 + contentLen - 1, &secondRecord); | |
151 + if (rv == SECSuccess) { | |
152 + PRINT_BUF(50, (ss, "send (encrypted) record data [2/2]:", | |
153 + secondRecord.buf, secondRecord.len)); | |
154 + wrBuf->len += secondRecord.len; | |
155 + } | |
156 + } else { | |
157 + rv = ssl3_CompressMACEncryptRecord(ss->ssl3.cwSpec, | |
158 + ss->sec.isServer, type, pIn, | |
159 + contentLen, wrBuf); | |
160 + if (rv == SECSuccess) { | |
161 + PRINT_BUF(50, (ss, "send (encrypted) record data [1/1]:", | |
162 + wrBuf->buf, wrBuf->len)); | |
163 } | |
164 } | |
165 | |
166 - rv = ssl3_CompressMACEncryptRecord( ss, type, pIn, contentLen); | |
167 +spec_locked_loser: | |
168 + ssl_ReleaseSpecReadLock(ss); /************************************/ | |
169 + | |
170 if (rv != SECSuccess) | |
171 return SECFailure; | |
172 | |
173 @@ -2248,8 +2293,6 @@ ssl3_SendRecord( sslSocket * ss, | |
174 nIn -= contentLen; | |
175 PORT_Assert( nIn >= 0 ); | |
176 | |
177 - PRINT_BUF(50, (ss, "send (encrypted) record data:", wrBuf->buf, wrBuf->l
en)); | |
178 - | |
179 /* If there's still some previously saved ciphertext, | |
180 * or the caller doesn't want us to send the data yet, | |
181 * then add all our new ciphertext to the amount previously saved. | |
OLD | NEW |