OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 | |
690 if (!ss->opt.enableCachedInfo) | |
691 return 0; | |
692 | |
693 CERTCertificate ** predictedCertChain = ss->ssl3.predictedCertChain; | |
694 //send_empty = (predictedCertChain == NULL || predictedCertChain[0] == NULL) | |
695 // ? PR_TRUE : PR_FALSE; | |
wtc
2011/06/17 22:57:09
Declare predictedCertChain at the beginning of the
rkn
2011/06/20 21:21:09
Done.
| |
696 send_empty = (predictedCertChain == NULL) ? PR_TRUE : PR_FALSE; | |
wtc
2011/06/17 22:57:09
This can be written simply as:
send_empty = (p
rkn
2011/06/20 21:21:09
Done.
| |
697 | |
698 /* minimum extension: | |
699 * extension_type (2-bytes) + | |
700 * length(extension_data) (2-bytes) + | |
701 * length(cached_info) (2-bytes) + | |
702 */ | |
703 extension_length = send_empty ? 6 : 16; | |
704 | |
705 if (append && maxBytes >= extension_length) { | |
706 SECStatus rv; | |
707 | |
708 /* ExtensionType */ | |
709 rv = ssl3_AppendHandshakeNumber(ss, ssl_cached_info_xtn, 2); | |
710 if (rv != SECSuccess) | |
711 return -1; | |
712 /* Extension Length */ | |
713 rv = ssl3_AppendHandshakeNumber(ss, extension_length - 4, 2); | |
714 if (rv != SECSuccess) | |
715 return -1; | |
716 if (send_empty) { | |
717 /* Cached Information Length */ | |
718 rv = ssl3_AppendHandshakeNumber(ss, 0, 2); | |
719 if (rv != SECSuccess) | |
720 return -1; | |
721 } else { | |
722 /* Cached Information Length */ | |
723 rv = ssl3_AppendHandshakeNumber(ss, 10, 2); | |
724 if (rv != SECSuccess) | |
725 return -1; | |
726 /* Cached Information Type */ | |
727 rv = ssl3_AppendHandshakeNumber(ss, 1 /* certificate_chain */, 1); | |
728 if (rv != SECSuccess) | |
729 return -1; | |
730 /* hash length */ | |
731 rv = ssl3_AppendHandshakeNumber(ss, 8, 1); | |
732 if (rv != SECSuccess) | |
733 return -1; | |
734 /* hash */ | |
735 PRUint64 certChainHash; | |
736 FNV1A64_Init(&certChainHash); | |
737 int i; | |
738 for (i = 0; predictedCertChain[i] != NULL; i++) { | |
739 unsigned int certLen = predictedCertChain[i]->derCert.len; | |
740 unsigned char certLenArray[3] = | |
741 {(certLen & 0xff0000) >> 16, (certLen & 0xff00) >> 8, | |
742 certLen & 0xff}; | |
wtc
2011/06/17 22:57:09
Nit: format this as:
unsigned char certLenArra
rkn
2011/06/20 21:21:09
Done.
| |
743 FNV1A64_Update(&certChainHash, certLenArray, 3); | |
744 FNV1A64_Update(&certChainHash, | |
745 predictedCertChain[i]->derCert.data, certLen); | |
746 } | |
747 FNV1A64_Final(&certChainHash); | |
748 rv = ssl3_AppendHandshake(ss, &certChainHash, 8); | |
749 if (rv != SECSuccess) | |
750 return -1; | |
751 PRUint8* digestPtr = (PRUint8*) &certChainHash; | |
752 for (i = 0; i < 8; i++) { | |
753 ss->ssl3.certChainDigest[i] = digestPtr[i]; | |
754 } | |
755 } | |
756 | |
757 } else if (maxBytes < extension_length) { | |
758 PORT_Assert(0); | |
759 return 0; | |
760 } | |
761 ss->xtnData.advertised[ss->xtnData.numAdvertised++] = | |
762 ssl_cached_info_xtn; | |
763 return extension_length; | |
764 } | |
765 | |
766 SECStatus | |
767 ssl3_ClientHandleCachedInfoXtn(sslSocket *ss, PRUint16 ex_type, | |
768 SECItem *data) | |
769 { | |
770 /* If we didn't request this extension, then the server may not echo it. */ | |
771 if (!ss->opt.enableCachedInfo) | |
772 return SECFailure; | |
773 | |
774 if (data->len == 0) { | |
775 /* The server supports information caching, but provides no information | |
776 * about what information types it supports */ | |
777 ss->xtnData.negotiated[ss->xtnData.numNegotiated++] = ex_type; | |
778 return SECSuccess; | |
779 } | |
780 | |
781 if (data->len < 2) | |
782 return SECFailure; | |
783 unsigned char * cached_info = data->data; | |
784 unsigned int remaining_cached_info_length = | |
785 (cached_info[0] << 8) | cached_info[1]; | |
786 if (remaining_cached_info_length != data->len - 2) | |
787 return SECFailure; | |
788 cached_info += 2; | |
789 PRBool has_correct_cert_chain = PR_FALSE; | |
790 while (remaining_cached_info_length >= 2) { | |
791 /* The server supports only those CachedInformationType types that are | |
792 * identified by a present CachedObject */ | |
793 unsigned char cached_object_type; | |
794 unsigned int cached_object_length; | |
795 unsigned char cached_object_digest[8]; | |
796 cached_object_type = *cached_info++; | |
797 cached_object_length = *cached_info++; | |
798 remaining_cached_info_length -= 2; | |
799 if (remaining_cached_info_length < cached_object_length) | |
800 return SECFailure; | |
801 if (cached_object_length != 0 && cached_object_length != 8) | |
802 return SECFailure; | |
803 remaining_cached_info_length -= cached_object_length; | |
804 if (cached_object_type == cached_info_certificate_chain) { | |
805 if (cached_object_length == 0) | |
806 has_correct_cert_chain = PR_TRUE; | |
807 else { /* Hashes must match */ | |
808 int i; | |
809 for (i = 0; i < 8; i++) | |
810 cached_object_digest[i] = *cached_info++; | |
811 if (!memcmp(cached_object_digest, ss->ssl3.certChainDigest, 8)) | |
812 has_correct_cert_chain = PR_TRUE; | |
813 } | |
814 } | |
815 } | |
816 | |
817 if (remaining_cached_info_length != 0) | |
818 return SECFailure; | |
819 | |
820 if (has_correct_cert_chain) { | |
821 ss->xtnData.negotiated[ss->xtnData.numNegotiated++] = ex_type; | |
822 return SECSuccess; | |
823 } | |
824 | |
825 return SECFailure; | |
826 } | |
827 | |
679 /* ssl3_ClientSendStatusRequestXtn builds the status_request extension on the | 828 /* ssl3_ClientSendStatusRequestXtn builds the status_request extension on the |
680 * client side. See RFC 4366 section 3.6. */ | 829 * client side. See RFC 4366 section 3.6. */ |
681 PRInt32 | 830 PRInt32 |
682 ssl3_ClientSendStatusRequestXtn(sslSocket * ss, PRBool append, | 831 ssl3_ClientSendStatusRequestXtn(sslSocket * ss, PRBool append, |
683 PRUint32 maxBytes) | 832 PRUint32 maxBytes) |
684 { | 833 { |
685 PRInt32 extension_length; | 834 PRInt32 extension_length; |
686 | 835 |
687 if (!ss->opt.enableOCSPStapling) | 836 if (!ss->opt.enableOCSPStapling) |
688 return 0; | 837 return 0; |
(...skipping 1019 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1708 ss->peerRequestedProtection = 1; | 1857 ss->peerRequestedProtection = 1; |
1709 ss->xtnData.negotiated[ss->xtnData.numNegotiated++] = ex_type; | 1858 ss->xtnData.negotiated[ss->xtnData.numNegotiated++] = ex_type; |
1710 if (ss->sec.isServer) { | 1859 if (ss->sec.isServer) { |
1711 /* prepare to send back the appropriate response */ | 1860 /* prepare to send back the appropriate response */ |
1712 rv = ssl3_RegisterServerHelloExtensionSender(ss, ex_type, | 1861 rv = ssl3_RegisterServerHelloExtensionSender(ss, ex_type, |
1713 ssl3_SendRenegotiationInfoXtn); | 1862 ssl3_SendRenegotiationInfoXtn); |
1714 } | 1863 } |
1715 return rv; | 1864 return rv; |
1716 } | 1865 } |
1717 | 1866 |
OLD | NEW |