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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 EXPECT_EQ(1u, key.algorithm().hmacParams()->lengthBits()); | 201 EXPECT_EQ(1u, key.algorithm().hmacParams()->lengthBits()); |
202 | 202 |
203 std::vector<uint8_t> raw_key; | 203 std::vector<uint8_t> raw_key; |
204 ASSERT_EQ(Status::Success(), | 204 ASSERT_EQ(Status::Success(), |
205 ExportKey(blink::WebCryptoKeyFormatRaw, key, &raw_key)); | 205 ExportKey(blink::WebCryptoKeyFormatRaw, key, &raw_key)); |
206 ASSERT_EQ(1U, raw_key.size()); | 206 ASSERT_EQ(1U, raw_key.size()); |
207 | 207 |
208 EXPECT_FALSE(raw_key[0] & 0x7F); | 208 EXPECT_FALSE(raw_key[0] & 0x7F); |
209 } | 209 } |
210 | 210 |
| 211 TEST(WebCryptoHmacTest, ImportKeyEmptyUsage) { |
| 212 blink::WebCryptoKey key; |
| 213 std::string key_raw_hex_in = "025a8cf3f08b4f6c5f33bbc76a471939"; |
| 214 EXPECT_EQ( |
| 215 Status::ErrorCreateKeyEmptyUsages(), |
| 216 ImportKey(blink::WebCryptoKeyFormatRaw, |
| 217 CryptoData(HexStringToBytes(key_raw_hex_in)), |
| 218 CreateHmacImportAlgorithmNoLength( |
| 219 blink::WebCryptoAlgorithmIdSha1), |
| 220 true, 0, &key)); |
| 221 } |
| 222 |
211 TEST(WebCryptoHmacTest, ImportKeyJwkKeyOpsSignVerify) { | 223 TEST(WebCryptoHmacTest, ImportKeyJwkKeyOpsSignVerify) { |
212 blink::WebCryptoKey key; | 224 blink::WebCryptoKey key; |
213 base::DictionaryValue dict; | 225 base::DictionaryValue dict; |
214 dict.SetString("kty", "oct"); | 226 dict.SetString("kty", "oct"); |
215 dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg"); | 227 dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg"); |
216 base::ListValue* key_ops = new base::ListValue; | 228 base::ListValue* key_ops = new base::ListValue; |
217 dict.Set("key_ops", key_ops); // Takes ownership. | 229 dict.Set("key_ops", key_ops); // Takes ownership. |
218 | 230 |
219 key_ops->AppendString("sign"); | 231 key_ops->AppendString("sign"); |
220 | 232 |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 | 462 |
451 // HMAC SHA-384 | 463 // HMAC SHA-384 |
452 ImportExportJwkSymmetricKey( | 464 ImportExportJwkSymmetricKey( |
453 384, CreateHmacImportAlgorithmNoLength(blink::WebCryptoAlgorithmIdSha384), | 465 384, CreateHmacImportAlgorithmNoLength(blink::WebCryptoAlgorithmIdSha384), |
454 blink::WebCryptoKeyUsageSign, "HS384"); | 466 blink::WebCryptoKeyUsageSign, "HS384"); |
455 | 467 |
456 // HMAC SHA-512 | 468 // HMAC SHA-512 |
457 ImportExportJwkSymmetricKey( | 469 ImportExportJwkSymmetricKey( |
458 512, CreateHmacImportAlgorithmNoLength(blink::WebCryptoAlgorithmIdSha512), | 470 512, CreateHmacImportAlgorithmNoLength(blink::WebCryptoAlgorithmIdSha512), |
459 blink::WebCryptoKeyUsageVerify, "HS512"); | 471 blink::WebCryptoKeyUsageVerify, "HS512"); |
460 | |
461 // Zero usage value | |
462 ImportExportJwkSymmetricKey( | |
463 512, CreateHmacImportAlgorithmNoLength(blink::WebCryptoAlgorithmIdSha512), | |
464 0, "HS512"); | |
465 } | 472 } |
466 | 473 |
467 TEST(WebCryptoHmacTest, ExportJwkEmptyKey) { | 474 TEST(WebCryptoHmacTest, ExportJwkEmptyKey) { |
468 const blink::WebCryptoAlgorithm import_algorithm = | 475 const blink::WebCryptoAlgorithm import_algorithm = |
469 CreateHmacImportAlgorithmNoLength(blink::WebCryptoAlgorithmIdSha1); | 476 CreateHmacImportAlgorithmNoLength(blink::WebCryptoAlgorithmIdSha1); |
470 | 477 |
471 blink::WebCryptoKeyUsageMask usages = blink::WebCryptoKeyUsageSign; | 478 blink::WebCryptoKeyUsageMask usages = blink::WebCryptoKeyUsageSign; |
472 blink::WebCryptoKey key; | 479 blink::WebCryptoKey key; |
473 | 480 |
474 // Import a zero-byte HMAC key. | 481 // Import a zero-byte HMAC key. |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 EXPECT_EQ(Status::Success(), | 577 EXPECT_EQ(Status::Success(), |
571 ExportKey(blink::WebCryptoKeyFormatRaw, key, &raw_key)); | 578 ExportKey(blink::WebCryptoKeyFormatRaw, key, &raw_key)); |
572 EXPECT_BYTES_EQ(HexStringToBytes("b1f0"), raw_key); | 579 EXPECT_BYTES_EQ(HexStringToBytes("b1f0"), raw_key); |
573 } | 580 } |
574 | 581 |
575 } // namespace | 582 } // namespace |
576 | 583 |
577 } // namespace webcrypto | 584 } // namespace webcrypto |
578 | 585 |
579 } // namespace content | 586 } // namespace content |
OLD | NEW |