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

Side by Side Diff: net/third_party/nss/ssl/ssl3ecc.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 /* ECC code moved here from ssl3con.c */ 8 /* ECC code moved here from ssl3con.c */
9 /* $Id: ssl3ecc.c,v 1.29 2012/06/11 02:38:30 emaldona%redhat.com Exp $ */ 9 /* $Id$ */
10 10
11 #include "nss.h" 11 #include "nss.h"
12 #include "cert.h" 12 #include "cert.h"
13 #include "ssl.h" 13 #include "ssl.h"
14 #include "cryptohi.h" /* for DSAU_ stuff */ 14 #include "cryptohi.h" /* for DSAU_ stuff */
15 #include "keyhi.h" 15 #include "keyhi.h"
16 #include "secder.h" 16 #include "secder.h"
17 #include "secitem.h" 17 #include "secitem.h"
18 18
19 #include "sslimpl.h" 19 #include "sslimpl.h"
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 } 962 }
963 } 963 }
964 } 964 }
965 965
966 /* Ask: is ANY ECC cipher suite enabled on this socket? */ 966 /* Ask: is ANY ECC cipher suite enabled on this socket? */
967 /* Order(N^2). Yuk. Also, this ignores export policy. */ 967 /* Order(N^2). Yuk. Also, this ignores export policy. */
968 PRBool 968 PRBool
969 ssl3_IsECCEnabled(sslSocket * ss) 969 ssl3_IsECCEnabled(sslSocket * ss)
970 { 970 {
971 const ssl3CipherSuite * suite; 971 const ssl3CipherSuite * suite;
972 PK11SlotInfo *slot;
972 973
974 /* make sure we can do ECC */
975 slot = PK11_GetBestSlot(CKM_ECDH1_DERIVE, ss->pkcs11PinArg);
976 if (!slot) {
977 return PR_FALSE;
978 }
979 PK11_FreeSlot(slot);
980
981 /* make sure an ECC cipher is enabled */
973 for (suite = ecSuites; *suite; ++suite) { 982 for (suite = ecSuites; *suite; ++suite) {
974 PRBool enabled = PR_FALSE; 983 PRBool enabled = PR_FALSE;
975 SECStatus rv = ssl3_CipherPrefGet(ss, *suite, &enabled); 984 SECStatus rv = ssl3_CipherPrefGet(ss, *suite, &enabled);
976 985
977 PORT_Assert(rv == SECSuccess); /* else is coding error */ 986 PORT_Assert(rv == SECSuccess); /* else is coding error */
978 if (rv == SECSuccess && enabled) 987 if (rv == SECSuccess && enabled)
979 return PR_TRUE; 988 return PR_TRUE;
980 } 989 }
981 return PR_FALSE; 990 return PR_FALSE;
982 } 991 }
983 992
984 #define BE(n) 0, n 993 #define BE(n) 0, n
985 994
986 #ifndef NSS_ECC_MORE_THAN_SUITE_B
987 /* Prefabricated TLS client hello extension, Elliptic Curves List, 995 /* Prefabricated TLS client hello extension, Elliptic Curves List,
988 * offers only 3 curves, the Suite B curves, 23-25 996 * offers only 3 curves, the Suite B curves, 23-25
989 */ 997 */
990 static const PRUint8 EClist[12] = { 998 static const PRUint8 suiteBECList[12] = {
991 BE(10), /* Extension type */ 999 BE(10), /* Extension type */
992 BE( 8), /* octets that follow ( 3 pairs + 1 length pair) */ 1000 BE( 8), /* octets that follow ( 3 pairs + 1 length pair) */
993 BE( 6), /* octets that follow ( 3 pairs) */ 1001 BE( 6), /* octets that follow ( 3 pairs) */
994 BE(23), BE(24), BE(25) 1002 BE(23), BE(24), BE(25)
995 }; 1003 };
996 #else 1004
997 /* Prefabricated TLS client hello extension, Elliptic Curves List, 1005 /* Prefabricated TLS client hello extension, Elliptic Curves List,
998 * offers curves 1-25. 1006 * offers curves 1-25.
999 */ 1007 */
1000 static const PRUint8 EClist[56] = { 1008 static const PRUint8 tlsECList[56] = {
1001 BE(10), /* Extension type */ 1009 BE(10), /* Extension type */
1002 BE(52), /* octets that follow (25 pairs + 1 length pair) */ 1010 BE(52), /* octets that follow (25 pairs + 1 length pair) */
1003 BE(50), /* octets that follow (25 pairs) */ 1011 BE(50), /* octets that follow (25 pairs) */
1004 BE( 1), BE( 2), BE( 3), BE( 4), BE( 5), BE( 6), BE( 7), 1012 BE( 1), BE( 2), BE( 3), BE( 4), BE( 5), BE( 6), BE( 7),
1005 BE( 8), BE( 9), BE(10), BE(11), BE(12), BE(13), BE(14), BE(15), 1013 BE( 8), BE( 9), BE(10), BE(11), BE(12), BE(13), BE(14), BE(15),
1006 BE(16), BE(17), BE(18), BE(19), BE(20), BE(21), BE(22), BE(23), 1014 BE(16), BE(17), BE(18), BE(19), BE(20), BE(21), BE(22), BE(23),
1007 BE(24), BE(25) 1015 BE(24), BE(25)
1008 }; 1016 };
1009 #endif
1010 1017
1011 static const PRUint8 ECPtFmt[6] = { 1018 static const PRUint8 ECPtFmt[6] = {
1012 BE(11), /* Extension type */ 1019 BE(11), /* Extension type */
1013 BE( 2), /* octets that follow */ 1020 BE( 2), /* octets that follow */
1014 1, /* octets that follow */ 1021 1, /* octets that follow */
1015 0 /* uncompressed type only */ 1022 0 /* uncompressed type only */
1016 }; 1023 };
1017 1024
1025 /* This function already presumes we can do ECC, ssl_IsECCEnabled must be
1026 * called before this function. It looks to see if we have a token which
1027 * is capable of doing smaller than SuiteB curves. If the token can, we
1028 * presume the token can do the whole SSL suite of curves. If it can't we
1029 * presume the token that allowed ECC to be enabled can only do suite B
1030 * curves. */
1031 static PRBool
1032 ssl3_SuiteBOnly(sslSocket *ss)
1033 {
1034 #if 0
1035 /* look to see if we can handle certs less than 163 bits */
1036 PK11SlotInfo *slot =
1037 PK11_GetBestSlotWithAttributes(CKM_ECDH1_DERIVE, 0, 163,
1038 ss ? ss->pkcs11PinArg : NULL);
1039
1040 if (!slot) {
1041 /* nope, presume we can only do suite B */
1042 return PR_TRUE;
1043 }
1044 /* we can, presume we can do all curves */
1045 PK11_FreeSlot(slot);
1046 return PR_FALSE;
1047 #else
1048 return PR_TRUE;
1049 #endif
1050 }
1051
1018 /* Send our "canned" (precompiled) Supported Elliptic Curves extension, 1052 /* Send our "canned" (precompiled) Supported Elliptic Curves extension,
1019 * which says that we support all TLS-defined named curves. 1053 * which says that we support all TLS-defined named curves.
1020 */ 1054 */
1021 PRInt32 1055 PRInt32
1022 ssl3_SendSupportedCurvesXtn( 1056 ssl3_SendSupportedCurvesXtn(
1023 sslSocket * ss, 1057 sslSocket * ss,
1024 PRBool append, 1058 PRBool append,
1025 PRUint32 maxBytes) 1059 PRUint32 maxBytes)
1026 { 1060 {
1061 int ECListSize = 0;
agl 2013/05/02 14:43:57 nit: starting with a capital letter is odd for a l
wtc 2013/05/02 22:32:00 Done.
1062 const PRUint8 *ECList = NULL;
1063
1027 if (!ss || !ssl3_IsECCEnabled(ss)) 1064 if (!ss || !ssl3_IsECCEnabled(ss))
1028 return 0; 1065 return 0;
1029 if (append && maxBytes >= (sizeof EClist)) { 1066
1030 » SECStatus rv = ssl3_AppendHandshake(ss, EClist, (sizeof EClist)); 1067 if (ssl3_SuiteBOnly(ss)) {
1068 » ECListSize = sizeof (suiteBECList);
1069 » ECList = suiteBECList;
1070 } else {
1071 » ECListSize = sizeof (tlsECList);
1072 » ECList = tlsECList;
1073 }
1074
1075 if (append && maxBytes >= ECListSize) {
1076 » SECStatus rv = ssl3_AppendHandshake(ss, ECList, ECListSize);
1031 if (rv != SECSuccess) 1077 if (rv != SECSuccess)
1032 return -1; 1078 return -1;
1033 if (!ss->sec.isServer) { 1079 if (!ss->sec.isServer) {
1034 TLSExtensionData *xtnData = &ss->xtnData; 1080 TLSExtensionData *xtnData = &ss->xtnData;
1035 xtnData->advertised[xtnData->numAdvertised++] = 1081 xtnData->advertised[xtnData->numAdvertised++] =
1036 ssl_elliptic_curves_xtn; 1082 ssl_elliptic_curves_xtn;
1037 } 1083 }
1038 } 1084 }
1039 return (sizeof EClist); 1085 return ECListSize;
1086 }
1087
1088 PRInt32
1089 ssl3_GetSupportedECCCurveMask(sslSocket *ss)
1090 {
1091 if (ssl3_SuiteBOnly(ss)) {
1092 » return SSL3_SUITE_B_SUPPORTED_CURVES_MASK;
1093 }
1094 return SSL3_ALL_SUPPORTED_CURVES_MASK;
1040 } 1095 }
1041 1096
1042 /* Send our "canned" (precompiled) Supported Point Formats extension, 1097 /* Send our "canned" (precompiled) Supported Point Formats extension,
1043 * which says that we only support uncompressed points. 1098 * which says that we only support uncompressed points.
1044 */ 1099 */
1045 PRInt32 1100 PRInt32
1046 ssl3_SendSupportedPointFormatsXtn( 1101 ssl3_SendSupportedPointFormatsXtn(
1047 sslSocket * ss, 1102 sslSocket * ss,
1048 PRBool append, 1103 PRBool append,
1049 PRUint32 maxBytes) 1104 PRUint32 maxBytes)
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 ssl3_DisableECCSuites(ss, ecdhe_ecdsa_suites); 1213 ssl3_DisableECCSuites(ss, ecdhe_ecdsa_suites);
1159 return SECFailure; 1214 return SECFailure;
1160 1215
1161 loser: 1216 loser:
1162 /* no common curve supported */ 1217 /* no common curve supported */
1163 ssl3_DisableECCSuites(ss, ecSuites); 1218 ssl3_DisableECCSuites(ss, ecSuites);
1164 return SECFailure; 1219 return SECFailure;
1165 } 1220 }
1166 1221
1167 #endif /* NSS_ENABLE_ECC */ 1222 #endif /* NSS_ENABLE_ECC */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698