summaryrefslogtreecommitdiff
path: root/chromium/net/third_party/nss/patches/restartclientauth.patch
blob: 811e98c8049ec340d0fc2354f8e496d8f422d8fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
diff --git a/lib/ssl/ssl.h b/lib/ssl/ssl.h
index 9e57220..aa4a3e5 100644
--- a/lib/ssl/ssl.h
+++ b/lib/ssl/ssl.h
@@ -516,6 +516,11 @@ SSL_IMPORT SECStatus SSL_ForceHandshake(PRFileDesc *fd);
 SSL_IMPORT SECStatus SSL_ForceHandshakeWithTimeout(PRFileDesc *fd,
                                                    PRIntervalTime timeout);
 
+SSL_IMPORT SECStatus SSL_RestartHandshakeAfterCertReq(PRFileDesc *fd,
+                                                      CERTCertificate *cert,
+                                                      SECKEYPrivateKey *key,
+                                                      CERTCertificateList *certChain);
+
 /*
 ** Query security status of socket. *on is set to one if security is
 ** enabled. *keySize will contain the stream key size used. *issuer will
diff --git a/lib/ssl/ssl3con.c b/lib/ssl/ssl3con.c
index 784f59b..2a2e644 100644
--- a/lib/ssl/ssl3con.c
+++ b/lib/ssl/ssl3con.c
@@ -7803,6 +7803,85 @@ ssl3_CompleteHandleCertificateRequest(sslSocket *ss, SECItem *algorithms,
     return rv;
 }
 
+/*
+ * attempt to restart the handshake after asynchronously handling
+ * a request for the client's certificate.
+ *
+ * inputs:
+ *	cert	Client cert chosen by application.
+ *		Note: ssl takes this reference, and does not bump the
+ *		reference count.  The caller should drop its reference
+ *		without calling CERT_DestroyCert after calling this function.
+ *
+ *	key	Private key associated with cert.  This function takes
+ *		ownership of the private key, so the caller should drop its
+ *		reference without destroying the private key after this
+ *		function returns.
+ *
+ *	certChain  DER-encoded certs, client cert and its signers.
+ *		Note: ssl takes this reference, and does not copy the chain.
+ *		The caller should drop its reference without destroying the
+ *		chain.  SSL will free the chain when it is done with it.
+ *
+ * Return value: XXX
+ *
+ * XXX This code only works on the initial handshake on a connection, XXX
+ *     It does not work on a subsequent handshake (redo).
+ *
+ * Caller holds 1stHandshakeLock.
+ */
+SECStatus
+ssl3_RestartHandshakeAfterCertReq(sslSocket *ss,
+                                  CERTCertificate *cert,
+                                  SECKEYPrivateKey *key,
+                                  CERTCertificateList *certChain)
+{
+    SECStatus rv = SECSuccess;
+
+    /* XXX This code only works on the initial handshake on a connection,
+    ** XXX It does not work on a subsequent handshake (redo).
+    */
+    if (ss->handshake != 0) {
+        ss->handshake = ssl_GatherRecord1stHandshake;
+        ss->ssl3.clientCertificate = cert;
+        ss->ssl3.clientPrivateKey = key;
+        ss->ssl3.clientCertChain = certChain;
+        if (!cert || !key || !certChain) {
+            /* we are missing the key, cert, or cert chain */
+            if (ss->ssl3.clientCertificate) {
+                CERT_DestroyCertificate(ss->ssl3.clientCertificate);
+                ss->ssl3.clientCertificate = NULL;
+            }
+            if (ss->ssl3.clientPrivateKey) {
+                SECKEY_DestroyPrivateKey(ss->ssl3.clientPrivateKey);
+                ss->ssl3.clientPrivateKey = NULL;
+            }
+            if (ss->ssl3.clientCertChain != NULL) {
+                CERT_DestroyCertificateList(ss->ssl3.clientCertChain);
+                ss->ssl3.clientCertChain = NULL;
+            }
+            if (ss->ssl3.prSpec->version > SSL_LIBRARY_VERSION_3_0) {
+                ss->ssl3.sendEmptyCert = PR_TRUE;
+            } else {
+                (void)SSL3_SendAlert(ss, alert_warning, no_certificate);
+            }
+        }
+    } else {
+        if (cert) {
+            CERT_DestroyCertificate(cert);
+        }
+        if (key) {
+            SECKEY_DestroyPrivateKey(key);
+        }
+        if (certChain) {
+            CERT_DestroyCertificateList(certChain);
+        }
+        PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
+        rv = SECFailure;
+    }
+    return rv;
+}
+
 static SECStatus
 ssl3_CheckFalseStart(sslSocket *ss)
 {
diff --git a/lib/ssl/sslimpl.h b/lib/ssl/sslimpl.h
index 5f0e6c9..dad75b2 100644
--- a/lib/ssl/sslimpl.h
+++ b/lib/ssl/sslimpl.h
@@ -1702,16 +1702,16 @@ extern SECStatus ssl3_MasterSecretDeriveBypass(ssl3CipherSpec *pwSpec,
 /* These functions are called from secnav, even though they're "private". */
 
 extern int ssl2_SendErrorMessage(struct sslSocketStr *ss, int error);
-extern int SSL_RestartHandshakeAfterCertReq(struct sslSocketStr *ss,
-                                            CERTCertificate *cert,
-                                            SECKEYPrivateKey *key,
-                                            CERTCertificateList *certChain);
 extern sslSocket *ssl_FindSocket(PRFileDesc *fd);
 extern void ssl_FreeSocket(struct sslSocketStr *ssl);
 extern SECStatus SSL3_SendAlert(sslSocket *ss, SSL3AlertLevel level,
                                 SSL3AlertDescription desc);
 extern SECStatus ssl3_DecodeError(sslSocket *ss);
 
+extern SECStatus ssl3_RestartHandshakeAfterCertReq(struct sslSocketStr *ss,
+                                                   CERTCertificate *cert,
+                                                   SECKEYPrivateKey *key,
+                                                   CERTCertificateList *certChain);
 extern SECStatus ssl3_AuthCertificateComplete(sslSocket *ss, PRErrorCode error);
 
 /*
diff --git a/lib/ssl/sslsecur.c b/lib/ssl/sslsecur.c
index 5773748..a087ffc 100644
--- a/lib/ssl/sslsecur.c
+++ b/lib/ssl/sslsecur.c
@@ -1535,17 +1535,70 @@ SSL_CertDBHandleSet(PRFileDesc *fd, CERTCertDBHandle *dbHandle)
     return SECSuccess;
 }
 
-/* DO NOT USE. This function was exported in ssl.def with the wrong signature;
- * this implementation exists to maintain link-time compatibility.
- */
-int
-SSL_RestartHandshakeAfterCertReq(sslSocket *ss,
+/*
+ * attempt to restart the handshake after asynchronously handling
+ * a request for the client's certificate.
+ *
+ * inputs:  
+ *	cert	Client cert chosen by application.
+ *		Note: ssl takes this reference, and does not bump the 
+ *		reference count.  The caller should drop its reference
+ *		without calling CERT_DestroyCertificate after calling this
+ *		function.
+ *
+ *	key	Private key associated with cert.  This function takes
+ *		ownership of the private key, so the caller should drop its
+ *		reference without destroying the private key after this
+ *		function returns.
+ *
+ *	certChain  Chain of signers for cert.  
+ *		Note: ssl takes this reference, and does not copy the chain.
+ *		The caller should drop its reference without destroying the 
+ *		chain.  SSL will free the chain when it is done with it.
+ *
+ * Return value: XXX
+ *
+ * XXX This code only works on the initial handshake on a connection, XXX
+ *     It does not work on a subsequent handshake (redo).
+   */
+SECStatus
+SSL_RestartHandshakeAfterCertReq(PRFileDesc *fd,
                                  CERTCertificate *cert,
                                  SECKEYPrivateKey *key,
                                  CERTCertificateList *certChain)
 {
-    PORT_SetError(PR_NOT_IMPLEMENTED_ERROR);
-    return -1;
+    sslSocket *ss = ssl_FindSocket(fd);
+    SECStatus ret;
+
+    if (!ss) {
+        SSL_DBG(("%d: SSL[%d]: bad socket in SSL_RestartHandshakeAfterCertReq",
+                 SSL_GETPID(), fd));
+        if (cert) {
+            CERT_DestroyCertificate(cert);
+        }
+        if (key) {
+            SECKEY_DestroyPrivateKey(key);
+        }
+        if (certChain) {
+            CERT_DestroyCertificateList(certChain);
+        }
+        return SECFailure;
+    }
+
+    ssl_Get1stHandshakeLock(ss); /************************************/
+
+    if (ss->version >= SSL_LIBRARY_VERSION_3_0) {
+        ret = ssl3_RestartHandshakeAfterCertReq(ss, cert, key, certChain);
+    } else {
+        if (certChain != NULL) {
+            CERT_DestroyCertificateList(certChain);
+        }
+        PORT_SetError(SSL_ERROR_FEATURE_NOT_SUPPORTED_FOR_SSL2);
+        ret = SECFailure;
+    }
+
+    ssl_Release1stHandshakeLock(ss); /************************************/
+    return ret;
 }
 
 /* DO NOT USE. This function was exported in ssl.def with the wrong signature;