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 <algorithm> | 5 #include <algorithm> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 // TODO(eroman): Exclude version test for OS_CHROMEOS | 115 // TODO(eroman): Exclude version test for OS_CHROMEOS |
116 #if defined(USE_NSS) | 116 #if defined(USE_NSS) |
117 if (!NSS_VersionCheck("3.16.2")) | 117 if (!NSS_VersionCheck("3.16.2")) |
118 return false; | 118 return false; |
119 #endif | 119 #endif |
120 crypto::ScopedPK11Slot slot(PK11_GetInternalKeySlot()); | 120 crypto::ScopedPK11Slot slot(PK11_GetInternalKeySlot()); |
121 return !!PK11_DoesMechanism(slot.get(), CKM_RSA_PKCS_OAEP); | 121 return !!PK11_DoesMechanism(slot.get(), CKM_RSA_PKCS_OAEP); |
122 #endif | 122 #endif |
123 } | 123 } |
124 | 124 |
125 bool SupportsRsaKeyImport() { | 125 bool SupportsRsaPrivateKeyImport() { |
126 // TODO(eroman): Exclude version test for OS_CHROMEOS | 126 // TODO(eroman): Exclude version test for OS_CHROMEOS |
127 #if defined(USE_NSS) | 127 #if defined(USE_NSS) |
128 crypto::EnsureNSSInit(); | 128 crypto::EnsureNSSInit(); |
129 if (!NSS_VersionCheck("3.16.2")) { | 129 if (!NSS_VersionCheck("3.16.2")) { |
130 LOG(WARNING) << "RSA key import is not supported by this version of NSS. " | 130 LOG(WARNING) << "RSA key import is not supported by this version of NSS. " |
131 "Skipping some tests"; | 131 "Skipping some tests"; |
132 return false; | 132 return false; |
133 } | 133 } |
134 #endif | 134 #endif |
135 return true; | 135 return true; |
(...skipping 1698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1834 EXPECT_EQ( | 1834 EXPECT_EQ( |
1835 Status::ErrorJwkIncorrectKeyLength(), | 1835 Status::ErrorJwkIncorrectKeyLength(), |
1836 ImportKeyJwkFromDict(dict, | 1836 ImportKeyJwkFromDict(dict, |
1837 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc), | 1837 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc), |
1838 false, | 1838 false, |
1839 blink::WebCryptoKeyUsageEncrypt, | 1839 blink::WebCryptoKeyUsageEncrypt, |
1840 &key)); | 1840 &key)); |
1841 } | 1841 } |
1842 | 1842 |
1843 TEST(WebCryptoRsaSsaTest, ImportExportJwkRsaPublicKey) { | 1843 TEST(WebCryptoRsaSsaTest, ImportExportJwkRsaPublicKey) { |
1844 if (!SupportsRsaKeyImport()) | |
1845 return; | |
1846 | |
1847 struct TestCase { | 1844 struct TestCase { |
1848 const blink::WebCryptoAlgorithmId hash; | 1845 const blink::WebCryptoAlgorithmId hash; |
1849 const blink::WebCryptoKeyUsageMask usage; | 1846 const blink::WebCryptoKeyUsageMask usage; |
1850 const char* const jwk_alg; | 1847 const char* const jwk_alg; |
1851 }; | 1848 }; |
1852 const TestCase kTests[] = { | 1849 const TestCase kTests[] = { |
1853 {blink::WebCryptoAlgorithmIdSha1, blink::WebCryptoKeyUsageVerify, "RS1"}, | 1850 {blink::WebCryptoAlgorithmIdSha1, blink::WebCryptoKeyUsageVerify, "RS1"}, |
1854 {blink::WebCryptoAlgorithmIdSha256, blink::WebCryptoKeyUsageVerify, | 1851 {blink::WebCryptoAlgorithmIdSha256, blink::WebCryptoKeyUsageVerify, |
1855 "RS256"}, | 1852 "RS256"}, |
1856 {blink::WebCryptoAlgorithmIdSha384, blink::WebCryptoKeyUsageVerify, | 1853 {blink::WebCryptoAlgorithmIdSha384, blink::WebCryptoKeyUsageVerify, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1900 | 1897 |
1901 // Export the new key as spki and compare to the original. | 1898 // Export the new key as spki and compare to the original. |
1902 std::vector<uint8_t> spki; | 1899 std::vector<uint8_t> spki; |
1903 ASSERT_EQ(Status::Success(), | 1900 ASSERT_EQ(Status::Success(), |
1904 ExportKey(blink::WebCryptoKeyFormatSpki, public_key2, &spki)); | 1901 ExportKey(blink::WebCryptoKeyFormatSpki, public_key2, &spki)); |
1905 EXPECT_BYTES_EQ_HEX(kPublicKeySpkiDerHex, CryptoData(spki)); | 1902 EXPECT_BYTES_EQ_HEX(kPublicKeySpkiDerHex, CryptoData(spki)); |
1906 } | 1903 } |
1907 } | 1904 } |
1908 | 1905 |
1909 TEST(WebCryptoRsaOaepTest, ImportExportJwkRsaPublicKey) { | 1906 TEST(WebCryptoRsaOaepTest, ImportExportJwkRsaPublicKey) { |
1910 if (!SupportsRsaKeyImport()) | |
1911 return; | |
1912 | |
1913 if (!SupportsRsaOaep()) { | 1907 if (!SupportsRsaOaep()) { |
1914 LOG(WARNING) << "RSA-OAEP support not present; skipping."; | 1908 LOG(WARNING) << "RSA-OAEP support not present; skipping."; |
1915 return; | 1909 return; |
1916 } | 1910 } |
1917 | 1911 |
1918 struct TestCase { | 1912 struct TestCase { |
1919 const blink::WebCryptoAlgorithmId hash; | 1913 const blink::WebCryptoAlgorithmId hash; |
1920 const blink::WebCryptoKeyUsageMask usage; | 1914 const blink::WebCryptoKeyUsageMask usage; |
1921 const char* const jwk_alg; | 1915 const char* const jwk_alg; |
1922 }; | 1916 }; |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2388 EXPECT_EQ(0u, key.algorithm().hmacParams()->lengthBits()); | 2382 EXPECT_EQ(0u, key.algorithm().hmacParams()->lengthBits()); |
2389 | 2383 |
2390 std::vector<uint8_t> exported_key_data; | 2384 std::vector<uint8_t> exported_key_data; |
2391 EXPECT_EQ(Status::Success(), | 2385 EXPECT_EQ(Status::Success(), |
2392 ExportKey(blink::WebCryptoKeyFormatRaw, key, &exported_key_data)); | 2386 ExportKey(blink::WebCryptoKeyFormatRaw, key, &exported_key_data)); |
2393 | 2387 |
2394 EXPECT_EQ(0u, exported_key_data.size()); | 2388 EXPECT_EQ(0u, exported_key_data.size()); |
2395 } | 2389 } |
2396 | 2390 |
2397 TEST(WebCryptoRsaSsaTest, ImportExportSpki) { | 2391 TEST(WebCryptoRsaSsaTest, ImportExportSpki) { |
2398 if (!SupportsRsaKeyImport()) | |
2399 return; | |
2400 | |
2401 // Passing case: Import a valid RSA key in SPKI format. | 2392 // Passing case: Import a valid RSA key in SPKI format. |
2402 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); | 2393 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); |
2403 ASSERT_EQ(Status::Success(), | 2394 ASSERT_EQ(Status::Success(), |
2404 ImportKey(blink::WebCryptoKeyFormatSpki, | 2395 ImportKey(blink::WebCryptoKeyFormatSpki, |
2405 CryptoData(HexStringToBytes(kPublicKeySpkiDerHex)), | 2396 CryptoData(HexStringToBytes(kPublicKeySpkiDerHex)), |
2406 CreateRsaHashedImportAlgorithm( | 2397 CreateRsaHashedImportAlgorithm( |
2407 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 2398 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
2408 blink::WebCryptoAlgorithmIdSha256), | 2399 blink::WebCryptoAlgorithmIdSha256), |
2409 true, | 2400 true, |
2410 blink::WebCryptoKeyUsageVerify, | 2401 blink::WebCryptoKeyUsageVerify, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2477 | 2468 |
2478 // TODO(eroman): Failing test: Import a SPKI with an unrecognized hash OID | 2469 // TODO(eroman): Failing test: Import a SPKI with an unrecognized hash OID |
2479 // TODO(eroman): Failing test: Import a SPKI with invalid algorithm params | 2470 // TODO(eroman): Failing test: Import a SPKI with invalid algorithm params |
2480 // TODO(eroman): Failing test: Import a SPKI with inconsistent parameters | 2471 // TODO(eroman): Failing test: Import a SPKI with inconsistent parameters |
2481 // (e.g. SHA-1 in OID, SHA-256 in params) | 2472 // (e.g. SHA-1 in OID, SHA-256 in params) |
2482 // TODO(eroman): Failing test: Import a SPKI for RSA-SSA, but with params | 2473 // TODO(eroman): Failing test: Import a SPKI for RSA-SSA, but with params |
2483 // as OAEP/PSS | 2474 // as OAEP/PSS |
2484 } | 2475 } |
2485 | 2476 |
2486 TEST(WebCryptoRsaSsaTest, ImportExportPkcs8) { | 2477 TEST(WebCryptoRsaSsaTest, ImportExportPkcs8) { |
2487 if (!SupportsRsaKeyImport()) | 2478 if (!SupportsRsaPrivateKeyImport()) |
2488 return; | 2479 return; |
2489 | 2480 |
2490 // Passing case: Import a valid RSA key in PKCS#8 format. | 2481 // Passing case: Import a valid RSA key in PKCS#8 format. |
2491 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); | 2482 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); |
2492 ASSERT_EQ(Status::Success(), | 2483 ASSERT_EQ(Status::Success(), |
2493 ImportKey(blink::WebCryptoKeyFormatPkcs8, | 2484 ImportKey(blink::WebCryptoKeyFormatPkcs8, |
2494 CryptoData(HexStringToBytes(kPrivateKeyPkcs8DerHex)), | 2485 CryptoData(HexStringToBytes(kPrivateKeyPkcs8DerHex)), |
2495 CreateRsaHashedImportAlgorithm( | 2486 CreateRsaHashedImportAlgorithm( |
2496 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 2487 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
2497 blink::WebCryptoAlgorithmIdSha1), | 2488 blink::WebCryptoAlgorithmIdSha1), |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2544 ImportKey(blink::WebCryptoKeyFormatPkcs8, | 2535 ImportKey(blink::WebCryptoKeyFormatPkcs8, |
2545 CryptoData(HexStringToBytes(kPrivateKeyPkcs8DerHex)), | 2536 CryptoData(HexStringToBytes(kPrivateKeyPkcs8DerHex)), |
2546 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc), | 2537 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc), |
2547 true, | 2538 true, |
2548 blink::WebCryptoKeyUsageSign, | 2539 blink::WebCryptoKeyUsageSign, |
2549 &key)); | 2540 &key)); |
2550 } | 2541 } |
2551 | 2542 |
2552 // Tests importing of PKCS8 data that does not define a valid RSA key. | 2543 // Tests importing of PKCS8 data that does not define a valid RSA key. |
2553 TEST(WebCryptoRsaSsaTest, ImportInvalidPkcs8) { | 2544 TEST(WebCryptoRsaSsaTest, ImportInvalidPkcs8) { |
2554 if (!SupportsRsaKeyImport()) | 2545 if (!SupportsRsaPrivateKeyImport()) |
2555 return; | 2546 return; |
2556 | 2547 |
2557 // kPrivateKeyPkcs8DerHex defines an RSA private key in PKCS8 format, whose | 2548 // kPrivateKeyPkcs8DerHex defines an RSA private key in PKCS8 format, whose |
2558 // parameters appear at the following offsets: | 2549 // parameters appear at the following offsets: |
2559 // | 2550 // |
2560 // n: (offset=36, len=129) | 2551 // n: (offset=36, len=129) |
2561 // e: (offset=167, len=3) | 2552 // e: (offset=167, len=3) |
2562 // d: (offset=173, len=128) | 2553 // d: (offset=173, len=128) |
2563 // p: (offset=303, len=65) | 2554 // p: (offset=303, len=65) |
2564 // q: (offset=370, len=65) | 2555 // q: (offset=370, len=65) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2598 blink::WebCryptoKeyUsageSign, | 2589 blink::WebCryptoKeyUsageSign, |
2599 &key)); | 2590 &key)); |
2600 } | 2591 } |
2601 } | 2592 } |
2602 | 2593 |
2603 // Tests JWK import and export by doing a roundtrip key conversion and ensuring | 2594 // Tests JWK import and export by doing a roundtrip key conversion and ensuring |
2604 // it was lossless: | 2595 // it was lossless: |
2605 // | 2596 // |
2606 // PKCS8 --> JWK --> PKCS8 | 2597 // PKCS8 --> JWK --> PKCS8 |
2607 TEST(WebCryptoRsaSsaTest, ImportRsaPrivateKeyJwkToPkcs8RoundTrip) { | 2598 TEST(WebCryptoRsaSsaTest, ImportRsaPrivateKeyJwkToPkcs8RoundTrip) { |
2608 if (!SupportsRsaKeyImport()) | 2599 if (!SupportsRsaPrivateKeyImport()) |
2609 return; | 2600 return; |
2610 | 2601 |
2611 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); | 2602 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); |
2612 ASSERT_EQ(Status::Success(), | 2603 ASSERT_EQ(Status::Success(), |
2613 ImportKey(blink::WebCryptoKeyFormatPkcs8, | 2604 ImportKey(blink::WebCryptoKeyFormatPkcs8, |
2614 CryptoData(HexStringToBytes(kPrivateKeyPkcs8DerHex)), | 2605 CryptoData(HexStringToBytes(kPrivateKeyPkcs8DerHex)), |
2615 CreateRsaHashedImportAlgorithm( | 2606 CreateRsaHashedImportAlgorithm( |
2616 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 2607 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
2617 blink::WebCryptoAlgorithmIdSha1), | 2608 blink::WebCryptoAlgorithmIdSha1), |
2618 true, | 2609 true, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2666 } | 2657 } |
2667 | 2658 |
2668 // Tests importing multiple RSA private keys from JWK, and then exporting to | 2659 // Tests importing multiple RSA private keys from JWK, and then exporting to |
2669 // PKCS8. | 2660 // PKCS8. |
2670 // | 2661 // |
2671 // This is a regression test for http://crbug.com/378315, for which importing | 2662 // This is a regression test for http://crbug.com/378315, for which importing |
2672 // a sequence of keys from JWK could yield the wrong key. The first key would | 2663 // a sequence of keys from JWK could yield the wrong key. The first key would |
2673 // be imported correctly, however every key after that would actually import | 2664 // be imported correctly, however every key after that would actually import |
2674 // the first key. | 2665 // the first key. |
2675 TEST(WebCryptoRsaSsaTest, ImportMultipleRSAPrivateKeysJwk) { | 2666 TEST(WebCryptoRsaSsaTest, ImportMultipleRSAPrivateKeysJwk) { |
2676 if (!SupportsRsaKeyImport()) | 2667 if (!SupportsRsaPrivateKeyImport()) |
2677 return; | 2668 return; |
2678 | 2669 |
2679 scoped_ptr<base::ListValue> key_list; | 2670 scoped_ptr<base::ListValue> key_list; |
2680 ASSERT_TRUE(ReadJsonTestFileToList("rsa_private_keys.json", &key_list)); | 2671 ASSERT_TRUE(ReadJsonTestFileToList("rsa_private_keys.json", &key_list)); |
2681 | 2672 |
2682 // For this test to be meaningful the keys MUST be kept alive before importing | 2673 // For this test to be meaningful the keys MUST be kept alive before importing |
2683 // new keys. | 2674 // new keys. |
2684 std::vector<blink::WebCryptoKey> live_keys; | 2675 std::vector<blink::WebCryptoKey> live_keys; |
2685 | 2676 |
2686 for (size_t key_index = 0; key_index < key_list->GetSize(); ++key_index) { | 2677 for (size_t key_index = 0; key_index < key_list->GetSize(); ++key_index) { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2830 &key)); | 2821 &key)); |
2831 } | 2822 } |
2832 | 2823 |
2833 // Import a JWK RSA private key, without any of the optional parameters. | 2824 // Import a JWK RSA private key, without any of the optional parameters. |
2834 // | 2825 // |
2835 // According to JWA, such keys are valid, but applications SHOULD | 2826 // According to JWA, such keys are valid, but applications SHOULD |
2836 // include all the parameters when sending, and recipients MAY | 2827 // include all the parameters when sending, and recipients MAY |
2837 // accept them, but are not required to. Chromium's WebCrypto does | 2828 // accept them, but are not required to. Chromium's WebCrypto does |
2838 // not allow such degenerate keys. | 2829 // not allow such degenerate keys. |
2839 TEST(WebCryptoRsaSsaTest, ImportRsaPrivateKeyJwkIncorrectOptionalEmpty) { | 2830 TEST(WebCryptoRsaSsaTest, ImportRsaPrivateKeyJwkIncorrectOptionalEmpty) { |
2840 if (!SupportsRsaKeyImport()) | 2831 if (!SupportsRsaPrivateKeyImport()) |
2841 return; | 2832 return; |
2842 | 2833 |
2843 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); | 2834 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); |
2844 | 2835 |
2845 base::DictionaryValue dict; | 2836 base::DictionaryValue dict; |
2846 dict.SetString("kty", "RSA"); | 2837 dict.SetString("kty", "RSA"); |
2847 dict.SetString("alg", "RS1"); | 2838 dict.SetString("alg", "RS1"); |
2848 | 2839 |
2849 dict.SetString( | 2840 dict.SetString( |
2850 "n", | 2841 "n", |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2928 EXPECT_EQ(usage_mask, public_key.usages()); | 2919 EXPECT_EQ(usage_mask, public_key.usages()); |
2929 EXPECT_EQ(usage_mask, private_key.usages()); | 2920 EXPECT_EQ(usage_mask, private_key.usages()); |
2930 | 2921 |
2931 // Try exporting the generated key pair, and then re-importing to verify that | 2922 // Try exporting the generated key pair, and then re-importing to verify that |
2932 // the exported data was valid. | 2923 // the exported data was valid. |
2933 std::vector<uint8_t> public_key_spki; | 2924 std::vector<uint8_t> public_key_spki; |
2934 EXPECT_EQ( | 2925 EXPECT_EQ( |
2935 Status::Success(), | 2926 Status::Success(), |
2936 ExportKey(blink::WebCryptoKeyFormatSpki, public_key, &public_key_spki)); | 2927 ExportKey(blink::WebCryptoKeyFormatSpki, public_key, &public_key_spki)); |
2937 | 2928 |
2938 if (SupportsRsaKeyImport()) { | 2929 if (SupportsRsaPrivateKeyImport()) { |
2939 public_key = blink::WebCryptoKey::createNull(); | 2930 public_key = blink::WebCryptoKey::createNull(); |
2940 EXPECT_EQ(Status::Success(), | 2931 EXPECT_EQ(Status::Success(), |
2941 ImportKey(blink::WebCryptoKeyFormatSpki, | 2932 ImportKey(blink::WebCryptoKeyFormatSpki, |
2942 CryptoData(public_key_spki), | 2933 CryptoData(public_key_spki), |
2943 CreateRsaHashedImportAlgorithm( | 2934 CreateRsaHashedImportAlgorithm( |
2944 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 2935 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
2945 blink::WebCryptoAlgorithmIdSha256), | 2936 blink::WebCryptoAlgorithmIdSha256), |
2946 true, | 2937 true, |
2947 usage_mask, | 2938 usage_mask, |
2948 &public_key)); | 2939 &public_key)); |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3132 | 3123 |
3133 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); | 3124 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); |
3134 blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); | 3125 blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); |
3135 | 3126 |
3136 EXPECT_EQ(Status::ErrorGenerateKeyPublicExponent(), | 3127 EXPECT_EQ(Status::ErrorGenerateKeyPublicExponent(), |
3137 GenerateKeyPair(algorithm, true, 0, &public_key, &private_key)); | 3128 GenerateKeyPair(algorithm, true, 0, &public_key, &private_key)); |
3138 } | 3129 } |
3139 } | 3130 } |
3140 | 3131 |
3141 TEST(WebCryptoRsaSsaTest, SignVerifyFailures) { | 3132 TEST(WebCryptoRsaSsaTest, SignVerifyFailures) { |
3142 if (!SupportsRsaKeyImport()) | 3133 if (!SupportsRsaPrivateKeyImport()) |
3143 return; | 3134 return; |
3144 | 3135 |
3145 // Import a key pair. | 3136 // Import a key pair. |
3146 blink::WebCryptoAlgorithm import_algorithm = | 3137 blink::WebCryptoAlgorithm import_algorithm = |
3147 CreateRsaHashedImportAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 3138 CreateRsaHashedImportAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
3148 blink::WebCryptoAlgorithmIdSha1); | 3139 blink::WebCryptoAlgorithmIdSha1); |
3149 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); | 3140 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); |
3150 blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); | 3141 blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); |
3151 ASSERT_NO_FATAL_FAILURE( | 3142 ASSERT_NO_FATAL_FAILURE( |
3152 ImportRsaKeyPair(HexStringToBytes(kPublicKeySpkiDerHex), | 3143 ImportRsaKeyPair(HexStringToBytes(kPublicKeySpkiDerHex), |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3264 EXPECT_EQ(Status::Success(), | 3255 EXPECT_EQ(Status::Success(), |
3265 Verify(CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5), | 3256 Verify(CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5), |
3266 public_key_256, | 3257 public_key_256, |
3267 CryptoData(signature), | 3258 CryptoData(signature), |
3268 CryptoData(data), | 3259 CryptoData(data), |
3269 &is_match)); | 3260 &is_match)); |
3270 EXPECT_FALSE(is_match); | 3261 EXPECT_FALSE(is_match); |
3271 } | 3262 } |
3272 | 3263 |
3273 TEST(WebCryptoRsaSsaTest, SignVerifyKnownAnswer) { | 3264 TEST(WebCryptoRsaSsaTest, SignVerifyKnownAnswer) { |
3274 if (!SupportsRsaKeyImport()) | 3265 if (!SupportsRsaPrivateKeyImport()) |
3275 return; | 3266 return; |
3276 | 3267 |
3277 scoped_ptr<base::ListValue> tests; | 3268 scoped_ptr<base::ListValue> tests; |
3278 ASSERT_TRUE(ReadJsonTestFileToList("pkcs1v15_sign.json", &tests)); | 3269 ASSERT_TRUE(ReadJsonTestFileToList("pkcs1v15_sign.json", &tests)); |
3279 | 3270 |
3280 // Import the key pair. | 3271 // Import the key pair. |
3281 blink::WebCryptoAlgorithm import_algorithm = | 3272 blink::WebCryptoAlgorithm import_algorithm = |
3282 CreateRsaHashedImportAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 3273 CreateRsaHashedImportAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
3283 blink::WebCryptoAlgorithmIdSha1); | 3274 blink::WebCryptoAlgorithmIdSha1); |
3284 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); | 3275 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); |
(...skipping 1458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4743 &private_key)); | 4734 &private_key)); |
4744 | 4735 |
4745 EXPECT_EQ(0, public_key.usages()); | 4736 EXPECT_EQ(0, public_key.usages()); |
4746 EXPECT_EQ(blink::WebCryptoKeyUsageSign, private_key.usages()); | 4737 EXPECT_EQ(blink::WebCryptoKeyUsageSign, private_key.usages()); |
4747 } | 4738 } |
4748 | 4739 |
4749 // Generate an AES-CBC key and an RSA key pair. Use the AES-CBC key to wrap the | 4740 // Generate an AES-CBC key and an RSA key pair. Use the AES-CBC key to wrap the |
4750 // key pair (using SPKI format for public key, PKCS8 format for private key). | 4741 // key pair (using SPKI format for public key, PKCS8 format for private key). |
4751 // Then unwrap the wrapped key pair and verify that the key data is the same. | 4742 // Then unwrap the wrapped key pair and verify that the key data is the same. |
4752 TEST(WebCryptoAesCbcTest, WrapUnwrapRoundtripSpkiPkcs8) { | 4743 TEST(WebCryptoAesCbcTest, WrapUnwrapRoundtripSpkiPkcs8) { |
4753 if (!SupportsRsaKeyImport()) | 4744 if (!SupportsRsaPrivateKeyImport()) |
4754 return; | 4745 return; |
4755 | 4746 |
4756 // Generate the wrapping key. | 4747 // Generate the wrapping key. |
4757 blink::WebCryptoKey wrapping_key = blink::WebCryptoKey::createNull(); | 4748 blink::WebCryptoKey wrapping_key = blink::WebCryptoKey::createNull(); |
4758 ASSERT_EQ(Status::Success(), | 4749 ASSERT_EQ(Status::Success(), |
4759 GenerateSecretKey(CreateAesCbcKeyGenAlgorithm(128), | 4750 GenerateSecretKey(CreateAesCbcKeyGenAlgorithm(128), |
4760 true, | 4751 true, |
4761 blink::WebCryptoKeyUsageWrapKey | | 4752 blink::WebCryptoKeyUsageWrapKey | |
4762 blink::WebCryptoKeyUsageUnwrapKey, | 4753 blink::WebCryptoKeyUsageUnwrapKey, |
4763 &wrapping_key)); | 4754 &wrapping_key)); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4858 | 4849 |
4859 EXPECT_NE(public_key_spki, wrapped_public_key); | 4850 EXPECT_NE(public_key_spki, wrapped_public_key); |
4860 EXPECT_NE(private_key_pkcs8, wrapped_private_key); | 4851 EXPECT_NE(private_key_pkcs8, wrapped_private_key); |
4861 } | 4852 } |
4862 | 4853 |
4863 } // namespace | 4854 } // namespace |
4864 | 4855 |
4865 } // namespace webcrypto | 4856 } // namespace webcrypto |
4866 | 4857 |
4867 } // namespace content | 4858 } // namespace content |
OLD | NEW |