| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "base/stl_util.h" | 6 #include "base/stl_util.h" |
| 7 #include "content/child/webcrypto/algorithm_dispatch.h" | 7 #include "content/child/webcrypto/algorithm_dispatch.h" |
| 8 #include "content/child/webcrypto/crypto_data.h" | 8 #include "content/child/webcrypto/crypto_data.h" |
| 9 #include "content/child/webcrypto/status.h" | 9 #include "content/child/webcrypto/status.h" |
| 10 #include "content/child/webcrypto/test/test_helpers.h" | 10 #include "content/child/webcrypto/test/test_helpers.h" |
| (...skipping 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1096 }; | 1096 }; |
| 1097 const TestCase kTests[] = { | 1097 const TestCase kTests[] = { |
| 1098 {blink::WebCryptoAlgorithmIdSha1, blink::WebCryptoKeyUsageVerify, "RS1"}, | 1098 {blink::WebCryptoAlgorithmIdSha1, blink::WebCryptoKeyUsageVerify, "RS1"}, |
| 1099 {blink::WebCryptoAlgorithmIdSha256, blink::WebCryptoKeyUsageVerify, | 1099 {blink::WebCryptoAlgorithmIdSha256, blink::WebCryptoKeyUsageVerify, |
| 1100 "RS256"}, | 1100 "RS256"}, |
| 1101 {blink::WebCryptoAlgorithmIdSha384, blink::WebCryptoKeyUsageVerify, | 1101 {blink::WebCryptoAlgorithmIdSha384, blink::WebCryptoKeyUsageVerify, |
| 1102 "RS384"}, | 1102 "RS384"}, |
| 1103 {blink::WebCryptoAlgorithmIdSha512, blink::WebCryptoKeyUsageVerify, | 1103 {blink::WebCryptoAlgorithmIdSha512, blink::WebCryptoKeyUsageVerify, |
| 1104 "RS512"}}; | 1104 "RS512"}}; |
| 1105 | 1105 |
| 1106 for (size_t test_index = 0; test_index < ARRAYSIZE_UNSAFE(kTests); | 1106 for (size_t test_index = 0; test_index < arraysize(kTests); ++test_index) { |
| 1107 ++test_index) { | |
| 1108 SCOPED_TRACE(test_index); | 1107 SCOPED_TRACE(test_index); |
| 1109 const TestCase& test = kTests[test_index]; | 1108 const TestCase& test = kTests[test_index]; |
| 1110 | 1109 |
| 1111 const blink::WebCryptoAlgorithm import_algorithm = | 1110 const blink::WebCryptoAlgorithm import_algorithm = |
| 1112 CreateRsaHashedImportAlgorithm( | 1111 CreateRsaHashedImportAlgorithm( |
| 1113 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, test.hash); | 1112 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, test.hash); |
| 1114 | 1113 |
| 1115 // Import the spki to create a public key | 1114 // Import the spki to create a public key |
| 1116 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); | 1115 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); |
| 1117 ASSERT_EQ(Status::Success(), | 1116 ASSERT_EQ(Status::Success(), |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1174 ImportKeyJwkFromDict(dict, algorithm, false, usage_mask, &key)); | 1173 ImportKeyJwkFromDict(dict, algorithm, false, usage_mask, &key)); |
| 1175 EXPECT_EQ(algorithm.id(), key.algorithm().id()); | 1174 EXPECT_EQ(algorithm.id(), key.algorithm().id()); |
| 1176 EXPECT_FALSE(key.extractable()); | 1175 EXPECT_FALSE(key.extractable()); |
| 1177 EXPECT_EQ(blink::WebCryptoKeyUsageVerify, key.usages()); | 1176 EXPECT_EQ(blink::WebCryptoKeyUsageVerify, key.usages()); |
| 1178 EXPECT_EQ(blink::WebCryptoKeyTypePublic, key.type()); | 1177 EXPECT_EQ(blink::WebCryptoKeyTypePublic, key.type()); |
| 1179 | 1178 |
| 1180 // The following are specific failure cases for when kty = "RSA". | 1179 // The following are specific failure cases for when kty = "RSA". |
| 1181 | 1180 |
| 1182 // Fail if either "n" or "e" is not present or malformed. | 1181 // Fail if either "n" or "e" is not present or malformed. |
| 1183 const std::string kKtyParmName[] = {"n", "e"}; | 1182 const std::string kKtyParmName[] = {"n", "e"}; |
| 1184 for (size_t idx = 0; idx < ARRAYSIZE_UNSAFE(kKtyParmName); ++idx) { | 1183 for (size_t idx = 0; idx < arraysize(kKtyParmName); ++idx) { |
| 1185 // Fail on missing parameter. | 1184 // Fail on missing parameter. |
| 1186 dict.Remove(kKtyParmName[idx], NULL); | 1185 dict.Remove(kKtyParmName[idx], NULL); |
| 1187 EXPECT_NE(Status::Success(), | 1186 EXPECT_NE(Status::Success(), |
| 1188 ImportKeyJwkFromDict(dict, algorithm, false, usage_mask, &key)); | 1187 ImportKeyJwkFromDict(dict, algorithm, false, usage_mask, &key)); |
| 1189 RestoreJwkRsaDictionary(&dict); | 1188 RestoreJwkRsaDictionary(&dict); |
| 1190 | 1189 |
| 1191 // Fail on bad b64 parameter encoding. | 1190 // Fail on bad b64 parameter encoding. |
| 1192 dict.SetString(kKtyParmName[idx], "Qk3f0DsytU8lfza2au #$% Htaw2xpop9yTuH0"); | 1191 dict.SetString(kKtyParmName[idx], "Qk3f0DsytU8lfza2au #$% Htaw2xpop9yTuH0"); |
| 1193 EXPECT_NE(Status::Success(), | 1192 EXPECT_NE(Status::Success(), |
| 1194 ImportKeyJwkFromDict(dict, algorithm, false, usage_mask, &key)); | 1193 ImportKeyJwkFromDict(dict, algorithm, false, usage_mask, &key)); |
| 1195 RestoreJwkRsaDictionary(&dict); | 1194 RestoreJwkRsaDictionary(&dict); |
| 1196 | 1195 |
| 1197 // Fail on empty parameter. | 1196 // Fail on empty parameter. |
| 1198 dict.SetString(kKtyParmName[idx], ""); | 1197 dict.SetString(kKtyParmName[idx], ""); |
| 1199 EXPECT_EQ(Status::ErrorJwkEmptyBigInteger(kKtyParmName[idx]), | 1198 EXPECT_EQ(Status::ErrorJwkEmptyBigInteger(kKtyParmName[idx]), |
| 1200 ImportKeyJwkFromDict(dict, algorithm, false, usage_mask, &key)); | 1199 ImportKeyJwkFromDict(dict, algorithm, false, usage_mask, &key)); |
| 1201 RestoreJwkRsaDictionary(&dict); | 1200 RestoreJwkRsaDictionary(&dict); |
| 1202 } | 1201 } |
| 1203 } | 1202 } |
| 1204 | 1203 |
| 1205 } // namespace | 1204 } // namespace |
| 1206 | 1205 |
| 1207 } // namespace webcrypto | 1206 } // namespace webcrypto |
| 1208 | 1207 |
| 1209 } // namespace content | 1208 } // namespace content |
| OLD | NEW |