OLD | NEW |
| (Empty) |
1 commit 95cc0cf361c92681803e7ee5d4afe5e40673a4b8 | |
2 Author: Adam Langley <agl@chromium.org> | |
3 Date: Wed Jun 22 13:36:50 2011 -0400 | |
4 | |
5 cbcrandomiv.patch | |
6 | |
7 diff --git a/mozilla/security/nss/lib/ssl/ssl3con.c b/mozilla/security/nss/lib/s
sl/ssl3con.c | |
8 index f7064ef..c39b8f8 100644 | |
9 --- a/mozilla/security/nss/lib/ssl/ssl3con.c | |
10 +++ b/mozilla/security/nss/lib/ssl/ssl3con.c | |
11 @@ -2229,7 +2229,7 @@ ssl3_SendRecord( sslSocket * ss, | |
12 return SECFailure; | |
13 } | |
14 | |
15 - while (nIn > 0) { | |
16 + do { | |
17 PRUint32 contentLen = PR_MIN(nIn, MAX_FRAGMENT_LENGTH); | |
18 | |
19 if (wrBuf->space < contentLen + SSL3_BUFFER_FUDGE) { | |
20 @@ -2306,7 +2306,7 @@ ssl3_SendRecord( sslSocket * ss, | |
21 } | |
22 } | |
23 totalSent += contentLen; | |
24 - } | |
25 + } while (nIn > 0); | |
26 return totalSent; | |
27 } | |
28 | |
29 @@ -2321,6 +2321,7 @@ ssl3_SendApplicationData(sslSocket *ss, const unsigned cha
r *in, | |
30 { | |
31 PRInt32 totalSent = 0; | |
32 PRInt32 discarded = 0; | |
33 + PRBool isBlockCipher; | |
34 | |
35 PORT_Assert( ss->opt.noLocks || ssl_HaveXmitBufLock(ss) ); | |
36 if (len < 0 || !in) { | |
37 @@ -2345,6 +2346,28 @@ ssl3_SendApplicationData(sslSocket *ss, const unsigned ch
ar *in, | |
38 len--; | |
39 discarded = 1; | |
40 } | |
41 + | |
42 + ssl_GetSpecReadLock(ss); | |
43 + isBlockCipher = ss->ssl3.cwSpec->cipher_def->type == type_block; | |
44 + ssl_ReleaseSpecReadLock(ss); | |
45 + | |
46 + if (isBlockCipher && len > 0) { | |
47 + // We assume that block ciphers are used in CBC mode and prepend an | |
48 + // empty record. This effectively randomizes the IV in a backwards | |
49 + // compatible way. | |
50 + PRInt32 sent = ssl3_SendRecord(ss, content_application_data, | |
51 + in, 0 /* no payload */, flags); | |
52 + if (sent < 0) { | |
53 + return SECFailure; /* error code set by ssl3_SendRecord */ | |
54 + } | |
55 + if (ss->pendingBuf.len) { | |
56 + /* must be a non-blocking socket */ | |
57 + PORT_Assert(!ssl_SocketIsBlocking(ss)); | |
58 + PORT_Assert(ss->lastWriteBlocked); | |
59 + return SECFailure; | |
60 + } | |
61 + } | |
62 + | |
63 while (len > totalSent) { | |
64 PRInt32 sent, toSend; | |
65 | |
66 @@ -2377,6 +2400,7 @@ ssl3_SendApplicationData(sslSocket *ss, const unsigned cha
r *in, | |
67 break; | |
68 } | |
69 } | |
70 + | |
71 if (ss->pendingBuf.len) { | |
72 /* Must be non-blocking. */ | |
73 PORT_Assert(!ssl_SocketIsBlocking(ss)); | |
OLD | NEW |