| OLD | NEW |
| 1 /* | 1 /* |
| 2 * SSL v2 handshake functions, and functions common to SSL2 and SSL3. | 2 * SSL v2 handshake functions, and functions common to SSL2 and SSL3. |
| 3 * | 3 * |
| 4 * ***** BEGIN LICENSE BLOCK ***** | 4 * ***** BEGIN LICENSE BLOCK ***** |
| 5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
| 6 * | 6 * |
| 7 * The contents of this file are subject to the Mozilla Public License Version | 7 * The contents of this file are subject to the Mozilla Public License Version |
| 8 * 1.1 (the "License"); you may not use this file except in compliance with | 8 * 1.1 (the "License"); you may not use this file except in compliance with |
| 9 * the License. You may obtain a copy of the License at | 9 * the License. You may obtain a copy of the License at |
| 10 * http://www.mozilla.org/MPL/ | 10 * http://www.mozilla.org/MPL/ |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 * in which case the provisions of the GPL or the LGPL are applicable instead | 30 * in which case the provisions of the GPL or the LGPL are applicable instead |
| 31 * of those above. If you wish to allow use of your version of this file only | 31 * of those above. If you wish to allow use of your version of this file only |
| 32 * under the terms of either the GPL or the LGPL, and not to allow others to | 32 * under the terms of either the GPL or the LGPL, and not to allow others to |
| 33 * use your version of this file under the terms of the MPL, indicate your | 33 * use your version of this file under the terms of the MPL, indicate your |
| 34 * decision by deleting the provisions above and replace them with the notice | 34 * decision by deleting the provisions above and replace them with the notice |
| 35 * and other provisions required by the GPL or the LGPL. If you do not delete | 35 * and other provisions required by the GPL or the LGPL. If you do not delete |
| 36 * the provisions above, a recipient may use your version of this file under | 36 * the provisions above, a recipient may use your version of this file under |
| 37 * the terms of any one of the MPL, the GPL or the LGPL. | 37 * the terms of any one of the MPL, the GPL or the LGPL. |
| 38 * | 38 * |
| 39 * ***** END LICENSE BLOCK ***** */ | 39 * ***** END LICENSE BLOCK ***** */ |
| 40 /* $Id: sslcon.c,v 1.40 2010/04/25 23:37:38 nelson%bolyard.com Exp $ */ | 40 /* $Id: sslcon.c,v 1.45 2011/11/19 21:58:21 bsmith%mozilla.com Exp $ */ |
| 41 | 41 |
| 42 #include "nssrenam.h" | 42 #include "nssrenam.h" |
| 43 #include "cert.h" | 43 #include "cert.h" |
| 44 #include "secitem.h" | 44 #include "secitem.h" |
| 45 #include "sechash.h" | 45 #include "sechash.h" |
| 46 #include "cryptohi.h" /* for SGN_ funcs */ | 46 #include "cryptohi.h" /* for SGN_ funcs */ |
| 47 #include "keyhi.h" /* for SECKEY_ high level functions. */ | 47 #include "keyhi.h" /* for SECKEY_ high level functions. */ |
| 48 #include "ssl.h" | 48 #include "ssl.h" |
| 49 #include "sslimpl.h" | 49 #include "sslimpl.h" |
| 50 #include "sslproto.h" | 50 #include "sslproto.h" |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 return rv; | 511 return rv; |
| 512 } | 512 } |
| 513 | 513 |
| 514 /* Called from: | 514 /* Called from: |
| 515 * ssl2_ClientSetupSessionCypher() <- ssl2_HandleServerHelloMessage() | 515 * ssl2_ClientSetupSessionCypher() <- ssl2_HandleServerHelloMessage() |
| 516 * ssl2_HandleRequestCertificate() <- ssl2_HandleMessage() <- | 516 * ssl2_HandleRequestCertificate() <- ssl2_HandleMessage() <- |
| 517 ssl_Do1stHandshake() | 517 ssl_Do1stHandshake() |
| 518 * ssl2_HandleMessage() <- ssl_Do1stHandshake() | 518 * ssl2_HandleMessage() <- ssl_Do1stHandshake() |
| 519 * ssl2_HandleServerHelloMessage() <- ssl_Do1stHandshake() | 519 * ssl2_HandleServerHelloMessage() <- ssl_Do1stHandshake() |
| 520 after ssl2_BeginClientHandshake() | 520 after ssl2_BeginClientHandshake() |
| 521 * ssl2_RestartHandshakeAfterCertReq() <- Called from certdlgs.c in nav. | |
| 522 * ssl2_HandleClientHelloMessage() <- ssl_Do1stHandshake() | 521 * ssl2_HandleClientHelloMessage() <- ssl_Do1stHandshake() |
| 523 after ssl2_BeginServerHandshake() | 522 after ssl2_BeginServerHandshake() |
| 524 * | 523 * |
| 525 * Acquires and releases the socket's xmitBufLock. | 524 * Acquires and releases the socket's xmitBufLock. |
| 526 */ | 525 */ |
| 527 int | 526 int |
| 528 ssl2_SendErrorMessage(sslSocket *ss, int error) | 527 ssl2_SendErrorMessage(sslSocket *ss, int error) |
| 529 { | 528 { |
| 530 int rv; | 529 int rv; |
| 531 PRUint8 msg[SSL_HL_ERROR_HBYTES]; | 530 PRUint8 msg[SSL_HL_ERROR_HBYTES]; |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 | 757 |
| 759 DUMP_MSG(29, (ss, msg, sendLen)); | 758 DUMP_MSG(29, (ss, msg, sendLen)); |
| 760 sent = (*ss->sec.send)(ss, msg, sendLen, 0); | 759 sent = (*ss->sec.send)(ss, msg, sendLen, 0); |
| 761 rv = (sent >= 0) ? SECSuccess : (SECStatus)sent; | 760 rv = (sent >= 0) ? SECSuccess : (SECStatus)sent; |
| 762 done: | 761 done: |
| 763 ssl_ReleaseXmitBufLock(ss); /***************************************/ | 762 ssl_ReleaseXmitBufLock(ss); /***************************************/ |
| 764 return rv; | 763 return rv; |
| 765 } | 764 } |
| 766 | 765 |
| 767 /* Called from ssl2_HandleRequestCertificate() <- ssl2_HandleMessage() | 766 /* Called from ssl2_HandleRequestCertificate() <- ssl2_HandleMessage() |
| 768 * ssl2_RestartHandshakeAfterCertReq() <- (application) | |
| 769 * Acquires and releases the socket's xmitBufLock. | 767 * Acquires and releases the socket's xmitBufLock. |
| 770 */ | 768 */ |
| 771 static int | 769 static int |
| 772 ssl2_SendCertificateResponseMessage(sslSocket *ss, SECItem *cert, | 770 ssl2_SendCertificateResponseMessage(sslSocket *ss, SECItem *cert, |
| 773 SECItem *encCode) | 771 SECItem *encCode) |
| 774 { | 772 { |
| 775 PRUint8 *msg; | 773 PRUint8 *msg; |
| 776 int rv, sendLen; | 774 int rv, sendLen; |
| 777 | 775 |
| 778 PORT_Assert( ss->opt.noLocks || ssl_Have1stHandshakeLock(ss) ); | 776 PORT_Assert( ss->opt.noLocks || ssl_Have1stHandshakeLock(ss) ); |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1170 return count; | 1168 return count; |
| 1171 | 1169 |
| 1172 loser: | 1170 loser: |
| 1173 ssl_ReleaseSpecReadLock(ss); | 1171 ssl_ReleaseSpecReadLock(ss); |
| 1174 return SECFailure; | 1172 return SECFailure; |
| 1175 } | 1173 } |
| 1176 | 1174 |
| 1177 /* | 1175 /* |
| 1178 ** Called from: ssl2_HandleServerHelloMessage, | 1176 ** Called from: ssl2_HandleServerHelloMessage, |
| 1179 ** ssl2_HandleClientSessionKeyMessage, | 1177 ** ssl2_HandleClientSessionKeyMessage, |
| 1180 ** ssl2_RestartHandshakeAfterServerCert, | |
| 1181 ** ssl2_HandleClientHelloMessage, | 1178 ** ssl2_HandleClientHelloMessage, |
| 1182 ** | 1179 ** |
| 1183 */ | 1180 */ |
| 1184 static void | 1181 static void |
| 1185 ssl2_UseEncryptedSendFunc(sslSocket *ss) | 1182 ssl2_UseEncryptedSendFunc(sslSocket *ss) |
| 1186 { | 1183 { |
| 1187 ssl_GetXmitBufLock(ss); | 1184 ssl_GetXmitBufLock(ss); |
| 1188 PORT_Assert(ss->sec.hashcx != 0); | 1185 PORT_Assert(ss->sec.hashcx != 0); |
| 1189 | 1186 |
| 1190 ss->gs.encrypted = 1; | 1187 ss->gs.encrypted = 1; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1230 * | 1227 * |
| 1231 * This code is similar to, and easily confused with, DoRecv() in sslsecur.c | 1228 * This code is similar to, and easily confused with, DoRecv() in sslsecur.c |
| 1232 * | 1229 * |
| 1233 * This function is called from ssl_Do1stHandshake(). | 1230 * This function is called from ssl_Do1stHandshake(). |
| 1234 * The following functions put ssl_GatherRecord1stHandshake into ss->handshake: | 1231 * The following functions put ssl_GatherRecord1stHandshake into ss->handshake: |
| 1235 * ssl2_HandleMessage | 1232 * ssl2_HandleMessage |
| 1236 * ssl2_HandleVerifyMessage | 1233 * ssl2_HandleVerifyMessage |
| 1237 * ssl2_HandleServerHelloMessage | 1234 * ssl2_HandleServerHelloMessage |
| 1238 * ssl2_BeginClientHandshake | 1235 * ssl2_BeginClientHandshake |
| 1239 * ssl2_HandleClientSessionKeyMessage | 1236 * ssl2_HandleClientSessionKeyMessage |
| 1240 * ssl2_RestartHandshakeAfterCertReq | |
| 1241 * ssl3_RestartHandshakeAfterCertReq | 1237 * ssl3_RestartHandshakeAfterCertReq |
| 1242 * ssl2_RestartHandshakeAfterServerCert | |
| 1243 * ssl3_RestartHandshakeAfterServerCert | 1238 * ssl3_RestartHandshakeAfterServerCert |
| 1244 * ssl2_HandleClientHelloMessage | 1239 * ssl2_HandleClientHelloMessage |
| 1245 * ssl2_BeginServerHandshake | 1240 * ssl2_BeginServerHandshake |
| 1246 */ | 1241 */ |
| 1247 SECStatus | 1242 SECStatus |
| 1248 ssl_GatherRecord1stHandshake(sslSocket *ss) | 1243 ssl_GatherRecord1stHandshake(sslSocket *ss) |
| 1249 { | 1244 { |
| 1250 int rv; | 1245 int rv; |
| 1251 | 1246 |
| 1252 PORT_Assert( ss->opt.noLocks || ssl_Have1stHandshakeLock(ss) ); | 1247 PORT_Assert( ss->opt.noLocks || ssl_Have1stHandshakeLock(ss) ); |
| (...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2225 } | 2220 } |
| 2226 | 2221 |
| 2227 /* See if it's time to send our finished message, or if the handshakes are | 2222 /* See if it's time to send our finished message, or if the handshakes are |
| 2228 ** complete. Send finished message if appropriate. | 2223 ** complete. Send finished message if appropriate. |
| 2229 ** Returns SECSuccess unless anything goes wrong. | 2224 ** Returns SECSuccess unless anything goes wrong. |
| 2230 ** | 2225 ** |
| 2231 ** Called from ssl2_HandleMessage, | 2226 ** Called from ssl2_HandleMessage, |
| 2232 ** ssl2_HandleVerifyMessage | 2227 ** ssl2_HandleVerifyMessage |
| 2233 ** ssl2_HandleServerHelloMessage | 2228 ** ssl2_HandleServerHelloMessage |
| 2234 ** ssl2_HandleClientSessionKeyMessage | 2229 ** ssl2_HandleClientSessionKeyMessage |
| 2235 ** ssl2_RestartHandshakeAfterCertReq | |
| 2236 ** ssl2_RestartHandshakeAfterServerCert | |
| 2237 */ | 2230 */ |
| 2238 static SECStatus | 2231 static SECStatus |
| 2239 ssl2_TryToFinish(sslSocket *ss) | 2232 ssl2_TryToFinish(sslSocket *ss) |
| 2240 { | 2233 { |
| 2241 SECStatus rv; | 2234 SECStatus rv; |
| 2242 char e, ef; | 2235 char e, ef; |
| 2243 | 2236 |
| 2244 PORT_Assert( ss->opt.noLocks || ssl_Have1stHandshakeLock(ss) ); | 2237 PORT_Assert( ss->opt.noLocks || ssl_Have1stHandshakeLock(ss) ); |
| 2245 | 2238 |
| 2246 e = ss->sec.ci.elements; | 2239 e = ss->sec.ci.elements; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2260 /* Totally finished */ | 2253 /* Totally finished */ |
| 2261 ss->handshake = 0; | 2254 ss->handshake = 0; |
| 2262 return SECSuccess; | 2255 return SECSuccess; |
| 2263 } | 2256 } |
| 2264 } | 2257 } |
| 2265 return SECSuccess; | 2258 return SECSuccess; |
| 2266 } | 2259 } |
| 2267 | 2260 |
| 2268 /* | 2261 /* |
| 2269 ** Called from ssl2_HandleRequestCertificate | 2262 ** Called from ssl2_HandleRequestCertificate |
| 2270 ** ssl2_RestartHandshakeAfterCertReq | |
| 2271 */ | 2263 */ |
| 2272 static SECStatus | 2264 static SECStatus |
| 2273 ssl2_SignResponse(sslSocket *ss, | 2265 ssl2_SignResponse(sslSocket *ss, |
| 2274 SECKEYPrivateKey *key, | 2266 SECKEYPrivateKey *key, |
| 2275 SECItem *response) | 2267 SECItem *response) |
| 2276 { | 2268 { |
| 2277 SGNContext * sgn = NULL; | 2269 SGNContext * sgn = NULL; |
| 2278 PRUint8 * challenge; | 2270 PRUint8 * challenge; |
| 2279 unsigned int len; | 2271 unsigned int len; |
| 2280 SECStatus rv = SECFailure; | 2272 SECStatus rv = SECFailure; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2347 | 2339 |
| 2348 /* Get certificate and private-key from client */ | 2340 /* Get certificate and private-key from client */ |
| 2349 if (!ss->getClientAuthData) { | 2341 if (!ss->getClientAuthData) { |
| 2350 SSL_TRC(7, ("%d: SSL[%d]: client doesn't support client-auth", | 2342 SSL_TRC(7, ("%d: SSL[%d]: client doesn't support client-auth", |
| 2351 SSL_GETPID(), ss->fd)); | 2343 SSL_GETPID(), ss->fd)); |
| 2352 goto no_cert_error; | 2344 goto no_cert_error; |
| 2353 } | 2345 } |
| 2354 ret = (*ss->getClientAuthData)(ss->getClientAuthDataArg, ss->fd, | 2346 ret = (*ss->getClientAuthData)(ss->getClientAuthDataArg, ss->fd, |
| 2355 NULL, &cert, &key); | 2347 NULL, &cert, &key); |
| 2356 if ( ret == SECWouldBlock ) { | 2348 if ( ret == SECWouldBlock ) { |
| 2357 » ssl_SetAlwaysBlock(ss); | 2349 » PORT_SetError(SSL_ERROR_FEATURE_NOT_SUPPORTED_FOR_SSL2); |
| 2358 » goto done; | 2350 » ret = -1; |
| 2351 » goto loser; |
| 2359 } | 2352 } |
| 2360 | 2353 |
| 2361 if (ret) { | 2354 if (ret) { |
| 2362 goto no_cert_error; | 2355 goto no_cert_error; |
| 2363 } | 2356 } |
| 2364 | 2357 |
| 2365 /* check what the callback function returned */ | 2358 /* check what the callback function returned */ |
| 2366 if ((!cert) || (!key)) { | 2359 if ((!cert) || (!key)) { |
| 2367 /* we are missing either the key or cert */ | 2360 /* we are missing either the key or cert */ |
| 2368 if (cert) { | 2361 if (cert) { |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2708 PORT_SetError(ss->sec.isServer ? SSL_ERROR_BAD_CLIENT : SSL_ERROR_BAD_SERVER
); | 2701 PORT_SetError(ss->sec.isServer ? SSL_ERROR_BAD_CLIENT : SSL_ERROR_BAD_SERVER
); |
| 2709 /* FALL THROUGH */ | 2702 /* FALL THROUGH */ |
| 2710 | 2703 |
| 2711 loser: | 2704 loser: |
| 2712 ssl_ReleaseRecvBufLock(ss); | 2705 ssl_ReleaseRecvBufLock(ss); |
| 2713 return SECFailure; | 2706 return SECFailure; |
| 2714 } | 2707 } |
| 2715 | 2708 |
| 2716 /************************************************************************/ | 2709 /************************************************************************/ |
| 2717 | 2710 |
| 2718 /* Called from ssl_Do1stHandshake, after ssl2_HandleServerHelloMessage or | 2711 /* Called from ssl_Do1stHandshake, after ssl2_HandleServerHelloMessage. |
| 2719 ** ssl2_RestartHandshakeAfterServerCert. | |
| 2720 */ | 2712 */ |
| 2721 static SECStatus | 2713 static SECStatus |
| 2722 ssl2_HandleVerifyMessage(sslSocket *ss) | 2714 ssl2_HandleVerifyMessage(sslSocket *ss) |
| 2723 { | 2715 { |
| 2724 PRUint8 * data; | 2716 PRUint8 * data; |
| 2725 SECStatus rv; | 2717 SECStatus rv; |
| 2726 | 2718 |
| 2727 PORT_Assert( ss->opt.noLocks || ssl_Have1stHandshakeLock(ss) ); | 2719 PORT_Assert( ss->opt.noLocks || ssl_Have1stHandshakeLock(ss) ); |
| 2728 ssl_GetRecvBufLock(ss); | 2720 ssl_GetRecvBufLock(ss); |
| 2729 | 2721 |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2929 | 2921 |
| 2930 if (!sidHit) { | 2922 if (!sidHit) { |
| 2931 /* verify the server's certificate. if sidHit, don't check signatures */ | 2923 /* verify the server's certificate. if sidHit, don't check signatures */ |
| 2932 rv = (* ss->authCertificate)(ss->authCertificateArg, ss->fd, | 2924 rv = (* ss->authCertificate)(ss->authCertificateArg, ss->fd, |
| 2933 (PRBool)(!sidHit), PR_FALSE); | 2925 (PRBool)(!sidHit), PR_FALSE); |
| 2934 if (rv) { | 2926 if (rv) { |
| 2935 if (ss->handleBadCert) { | 2927 if (ss->handleBadCert) { |
| 2936 rv = (*ss->handleBadCert)(ss->badCertArg, ss->fd); | 2928 rv = (*ss->handleBadCert)(ss->badCertArg, ss->fd); |
| 2937 if ( rv ) { | 2929 if ( rv ) { |
| 2938 if ( rv == SECWouldBlock ) { | 2930 if ( rv == SECWouldBlock ) { |
| 2939 » » /* someone will handle this connection asynchronously*/ | 2931 » » SSL_DBG(("%d: SSL[%d]: SSL2 bad cert handler returned " |
| 2940 | 2932 » » » "SECWouldBlock", SSL_GETPID(), ss->fd)); |
| 2941 » » SSL_DBG(("%d: SSL[%d]: go to async cert handler", | 2933 » » PORT_SetError(SSL_ERROR_FEATURE_NOT_SUPPORTED_FOR_SSL2); |
| 2942 » » » SSL_GETPID(), ss->fd)); | 2934 » » rv = SECFailure; |
| 2943 » » ssl_ReleaseRecvBufLock(ss); | 2935 » » } else { |
| 2944 » » ssl_SetAlwaysBlock(ss); | 2936 » » /* cert is bad */ |
| 2945 » » return SECWouldBlock; | 2937 » » SSL_DBG(("%d: SSL[%d]: server certificate is no good: error=
%d", |
| 2938 » » » SSL_GETPID(), ss->fd, PORT_GetError())); |
| 2946 } | 2939 } |
| 2947 /* cert is bad */ | |
| 2948 SSL_DBG(("%d: SSL[%d]: server certificate is no good: error=%d", | |
| 2949 SSL_GETPID(), ss->fd, PORT_GetError())); | |
| 2950 goto loser; | 2940 goto loser; |
| 2951 | |
| 2952 } | 2941 } |
| 2953 /* cert is good */ | 2942 /* cert is good */ |
| 2954 } else { | 2943 } else { |
| 2955 SSL_DBG(("%d: SSL[%d]: server certificate is no good: error=%d", | 2944 SSL_DBG(("%d: SSL[%d]: server certificate is no good: error=%d", |
| 2956 SSL_GETPID(), ss->fd, PORT_GetError())); | 2945 SSL_GETPID(), ss->fd, PORT_GetError())); |
| 2957 goto loser; | 2946 goto loser; |
| 2958 } | 2947 } |
| 2959 } | 2948 } |
| 2960 } | 2949 } |
| 2961 /* | 2950 /* |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3118 | 3107 |
| 3119 if ((sid->version >= SSL_LIBRARY_VERSION_3_0 || !ss->opt.v2CompatibleHello)
&& | 3108 if ((sid->version >= SSL_LIBRARY_VERSION_3_0 || !ss->opt.v2CompatibleHello)
&& |
| 3120 (ss->opt.enableSSL3 || ss->opt.enableTLS)) { | 3109 (ss->opt.enableSSL3 || ss->opt.enableTLS)) { |
| 3121 | 3110 |
| 3122 ss->gs.state = GS_INIT; | 3111 ss->gs.state = GS_INIT; |
| 3123 ss->handshake = ssl_GatherRecord1stHandshake; | 3112 ss->handshake = ssl_GatherRecord1stHandshake; |
| 3124 | 3113 |
| 3125 /* ssl3_SendClientHello will override this if it succeeds. */ | 3114 /* ssl3_SendClientHello will override this if it succeeds. */ |
| 3126 ss->version = SSL_LIBRARY_VERSION_3_0; | 3115 ss->version = SSL_LIBRARY_VERSION_3_0; |
| 3127 | 3116 |
| 3128 ssl_GetXmitBufLock(ss); /***************************************/ | |
| 3129 ssl_GetSSL3HandshakeLock(ss); | 3117 ssl_GetSSL3HandshakeLock(ss); |
| 3118 ssl_GetXmitBufLock(ss); |
| 3130 rv = ssl3_SendClientHello(ss); | 3119 rv = ssl3_SendClientHello(ss); |
| 3120 ssl_ReleaseXmitBufLock(ss); |
| 3131 ssl_ReleaseSSL3HandshakeLock(ss); | 3121 ssl_ReleaseSSL3HandshakeLock(ss); |
| 3132 ssl_ReleaseXmitBufLock(ss); /***************************************/ | |
| 3133 | 3122 |
| 3134 return rv; | 3123 return rv; |
| 3135 } | 3124 } |
| 3136 #if defined(NSS_ENABLE_ECC) && !defined(NSS_ECC_MORE_THAN_SUITE_B) | 3125 #if defined(NSS_ENABLE_ECC) && !defined(NSS_ECC_MORE_THAN_SUITE_B) |
| 3137 /* ensure we don't neogtiate ECC cipher suites with SSL2 hello */ | 3126 /* ensure we don't neogtiate ECC cipher suites with SSL2 hello */ |
| 3138 ssl3_DisableECCSuites(ss, NULL); /* disable all ECC suites */ | 3127 ssl3_DisableECCSuites(ss, NULL); /* disable all ECC suites */ |
| 3139 if (ss->cipherSpecs != NULL) { | 3128 if (ss->cipherSpecs != NULL) { |
| 3140 PORT_Free(ss->cipherSpecs); | 3129 PORT_Free(ss->cipherSpecs); |
| 3141 ss->cipherSpecs = NULL; | 3130 ss->cipherSpecs = NULL; |
| 3142 ss->sizeCipherSpecs = 0; | 3131 ss->sizeCipherSpecs = 0; |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3324 bad_client: | 3313 bad_client: |
| 3325 ssl_ReleaseRecvBufLock(ss); | 3314 ssl_ReleaseRecvBufLock(ss); |
| 3326 PORT_SetError(SSL_ERROR_BAD_CLIENT); | 3315 PORT_SetError(SSL_ERROR_BAD_CLIENT); |
| 3327 /* FALLTHROUGH */ | 3316 /* FALLTHROUGH */ |
| 3328 | 3317 |
| 3329 loser: | 3318 loser: |
| 3330 return SECFailure; | 3319 return SECFailure; |
| 3331 } | 3320 } |
| 3332 | 3321 |
| 3333 /* | 3322 /* |
| 3334 * attempt to restart the handshake after asynchronously handling | |
| 3335 * a request for the client's certificate. | |
| 3336 * | |
| 3337 * inputs: | |
| 3338 * cert Client cert chosen by application. | |
| 3339 * key Private key associated with cert. | |
| 3340 * | |
| 3341 * XXX: need to make ssl2 and ssl3 versions of this function agree on whether | |
| 3342 * they take the reference, or bump the ref count! | |
| 3343 * | |
| 3344 * Return value: XXX | |
| 3345 * | |
| 3346 * Caller holds 1stHandshakeLock. | |
| 3347 */ | |
| 3348 int | |
| 3349 ssl2_RestartHandshakeAfterCertReq(sslSocket * ss, | |
| 3350 CERTCertificate * cert, | |
| 3351 SECKEYPrivateKey * key) | |
| 3352 { | |
| 3353 int ret; | |
| 3354 SECStatus rv = SECSuccess; | |
| 3355 SECItem response; | |
| 3356 | |
| 3357 if (ss->version >= SSL_LIBRARY_VERSION_3_0) | |
| 3358 return SECFailure; | |
| 3359 | |
| 3360 response.data = NULL; | |
| 3361 | |
| 3362 /* generate error if no cert or key */ | |
| 3363 if ( ( cert == NULL ) || ( key == NULL ) ) { | |
| 3364 goto no_cert; | |
| 3365 } | |
| 3366 | |
| 3367 /* generate signed response to the challenge */ | |
| 3368 rv = ssl2_SignResponse(ss, key, &response); | |
| 3369 if ( rv != SECSuccess ) { | |
| 3370 goto no_cert; | |
| 3371 } | |
| 3372 | |
| 3373 /* Send response message */ | |
| 3374 ret = ssl2_SendCertificateResponseMessage(ss, &cert->derCert, &response); | |
| 3375 if (ret) { | |
| 3376 goto no_cert; | |
| 3377 } | |
| 3378 | |
| 3379 /* try to finish the handshake */ | |
| 3380 ret = ssl2_TryToFinish(ss); | |
| 3381 if (ret) { | |
| 3382 goto loser; | |
| 3383 } | |
| 3384 | |
| 3385 /* done with handshake */ | |
| 3386 if (ss->handshake == 0) { | |
| 3387 ret = SECSuccess; | |
| 3388 goto done; | |
| 3389 } | |
| 3390 | |
| 3391 /* continue handshake */ | |
| 3392 ssl_GetRecvBufLock(ss); | |
| 3393 ss->gs.recordLen = 0; | |
| 3394 ssl_ReleaseRecvBufLock(ss); | |
| 3395 | |
| 3396 ss->handshake = ssl_GatherRecord1stHandshake; | |
| 3397 ss->nextHandshake = ssl2_HandleMessage; | |
| 3398 ret = ssl2_TriggerNextMessage(ss); | |
| 3399 goto done; | |
| 3400 | |
| 3401 no_cert: | |
| 3402 /* no cert - send error */ | |
| 3403 ret = ssl2_SendErrorMessage(ss, SSL_PE_NO_CERTIFICATE); | |
| 3404 goto done; | |
| 3405 | |
| 3406 loser: | |
| 3407 ret = SECFailure; | |
| 3408 done: | |
| 3409 /* free allocated data */ | |
| 3410 if ( response.data ) { | |
| 3411 PORT_Free(response.data); | |
| 3412 } | |
| 3413 | |
| 3414 return ret; | |
| 3415 } | |
| 3416 | |
| 3417 | |
| 3418 /* restart an SSL connection that we stopped to run certificate dialogs | |
| 3419 ** XXX Need to document here how an application marks a cert to show that | |
| 3420 ** the application has accepted it (overridden CERT_VerifyCert). | |
| 3421 * | |
| 3422 * Return value: XXX | |
| 3423 * | |
| 3424 * Caller holds 1stHandshakeLock. | |
| 3425 */ | |
| 3426 int | |
| 3427 ssl2_RestartHandshakeAfterServerCert(sslSocket *ss) | |
| 3428 { | |
| 3429 int rv = SECSuccess; | |
| 3430 | |
| 3431 if (ss->version >= SSL_LIBRARY_VERSION_3_0) | |
| 3432 return SECFailure; | |
| 3433 | |
| 3434 /* SSL 2 | |
| 3435 ** At this point we have a completed session key and our session | |
| 3436 ** cipher is setup and ready to go. Switch to encrypted write routine | |
| 3437 ** as all future message data is to be encrypted. | |
| 3438 */ | |
| 3439 ssl2_UseEncryptedSendFunc(ss); | |
| 3440 | |
| 3441 rv = ssl2_TryToFinish(ss); | |
| 3442 if (rv == SECSuccess && ss->handshake != NULL) { | |
| 3443 /* handshake is not yet finished. */ | |
| 3444 | |
| 3445 SSL_TRC(5, ("%d: SSL[%d]: got server-hello, required=0x%d got=0x%x", | |
| 3446 SSL_GETPID(), ss->fd, ss->sec.ci.requiredElements, | |
| 3447 ss->sec.ci.elements)); | |
| 3448 | |
| 3449 ssl_GetRecvBufLock(ss); | |
| 3450 ss->gs.recordLen = 0; /* mark it all used up. */ | |
| 3451 ssl_ReleaseRecvBufLock(ss); | |
| 3452 | |
| 3453 ss->handshake = ssl_GatherRecord1stHandshake; | |
| 3454 ss->nextHandshake = ssl2_HandleVerifyMessage; | |
| 3455 } | |
| 3456 | |
| 3457 return rv; | |
| 3458 } | |
| 3459 | |
| 3460 /* | |
| 3461 ** Handle the initial hello message from the client | 3323 ** Handle the initial hello message from the client |
| 3462 ** | 3324 ** |
| 3463 ** not static because ssl2_GatherData() tests ss->nextHandshake for this value. | 3325 ** not static because ssl2_GatherData() tests ss->nextHandshake for this value. |
| 3464 */ | 3326 */ |
| 3465 SECStatus | 3327 SECStatus |
| 3466 ssl2_HandleClientHelloMessage(sslSocket *ss) | 3328 ssl2_HandleClientHelloMessage(sslSocket *ss) |
| 3467 { | 3329 { |
| 3468 sslSessionID *sid; | 3330 sslSessionID *sid; |
| 3469 sslServerCerts * sc; | 3331 sslServerCerts * sc; |
| 3470 CERTCertificate *serverCert; | 3332 CERTCertificate *serverCert; |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3845 * check algorithm. This release is not backward | 3707 * check algorithm. This release is not backward |
| 3846 * compatible with previous major releases. It is | 3708 * compatible with previous major releases. It is |
| 3847 * not compatible with future major, minor, or | 3709 * not compatible with future major, minor, or |
| 3848 * patch releases. | 3710 * patch releases. |
| 3849 */ | 3711 */ |
| 3850 volatile char c; /* force a reference that won't get optimized away */ | 3712 volatile char c; /* force a reference that won't get optimized away */ |
| 3851 | 3713 |
| 3852 c = __nss_ssl_rcsid[0] + __nss_ssl_sccsid[0]; | 3714 c = __nss_ssl_rcsid[0] + __nss_ssl_sccsid[0]; |
| 3853 return NSS_VersionCheck(importedVersion); | 3715 return NSS_VersionCheck(importedVersion); |
| 3854 } | 3716 } |
| 3717 |
| 3718 const char * |
| 3719 NSSSSL_GetVersion(void) |
| 3720 { |
| 3721 return NSS_VERSION; |
| 3722 } |
| OLD | NEW |