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 1182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1193 RestoreJwkRsaDictionary(&dict); | 1193 RestoreJwkRsaDictionary(&dict); |
1194 | 1194 |
1195 // Fail on empty parameter. | 1195 // Fail on empty parameter. |
1196 dict.SetString(kKtyParmName[idx], ""); | 1196 dict.SetString(kKtyParmName[idx], ""); |
1197 EXPECT_EQ(Status::ErrorJwkEmptyBigInteger(kKtyParmName[idx]), | 1197 EXPECT_EQ(Status::ErrorJwkEmptyBigInteger(kKtyParmName[idx]), |
1198 ImportKeyJwkFromDict(dict, algorithm, false, usages, &key)); | 1198 ImportKeyJwkFromDict(dict, algorithm, false, usages, &key)); |
1199 RestoreJwkRsaDictionary(&dict); | 1199 RestoreJwkRsaDictionary(&dict); |
1200 } | 1200 } |
1201 } | 1201 } |
1202 | 1202 |
| 1203 // Try importing an RSA-SSA key from JWK format, having specified both Sign and |
| 1204 // Verify usage, and an invalid JWK. |
| 1205 // |
| 1206 // The test must fail with a usage error BEFORE attempting to read the JWK data. |
| 1207 // Although both Sign and Verify are valid usages for RSA-SSA keys, it is |
| 1208 // invalid to have them both at the same time for one key (since Sign applies to |
| 1209 // private keys, whereas Verify applies to public keys). |
| 1210 // |
| 1211 // If the implementation does not fail fast, this test will crash dereferencing |
| 1212 // invalid memory. |
| 1213 TEST(WebCryptoRsaSsaTest, ImportRsaSsaJwkBadUsageFailFast) { |
| 1214 CryptoData bad_data(NULL, 128); // Invalid buffer of length 128. |
| 1215 |
| 1216 blink::WebCryptoKey key; |
| 1217 ASSERT_EQ( |
| 1218 Status::ErrorCreateKeyBadUsages(), |
| 1219 ImportKey(blink::WebCryptoKeyFormatJwk, |
| 1220 bad_data, |
| 1221 CreateRsaHashedImportAlgorithm( |
| 1222 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
| 1223 blink::WebCryptoAlgorithmIdSha256), |
| 1224 true, |
| 1225 blink::WebCryptoKeyUsageVerify | blink::WebCryptoKeyUsageSign, |
| 1226 &key)); |
| 1227 } |
| 1228 |
1203 } // namespace | 1229 } // namespace |
1204 | 1230 |
1205 } // namespace webcrypto | 1231 } // namespace webcrypto |
1206 | 1232 |
1207 } // namespace content | 1233 } // namespace content |
OLD | NEW |