| 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/stl_util.h" | 5 #include "base/stl_util.h" |
| 6 #include "content/child/webcrypto/algorithm_dispatch.h" | 6 #include "content/child/webcrypto/algorithm_dispatch.h" |
| 7 #include "content/child/webcrypto/crypto_data.h" | 7 #include "content/child/webcrypto/crypto_data.h" |
| 8 #include "content/child/webcrypto/status.h" | 8 #include "content/child/webcrypto/status.h" |
| 9 #include "content/child/webcrypto/test/test_helpers.h" | 9 #include "content/child/webcrypto/test/test_helpers.h" |
| 10 #include "content/child/webcrypto/webcrypto_util.h" | 10 #include "content/child/webcrypto/webcrypto_util.h" |
| 11 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" | 11 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" |
| 12 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" | 12 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 | 15 |
| 16 namespace webcrypto { | 16 namespace webcrypto { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 blink::WebCryptoAlgorithm CreateAesKwKeyGenAlgorithm( | 20 blink::WebCryptoAlgorithm CreateAesKwKeyGenAlgorithm( |
| 21 unsigned short key_length_bits) { | 21 unsigned short key_length_bits) { |
| 22 return CreateAesKeyGenAlgorithm(blink::WebCryptoAlgorithmIdAesKw, | 22 return CreateAesKeyGenAlgorithm(blink::WebCryptoAlgorithmIdAesKw, |
| 23 key_length_bits); | 23 key_length_bits); |
| 24 } | 24 } |
| 25 | 25 |
| 26 TEST(WebCryptoAesKwTest, GenerateKeyBadLength) { | 26 TEST(WebCryptoAesKwTest, GenerateKeyBadLength) { |
| 27 const unsigned short kKeyLen[] = {0, 127, 257}; | 27 const unsigned short kKeyLen[] = {0, 127, 257}; |
| 28 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); | 28 blink::WebCryptoKey key; |
| 29 for (size_t i = 0; i < arraysize(kKeyLen); ++i) { | 29 for (size_t i = 0; i < arraysize(kKeyLen); ++i) { |
| 30 SCOPED_TRACE(i); | 30 SCOPED_TRACE(i); |
| 31 EXPECT_EQ(Status::ErrorGenerateKeyLength(), | 31 EXPECT_EQ(Status::ErrorGenerateKeyLength(), |
| 32 GenerateSecretKey( | 32 GenerateSecretKey( |
| 33 CreateAesKwKeyGenAlgorithm(kKeyLen[i]), true, 0, &key)); | 33 CreateAesKwKeyGenAlgorithm(kKeyLen[i]), true, 0, &key)); |
| 34 } | 34 } |
| 35 } | 35 } |
| 36 | 36 |
| 37 TEST(WebCryptoAesKwTest, ImportKeyJwkKeyOpsWrapUnwrap) { | 37 TEST(WebCryptoAesKwTest, ImportKeyJwkKeyOpsWrapUnwrap) { |
| 38 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); | 38 blink::WebCryptoKey key; |
| 39 base::DictionaryValue dict; | 39 base::DictionaryValue dict; |
| 40 dict.SetString("kty", "oct"); | 40 dict.SetString("kty", "oct"); |
| 41 dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg=="); | 41 dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg=="); |
| 42 base::ListValue* key_ops = new base::ListValue; | 42 base::ListValue* key_ops = new base::ListValue; |
| 43 dict.Set("key_ops", key_ops); // Takes ownership. | 43 dict.Set("key_ops", key_ops); // Takes ownership. |
| 44 | 44 |
| 45 key_ops->AppendString("wrapKey"); | 45 key_ops->AppendString("wrapKey"); |
| 46 | 46 |
| 47 EXPECT_EQ( | 47 EXPECT_EQ( |
| 48 Status::Success(), | 48 Status::Success(), |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 80 |
| 81 // AES-KW 256 | 81 // AES-KW 256 |
| 82 ImportExportJwkSymmetricKey( | 82 ImportExportJwkSymmetricKey( |
| 83 256, | 83 256, |
| 84 algorithm, | 84 algorithm, |
| 85 blink::WebCryptoKeyUsageWrapKey | blink::WebCryptoKeyUsageUnwrapKey, | 85 blink::WebCryptoKeyUsageWrapKey | blink::WebCryptoKeyUsageUnwrapKey, |
| 86 "A256KW"); | 86 "A256KW"); |
| 87 } | 87 } |
| 88 | 88 |
| 89 TEST(WebCryptoAesKwTest, AesKwKeyImport) { | 89 TEST(WebCryptoAesKwTest, AesKwKeyImport) { |
| 90 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); | 90 blink::WebCryptoKey key; |
| 91 blink::WebCryptoAlgorithm algorithm = | 91 blink::WebCryptoAlgorithm algorithm = |
| 92 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesKw); | 92 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesKw); |
| 93 | 93 |
| 94 // Import a 128-bit Key Encryption Key (KEK) | 94 // Import a 128-bit Key Encryption Key (KEK) |
| 95 std::string key_raw_hex_in = "025a8cf3f08b4f6c5f33bbc76a471939"; | 95 std::string key_raw_hex_in = "025a8cf3f08b4f6c5f33bbc76a471939"; |
| 96 ASSERT_EQ(Status::Success(), | 96 ASSERT_EQ(Status::Success(), |
| 97 ImportKey(blink::WebCryptoKeyFormatRaw, | 97 ImportKey(blink::WebCryptoKeyFormatRaw, |
| 98 CryptoData(HexStringToBytes(key_raw_hex_in)), | 98 CryptoData(HexStringToBytes(key_raw_hex_in)), |
| 99 algorithm, | 99 algorithm, |
| 100 true, | 100 true, |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 TEST(WebCryptoAesKwTest, UnwrapFailures) { | 173 TEST(WebCryptoAesKwTest, UnwrapFailures) { |
| 174 // This test exercises the code path common to all unwrap operations. | 174 // This test exercises the code path common to all unwrap operations. |
| 175 scoped_ptr<base::ListValue> tests; | 175 scoped_ptr<base::ListValue> tests; |
| 176 ASSERT_TRUE(ReadJsonTestFileToList("aes_kw.json", &tests)); | 176 ASSERT_TRUE(ReadJsonTestFileToList("aes_kw.json", &tests)); |
| 177 base::DictionaryValue* test; | 177 base::DictionaryValue* test; |
| 178 ASSERT_TRUE(tests->GetDictionary(0, &test)); | 178 ASSERT_TRUE(tests->GetDictionary(0, &test)); |
| 179 const std::vector<uint8_t> test_kek = GetBytesFromHexString(test, "kek"); | 179 const std::vector<uint8_t> test_kek = GetBytesFromHexString(test, "kek"); |
| 180 const std::vector<uint8_t> test_ciphertext = | 180 const std::vector<uint8_t> test_ciphertext = |
| 181 GetBytesFromHexString(test, "ciphertext"); | 181 GetBytesFromHexString(test, "ciphertext"); |
| 182 | 182 |
| 183 blink::WebCryptoKey unwrapped_key = blink::WebCryptoKey::createNull(); | 183 blink::WebCryptoKey unwrapped_key; |
| 184 | 184 |
| 185 // Using a wrapping algorithm that does not match the wrapping key algorithm | 185 // Using a wrapping algorithm that does not match the wrapping key algorithm |
| 186 // should fail. | 186 // should fail. |
| 187 blink::WebCryptoKey wrapping_key = | 187 blink::WebCryptoKey wrapping_key = |
| 188 ImportSecretKeyFromRaw(test_kek, | 188 ImportSecretKeyFromRaw(test_kek, |
| 189 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesKw), | 189 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesKw), |
| 190 blink::WebCryptoKeyUsageUnwrapKey); | 190 blink::WebCryptoKeyUsageUnwrapKey); |
| 191 EXPECT_EQ(Status::ErrorUnexpected(), | 191 EXPECT_EQ(Status::ErrorUnexpected(), |
| 192 UnwrapKey(blink::WebCryptoKeyFormatRaw, | 192 UnwrapKey(blink::WebCryptoKeyFormatRaw, |
| 193 CryptoData(test_ciphertext), | 193 CryptoData(test_ciphertext), |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 std::vector<uint8_t> wrapped_key; | 230 std::vector<uint8_t> wrapped_key; |
| 231 ASSERT_EQ(Status::Success(), | 231 ASSERT_EQ(Status::Success(), |
| 232 WrapKey(blink::WebCryptoKeyFormatRaw, | 232 WrapKey(blink::WebCryptoKeyFormatRaw, |
| 233 key, | 233 key, |
| 234 wrapping_key, | 234 wrapping_key, |
| 235 wrapping_algorithm, | 235 wrapping_algorithm, |
| 236 &wrapped_key)); | 236 &wrapped_key)); |
| 237 EXPECT_BYTES_EQ(test_ciphertext, wrapped_key); | 237 EXPECT_BYTES_EQ(test_ciphertext, wrapped_key); |
| 238 | 238 |
| 239 // Unwrap the known ciphertext to get a new test_key. | 239 // Unwrap the known ciphertext to get a new test_key. |
| 240 blink::WebCryptoKey unwrapped_key = blink::WebCryptoKey::createNull(); | 240 blink::WebCryptoKey unwrapped_key; |
| 241 ASSERT_EQ( | 241 ASSERT_EQ( |
| 242 Status::Success(), | 242 Status::Success(), |
| 243 UnwrapKey(blink::WebCryptoKeyFormatRaw, | 243 UnwrapKey(blink::WebCryptoKeyFormatRaw, |
| 244 CryptoData(test_ciphertext), | 244 CryptoData(test_ciphertext), |
| 245 wrapping_key, | 245 wrapping_key, |
| 246 wrapping_algorithm, | 246 wrapping_algorithm, |
| 247 CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha1), | 247 CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha1), |
| 248 true, | 248 true, |
| 249 blink::WebCryptoKeyUsageSign, | 249 blink::WebCryptoKeyUsageSign, |
| 250 &unwrapped_key)); | 250 &unwrapped_key)); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 275 const std::vector<uint8_t> test_ciphertext = | 275 const std::vector<uint8_t> test_ciphertext = |
| 276 GetBytesFromHexString(test, "ciphertext"); | 276 GetBytesFromHexString(test, "ciphertext"); |
| 277 const blink::WebCryptoAlgorithm wrapping_algorithm = | 277 const blink::WebCryptoAlgorithm wrapping_algorithm = |
| 278 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesKw); | 278 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesKw); |
| 279 | 279 |
| 280 // Import the wrapping key. | 280 // Import the wrapping key. |
| 281 blink::WebCryptoKey wrapping_key = ImportSecretKeyFromRaw( | 281 blink::WebCryptoKey wrapping_key = ImportSecretKeyFromRaw( |
| 282 test_kek, wrapping_algorithm, blink::WebCryptoKeyUsageUnwrapKey); | 282 test_kek, wrapping_algorithm, blink::WebCryptoKeyUsageUnwrapKey); |
| 283 | 283 |
| 284 // Unwrap the known ciphertext. | 284 // Unwrap the known ciphertext. |
| 285 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); | 285 blink::WebCryptoKey key; |
| 286 ASSERT_EQ( | 286 ASSERT_EQ( |
| 287 Status::Success(), | 287 Status::Success(), |
| 288 UnwrapKey(blink::WebCryptoKeyFormatRaw, | 288 UnwrapKey(blink::WebCryptoKeyFormatRaw, |
| 289 CryptoData(test_ciphertext), | 289 CryptoData(test_ciphertext), |
| 290 wrapping_key, | 290 wrapping_key, |
| 291 wrapping_algorithm, | 291 wrapping_algorithm, |
| 292 CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha1), | 292 CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha1), |
| 293 false, | 293 false, |
| 294 blink::WebCryptoKeyUsageSign | blink::WebCryptoKeyUsageVerify, | 294 blink::WebCryptoKeyUsageSign | blink::WebCryptoKeyUsageVerify, |
| 295 &key)); | 295 &key)); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 blink::WebCryptoKeyUsageWrapKey | blink::WebCryptoKeyUsageUnwrapKey); | 342 blink::WebCryptoKeyUsageWrapKey | blink::WebCryptoKeyUsageUnwrapKey); |
| 343 // Import the key to be wrapped. | 343 // Import the key to be wrapped. |
| 344 blink::WebCryptoKey key = | 344 blink::WebCryptoKey key = |
| 345 ImportSecretKeyFromRaw(test_key, | 345 ImportSecretKeyFromRaw(test_key, |
| 346 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc), | 346 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc), |
| 347 blink::WebCryptoKeyUsageEncrypt); | 347 blink::WebCryptoKeyUsageEncrypt); |
| 348 | 348 |
| 349 // Unwrap with wrapped data too small must fail. | 349 // Unwrap with wrapped data too small must fail. |
| 350 const std::vector<uint8_t> small_data(test_ciphertext.begin(), | 350 const std::vector<uint8_t> small_data(test_ciphertext.begin(), |
| 351 test_ciphertext.begin() + 23); | 351 test_ciphertext.begin() + 23); |
| 352 blink::WebCryptoKey unwrapped_key = blink::WebCryptoKey::createNull(); | 352 blink::WebCryptoKey unwrapped_key; |
| 353 EXPECT_EQ(Status::ErrorDataTooSmall(), | 353 EXPECT_EQ(Status::ErrorDataTooSmall(), |
| 354 UnwrapKey(blink::WebCryptoKeyFormatRaw, | 354 UnwrapKey(blink::WebCryptoKeyFormatRaw, |
| 355 CryptoData(small_data), | 355 CryptoData(small_data), |
| 356 wrapping_key, | 356 wrapping_key, |
| 357 wrapping_algorithm, | 357 wrapping_algorithm, |
| 358 key_algorithm, | 358 key_algorithm, |
| 359 true, | 359 true, |
| 360 blink::WebCryptoKeyUsageEncrypt, | 360 blink::WebCryptoKeyUsageEncrypt, |
| 361 &unwrapped_key)); | 361 &unwrapped_key)); |
| 362 | 362 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 388 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesKw); | 388 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesKw); |
| 389 | 389 |
| 390 // Import the wrapping key. | 390 // Import the wrapping key. |
| 391 blink::WebCryptoKey wrapping_key = ImportSecretKeyFromRaw( | 391 blink::WebCryptoKey wrapping_key = ImportSecretKeyFromRaw( |
| 392 test_kek, | 392 test_kek, |
| 393 wrapping_algorithm, | 393 wrapping_algorithm, |
| 394 blink::WebCryptoKeyUsageWrapKey | blink::WebCryptoKeyUsageUnwrapKey); | 394 blink::WebCryptoKeyUsageWrapKey | blink::WebCryptoKeyUsageUnwrapKey); |
| 395 | 395 |
| 396 // Unwrap of a corrupted version of the known ciphertext should fail, due to | 396 // Unwrap of a corrupted version of the known ciphertext should fail, due to |
| 397 // AES-KW's built-in integrity check. | 397 // AES-KW's built-in integrity check. |
| 398 blink::WebCryptoKey unwrapped_key = blink::WebCryptoKey::createNull(); | 398 blink::WebCryptoKey unwrapped_key; |
| 399 EXPECT_EQ(Status::OperationError(), | 399 EXPECT_EQ(Status::OperationError(), |
| 400 UnwrapKey(blink::WebCryptoKeyFormatRaw, | 400 UnwrapKey(blink::WebCryptoKeyFormatRaw, |
| 401 CryptoData(Corrupted(test_ciphertext)), | 401 CryptoData(Corrupted(test_ciphertext)), |
| 402 wrapping_key, | 402 wrapping_key, |
| 403 wrapping_algorithm, | 403 wrapping_algorithm, |
| 404 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc), | 404 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc), |
| 405 true, | 405 true, |
| 406 blink::WebCryptoKeyUsageEncrypt, | 406 blink::WebCryptoKeyUsageEncrypt, |
| 407 &unwrapped_key)); | 407 &unwrapped_key)); |
| 408 } | 408 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 425 const std::vector<uint8_t> wrapping_key_data = | 425 const std::vector<uint8_t> wrapping_key_data = |
| 426 HexStringToBytes("000102030405060708090A0B0C0D0E0F"); | 426 HexStringToBytes("000102030405060708090A0B0C0D0E0F"); |
| 427 const blink::WebCryptoAlgorithm wrapping_algorithm = | 427 const blink::WebCryptoAlgorithm wrapping_algorithm = |
| 428 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesKw); | 428 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesKw); |
| 429 | 429 |
| 430 // Import the wrapping key. | 430 // Import the wrapping key. |
| 431 blink::WebCryptoKey wrapping_key = ImportSecretKeyFromRaw( | 431 blink::WebCryptoKey wrapping_key = ImportSecretKeyFromRaw( |
| 432 wrapping_key_data, wrapping_algorithm, blink::WebCryptoKeyUsageUnwrapKey); | 432 wrapping_key_data, wrapping_algorithm, blink::WebCryptoKeyUsageUnwrapKey); |
| 433 | 433 |
| 434 // Unwrap the known wrapped key data to produce a new key | 434 // Unwrap the known wrapped key data to produce a new key |
| 435 blink::WebCryptoKey unwrapped_key = blink::WebCryptoKey::createNull(); | 435 blink::WebCryptoKey unwrapped_key; |
| 436 ASSERT_EQ( | 436 ASSERT_EQ( |
| 437 Status::Success(), | 437 Status::Success(), |
| 438 UnwrapKey(blink::WebCryptoKeyFormatJwk, | 438 UnwrapKey(blink::WebCryptoKeyFormatJwk, |
| 439 CryptoData(wrapped_key_data), | 439 CryptoData(wrapped_key_data), |
| 440 wrapping_key, | 440 wrapping_key, |
| 441 wrapping_algorithm, | 441 wrapping_algorithm, |
| 442 CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha256), | 442 CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha256), |
| 443 true, | 443 true, |
| 444 blink::WebCryptoKeyUsageVerify, | 444 blink::WebCryptoKeyUsageVerify, |
| 445 &unwrapped_key)); | 445 &unwrapped_key)); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 476 blink::WebCryptoKeyUsageSign | blink::WebCryptoKeyUsageUnwrapKey, | 476 blink::WebCryptoKeyUsageSign | blink::WebCryptoKeyUsageUnwrapKey, |
| 477 blink::WebCryptoKeyUsageDeriveBits, | 477 blink::WebCryptoKeyUsageDeriveBits, |
| 478 blink::WebCryptoKeyUsageUnwrapKey | blink::WebCryptoKeyUsageVerify, | 478 blink::WebCryptoKeyUsageUnwrapKey | blink::WebCryptoKeyUsageVerify, |
| 479 }; | 479 }; |
| 480 | 480 |
| 481 std::vector<uint8_t> key_bytes(16); | 481 std::vector<uint8_t> key_bytes(16); |
| 482 | 482 |
| 483 for (size_t i = 0; i < arraysize(bad_usages); ++i) { | 483 for (size_t i = 0; i < arraysize(bad_usages); ++i) { |
| 484 SCOPED_TRACE(i); | 484 SCOPED_TRACE(i); |
| 485 | 485 |
| 486 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); | 486 blink::WebCryptoKey key; |
| 487 ASSERT_EQ(Status::ErrorCreateKeyBadUsages(), | 487 ASSERT_EQ(Status::ErrorCreateKeyBadUsages(), |
| 488 ImportKey(blink::WebCryptoKeyFormatRaw, | 488 ImportKey(blink::WebCryptoKeyFormatRaw, |
| 489 CryptoData(key_bytes), | 489 CryptoData(key_bytes), |
| 490 algorithm, | 490 algorithm, |
| 491 true, | 491 true, |
| 492 bad_usages[i], | 492 bad_usages[i], |
| 493 &key)); | 493 &key)); |
| 494 } | 494 } |
| 495 } | 495 } |
| 496 | 496 |
| 497 // Try unwrapping an HMAC key with unsupported usages using JWK format and | 497 // Try unwrapping an HMAC key with unsupported usages using JWK format and |
| 498 // AES-KW. HMAC keys support the following usages: | 498 // AES-KW. HMAC keys support the following usages: |
| 499 // 'sign', 'verify' | 499 // 'sign', 'verify' |
| 500 TEST(WebCryptoAesKwTest, UnwrapHmacKeyBadUsage_JWK) { | 500 TEST(WebCryptoAesKwTest, UnwrapHmacKeyBadUsage_JWK) { |
| 501 const blink::WebCryptoAlgorithm unwrap_algorithm = | 501 const blink::WebCryptoAlgorithm unwrap_algorithm = |
| 502 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesKw); | 502 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesKw); |
| 503 | 503 |
| 504 blink::WebCryptoKeyUsageMask bad_usages[] = { | 504 blink::WebCryptoKeyUsageMask bad_usages[] = { |
| 505 blink::WebCryptoKeyUsageEncrypt, | 505 blink::WebCryptoKeyUsageEncrypt, |
| 506 blink::WebCryptoKeyUsageDecrypt, | 506 blink::WebCryptoKeyUsageDecrypt, |
| 507 blink::WebCryptoKeyUsageWrapKey, | 507 blink::WebCryptoKeyUsageWrapKey, |
| 508 blink::WebCryptoKeyUsageSign | blink::WebCryptoKeyUsageWrapKey, | 508 blink::WebCryptoKeyUsageSign | blink::WebCryptoKeyUsageWrapKey, |
| 509 blink::WebCryptoKeyUsageVerify | blink::WebCryptoKeyUsageDeriveKey, | 509 blink::WebCryptoKeyUsageVerify | blink::WebCryptoKeyUsageDeriveKey, |
| 510 }; | 510 }; |
| 511 | 511 |
| 512 // Import the wrapping key. | 512 // Import the wrapping key. |
| 513 blink::WebCryptoKey wrapping_key = blink::WebCryptoKey::createNull(); | 513 blink::WebCryptoKey wrapping_key; |
| 514 ASSERT_EQ(Status::Success(), | 514 ASSERT_EQ(Status::Success(), |
| 515 ImportKey(blink::WebCryptoKeyFormatRaw, | 515 ImportKey(blink::WebCryptoKeyFormatRaw, |
| 516 CryptoData(std::vector<uint8_t>(16)), | 516 CryptoData(std::vector<uint8_t>(16)), |
| 517 unwrap_algorithm, | 517 unwrap_algorithm, |
| 518 true, | 518 true, |
| 519 blink::WebCryptoKeyUsageUnwrapKey, | 519 blink::WebCryptoKeyUsageUnwrapKey, |
| 520 &wrapping_key)); | 520 &wrapping_key)); |
| 521 | 521 |
| 522 // The JWK plain text is: | 522 // The JWK plain text is: |
| 523 // { "kty": "oct","alg": "HS256","k": "GADWrMRHwQfoNaXU5fZvTg=="} | 523 // { "kty": "oct","alg": "HS256","k": "GADWrMRHwQfoNaXU5fZvTg=="} |
| 524 const char* kWrappedJwk = | 524 const char* kWrappedJwk = |
| 525 "0AA245F17064FFB2A7A094436A39BEBFC962C627303D1327EA750CE9F917688C2782A943" | 525 "0AA245F17064FFB2A7A094436A39BEBFC962C627303D1327EA750CE9F917688C2782A943" |
| 526 "7AE7586547AC490E8AE7D5B02D63868D5C3BB57D36C4C8C5BF3962ACEC6F42E767E5706" | 526 "7AE7586547AC490E8AE7D5B02D63868D5C3BB57D36C4C8C5BF3962ACEC6F42E767E5706" |
| 527 "4"; | 527 "4"; |
| 528 | 528 |
| 529 for (size_t i = 0; i < arraysize(bad_usages); ++i) { | 529 for (size_t i = 0; i < arraysize(bad_usages); ++i) { |
| 530 SCOPED_TRACE(i); | 530 SCOPED_TRACE(i); |
| 531 | 531 |
| 532 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); | 532 blink::WebCryptoKey key; |
| 533 | 533 |
| 534 ASSERT_EQ( | 534 ASSERT_EQ( |
| 535 Status::ErrorCreateKeyBadUsages(), | 535 Status::ErrorCreateKeyBadUsages(), |
| 536 UnwrapKey(blink::WebCryptoKeyFormatJwk, | 536 UnwrapKey(blink::WebCryptoKeyFormatJwk, |
| 537 CryptoData(HexStringToBytes(kWrappedJwk)), | 537 CryptoData(HexStringToBytes(kWrappedJwk)), |
| 538 wrapping_key, | 538 wrapping_key, |
| 539 unwrap_algorithm, | 539 unwrap_algorithm, |
| 540 CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha256), | 540 CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha256), |
| 541 true, | 541 true, |
| 542 bad_usages[i], | 542 bad_usages[i], |
| (...skipping 10 matching lines...) Expand all Loading... |
| 553 | 553 |
| 554 blink::WebCryptoKeyUsageMask bad_usages[] = { | 554 blink::WebCryptoKeyUsageMask bad_usages[] = { |
| 555 blink::WebCryptoKeyUsageEncrypt, | 555 blink::WebCryptoKeyUsageEncrypt, |
| 556 blink::WebCryptoKeyUsageSign, | 556 blink::WebCryptoKeyUsageSign, |
| 557 blink::WebCryptoKeyUsageDecrypt, | 557 blink::WebCryptoKeyUsageDecrypt, |
| 558 blink::WebCryptoKeyUsageWrapKey, | 558 blink::WebCryptoKeyUsageWrapKey, |
| 559 blink::WebCryptoKeyUsageSign | blink::WebCryptoKeyUsageWrapKey, | 559 blink::WebCryptoKeyUsageSign | blink::WebCryptoKeyUsageWrapKey, |
| 560 }; | 560 }; |
| 561 | 561 |
| 562 // Import the wrapping key. | 562 // Import the wrapping key. |
| 563 blink::WebCryptoKey wrapping_key = blink::WebCryptoKey::createNull(); | 563 blink::WebCryptoKey wrapping_key; |
| 564 ASSERT_EQ(Status::Success(), | 564 ASSERT_EQ(Status::Success(), |
| 565 ImportKey(blink::WebCryptoKeyFormatRaw, | 565 ImportKey(blink::WebCryptoKeyFormatRaw, |
| 566 CryptoData(std::vector<uint8_t>(16)), | 566 CryptoData(std::vector<uint8_t>(16)), |
| 567 unwrap_algorithm, | 567 unwrap_algorithm, |
| 568 true, | 568 true, |
| 569 blink::WebCryptoKeyUsageUnwrapKey, | 569 blink::WebCryptoKeyUsageUnwrapKey, |
| 570 &wrapping_key)); | 570 &wrapping_key)); |
| 571 | 571 |
| 572 // The JWK plaintext is: | 572 // The JWK plaintext is: |
| 573 // { "kty": "RSA","alg": "RS256","n": "...","e": "AQAB"} | 573 // { "kty": "RSA","alg": "RS256","n": "...","e": "AQAB"} |
| 574 | 574 |
| 575 const char* kWrappedJwk = | 575 const char* kWrappedJwk = |
| 576 "CE8DAEF99E977EE58958B8C4494755C846E883B2ECA575C5366622839AF71AB30875F152" | 576 "CE8DAEF99E977EE58958B8C4494755C846E883B2ECA575C5366622839AF71AB30875F152" |
| 577 "E8E33E15A7817A3A2874EB53EFE05C774D98BC936BA9BA29BEB8BB3F3C3CE2323CB3359D" | 577 "E8E33E15A7817A3A2874EB53EFE05C774D98BC936BA9BA29BEB8BB3F3C3CE2323CB3359D" |
| 578 "E3F426605CF95CCF0E01E870ABD7E35F62E030B5FB6E520A5885514D1D850FB64B57806D" | 578 "E3F426605CF95CCF0E01E870ABD7E35F62E030B5FB6E520A5885514D1D850FB64B57806D" |
| 579 "1ADA57C6E27DF345D8292D80F6B074F1BE51C4CF3D76ECC8886218551308681B44FAC60B" | 579 "1ADA57C6E27DF345D8292D80F6B074F1BE51C4CF3D76ECC8886218551308681B44FAC60B" |
| 580 "8CF6EA439BC63239103D0AE81ADB96F908680586C6169284E32EB7DD09D31103EBDAC0C2" | 580 "8CF6EA439BC63239103D0AE81ADB96F908680586C6169284E32EB7DD09D31103EBDAC0C2" |
| 581 "40C72DCF0AEA454113CC47457B13305B25507CBEAB9BDC8D8E0F867F9167F9DCEF0D9F9B" | 581 "40C72DCF0AEA454113CC47457B13305B25507CBEAB9BDC8D8E0F867F9167F9DCEF0D9F9B" |
| 582 "30F2EE83CEDFD51136852C8A5939B768"; | 582 "30F2EE83CEDFD51136852C8A5939B768"; |
| 583 | 583 |
| 584 for (size_t i = 0; i < arraysize(bad_usages); ++i) { | 584 for (size_t i = 0; i < arraysize(bad_usages); ++i) { |
| 585 SCOPED_TRACE(i); | 585 SCOPED_TRACE(i); |
| 586 | 586 |
| 587 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); | 587 blink::WebCryptoKey key; |
| 588 | 588 |
| 589 ASSERT_EQ(Status::ErrorCreateKeyBadUsages(), | 589 ASSERT_EQ(Status::ErrorCreateKeyBadUsages(), |
| 590 UnwrapKey(blink::WebCryptoKeyFormatJwk, | 590 UnwrapKey(blink::WebCryptoKeyFormatJwk, |
| 591 CryptoData(HexStringToBytes(kWrappedJwk)), | 591 CryptoData(HexStringToBytes(kWrappedJwk)), |
| 592 wrapping_key, | 592 wrapping_key, |
| 593 unwrap_algorithm, | 593 unwrap_algorithm, |
| 594 CreateRsaHashedImportAlgorithm( | 594 CreateRsaHashedImportAlgorithm( |
| 595 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 595 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
| 596 blink::WebCryptoAlgorithmIdSha256), | 596 blink::WebCryptoAlgorithmIdSha256), |
| 597 true, | 597 true, |
| 598 bad_usages[i], | 598 bad_usages[i], |
| 599 &key)); | 599 &key)); |
| 600 } | 600 } |
| 601 } | 601 } |
| 602 | 602 |
| 603 } // namespace | 603 } // namespace |
| 604 | 604 |
| 605 } // namespace webcrypto | 605 } // namespace webcrypto |
| 606 | 606 |
| 607 } // namespace content | 607 } // namespace content |
| OLD | NEW |