Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Side by Side Diff: content/renderer/webcrypto/webcrypto_impl_unittest.cc

Issue 68303009: [webcrypto] Add RSASSA-PKCS1-v1_5 sign and verify for NSS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes for eroman, and MAYBE'ed new tests (missed in last rebase) Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/renderer/webcrypto/webcrypto_impl.h" 5 #include "content/renderer/webcrypto/webcrypto_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 dict->SetString("alg", "RSA1_5"); 76 dict->SetString("alg", "RSA1_5");
77 dict->SetString("use", "enc"); 77 dict->SetString("use", "enc");
78 dict->SetBoolean("extractable", false); 78 dict->SetBoolean("extractable", false);
79 dict->SetString("n", 79 dict->SetString("n",
80 "qLOyhK-OtQs4cDSoYPFGxJGfMYdjzWxVmMiuSBGh4KvEx-CwgtaTpef87Wdc9GaFEncsDLxk" 80 "qLOyhK-OtQs4cDSoYPFGxJGfMYdjzWxVmMiuSBGh4KvEx-CwgtaTpef87Wdc9GaFEncsDLxk"
81 "p0LGxjD1M8jMcvYq6DPEC_JYQumEu3i9v5fAEH1VvbZi9cTg-rmEXLUUjvc5LdOq_5OuHmtm" 81 "p0LGxjD1M8jMcvYq6DPEC_JYQumEu3i9v5fAEH1VvbZi9cTg-rmEXLUUjvc5LdOq_5OuHmtm"
82 "e7PUJHYW1PW6ENTP0ibeiNOfFvs"); 82 "e7PUJHYW1PW6ENTP0ibeiNOfFvs");
83 dict->SetString("e", "AQAB"); 83 dict->SetString("e", "AQAB");
84 } 84 }
85 85
86 blink::WebCryptoAlgorithm CreateRsaAlgorithmWithInnerHash(
87 blink::WebCryptoAlgorithmId algorithm_id,
88 blink::WebCryptoAlgorithmId hash_id) {
89 DCHECK(algorithm_id == blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 ||
90 algorithm_id == blink::WebCryptoAlgorithmIdRsaOaep);
91 DCHECK(webcrypto::IsHashAlgorithm(hash_id));
92 return blink::WebCryptoAlgorithm::adoptParamsAndCreate(
93 algorithm_id,
94 new blink::WebCryptoRsaSsaParams(webcrypto::CreateAlgorithm(hash_id)));
95 }
96
86 // Determines if two ArrayBuffers have identical content. 97 // Determines if two ArrayBuffers have identical content.
87 bool ArrayBuffersEqual( 98 bool ArrayBuffersEqual(
88 const blink::WebArrayBuffer& a, 99 const blink::WebArrayBuffer& a,
89 const blink::WebArrayBuffer& b) { 100 const blink::WebArrayBuffer& b) {
90 return a.byteLength() == b.byteLength() && 101 return a.byteLength() == b.byteLength() &&
91 memcmp(a.data(), b.data(), a.byteLength()) == 0; 102 memcmp(a.data(), b.data(), a.byteLength()) == 0;
92 } 103 }
93 104
94 // Given a vector of WebArrayBuffers, determines if there are any copies. 105 // Given a vector of WebArrayBuffers, determines if there are any copies.
95 bool CopiesExist(std::vector<blink::WebArrayBuffer> bufs) { 106 bool CopiesExist(std::vector<blink::WebArrayBuffer> bufs) {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 bool* signature_match) { 212 bool* signature_match) {
202 return crypto_.VerifySignatureInternal(algorithm, 213 return crypto_.VerifySignatureInternal(algorithm,
203 key, 214 key,
204 signature, 215 signature,
205 signature_size, 216 signature_size,
206 webcrypto::Uint8VectorStart(data), 217 webcrypto::Uint8VectorStart(data),
207 data.size(), 218 data.size(),
208 signature_match); 219 signature_match);
209 } 220 }
210 221
222 bool VerifySignatureInternal(
223 const blink::WebCryptoAlgorithm& algorithm,
224 const blink::WebCryptoKey& key,
225 const std::vector<uint8>& signature,
226 const std::vector<uint8>& data,
227 bool* signature_match) {
228 return crypto_.VerifySignatureInternal(
229 algorithm,
230 key,
231 webcrypto::Uint8VectorStart(signature),
232 signature.size(),
233 webcrypto::Uint8VectorStart(data),
234 data.size(),
235 signature_match);
236 }
237
211 bool EncryptInternal( 238 bool EncryptInternal(
212 const blink::WebCryptoAlgorithm& algorithm, 239 const blink::WebCryptoAlgorithm& algorithm,
213 const blink::WebCryptoKey& key, 240 const blink::WebCryptoKey& key,
214 const unsigned char* data, 241 const unsigned char* data,
215 unsigned data_size, 242 unsigned data_size,
216 blink::WebArrayBuffer* buffer) { 243 blink::WebArrayBuffer* buffer) {
217 return crypto_.EncryptInternal(algorithm, key, data, data_size, buffer); 244 return crypto_.EncryptInternal(algorithm, key, data, data_size, buffer);
218 } 245 }
219 246
220 bool EncryptInternal( 247 bool EncryptInternal(
(...skipping 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after
1278 // Fail with bad modulus. 1305 // Fail with bad modulus.
1279 algorithm = webcrypto::CreateRsaKeyGenAlgorithm( 1306 algorithm = webcrypto::CreateRsaKeyGenAlgorithm(
1280 blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, 0, public_exponent); 1307 blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, 0, public_exponent);
1281 EXPECT_FALSE(GenerateKeyPairInternal( 1308 EXPECT_FALSE(GenerateKeyPairInternal(
1282 algorithm, extractable, usage_mask, &public_key, &private_key)); 1309 algorithm, extractable, usage_mask, &public_key, &private_key));
1283 1310
1284 // Fail with bad exponent: larger than unsigned long. 1311 // Fail with bad exponent: larger than unsigned long.
1285 unsigned exponent_length = sizeof(unsigned long) + 1; // NOLINT 1312 unsigned exponent_length = sizeof(unsigned long) + 1; // NOLINT
1286 const std::vector<uint8> long_exponent(exponent_length, 0x01); 1313 const std::vector<uint8> long_exponent(exponent_length, 0x01);
1287 algorithm = webcrypto::CreateRsaKeyGenAlgorithm( 1314 algorithm = webcrypto::CreateRsaKeyGenAlgorithm(
1288 blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, modulus_length, long_exponent); 1315 blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5,
1316 modulus_length,
1317 long_exponent);
1289 EXPECT_FALSE(GenerateKeyPairInternal( 1318 EXPECT_FALSE(GenerateKeyPairInternal(
1290 algorithm, extractable, usage_mask, &public_key, &private_key)); 1319 algorithm, extractable, usage_mask, &public_key, &private_key));
1291 1320
1292 // Fail with bad exponent: empty. 1321 // Fail with bad exponent: empty.
1293 const std::vector<uint8> empty_exponent; 1322 const std::vector<uint8> empty_exponent;
1294 algorithm = webcrypto::CreateRsaKeyGenAlgorithm( 1323 algorithm = webcrypto::CreateRsaKeyGenAlgorithm(
1295 blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, 1324 blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5,
1296 modulus_length, 1325 modulus_length,
1297 empty_exponent); 1326 empty_exponent);
1298 EXPECT_FALSE(GenerateKeyPairInternal( 1327 EXPECT_FALSE(GenerateKeyPairInternal(
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
1614 // Do a successful decrypt with good data just for confirmation. 1643 // Do a successful decrypt with good data just for confirmation.
1615 EXPECT_TRUE(DecryptInternal( 1644 EXPECT_TRUE(DecryptInternal(
1616 algorithm, 1645 algorithm,
1617 private_key, 1646 private_key,
1618 reinterpret_cast<const unsigned char*>(encrypted_data.data()), 1647 reinterpret_cast<const unsigned char*>(encrypted_data.data()),
1619 encrypted_data.byteLength(), 1648 encrypted_data.byteLength(),
1620 &decrypted_data)); 1649 &decrypted_data));
1621 ExpectArrayBufferMatchesHex(message_hex_str, decrypted_data); 1650 ExpectArrayBufferMatchesHex(message_hex_str, decrypted_data);
1622 } 1651 }
1623 1652
1653 TEST_F(WebCryptoImplTest, MAYBE(RsaSsaSignVerify)) {
1654
Ryan Sleevi 2013/12/20 02:08:50 unnecessary line break
padolph 2013/12/21 02:44:17 Done.
1655 // Generate an RSA key pair.
1656 blink::WebCryptoAlgorithm algorithm = webcrypto::CreateRsaKeyGenAlgorithm(
1657 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5,
1658 1024,
1659 HexStringToBytes("010001"));
1660 const blink::WebCryptoKeyUsageMask usage_mask =
1661 blink::WebCryptoKeyUsageSign | blink::WebCryptoKeyUsageVerify;
1662 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull();
1663 blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull();
1664 EXPECT_TRUE(GenerateKeyPairInternal(
1665 algorithm, true, usage_mask, &public_key, &private_key));
Ryan Sleevi 2013/12/20 02:08:50 Tests that generate keys = tests that slow down.
padolph 2013/12/21 02:44:17 Changed here to import known keys, and similarly c
1666 EXPECT_FALSE(public_key.isNull());
1667 EXPECT_FALSE(private_key.isNull());
1668
1669 algorithm = CreateRsaAlgorithmWithInnerHash(
1670 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5,
1671 blink::WebCryptoAlgorithmIdSha1);
1672 blink::WebArrayBuffer signature;
1673 bool signature_match;
1674
1675 const char* kTestData[] = {"", "00", "010203040506070809"};
Ryan Sleevi 2013/12/20 02:08:50 As a corpus of test data, this is not really a goo
padolph 2013/12/21 02:44:17 Me neither. I copied it from the HMAC sign/verify
1676 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestData); ++i) {
1677
Ryan Sleevi 2013/12/20 02:08:50 unnecessary line break
padolph 2013/12/21 02:44:17 Done.
1678 SCOPED_TRACE(i);
1679
1680 // Sign data with the private key.
1681 const std::vector<uint8> data = HexStringToBytes(kTestData[i]);
1682 ASSERT_TRUE(SignInternal(algorithm, private_key, data, &signature));
1683
1684 // Verify the signature with the public key.
1685 EXPECT_TRUE(VerifySignatureInternal(
1686 algorithm,
1687 public_key,
1688 static_cast<const unsigned char*>(signature.data()),
1689 signature.byteLength(),
1690 data,
1691 &signature_match));
1692 EXPECT_TRUE(signature_match);
1693 }
1694
1695 const std::vector<uint8> data = HexStringToBytes("010203040506070809");
1696 ASSERT_TRUE(SignInternal(algorithm, private_key, data, &signature));
1697
1698 // Ensure truncated signature does not verify by passing one less byte.
1699 EXPECT_TRUE(VerifySignatureInternal(
1700 algorithm,
1701 public_key,
1702 static_cast<const unsigned char*>(signature.data()),
1703 signature.byteLength() - 1,
1704 data,
1705 &signature_match));
1706 EXPECT_FALSE(signature_match);
1707
1708 // Ensure corrupted signature does not verify.
1709 std::vector<uint8> corrupt_sig(
1710 static_cast<uint8*>(signature.data()),
1711 static_cast<uint8*>(signature.data()) + signature.byteLength());
1712 corrupt_sig[corrupt_sig.size() / 2] ^= 0x1;
1713 EXPECT_TRUE(VerifySignatureInternal(
1714 algorithm,
1715 public_key,
1716 webcrypto::Uint8VectorStart(corrupt_sig),
1717 corrupt_sig.size(),
1718 data,
1719 &signature_match));
1720 EXPECT_FALSE(signature_match);
1721
1722 // Ensure extra long signature does not cause issues and fails.
Ryan Sleevi 2013/12/20 02:08:50 I have trouble parsing this sentence "does not ca
padolph 2013/12/21 02:44:17 1024 above is the modulus size in bits. The value
1723 const unsigned char kLongSignature[1024] = { 0 };
1724 EXPECT_TRUE(VerifySignatureInternal(
1725 algorithm,
1726 public_key,
1727 kLongSignature,
1728 sizeof(kLongSignature),
1729 data,
1730 &signature_match));
1731 EXPECT_FALSE(signature_match);
1732
1733 // Ensure can't verify using a private key.
Ryan Sleevi 2013/12/20 02:08:50 Proper sentence structure // Ensure that verifyin
padolph 2013/12/21 02:44:17 Done.
1734 EXPECT_FALSE(VerifySignatureInternal(
1735 algorithm,
1736 private_key,
1737 static_cast<const unsigned char*>(signature.data()),
1738 signature.byteLength(),
1739 data,
1740 &signature_match));
1741
1742 // Ensure can't sign using a public key.
1743 EXPECT_FALSE(SignInternal(algorithm, public_key, data, &signature));
1744
1745 // Fail sign with malformed algorithm (no inner hash)
1746 algorithm =
1747 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5);
1748 EXPECT_FALSE(SignInternal(algorithm, private_key, data, &signature));
1749
1750 // Fail sign and verify with incompatible algorithm
1751 algorithm =
1752 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5);
1753 EXPECT_FALSE(SignInternal(algorithm, private_key, data, &signature));
1754 EXPECT_FALSE(VerifySignatureInternal(
1755 algorithm,
1756 public_key,
1757 static_cast<const unsigned char*>(signature.data()),
1758 signature.byteLength(),
1759 data,
1760 &signature_match));
1761
1762 // Some crypto libraries (NSS) can automatically select the RSA SSA inner hash
1763 // based solely on the contents of the input signature data. In the Web Crypto
1764 // implementation, we want the inner hash instead to be specified by the input
1765 // algorithm parameter. To validate this behavior, call Verify with a computed
1766 // signature that used one hash type (SHA-1), but pass in an algorithm with a
1767 // different inner hash type (SHA-256). If the hash type is determined by the
1768 // signature itself (undesired), the verify will pass, while if the hash type
1769 // is specified by the input algorithm (desired), the verify will fail.
Ryan Sleevi 2013/12/20 02:08:50 Do not use pronouns in comments ("we").
padolph 2013/12/21 02:44:17 Done.
1770
1771 // Compute a signature using SHA-1 as the inner hash.
1772 EXPECT_TRUE(SignInternal(CreateRsaAlgorithmWithInnerHash(
1773 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5,
1774 blink::WebCryptoAlgorithmIdSha1),
1775 private_key,
1776 data,
1777 &signature));
1778
1779 // Now verify using an algorithm whose inner hash is SHA-256, not SHA-1. The
1780 // signature should not verify.
1781 // NOTE: public_key was produced by generateKey, and so its associated
1782 // algorithm has WebCryptoRsaKeyGenParams and not WebCryptoRsaSsaParams. Thus
1783 // it has no inner hash to conflict with the input algorithm.
1784 bool is_match;
1785 EXPECT_TRUE(VerifySignatureInternal(
1786 CreateRsaAlgorithmWithInnerHash(
1787 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5,
1788 blink::WebCryptoAlgorithmIdSha256),
1789 public_key,
1790 static_cast<const unsigned char*>(signature.data()),
1791 signature.byteLength(),
1792 data,
1793 &is_match));
1794 EXPECT_FALSE(is_match);
1795 }
1796
1797 TEST_F(WebCryptoImplTest, MAYBE(RsaSignVerifyKnownAnswer)) {
1798
1799 // Use the NIST test vectors from Example 1 of
1800 // ftp://ftp.rsa.com/pub/rsalabs/tmp/pkcs1v15sign-vectors.txt
1801 // These vectors are known answers for RSA PKCS#1 v1.5 Signature with a SHA-1
1802 // digest, using a predefined key pair.
1803
1804 // The following key pair is comprised of the SPKI (public key) and PKCS#8
1805 // (private key) representations of the key pair provided in Example 1 of the
1806 // NIST link above.
1807 const std::string public_key_spki_der_hex =
1808 "30819f300d06092a864886f70d010101050003818d0030818902818100a5"
1809 "6e4a0e701017589a5187dc7ea841d156f2ec0e36ad52a44dfeb1e61f7ad9"
1810 "91d8c51056ffedb162b4c0f283a12a88a394dff526ab7291cbb307ceabfc"
1811 "e0b1dfd5cd9508096d5b2b8b6df5d671ef6377c0921cb23c270a70e2598e"
1812 "6ff89d19f105acc2d3f0cb35f29280e1386b6f64c4ef22e1e1f20d0ce8cf"
1813 "fb2249bd9a21370203010001";
1814 const std::string private_key_pkcs8_der_hex =
1815 "30820275020100300d06092a864886f70d01010105000482025f3082025b"
1816 "02010002818100a56e4a0e701017589a5187dc7ea841d156f2ec0e36ad52"
1817 "a44dfeb1e61f7ad991d8c51056ffedb162b4c0f283a12a88a394dff526ab"
1818 "7291cbb307ceabfce0b1dfd5cd9508096d5b2b8b6df5d671ef6377c0921c"
1819 "b23c270a70e2598e6ff89d19f105acc2d3f0cb35f29280e1386b6f64c4ef"
1820 "22e1e1f20d0ce8cffb2249bd9a2137020301000102818033a5042a90b27d"
1821 "4f5451ca9bbbd0b44771a101af884340aef9885f2a4bbe92e894a724ac3c"
1822 "568c8f97853ad07c0266c8c6a3ca0929f1e8f11231884429fc4d9ae55fee"
1823 "896a10ce707c3ed7e734e44727a39574501a532683109c2abacaba283c31"
1824 "b4bd2f53c3ee37e352cee34f9e503bd80c0622ad79c6dcee883547c6a3b3"
1825 "25024100e7e8942720a877517273a356053ea2a1bc0c94aa72d55c6e8629"
1826 "6b2dfc967948c0a72cbccca7eacb35706e09a1df55a1535bd9b3cc34160b"
1827 "3b6dcd3eda8e6443024100b69dca1cf7d4d7ec81e75b90fcca874abcde12"
1828 "3fd2700180aa90479b6e48de8d67ed24f9f19d85ba275874f542cd20dc72"
1829 "3e6963364a1f9425452b269a6799fd024028fa13938655be1f8a159cbaca"
1830 "5a72ea190c30089e19cd274a556f36c4f6e19f554b34c077790427bbdd8d"
1831 "d3ede2448328f385d81b30e8e43b2fffa02786197902401a8b38f398fa71"
1832 "2049898d7fb79ee0a77668791299cdfa09efc0e507acb21ed74301ef5bfd"
1833 "48be455eaeb6e1678255827580a8e4e8e14151d1510a82a3f2e729024027"
1834 "156aba4126d24a81f3a528cbfb27f56886f840a9f6e86e17a44b94fe9319"
1835 "584b8e22fdde1e5a2e3bd8aa5ba8d8584194eb2190acf832b847f13a3d24"
1836 "a79f4d";
1837
1838 // The following data are the input messages and corresponding computed RSA
1839 // PKCS#1 v1.5 signatures from the NIST link above.
1840 struct TestCase {
1841 const std::string message_hex;
1842 const std::string signature_hex;
1843 };
1844
1845 const TestCase kTests[] = {
Ryan Sleevi 2013/12/20 02:08:50 I'm really getting the feeling that we're mixing t
padolph 2013/12/21 02:44:17 Adjusted wrapping. I'm hesitant to create a new f
1846 // PKCS#1 v1.5 Signature Example 1.1
1847 {"cdc87da223d786df3b45e0bbbc721326"
1848 "d1ee2af806cc315475cc6f0d9c66e1b6"
1849 "2371d45ce2392e1ac92844c310102f15"
1850 "6a0d8d52c1f4c40ba3aa65095786cb76"
1851 "9757a6563ba958fed0bcc984e8b517a3"
1852 "d5f515b23b8a41e74aa867693f90dfb0"
1853 "61a6e86dfaaee64472c00e5f20945729"
1854 "cbebe77f06ce78e08f4098fba41f9d61"
1855 "93c0317e8b60d4b6084acb42d29e3808"
1856 "a3bc372d85e331170fcbf7cc72d0b71c"
1857 "296648b3a4d10f416295d0807aa625ca"
1858 "b2744fd9ea8fd223c42537029828bd16"
1859 "be02546f130fd2e33b936d2676e08aed"
1860 "1b73318b750a0167d0",
1861 "6bc3a06656842930a247e30d5864b4d8"
1862 "19236ba7c68965862ad7dbc4e24af28e"
1863 "86bb531f03358be5fb74777c6086f850"
1864 "caef893f0d6fcc2d0c91ec013693b4ea"
1865 "00b80cd49aac4ecb5f8911afe539ada4"
1866 "a8f3823d1d13e472d1490547c659c761"
1867 "7f3d24087ddb6f2b72096167fc097cab"
1868 "18e9a458fcb634cdce8ee35894c484d7"},
1869 // PKCS#1 v1.5 Signature Example 1.2
1870 {"851384cdfe819c22ed6c4ccb30daeb5c"
1871 "f059bc8e1166b7e3530c4c233e2b5f8f"
1872 "71a1cca582d43ecc72b1bca16dfc7013"
1873 "226b9e",
1874 "84fd2ce734ec1da828d0f15bf49a8707"
1875 "c15d05948136de537a3db421384167c8"
1876 "6fae022587ee9e137daee75473826293"
1877 "2d271c744c6d3a189ad4311bdb020492"
1878 "e322fbddc40406ea860d4e8ea2a4084a"
1879 "a98b9622a446756fdb740ddb3d91db76"
1880 "70e211661bbf8709b11c08a70771422d"
1881 "1a12def29f0688a192aebd89e0f896f8"},
1882 // PKCS#1 v1.5 Signature Example1.3
1883 {"a4b159941761c40c6a82f2b80d1b94f5"
1884 "aa2654fd17e12d588864679b54cd04ef"
1885 "8bd03012be8dc37f4b83af7963faff0d"
1886 "fa225477437c48017ff2be8191cf3955"
1887 "fc07356eab3f322f7f620e21d254e5db"
1888 "4324279fe067e0910e2e81ca2cab31c7"
1889 "45e67a54058eb50d993cdb9ed0b4d029"
1890 "c06d21a94ca661c3ce27fae1d6cb20f4"
1891 "564d66ce4767583d0e5f060215b59017"
1892 "be85ea848939127bd8c9c4d47b51056c"
1893 "031cf336f17c9980f3b8f5b9b6878e8b"
1894 "797aa43b882684333e17893fe9caa6aa"
1895 "299f7ed1a18ee2c54864b7b2b99b7261"
1896 "8fb02574d139ef50f019c9eef4169713"
1897 "38e7d470",
1898 "0b1f2e5180e5c7b4b5e672929f664c48"
1899 "96e50c35134b6de4d5a934252a3a245f"
1900 "f48340920e1034b7d5a5b524eb0e1cf1"
1901 "2befef49b27b732d2c19e1c43217d6e1"
1902 "417381111a1d36de6375cf455b3c9812"
1903 "639dbc27600c751994fb61799ecf7da6"
1904 "bcf51540afd0174db4033188556675b1"
1905 "d763360af46feeca5b60f882829ee7b2"},
1906 // PKCS#1 v1.5 Signature Example 1.4
1907 {"bc656747fa9eafb3f0",
1908 "45607ad611cf5747a41ac94d0ffec878"
1909 "bdaf63f6b57a4b088bf36e34e109f840"
1910 "f24b742ada16102dabf951cbc44f8982"
1911 "e94ed4cd09448d20ec0efa73545f80b6"
1912 "5406bed6194a61c340b4ad1568cbb758"
1913 "51049f11af1734964076e02029aee200"
1914 "e40e80be0f4361f69841c4f92a4450a2"
1915 "286d43289b405554c54d25c6ecb584f4"},
1916 // PKCS#1 v1.5 Signature Example 1.5
1917 {"b45581547e5427770c768e8b82b75564"
1918 "e0ea4e9c32594d6bff706544de0a8776"
1919 "c7a80b4576550eee1b2acabc7e8b7d3e"
1920 "f7bb5b03e462c11047eadd00629ae575"
1921 "480ac1470fe046f13a2bf5af17921dc4"
1922 "b0aa8b02bee6334911651d7f8525d10f"
1923 "32b51d33be520d3ddf5a709955a3dfe7"
1924 "8283b9e0ab54046d150c177f037fdccc"
1925 "5be4ea5f68b5e5a38c9d7edcccc4975f"
1926 "455a6909b4",
1927 "54be9d90877515f450279c15b5f61ad6"
1928 "f15ecc95f18cbed82b65b1667a575809"
1929 "587994668044f3bc2ae7f884501f64f0"
1930 "b43f588cfa205a6ab704328c2d4ab92a"
1931 "7ae13440614d3e085f401da9ad28e210"
1932 "5e4a0edb681a6424df047388ce051ee9"
1933 "df7bc2163fe347520ad51ccd51806438"
1934 "3e741acad3cbdc2cb5a7c68e868464c2"},
1935 // PKCS#1 v1.5 Signature Example 1.6
1936 {"10aae9a0ab0b595d0841207b700d48d7"
1937 "5faedde3b775cd6b4cc88ae06e4694ec"
1938 "74ba18f8520d4f5ea69cbbe7cc2beba4"
1939 "3efdc10215ac4eb32dc302a1f53dc6c4"
1940 "352267e7936cfebf7c8d67035784a390"
1941 "9fa859c7b7b59b8e39c5c2349f1886b7"
1942 "05a30267d402f7486ab4f58cad5d69ad"
1943 "b17ab8cd0ce1caf5025af4ae24b1fb87"
1944 "94c6070cc09a51e2f9911311e3877d00"
1945 "44c71c57a993395008806b723ac38373"
1946 "d395481818528c1e7053739282053529"
1947 "510e935cd0fa77b8fa53cc2d474bd4fb"
1948 "3cc5c672d6ffdc90a00f9848712c4bcf"
1949 "e46c60573659b11e6457e861f0f604b6"
1950 "138d144f8ce4e2da73",
1951 "0e6ff63a856b9cbd5dbe423183122047"
1952 "dd39d6f76d1b2310e546fe9ee73b33ef"
1953 "a7c78f9474455c9e5b88cb383aafc369"
1954 "8668e7b7a59a9cbb5b0897b6c5afb7f8"
1955 "bac4b924e98d760a15fc43d2814ab2d5"
1956 "187f79bed9915a93397ebc22a7677506"
1957 "a02e076d3ffdc0441dbd4db00453dc28"
1958 "d830e0573f77b817b505c38b4a4bb5d0"},
1959 // PKCS#1 v1.5 Signature Example 1.7
1960 {"efb5da1b4d1e6d9a5dff92d0184da7e3"
1961 "1f877d1281ddda625664869e8379e67a"
1962 "d3b75eae74a580e9827abd6eb7a002cb"
1963 "5411f5266797768fb8e95ae40e3e8b34"
1964 "66f5ab15d69553952939ec23e61d5849"
1965 "7fac76aa1c0bb5a3cb4a54383587c7bb"
1966 "78d13eefda205443e6ce4365802df55c"
1967 "64713497984e7ca96722b3edf84d56",
1968 "8385d58533a995f72df262b70f40b391"
1969 "ddf515f464b9d2cc2d66398fc05689d8"
1970 "11632946d62eabdca7a31fcf6cd6c981"
1971 "d28bbc29083e4a6d5b2b378ca4e540f0"
1972 "60b96d53ad2693f82178b94e2e2f86b9"
1973 "accfa02025107e062ab7080175684501"
1974 "028f676461d81c008fe4750671649970"
1975 "878fc175cf98e96b2ecbf6874d77dacb"},
1976 // PKCS#1 v1.5 Signature Example 1.8
1977 {"53bb58ce42f1984940552657233b1496"
1978 "9af365c0a561a4132af18af39432280e"
1979 "3e437082434b19231837184f02cf2b2e"
1980 "726bebf74d7ae3256d8b72f3eafdb134"
1981 "d33de06f2991d299d59f5468d43b9958"
1982 "d6a968f5969edbbc6e7185cbc716c7c9"
1983 "45dafa9cc71ddfaaa01094a452ddf5e2"
1984 "407320400bf05ea9729cafbf0600e788"
1985 "07ef9462e3fde32ed7d981a56f4751ef"
1986 "64fb4549910ecc911d728053b3994300"
1987 "4740e6f5821fe8d75c0617bf2c6b24bb"
1988 "fc34013fc95f0dedf5ba297f504fb833"
1989 "da2a436d1d8ff1cc5193e2a64389fced"
1990 "918e7feb6716330f66801db9497549cf"
1991 "1d3bd97cf1bc6255",
1992 "8e1f3d26ec7c6bbb8c54c5d25f312058"
1993 "7803af6d3c2b99a37ced6a3657d4ae54"
1994 "266f63fffde660c866d65d0ab0589e1d"
1995 "12d9ce6054b05c8668ae127171ccaae7"
1996 "f1cd409677f52157b6123ab227f27a00"
1997 "966d1439b42a32169d1070394026fc8b"
1998 "c93545b1ac252d0f7da751c02e33a478"
1999 "31fbd71514c2bbbd3adb6740c0fd68ad"},
2000 // PKCS#1 v1.5 Signature Example 1.9
2001 {"27cadc698450945f204ec3cf8c6cbd8c"
2002 "eb4cc0cbe312274fa96b04deac855160"
2003 "c0e04e4ac5d38210c27c",
2004 "7b63f9223356f35f6117f68c8f822003"
2005 "4fc2384ab5dc6904141f139314d6ee89"
2006 "f54ec6ffd18c413a23c5931c7fbb13c5"
2007 "55ccfd590e0eaa853c8c94d2520cd425"
2008 "0d9a05a193b65dc749b82478af0156ee"
2009 "1de55ddad33ec1f0099cad6c891a3617"
2010 "c7393d05fbfbbb00528a001df0b204eb"
2011 "df1a341090dea89f870a877458427f7b"},
2012 // PKCS#1 v1.5 Signature Example 1.10
2013 {"716407e901b9ef92d761b013fd13eb7a"
2014 "d72aed",
2015 "2a22dbe3774d5b297201b55a0f17f42d"
2016 "ce63b7845cb325cfe951d0badb5c5a14"
2017 "472143d896c86cc339f83671164215ab"
2018 "c97862f2151654e75a3b357c37311b3d"
2019 "7268cab540202e23bee52736f2cd86cc"
2020 "e0c7dbde95e1c600a47395dc5eb0a472"
2021 "153fbc4fb21b643e0c04ae14dd37e97e"
2022 "617a7567c89652219781001ba6f83298"},
2023 // PKCS#1 v1.5 Signature Example 1.11
2024 {"46c24e4103001629c712dd4ce8d747ee"
2025 "595d6c744ccc4f71347d9b8abf49d1b8"
2026 "fb2ef91b95dc899d4c0e3d2997e638f4"
2027 "cf3f68e0498de5aabd13f0dfe02ff26b"
2028 "a4379104e78ffa95ffbd15067ef8cbd7"
2029 "eb7860fecc71abe13d5c720a66851f2d"
2030 "efd4e795054d7bec024bb422a46a7368"
2031 "b56d95b47aebafbeadd612812593a70d"
2032 "b9f96d451ee15edb299308d777f4bb68"
2033 "ed3377c32156b41b7a9c92a14c8b8114"
2034 "4399c56a5a432f4f770aa97da8415d0b"
2035 "da2e813206031e70620031c881d616bf"
2036 "fd5f03bf147c1e73766c26246208",
2037 "12235b0b406126d9d260d447e923a110"
2038 "51fb243079f446fd73a70181d53634d7"
2039 "a0968e4ee27777eda63f6e4a3a91ad59"
2040 "85998a4848da59ce697b24bb332fa2ad"
2041 "9ce462ca4affdc21dab908e8ce15af6e"
2042 "b9105b1abcf39142aa17b34c4c092386"
2043 "a7abbfe028afdbebc14f2ce26fbee5ed"
2044 "eca11502d39a6b7403154843d98a62a7"},
2045 // PKCS#1 v1.5 Signature Example 1.12
2046 {"bc99a932aa16d622bfff79c50b4c4235"
2047 "8673261129e28d6a918ff1b0f1c4f46a"
2048 "d8afa98b0ca0f56f967975b0a29be882"
2049 "e93b6cd3fc33e1faef72e52b2ae0a3f1"
2050 "2024506e25690e902e78298214555653"
2051 "2284cf505789738f4da31fa1333d3af8"
2052 "62b2ba6b6ce7ab4cce6aba",
2053 "872ec5ad4f1846256f17e9936ac50e43"
2054 "e9963ea8c1e76f15879b7874d77d122a"
2055 "609dc8c561145b94bf4ffdffdeb17e6e"
2056 "76ffc6c10c0747f5e37a9f434f5609e7"
2057 "9da5250215a457afdf12c6507cc1551f"
2058 "54a28010595826a2c9b97fa0aa851cc6"
2059 "8b705d7a06d720ba027e4a1c0b019500"
2060 "fb63b78071684dcfa9772700b982dc66"},
2061 // PKCS#1 v1.5 Signature Example 1.13
2062 {"731e172ac063992c5b11ba170dfb23bb"
2063 "000d47ba195329cf278061037381514c"
2064 "146064c5285db130dd5bae98b7722259"
2065 "50eab05d3ea996f6fffb9a8c8622913f"
2066 "279914c89ada4f3dd77666a868bfcbff"
2067 "2b95b7daf453d4e2c9d75beee7f8e709"
2068 "05e4066a4f73aecc67f956aa5a3292b8"
2069 "488c917d317cfdc86253e690381e15ab",
2070 "76204eacc1d63ec1d6ad5bd0692e1a2f"
2071 "686df6e64ca945c77a824de212efa6d9"
2072 "782d81b4591403ff4020620298c07ebd"
2073 "3a8a61c5bf4dad62cbfc4ae6a03937be"
2074 "4b49a216d570fc6e81872937876e27bd"
2075 "19cf601effc30ddca573c9d56cd4569b"
2076 "db4851c450c42cb21e738cdd61027b8b"
2077 "e5e9b410fc46aa3f29e4be9e64451346"},
2078 // PKCS#1 v1.5 Signature Example 1.14
2079 {"0211382683a74d8d2a2cb6a06550563b"
2080 "e1c26ca62821e4ff163b720464fc3a28"
2081 "d91bedddc62749a5538eaf41fbe0c82a"
2082 "77e06ad99383c9e985ffb8a93fd4d7c5"
2083 "8db51ad91ba461d69a8fd7ddabe24967"
2084 "57a0c49122c1a79a85cc0553e8214d03"
2085 "6dfe0185efa0d05860c612fa0882c82d"
2086 "246e5830a67355dff18a2c36b732f988"
2087 "cfedc562264c6254b40fcabb97b76094"
2088 "7568dcd6a17cda6ee8855bddbab93702"
2089 "471aa0cfb1bed2e13118eba1175b73c9"
2090 "6253c108d0b2aba05ab8e17e84392e20"
2091 "085f47404d8365527dc3fb8f2bb48a50"
2092 "038e71361ccf973407",
2093 "525500918331f1042eae0c5c2054aa7f"
2094 "92deb26991b5796634f229daf9b49eb2"
2095 "054d87319f3cfa9b466bd075ef6699ae"
2096 "a4bd4a195a1c52968b5e2b75e092d846"
2097 "ea1b5cc27905a8e1d5e5de0edfdb2139"
2098 "1ebb951864ebd9f0b0ec35b654287136"
2099 "0a317b7ef13ae06af684e38e21b1e19b"
2100 "c7298e5d6fe0013a164bfa25d3e7313d"},
2101 // PKCS#1 v1.5 Signature Example 1.15
2102 {"fc6b700d22583388ab2f8dafcaf1a056"
2103 "20698020da4bae44dafbd0877b501250"
2104 "6dc3181d5c66bf023f348b41fd9f9479"
2105 "5ab96452a4219f2d39d72af359cf1956"
2106 "51c7",
2107 "4452a6cc2626b01e95ab306df0d0cc74"
2108 "84fbab3c22e9703283567f66eadc248d"
2109 "bda58fce7dd0c70cce3f150fca4b369d"
2110 "ff3b6237e2b16281ab55b53fb13089c8"
2111 "5cd265056b3d62a88bfc2135b16791f7"
2112 "fbcab9fd2dc33becb617be419d2c0461"
2113 "42a4d47b338314552edd4b6fe9ce1104"
2114 "ecec4a9958d7331e930fc09bf08a6e64"},
2115 // PKCS#1 v1.5 Signature Example 1.16
2116 {"13ba086d709cfa5fedaa557a89181a61"
2117 "40f2300ed6d7c3febb6cf68abebcbc67"
2118 "8f2bca3dc2330295eec45bb1c4075f3a"
2119 "da987eae88b39c51606cb80429e649d9"
2120 "8acc8441b1f8897db86c5a4ce0abf28b"
2121 "1b81dca3667697b850696b74a5ebd85d"
2122 "ec56c90f8abe513efa857853720be319"
2123 "607921bca947522cd8fac8cace5b827c"
2124 "3e5a129e7ee57f6b84932f14141ac427"
2125 "4e8cbb46e6912b0d3e2177d499d1840c"
2126 "d47d4d7ae0b4cdc4d3",
2127 "1f3b5a87db72a2c97bb3eff2a65a3012"
2128 "68eacd89f42abc1098c1f2de77b0832a"
2129 "65d7815feb35070063f221bb3453bd43"
2130 "4386c9a3fde18e3ca1687fb649e86c51"
2131 "d658619dde5debb86fe15491ff77ab74"
2132 "8373f1be508880d66ea81e870e91cdf1"
2133 "704875c17f0b10103188bc64eef5a355"
2134 "1b414c733670215b1a22702562581ab1"},
2135 // PKCS#1 v1.5 Signature Example 1.17
2136 {"eb1e5935",
2137 "370cb9839ae6074f84b2acd6e6f6b792"
2138 "1b4b523463757f6446716140c4e6c0e7"
2139 "5bec6ad0197ebfa86bf46d094f5f6cd3"
2140 "6dca3a5cc73c8bbb70e2c7c9ab5d964e"
2141 "c8e3dfde481b4a1beffd01b4ad15b31a"
2142 "e7aebb9b70344a9411083165fdf9c375"
2143 "4bbb8b94dd34bd4813dfada1f6937de4"
2144 "267d5597ca09a31e83d7f1a79dd19b5e"},
2145 // PKCS#1 v1.5 Signature Example 1.18
2146 {"6346b153e889c8228209630071c8a577"
2147 "83f368760b8eb908cfc2b276",
2148 "2479c975c5b1ae4c4e940f473a9045b8"
2149 "bf5b0bfca78ec29a38dfbedc8a749b7a"
2150 "2692f7c52d5bc7c831c7232372a00fed"
2151 "3b6b49e760ec99e074ff2eead5134e83"
2152 "05725dfa39212b84bd4b8d80bc8bc17a"
2153 "512823a3beb18fc08e45ed19c26c8177"
2154 "07d67fb05832ef1f12a33e90cd93b8a7"
2155 "80319e2963ca25a2af7b09ad8f595c21"},
2156 // PKCS#1 v1.5 Signature Example 1.19
2157 {"64702db9f825a0f3abc361974659f5e9"
2158 "d30c3aa4f56feac69050c72905e77fe0"
2159 "c22f88a378c21fcf45fe8a5c71730209"
2160 "3929",
2161 "152f3451c858d69594e6567dfb31291c"
2162 "1ee7860b9d15ebd5a5edd276ac3e6f7a"
2163 "8d1480e42b3381d2be023acf7ebbdb28"
2164 "de3d2163ae44259c6df98c335d045b61"
2165 "dac9dba9dbbb4e6ab4a083cd76b580cb"
2166 "e472206a1a9fd60680ceea1a570a29b0"
2167 "881c775eaef5525d6d2f344c28837d0a"
2168 "ca422bbb0f1aba8f6861ae18bd73fe44"},
2169 // PKCS#1 v1.5 Signature Example 1.20
2170 {"941921de4a1c9c1618d6f3ca3c179f6e"
2171 "29bae6ddf9a6a564f929e3ce82cf3265"
2172 "d7837d5e692be8dcc9e86c",
2173 "7076c287fc6fff2b20537435e5a3107c"
2174 "e4da10716186d01539413e609d27d1da"
2175 "6fd952c61f4bab91c045fa4f8683ecc4"
2176 "f8dde74227f773cff3d96db84718c494"
2177 "4b06affeba94b725f1b07d3928b2490a"
2178 "85c2f1abf492a9177a7cd2ea0c966875"
2179 "6f825bbec900fa8ac3824e114387ef57"
2180 "3780ca334882387b94e5aad7a27a28dc"}};
2181
2182 // Import the public key.
2183 blink::WebCryptoAlgorithm algorithm = CreateRsaAlgorithmWithInnerHash(
2184 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5,
2185 blink::WebCryptoAlgorithmIdSha1);
2186 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull();
2187 ASSERT_TRUE(ImportKeyInternal(
2188 blink::WebCryptoKeyFormatSpki,
2189 HexStringToBytes(public_key_spki_der_hex),
2190 algorithm,
2191 true,
2192 blink::WebCryptoKeyUsageVerify,
2193 &public_key));
2194 EXPECT_FALSE(public_key.isNull());
2195 EXPECT_TRUE(public_key.handle());
2196
2197 // Import the private key.
2198 blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull();
2199 ASSERT_TRUE(ImportKeyInternal(
2200 blink::WebCryptoKeyFormatPkcs8,
2201 HexStringToBytes(private_key_pkcs8_der_hex),
2202 algorithm,
2203 true,
2204 blink::WebCryptoKeyUsageSign,
2205 &private_key));
2206 EXPECT_FALSE(private_key.isNull());
2207 EXPECT_TRUE(private_key.handle());
2208
2209 // Validate the signatures are computed and verified as expected.
2210 blink::WebArrayBuffer signature;
2211 for (size_t idx = 0; idx < ARRAYSIZE_UNSAFE(kTests); ++idx) {
2212
Ryan Sleevi 2013/12/20 02:08:50 unnecessary vertical whitespace.
padolph 2013/12/21 02:44:17 Done.
2213 SCOPED_TRACE(idx);
2214 const TestCase& test = kTests[idx];
2215 const std::vector<uint8> message = HexStringToBytes(test.message_hex);
2216
2217 signature.reset();
2218 ASSERT_TRUE(SignInternal(algorithm, private_key, message, &signature));
2219 ExpectArrayBufferMatchesHex(test.signature_hex, signature);
2220
2221 bool is_match = false;
2222 ASSERT_TRUE(VerifySignatureInternal(
2223 algorithm,
2224 public_key,
2225 HexStringToBytes(test.signature_hex),
2226 message,
2227 &is_match));
2228 EXPECT_TRUE(is_match);
2229 }
2230 }
2231
1624 TEST_F(WebCryptoImplTest, MAYBE(AesKwKeyImport)) { 2232 TEST_F(WebCryptoImplTest, MAYBE(AesKwKeyImport)) {
1625 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); 2233 blink::WebCryptoKey key = blink::WebCryptoKey::createNull();
1626 blink::WebCryptoAlgorithm algorithm = 2234 blink::WebCryptoAlgorithm algorithm =
1627 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdAesKw); 2235 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdAesKw);
1628 2236
1629 // Import a 128-bit Key Encryption Key (KEK) 2237 // Import a 128-bit Key Encryption Key (KEK)
1630 std::string key_raw_hex_in = "025a8cf3f08b4f6c5f33bbc76a471939"; 2238 std::string key_raw_hex_in = "025a8cf3f08b4f6c5f33bbc76a471939";
1631 ASSERT_TRUE(ImportKeyInternal(blink::WebCryptoKeyFormatRaw, 2239 ASSERT_TRUE(ImportKeyInternal(blink::WebCryptoKeyFormatRaw,
1632 HexStringToBytes(key_raw_hex_in), 2240 HexStringToBytes(key_raw_hex_in),
1633 algorithm, 2241 algorithm,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1698 "72d4e475ff34215416c9ad9c8281247a4d730c5f275ac23f376e73e3bce8d7d5a"; 2306 "72d4e475ff34215416c9ad9c8281247a4d730c5f275ac23f376e73e3bce8d7d5a";
1699 EXPECT_FALSE(ImportKeyInternal(blink::WebCryptoKeyFormatRaw, 2307 EXPECT_FALSE(ImportKeyInternal(blink::WebCryptoKeyFormatRaw,
1700 HexStringToBytes(key_raw_hex_in), 2308 HexStringToBytes(key_raw_hex_in),
1701 algorithm, 2309 algorithm,
1702 true, 2310 true,
1703 blink::WebCryptoKeyUsageWrapKey, 2311 blink::WebCryptoKeyUsageWrapKey,
1704 &key)); 2312 &key));
1705 } 2313 }
1706 2314
1707 } // namespace content 2315 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698