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

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

Issue 14522022: Update NSS libSSL to NSS_3_15_BETA2. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Make the changes rsleevi suggested Created 7 years, 7 months 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
OLDNEW
1 /* 1 /*
2 * SSL3 Protocol 2 * SSL3 Protocol
3 * 3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public 4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 7
8 /* TLS extension code moved here from ssl3ecc.c */ 8 /* TLS extension code moved here from ssl3ecc.c */
9 /* $Id: ssl3ext.c,v 1.28 2012/09/21 00:28:05 wtc%google.com Exp $ */ 9 /* $Id$ */
10 10
11 #include "nssrenam.h" 11 #include "nssrenam.h"
12 #include "nss.h" 12 #include "nss.h"
13 #include "ssl.h" 13 #include "ssl.h"
14 #include "sslimpl.h" 14 #include "sslimpl.h"
15 #include "sslproto.h" 15 #include "sslproto.h"
16 #include "pk11pub.h" 16 #include "pk11pub.h"
17 #ifdef NO_PKCS11_BYPASS 17 #ifdef NO_PKCS11_BYPASS
18 #include "blapit.h" 18 #include "blapit.h"
19 #else 19 #else
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 static PRInt32 ssl3_ClientSendNextProtoNegoXtn(sslSocket *ss, PRBool append, 58 static PRInt32 ssl3_ClientSendNextProtoNegoXtn(sslSocket *ss, PRBool append,
59 PRUint32 maxBytes); 59 PRUint32 maxBytes);
60 static PRInt32 ssl3_SendUseSRTPXtn(sslSocket *ss, PRBool append, 60 static PRInt32 ssl3_SendUseSRTPXtn(sslSocket *ss, PRBool append,
61 PRUint32 maxBytes); 61 PRUint32 maxBytes);
62 static SECStatus ssl3_HandleUseSRTPXtn(sslSocket * ss, PRUint16 ex_type, 62 static SECStatus ssl3_HandleUseSRTPXtn(sslSocket * ss, PRUint16 ex_type,
63 SECItem *data); 63 SECItem *data);
64 static SECStatus ssl3_ClientHandleChannelIDXtn(sslSocket *ss, 64 static SECStatus ssl3_ClientHandleChannelIDXtn(sslSocket *ss,
65 PRUint16 ex_type, SECItem *data); 65 PRUint16 ex_type, SECItem *data);
66 static PRInt32 ssl3_ClientSendChannelIDXtn(sslSocket *ss, PRBool append, 66 static PRInt32 ssl3_ClientSendChannelIDXtn(sslSocket *ss, PRBool append,
67 PRUint32 maxBytes); 67 PRUint32 maxBytes);
68 static SECStatus ssl3_ServerSendStatusRequestXtn(sslSocket * ss,
69 PRBool append, PRUint32 maxBytes);
agl 2013/05/02 14:43:57 nit: odd spacing here.
wtc 2013/05/02 22:32:00 Done.
70 static SECStatus ssl3_ServerHandleStatusRequestXtn(sslSocket *ss,
71 PRUint16 ex_type, SECItem *data);
72 static SECStatus ssl3_ClientHandleStatusRequestXtn(sslSocket *ss,
73 PRUint16 ex_type,
agl 2013/05/02 14:43:57 This seems to be one space too few (and in the nex
wtc 2013/05/02 22:32:00 Done. It is one space too few.
74 SECItem *data);
75 static PRInt32 ssl3_ClientSendStatusRequestXtn(sslSocket * ss, PRBool append,
76 PRUint32 maxBytes);
68 77
69 /* 78 /*
70 * Write bytes. Using this function means the SECItem structure 79 * Write bytes. Using this function means the SECItem structure
71 * cannot be freed. The caller is expected to call this function 80 * cannot be freed. The caller is expected to call this function
72 * on a shallow copy of the structure. 81 * on a shallow copy of the structure.
73 */ 82 */
74 static SECStatus 83 static SECStatus
75 ssl3_AppendToItem(SECItem *item, const unsigned char *buf, PRUint32 bytes) 84 ssl3_AppendToItem(SECItem *item, const unsigned char *buf, PRUint32 bytes)
76 { 85 {
77 if (bytes > item->len) 86 if (bytes > item->len)
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 static const ssl3HelloExtensionHandler clientHelloHandlers[] = { 228 static const ssl3HelloExtensionHandler clientHelloHandlers[] = {
220 { ssl_server_name_xtn, &ssl3_HandleServerNameXtn }, 229 { ssl_server_name_xtn, &ssl3_HandleServerNameXtn },
221 #ifdef NSS_ENABLE_ECC 230 #ifdef NSS_ENABLE_ECC
222 { ssl_elliptic_curves_xtn, &ssl3_HandleSupportedCurvesXtn }, 231 { ssl_elliptic_curves_xtn, &ssl3_HandleSupportedCurvesXtn },
223 { ssl_ec_point_formats_xtn, &ssl3_HandleSupportedPointFormatsXtn }, 232 { ssl_ec_point_formats_xtn, &ssl3_HandleSupportedPointFormatsXtn },
224 #endif 233 #endif
225 { ssl_session_ticket_xtn, &ssl3_ServerHandleSessionTicketXtn }, 234 { ssl_session_ticket_xtn, &ssl3_ServerHandleSessionTicketXtn },
226 { ssl_renegotiation_info_xtn, &ssl3_HandleRenegotiationInfoXtn }, 235 { ssl_renegotiation_info_xtn, &ssl3_HandleRenegotiationInfoXtn },
227 { ssl_next_proto_nego_xtn, &ssl3_ServerHandleNextProtoNegoXtn }, 236 { ssl_next_proto_nego_xtn, &ssl3_ServerHandleNextProtoNegoXtn },
228 { ssl_use_srtp_xtn, &ssl3_HandleUseSRTPXtn }, 237 { ssl_use_srtp_xtn, &ssl3_HandleUseSRTPXtn },
238 { ssl_cert_status_xtn, &ssl3_ServerHandleStatusRequestXtn },
229 { -1, NULL } 239 { -1, NULL }
230 }; 240 };
231 241
232 /* These two tables are used by the client, to handle server hello 242 /* These two tables are used by the client, to handle server hello
233 * extensions. */ 243 * extensions. */
234 static const ssl3HelloExtensionHandler serverHelloHandlersTLS[] = { 244 static const ssl3HelloExtensionHandler serverHelloHandlersTLS[] = {
235 { ssl_server_name_xtn, &ssl3_HandleServerNameXtn }, 245 { ssl_server_name_xtn, &ssl3_HandleServerNameXtn },
236 /* TODO: add a handler for ssl_ec_point_formats_xtn */ 246 /* TODO: add a handler for ssl_ec_point_formats_xtn */
237 { ssl_session_ticket_xtn, &ssl3_ClientHandleSessionTicketXtn }, 247 { ssl_session_ticket_xtn, &ssl3_ClientHandleSessionTicketXtn },
238 { ssl_renegotiation_info_xtn, &ssl3_HandleRenegotiationInfoXtn }, 248 { ssl_renegotiation_info_xtn, &ssl3_HandleRenegotiationInfoXtn },
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 ss->xtnData.advertised[ss->xtnData.numAdvertised++] = 705 ss->xtnData.advertised[ss->xtnData.numAdvertised++] =
696 ssl_channel_id_xtn; 706 ssl_channel_id_xtn;
697 } 707 }
698 708
699 return extension_length; 709 return extension_length;
700 710
701 loser: 711 loser:
702 return -1; 712 return -1;
703 } 713 }
704 714
705 SECStatus 715 static SECStatus
706 ssl3_ClientHandleStatusRequestXtn(sslSocket *ss, PRUint16 ex_type, 716 ssl3_ClientHandleStatusRequestXtn(sslSocket *ss, PRUint16 ex_type,
707 » » » » SECItem *data) 717 SECItem *data)
708 { 718 {
709 /* If we didn't request this extension, then the server may not echo it. */
710 if (!ss->opt.enableOCSPStapling)
711 return SECFailure;
712
713 /* The echoed extension must be empty. */ 719 /* The echoed extension must be empty. */
714 if (data->len != 0) 720 if (data->len != 0)
715 » return SECFailure; 721 return SECFailure;
716
717 ss->ssl3.hs.may_get_cert_status = PR_TRUE;
718 722
719 /* Keep track of negotiated extensions. */ 723 /* Keep track of negotiated extensions. */
720 ss->xtnData.negotiated[ss->xtnData.numNegotiated++] = ex_type; 724 ss->xtnData.negotiated[ss->xtnData.numNegotiated++] = ex_type;
721 725
722 return SECSuccess; 726 return SECSuccess;
723 } 727 }
724 728
729 static PRInt32
730 ssl3_ServerSendStatusRequestXtn(
731 sslSocket * ss,
732 PRBool append,
733 PRUint32 maxBytes)
734 {
735 PRInt32 extension_length;
736 SECStatus rv;
737
738 if (!ss->certStatusArray)
739 return 0;
740
741 extension_length = 2 + 2;
742 if (append && maxBytes >= extension_length) {
743 /* extension_type */
744 rv = ssl3_AppendHandshakeNumber(ss, ssl_cert_status_xtn, 2);
745 if (rv != SECSuccess)
746 return -1;
747 /* length of extension_data */
748 rv = ssl3_AppendHandshakeNumber(ss, 0, 2);
749 if (rv != SECSuccess)
750 return -1;
751 }
752
753 return extension_length;
754 }
755
725 /* ssl3_ClientSendStatusRequestXtn builds the status_request extension on the 756 /* ssl3_ClientSendStatusRequestXtn builds the status_request extension on the
726 * client side. See RFC 4366 section 3.6. */ 757 * client side. See RFC 4366 section 3.6. */
727 PRInt32 758 static PRInt32
728 ssl3_ClientSendStatusRequestXtn(sslSocket * ss, PRBool append, 759 ssl3_ClientSendStatusRequestXtn(sslSocket * ss, PRBool append,
729 » » » » PRUint32 maxBytes) 760 PRUint32 maxBytes)
730 { 761 {
731 PRInt32 extension_length; 762 PRInt32 extension_length;
732 763
733 if (!ss->opt.enableOCSPStapling) 764 if (!ss->opt.enableOCSPStapling)
734 » return 0; 765 return 0;
735 766
736 /* extension_type (2-bytes) + 767 /* extension_type (2-bytes) +
737 * length(extension_data) (2-bytes) + 768 * length(extension_data) (2-bytes) +
738 * status_type (1) + 769 * status_type (1) +
739 * responder_id_list length (2) + 770 * responder_id_list length (2) +
740 * request_extensions length (2) 771 * request_extensions length (2)
741 */ 772 */
742 extension_length = 9; 773 extension_length = 9;
743 774
744 if (append && maxBytes >= extension_length) { 775 if (append && maxBytes >= extension_length) {
745 » SECStatus rv; 776 SECStatus rv;
746 » TLSExtensionData *xtnData; 777 TLSExtensionData *xtnData;
747 778
748 » /* extension_type */ 779 /* extension_type */
749 » rv = ssl3_AppendHandshakeNumber(ss, ssl_cert_status_xtn, 2); 780 rv = ssl3_AppendHandshakeNumber(ss, ssl_cert_status_xtn, 2);
750 » if (rv != SECSuccess) 781 if (rv != SECSuccess)
751 » return -1; 782 return -1;
752 » rv = ssl3_AppendHandshakeNumber(ss, extension_length - 4, 2); 783 rv = ssl3_AppendHandshakeNumber(ss, extension_length - 4, 2);
753 » if (rv != SECSuccess) 784 if (rv != SECSuccess)
754 » return -1; 785 return -1;
755 » rv = ssl3_AppendHandshakeNumber(ss, 1 /* status_type ocsp */, 1); 786 rv = ssl3_AppendHandshakeNumber(ss, 1 /* status_type ocsp */, 1);
756 » if (rv != SECSuccess) 787 if (rv != SECSuccess)
757 » return -1; 788 return -1;
758 » /* A zero length responder_id_list means that the responders are 789 /* A zero length responder_id_list means that the responders are
759 » * implicitly known to the server. */ 790 * implicitly known to the server. */
760 » rv = ssl3_AppendHandshakeNumber(ss, 0, 2); 791 rv = ssl3_AppendHandshakeNumber(ss, 0, 2);
761 » if (rv != SECSuccess) 792 if (rv != SECSuccess)
762 » return -1; 793 return -1;
763 » /* A zero length request_extensions means that there are no extensions. 794 /* A zero length request_extensions means that there are no extensions.
764 » * Specifically, we don't set the id-pkix-ocsp-nonce extension. This 795 * Specifically, we don't set the id-pkix-ocsp-nonce extension. This
765 » * means that the server can replay a cached OCSP response to us. */ 796 * means that the server can replay a cached OCSP response to us. */
766 » rv = ssl3_AppendHandshakeNumber(ss, 0, 2); 797 rv = ssl3_AppendHandshakeNumber(ss, 0, 2);
767 » if (rv != SECSuccess) 798 if (rv != SECSuccess)
768 » return -1; 799 return -1;
769 800
770 » xtnData = &ss->xtnData; 801 xtnData = &ss->xtnData;
771 » xtnData->advertised[xtnData->numAdvertised++] = ssl_cert_status_xtn; 802 xtnData->advertised[xtnData->numAdvertised++] = ssl_cert_status_xtn;
772 } else if (maxBytes < extension_length) { 803 } else if (maxBytes < extension_length) {
773 » PORT_Assert(0); 804 PORT_Assert(0);
774 » return 0; 805 return 0;
775 } 806 }
776 return extension_length; 807 return extension_length;
777 } 808 }
778 809
779 /* 810 /*
780 * NewSessionTicket 811 * NewSessionTicket
781 * Called from ssl3_HandleFinished 812 * Called from ssl3_HandleFinished
782 */ 813 */
783 SECStatus 814 SECStatus
784 ssl3_SendNewSessionTicket(sslSocket *ss) 815 ssl3_SendNewSessionTicket(sslSocket *ss)
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 != SECSuccess) 1236 != SECSuccess)
1206 return SECFailure; 1237 return SECFailure;
1207 1238
1208 /* Get session ticket keys. */ 1239 /* Get session ticket keys. */
1209 #ifndef NO_PKCS11_BYPASS 1240 #ifndef NO_PKCS11_BYPASS
1210 if (ss->opt.bypassPKCS11) { 1241 if (ss->opt.bypassPKCS11) {
1211 rv = ssl3_GetSessionTicketKeys(&aes_key, &aes_key_length, 1242 rv = ssl3_GetSessionTicketKeys(&aes_key, &aes_key_length,
1212 &mac_key, &mac_key_length); 1243 &mac_key, &mac_key_length);
1213 } else 1244 } else
1214 #endif 1245 #endif
1215 { 1246 » {
1216 rv = ssl3_GetSessionTicketKeysPKCS11(ss, &aes_key_pkcs11, 1247 rv = ssl3_GetSessionTicketKeysPKCS11(ss, &aes_key_pkcs11,
1217 &mac_key_pkcs11); 1248 &mac_key_pkcs11);
1218 } 1249 }
1219 if (rv != SECSuccess) { 1250 if (rv != SECSuccess) {
1220 SSL_DBG(("%d: SSL[%d]: Unable to get/generate session ticket keys.", 1251 SSL_DBG(("%d: SSL[%d]: Unable to get/generate session ticket keys.",
1221 SSL_GETPID(), ss->fd)); 1252 SSL_GETPID(), ss->fd));
1222 goto loser; 1253 goto loser;
1223 } 1254 }
1224 1255
1225 /* If the ticket sent by the client was generated under a key different 1256 /* If the ticket sent by the client was generated under a key different
(...skipping 17 matching lines...) Expand all
1243 sizeof(session_ticket_mac_key), PR_FALSE) != SECSuccess) 1274 sizeof(session_ticket_mac_key), PR_FALSE) != SECSuccess)
1244 goto no_ticket; 1275 goto no_ticket;
1245 HMAC_Begin(hmac_ctx); 1276 HMAC_Begin(hmac_ctx);
1246 HMAC_Update(hmac_ctx, extension_data.data, 1277 HMAC_Update(hmac_ctx, extension_data.data,
1247 extension_data.len - TLS_EX_SESS_TICKET_MAC_LENGTH); 1278 extension_data.len - TLS_EX_SESS_TICKET_MAC_LENGTH);
1248 if (HMAC_Finish(hmac_ctx, computed_mac, &computed_mac_length, 1279 if (HMAC_Finish(hmac_ctx, computed_mac, &computed_mac_length,
1249 sizeof(computed_mac)) != SECSuccess) 1280 sizeof(computed_mac)) != SECSuccess)
1250 goto no_ticket; 1281 goto no_ticket;
1251 } else 1282 } else
1252 #endif 1283 #endif
1253 { 1284 » {
1254 SECItem macParam; 1285 SECItem macParam;
1255 macParam.data = NULL; 1286 macParam.data = NULL;
1256 macParam.len = 0; 1287 macParam.len = 0;
1257 hmac_ctx_pkcs11 = PK11_CreateContextBySymKey(macMech, 1288 hmac_ctx_pkcs11 = PK11_CreateContextBySymKey(macMech,
1258 CKA_SIGN, mac_key_pkcs11, &macParam); 1289 CKA_SIGN, mac_key_pkcs11, &macParam);
1259 if (!hmac_ctx_pkcs11) { 1290 if (!hmac_ctx_pkcs11) {
1260 SSL_DBG(("%d: SSL[%d]: Unable to create HMAC context: %d.", 1291 SSL_DBG(("%d: SSL[%d]: Unable to create HMAC context: %d.",
1261 SSL_GETPID(), ss->fd, PORT_GetError())); 1292 SSL_GETPID(), ss->fd, PORT_GetError()));
1262 goto no_ticket; 1293 goto no_ticket;
1263 } else { 1294 } else {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 } 1338 }
1308 1339
1309 rv = AES_Decrypt(aes_ctx, decrypted_state->data, 1340 rv = AES_Decrypt(aes_ctx, decrypted_state->data,
1310 &decrypted_state->len, decrypted_state->len, 1341 &decrypted_state->len, decrypted_state->len,
1311 enc_session_ticket.encrypted_state.data, 1342 enc_session_ticket.encrypted_state.data,
1312 enc_session_ticket.encrypted_state.len); 1343 enc_session_ticket.encrypted_state.len);
1313 if (rv != SECSuccess) 1344 if (rv != SECSuccess)
1314 goto no_ticket; 1345 goto no_ticket;
1315 } else 1346 } else
1316 #endif 1347 #endif
1317 { 1348 » {
1318 SECItem ivItem; 1349 SECItem ivItem;
1319 ivItem.data = enc_session_ticket.iv; 1350 ivItem.data = enc_session_ticket.iv;
1320 ivItem.len = AES_BLOCK_SIZE; 1351 ivItem.len = AES_BLOCK_SIZE;
1321 aes_ctx_pkcs11 = PK11_CreateContextBySymKey(cipherMech, 1352 aes_ctx_pkcs11 = PK11_CreateContextBySymKey(cipherMech,
1322 CKA_DECRYPT, aes_key_pkcs11, &ivItem); 1353 CKA_DECRYPT, aes_key_pkcs11, &ivItem);
1323 if (!aes_ctx_pkcs11) { 1354 if (!aes_ctx_pkcs11) {
1324 SSL_DBG(("%d: SSL[%d]: Unable to create AES context.", 1355 SSL_DBG(("%d: SSL[%d]: Unable to create AES context.",
1325 SSL_GETPID(), ss->fd)); 1356 SSL_GETPID(), ss->fd));
1326 goto no_ticket; 1357 goto no_ticket;
1327 } 1358 }
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
1751 if (rv != SECSuccess) return -1; 1782 if (rv != SECSuccess) return -1;
1752 if (!ss->sec.isServer) { 1783 if (!ss->sec.isServer) {
1753 TLSExtensionData *xtnData = &ss->xtnData; 1784 TLSExtensionData *xtnData = &ss->xtnData;
1754 xtnData->advertised[xtnData->numAdvertised++] = 1785 xtnData->advertised[xtnData->numAdvertised++] =
1755 ssl_renegotiation_info_xtn; 1786 ssl_renegotiation_info_xtn;
1756 } 1787 }
1757 } 1788 }
1758 return needed; 1789 return needed;
1759 } 1790 }
1760 1791
1792 static SECStatus
1793 ssl3_ServerHandleStatusRequestXtn(sslSocket *ss, PRUint16 ex_type,
1794 SECItem *data)
1795 {
1796 SECStatus rv = SECSuccess;
1797 PRUint32 len = 0;
1798
1799 /* remember that we got this extension. */
1800 ss->xtnData.negotiated[ss->xtnData.numNegotiated++] = ex_type;
1801 PORT_Assert(ss->sec.isServer);
1802 /* prepare to send back the appropriate response */
1803 rv = ssl3_RegisterServerHelloExtensionSender(ss, ex_type,
1804 ssl3_ServerSendStatusRequestXtn);
1805 return rv;
1806 }
1807
1761 /* This function runs in both the client and server. */ 1808 /* This function runs in both the client and server. */
1762 static SECStatus 1809 static SECStatus
1763 ssl3_HandleRenegotiationInfoXtn(sslSocket *ss, PRUint16 ex_type, SECItem *data) 1810 ssl3_HandleRenegotiationInfoXtn(sslSocket *ss, PRUint16 ex_type, SECItem *data)
1764 { 1811 {
1765 SECStatus rv = SECSuccess; 1812 SECStatus rv = SECSuccess;
1766 PRUint32 len = 0; 1813 PRUint32 len = 0;
1767 1814
1768 if (ss->firstHsDone) { 1815 if (ss->firstHsDone) {
1769 len = ss->sec.isServer ? ss->ssl3.hs.finishedBytes 1816 len = ss->sec.isServer ? ss->ssl3.hs.finishedBytes
1770 : ss->ssl3.hs.finishedBytes * 2; 1817 : ss->ssl3.hs.finishedBytes * 2;
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1985 return SECSuccess; 2032 return SECSuccess;
1986 } 2033 }
1987 2034
1988 /* OK, we have a valid cipher and we've selected it */ 2035 /* OK, we have a valid cipher and we've selected it */
1989 ss->ssl3.dtlsSRTPCipherSuite = cipher; 2036 ss->ssl3.dtlsSRTPCipherSuite = cipher;
1990 ss->xtnData.negotiated[ss->xtnData.numNegotiated++] = ssl_use_srtp_xtn; 2037 ss->xtnData.negotiated[ss->xtnData.numNegotiated++] = ssl_use_srtp_xtn;
1991 2038
1992 return ssl3_RegisterServerHelloExtensionSender(ss, ssl_use_srtp_xtn, 2039 return ssl3_RegisterServerHelloExtensionSender(ss, ssl_use_srtp_xtn,
1993 ssl3_SendUseSRTPXtn); 2040 ssl3_SendUseSRTPXtn);
1994 } 2041 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698