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

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

Issue 7058049: Added client-side support for the TLS cached info extension. This feature is disabled by default ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 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
« no previous file with comments | « net/third_party/nss/ssl/ssl3con.c ('k') | net/third_party/nss/ssl/sslauth.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * SSL3 Protocol 2 * SSL3 Protocol
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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 }; 240 };
241 241
242 /* 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
243 * extensions. */ 243 * extensions. */
244 static const ssl3HelloExtensionHandler serverHelloHandlersTLS[] = { 244 static const ssl3HelloExtensionHandler serverHelloHandlersTLS[] = {
245 { ssl_server_name_xtn, &ssl3_HandleServerNameXtn }, 245 { ssl_server_name_xtn, &ssl3_HandleServerNameXtn },
246 /* TODO: add a handler for ssl_ec_point_formats_xtn */ 246 /* TODO: add a handler for ssl_ec_point_formats_xtn */
247 { ssl_session_ticket_xtn, &ssl3_ClientHandleSessionTicketXtn }, 247 { ssl_session_ticket_xtn, &ssl3_ClientHandleSessionTicketXtn },
248 { ssl_renegotiation_info_xtn, &ssl3_HandleRenegotiationInfoXtn }, 248 { ssl_renegotiation_info_xtn, &ssl3_HandleRenegotiationInfoXtn },
249 { ssl_next_proto_neg_xtn, &ssl3_ClientHandleNextProtoNegoXtn }, 249 { ssl_next_proto_neg_xtn, &ssl3_ClientHandleNextProtoNegoXtn },
250 { ssl_cached_info_xtn, &ssl3_ClientHandleCachedInfoXtn },
250 { ssl_cert_status_xtn, &ssl3_ClientHandleStatusRequestXtn }, 251 { ssl_cert_status_xtn, &ssl3_ClientHandleStatusRequestXtn },
251 { -1, NULL } 252 { -1, NULL }
252 }; 253 };
253 254
254 static const ssl3HelloExtensionHandler serverHelloHandlersSSL3[] = { 255 static const ssl3HelloExtensionHandler serverHelloHandlersSSL3[] = {
255 { ssl_renegotiation_info_xtn, &ssl3_HandleRenegotiationInfoXtn }, 256 { ssl_renegotiation_info_xtn, &ssl3_HandleRenegotiationInfoXtn },
256 { -1, NULL } 257 { -1, NULL }
257 }; 258 };
258 259
259 /* Tables of functions to format TLS hello extensions, one function per 260 /* Tables of functions to format TLS hello extensions, one function per
260 * extension. 261 * extension.
261 * These static tables are for the formatting of client hello extensions. 262 * These static tables are for the formatting of client hello extensions.
262 * The server's table of hello senders is dynamic, in the socket struct, 263 * The server's table of hello senders is dynamic, in the socket struct,
263 * and sender functions are registered there. 264 * and sender functions are registered there.
264 */ 265 */
265 static const 266 static const
266 ssl3HelloExtensionSender clientHelloSendersTLS[SSL_MAX_EXTENSIONS] = { 267 ssl3HelloExtensionSender clientHelloSendersTLS[SSL_MAX_EXTENSIONS] = {
267 { ssl_server_name_xtn, &ssl3_SendServerNameXtn }, 268 { ssl_server_name_xtn, &ssl3_SendServerNameXtn },
268 { ssl_renegotiation_info_xtn, &ssl3_SendRenegotiationInfoXtn }, 269 { ssl_renegotiation_info_xtn, &ssl3_SendRenegotiationInfoXtn },
269 #ifdef NSS_ENABLE_ECC 270 #ifdef NSS_ENABLE_ECC
270 { ssl_elliptic_curves_xtn, &ssl3_SendSupportedCurvesXtn }, 271 { ssl_elliptic_curves_xtn, &ssl3_SendSupportedCurvesXtn },
271 { ssl_ec_point_formats_xtn, &ssl3_SendSupportedPointFormatsXtn }, 272 { ssl_ec_point_formats_xtn, &ssl3_SendSupportedPointFormatsXtn },
272 #endif 273 #endif
273 { ssl_session_ticket_xtn, &ssl3_SendSessionTicketXtn }, 274 { ssl_session_ticket_xtn, &ssl3_SendSessionTicketXtn },
274 { ssl_next_proto_neg_xtn, &ssl3_ClientSendNextProtoNegoXtn }, 275 { ssl_next_proto_neg_xtn, &ssl3_ClientSendNextProtoNegoXtn },
276 { ssl_cached_info_xtn, &ssl3_ClientSendCachedInfoXtn },
275 { ssl_cert_status_xtn, &ssl3_ClientSendStatusRequestXtn } 277 { ssl_cert_status_xtn, &ssl3_ClientSendStatusRequestXtn }
276 /* any extra entries will appear as { 0, NULL } */ 278 /* any extra entries will appear as { 0, NULL } */
277 }; 279 };
278 280
279 static const 281 static const
280 ssl3HelloExtensionSender clientHelloSendersSSL3[SSL_MAX_EXTENSIONS] = { 282 ssl3HelloExtensionSender clientHelloSendersSSL3[SSL_MAX_EXTENSIONS] = {
281 { ssl_renegotiation_info_xtn, &ssl3_SendRenegotiationInfoXtn } 283 { ssl_renegotiation_info_xtn, &ssl3_SendRenegotiationInfoXtn }
282 /* any extra entries will appear as { 0, NULL } */ 284 /* any extra entries will appear as { 0, NULL } */
283 }; 285 };
284 286
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 return SECFailure; 671 return SECFailure;
670 672
671 ss->ssl3.hs.may_get_cert_status = PR_TRUE; 673 ss->ssl3.hs.may_get_cert_status = PR_TRUE;
672 674
673 /* Keep track of negotiated extensions. */ 675 /* Keep track of negotiated extensions. */
674 ss->xtnData.negotiated[ss->xtnData.numNegotiated++] = ex_type; 676 ss->xtnData.negotiated[ss->xtnData.numNegotiated++] = ex_type;
675 677
676 return SECSuccess; 678 return SECSuccess;
677 } 679 }
678 680
681 /* ssl3_ClientSendCachedInfoXtn builds the cached_info extension on the
682 * client side. */
683 PRInt32
684 ssl3_ClientSendCachedInfoXtn(sslSocket * ss, PRBool append,
685 PRUint32 maxBytes)
686 {
687 PRInt32 extension_length;
688 PRBool send_empty;
689 CERTCertificate ** predictedCertChain;
690
691 if (!ss->opt.enableCachedInfo)
692 return 0;
693
694 predictedCertChain = ss->ssl3.predictedCertChain;
695 send_empty = (predictedCertChain == NULL);
696
697 /* minimum extension:
698 * extension_type (2-bytes) +
699 * length(extension_data) (2-bytes) +
700 * length(cached_info) (2-bytes) +
701 */
702 extension_length = send_empty ? 6 : 16;
703
704 if (append && maxBytes >= extension_length) {
705 SECStatus rv;
706
707 /* ExtensionType */
708 rv = ssl3_AppendHandshakeNumber(ss, ssl_cached_info_xtn, 2);
709 if (rv != SECSuccess)
710 return -1;
711 /* Extension Length */
712 rv = ssl3_AppendHandshakeNumber(ss, extension_length - 4, 2);
713 if (rv != SECSuccess)
714 return -1;
715 if (send_empty) {
716 /* Cached Information Length */
717 rv = ssl3_AppendHandshakeNumber(ss, 0, 2);
718 if (rv != SECSuccess)
719 return -1;
720 } else {
721 PRUint64 certChainHash;
722 int i;
723 PRUint8* digestPtr = (PRUint8*) &certChainHash;
724
725 /* Cached Information Length */
726 rv = ssl3_AppendHandshakeNumber(ss, 10, 2);
727 if (rv != SECSuccess)
728 return -1;
729 /* Cached Information Type */
730 rv = ssl3_AppendHandshakeNumber(ss, 1 /* certificate_chain */, 1);
731 if (rv != SECSuccess)
732 return -1;
733 /* hash length */
734 rv = ssl3_AppendHandshakeNumber(ss, 8, 1);
735 if (rv != SECSuccess)
736 return -1;
737 /* hash */
738 FNV1A64_Init(&certChainHash);
739 for (i = 0; predictedCertChain[i] != NULL; i++) {
740 unsigned int certLen = predictedCertChain[i]->derCert.len;
741 unsigned char certLenArray[3] = {
742 (certLen & 0xff0000) >> 16,
743 (certLen & 0xff00) >> 8,
744 certLen & 0xff
745 };
746 FNV1A64_Update(&certChainHash, certLenArray, 3);
747 FNV1A64_Update(&certChainHash,
748 predictedCertChain[i]->derCert.data, certLen);
749 }
750 FNV1A64_Final(&certChainHash);
751 rv = ssl3_AppendHandshake(ss, &certChainHash, 8);
752 if (rv != SECSuccess)
753 return -1;
754 for (i = 0; i < 8; i++) {
755 ss->ssl3.certChainDigest[i] = digestPtr[i];
756 }
757 }
758
759 } else if (maxBytes < extension_length) {
760 PORT_Assert(0);
761 return 0;
762 }
763 ss->xtnData.advertised[ss->xtnData.numAdvertised++] =
764 ssl_cached_info_xtn;
765 return extension_length;
766 }
767
768 SECStatus
769 ssl3_ClientHandleCachedInfoXtn(sslSocket *ss, PRUint16 ex_type,
770 SECItem *data)
771 {
772 unsigned char * cached_info = data->data;
773 unsigned int remaining_cached_info_length;
774 PRBool has_correct_cert_chain = PR_FALSE;
775
776 /* If we didn't request this extension, then the server may not echo it. */
777 if (!ss->opt.enableCachedInfo)
778 return SECFailure;
779
780 if (data->len == 0) {
781 /* The server supports information caching, but provides no information
782 * about what information types it supports */
783 ss->xtnData.negotiated[ss->xtnData.numNegotiated++] = ex_type;
784 return SECSuccess;
785 }
786
787 if (data->len < 2)
788 return SECFailure;
789 remaining_cached_info_length = (cached_info[0] << 8) | cached_info[1];
790 if (remaining_cached_info_length != data->len - 2)
791 return SECFailure;
792 cached_info += 2;
793 while (remaining_cached_info_length >= 2) {
794 /* The server supports only those CachedInformationType types that are
795 * identified by a present CachedObject */
796 unsigned char cached_object_type;
797 unsigned int cached_object_length;
798 unsigned char cached_object_digest[8];
799 cached_object_type = *cached_info++;
800 cached_object_length = *cached_info++;
801 remaining_cached_info_length -= 2;
802 if (remaining_cached_info_length < cached_object_length)
803 return SECFailure;
804 if (cached_object_length != 0 && cached_object_length != 8)
805 return SECFailure;
806 remaining_cached_info_length -= cached_object_length;
807 if (cached_object_type == cached_info_certificate_chain) {
808 if (cached_object_length == 0)
809 has_correct_cert_chain = PR_TRUE;
810 else { /* Hashes must match */
811 int i;
812 for (i = 0; i < 8; i++)
813 cached_object_digest[i] = *cached_info++;
814 if (!memcmp(cached_object_digest, ss->ssl3.certChainDigest, 8))
815 has_correct_cert_chain = PR_TRUE;
816 }
817 }
818 }
819
820 if (remaining_cached_info_length != 0)
821 return SECFailure;
822
823 if (has_correct_cert_chain) {
824 ss->xtnData.negotiated[ss->xtnData.numNegotiated++] = ex_type;
825 return SECSuccess;
826 }
827
828 return SECFailure;
829 }
830
679 /* ssl3_ClientSendStatusRequestXtn builds the status_request extension on the 831 /* ssl3_ClientSendStatusRequestXtn builds the status_request extension on the
680 * client side. See RFC 4366 section 3.6. */ 832 * client side. See RFC 4366 section 3.6. */
681 PRInt32 833 PRInt32
682 ssl3_ClientSendStatusRequestXtn(sslSocket * ss, PRBool append, 834 ssl3_ClientSendStatusRequestXtn(sslSocket * ss, PRBool append,
683 PRUint32 maxBytes) 835 PRUint32 maxBytes)
684 { 836 {
685 PRInt32 extension_length; 837 PRInt32 extension_length;
686 838
687 if (!ss->opt.enableOCSPStapling) 839 if (!ss->opt.enableOCSPStapling)
688 return 0; 840 return 0;
(...skipping 1019 matching lines...) Expand 10 before | Expand all | Expand 10 after
1708 ss->peerRequestedProtection = 1; 1860 ss->peerRequestedProtection = 1;
1709 ss->xtnData.negotiated[ss->xtnData.numNegotiated++] = ex_type; 1861 ss->xtnData.negotiated[ss->xtnData.numNegotiated++] = ex_type;
1710 if (ss->sec.isServer) { 1862 if (ss->sec.isServer) {
1711 /* prepare to send back the appropriate response */ 1863 /* prepare to send back the appropriate response */
1712 rv = ssl3_RegisterServerHelloExtensionSender(ss, ex_type, 1864 rv = ssl3_RegisterServerHelloExtensionSender(ss, ex_type,
1713 ssl3_SendRenegotiationInfoXtn); 1865 ssl3_SendRenegotiationInfoXtn);
1714 } 1866 }
1715 return rv; 1867 return rv;
1716 } 1868 }
1717 1869
OLDNEW
« no previous file with comments | « net/third_party/nss/ssl/ssl3con.c ('k') | net/third_party/nss/ssl/sslauth.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698