 Chromium Code Reviews
 Chromium Code Reviews Issue 777403004:
  [WebCrypto] Throw syntaxError if keyUsage is empty in ImportKey  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 777403004:
  [WebCrypto] Throw syntaxError if keyUsage is empty in ImportKey  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 348 public_key, &public_key_spki)); | 348 public_key, &public_key_spki)); | 
| 349 | 349 | 
| 350 if (SupportsRsaPrivateKeyImport()) { | 350 if (SupportsRsaPrivateKeyImport()) { | 
| 351 public_key = blink::WebCryptoKey::createNull(); | 351 public_key = blink::WebCryptoKey::createNull(); | 
| 352 EXPECT_EQ( | 352 EXPECT_EQ( | 
| 353 Status::Success(), | 353 Status::Success(), | 
| 354 ImportKey(blink::WebCryptoKeyFormatSpki, CryptoData(public_key_spki), | 354 ImportKey(blink::WebCryptoKeyFormatSpki, CryptoData(public_key_spki), | 
| 355 CreateRsaHashedImportAlgorithm( | 355 CreateRsaHashedImportAlgorithm( | 
| 356 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 356 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 
| 357 blink::WebCryptoAlgorithmIdSha256), | 357 blink::WebCryptoAlgorithmIdSha256), | 
| 358 true, usages, &public_key)); | 358 true, blink::WebCryptoKeyUsageVerify, &public_key)); | 
| 
eroman
2014/12/05 20:45:51
sync the code, this has already changed:
https://
 
Habib Virji
2014/12/08 15:05:21
Done.
 | |
| 359 EXPECT_EQ(modulus_length, | 359 EXPECT_EQ(modulus_length, | 
| 360 public_key.algorithm().rsaHashedParams()->modulusLengthBits()); | 360 public_key.algorithm().rsaHashedParams()->modulusLengthBits()); | 
| 361 | 361 | 
| 362 std::vector<uint8_t> private_key_pkcs8; | 362 std::vector<uint8_t> private_key_pkcs8; | 
| 363 EXPECT_EQ(Status::Success(), ExportKey(blink::WebCryptoKeyFormatPkcs8, | 363 EXPECT_EQ(Status::Success(), ExportKey(blink::WebCryptoKeyFormatPkcs8, | 
| 364 private_key, &private_key_pkcs8)); | 364 private_key, &private_key_pkcs8)); | 
| 365 private_key = blink::WebCryptoKey::createNull(); | 365 private_key = blink::WebCryptoKey::createNull(); | 
| 366 EXPECT_EQ( | 366 EXPECT_EQ( | 
| 367 Status::Success(), | 367 Status::Success(), | 
| 368 ImportKey(blink::WebCryptoKeyFormatPkcs8, CryptoData(private_key_pkcs8), | 368 ImportKey(blink::WebCryptoKeyFormatPkcs8, CryptoData(private_key_pkcs8), | 
| 369 CreateRsaHashedImportAlgorithm( | 369 CreateRsaHashedImportAlgorithm( | 
| 370 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 370 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 
| 371 blink::WebCryptoAlgorithmIdSha256), | 371 blink::WebCryptoAlgorithmIdSha256), | 
| 372 true, usages, &private_key)); | 372 true, blink::WebCryptoKeyUsageSign, &private_key)); | 
| 373 EXPECT_EQ(modulus_length, | 373 EXPECT_EQ(modulus_length, | 
| 374 private_key.algorithm().rsaHashedParams()->modulusLengthBits()); | 374 private_key.algorithm().rsaHashedParams()->modulusLengthBits()); | 
| 375 } | 375 } | 
| 376 | 376 | 
| 377 // Fail with bad modulus. | 377 // Fail with bad modulus. | 
| 378 algorithm = CreateRsaHashedKeyGenAlgorithm( | 378 algorithm = CreateRsaHashedKeyGenAlgorithm( | 
| 379 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 379 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 
| 380 blink::WebCryptoAlgorithmIdSha256, 0, public_exponent); | 380 blink::WebCryptoAlgorithmIdSha256, 0, public_exponent); | 
| 381 EXPECT_EQ(Status::ErrorGenerateRsaUnsupportedModulus(), | 381 EXPECT_EQ(Status::ErrorGenerateRsaUnsupportedModulus(), | 
| 382 GenerateKeyPair(algorithm, extractable, usages, &public_key, | 382 GenerateKeyPair(algorithm, extractable, usages, &public_key, | 
| (...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 942 | 942 | 
| 943 const base::DictionaryValue* test; | 943 const base::DictionaryValue* test; | 
| 944 ASSERT_TRUE(tests->GetDictionary(test_index, &test)); | 944 ASSERT_TRUE(tests->GetDictionary(test_index, &test)); | 
| 945 | 945 | 
| 946 blink::WebCryptoKeyFormat key_format = GetKeyFormatFromJsonTestCase(test); | 946 blink::WebCryptoKeyFormat key_format = GetKeyFormatFromJsonTestCase(test); | 
| 947 std::vector<uint8_t> key_data = | 947 std::vector<uint8_t> key_data = | 
| 948 GetKeyDataFromJsonTestCase(test, key_format); | 948 GetKeyDataFromJsonTestCase(test, key_format); | 
| 949 std::string test_error; | 949 std::string test_error; | 
| 950 ASSERT_TRUE(test->GetString("error", &test_error)); | 950 ASSERT_TRUE(test->GetString("error", &test_error)); | 
| 951 | 951 | 
| 952 blink::WebCryptoKeyUsage keyUsage = blink::WebCryptoKeyUsageSign; | |
| 953 if (key_format == blink::WebCryptoKeyFormatSpki) | |
| 954 keyUsage = blink::WebCryptoKeyUsageVerify; | |
| 955 | |
| 952 blink::WebCryptoKey key; | 956 blink::WebCryptoKey key; | 
| 953 Status status = ImportKey(key_format, CryptoData(key_data), | 957 Status status = ImportKey(key_format, CryptoData(key_data), | 
| 954 CreateRsaHashedImportAlgorithm( | 958 CreateRsaHashedImportAlgorithm( | 
| 955 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 959 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 
| 956 blink::WebCryptoAlgorithmIdSha256), | 960 blink::WebCryptoAlgorithmIdSha256), | 
| 957 true, 0, &key); | 961 true, keyUsage, &key); | 
| 962 | |
| 958 EXPECT_EQ(test_error, StatusToString(status)); | 963 EXPECT_EQ(test_error, StatusToString(status)); | 
| 959 } | 964 } | 
| 960 } | 965 } | 
| 961 | 966 | 
| 962 } // namespace | 967 } // namespace | 
| 963 | 968 | 
| 964 } // namespace webcrypto | 969 } // namespace webcrypto | 
| 965 | 970 | 
| 966 } // namespace content | 971 } // namespace content | 
| OLD | NEW |