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

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 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, RsaSsaSignVerify) {
1654
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));
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 = false;
eroman 2013/12/20 01:12:50 For the purpose of this test, I actually suggest l
padolph 2013/12/20 01:44:27 Done.
1674
1675 const char* kTestData[] = {"", "00", "010203040506070809"};
1676 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestData); ++i) {
1677
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 signature_match = false;
1686 EXPECT_TRUE(VerifySignatureInternal(
1687 algorithm,
1688 public_key,
1689 static_cast<const unsigned char*>(signature.data()),
1690 signature.byteLength(),
1691 data,
1692 &signature_match));
1693 EXPECT_TRUE(signature_match);
1694 }
1695
1696 const std::vector<uint8> data = HexStringToBytes("010203040506070809");
1697 ASSERT_TRUE(SignInternal(algorithm, private_key, data, &signature));
1698
1699 // Ensure truncated signature does not verify by passing one less byte.
1700 signature_match = false;
eroman 2013/12/20 01:12:50 Same here, leave off the reset
padolph 2013/12/20 01:44:27 Done.
1701 EXPECT_TRUE(VerifySignatureInternal(
1702 algorithm,
1703 public_key,
1704 static_cast<const unsigned char*>(signature.data()),
1705 signature.byteLength() - 1,
1706 data,
1707 &signature_match));
1708 EXPECT_FALSE(signature_match);
1709
1710 // Ensure corrupted signature does not verify.
1711 std::vector<uint8> corrupt_sig(
1712 static_cast<uint8*>(signature.data()),
1713 static_cast<uint8*>(signature.data()) + signature.byteLength());
1714 corrupt_sig[corrupt_sig.size() / 2] ^= 0x1;
1715 signature_match = false;
eroman 2013/12/20 01:12:50 remove
padolph 2013/12/20 01:44:27 Done.
1716 EXPECT_TRUE(VerifySignatureInternal(
1717 algorithm,
1718 public_key,
1719 webcrypto::Uint8VectorStart(corrupt_sig),
1720 corrupt_sig.size(),
1721 data,
1722 &signature_match));
1723 EXPECT_FALSE(signature_match);
1724
1725 // Ensure extra long signature does not cause issues and fails.
1726 const unsigned char kLongSignature[1024] = { 0 };
1727 EXPECT_TRUE(VerifySignatureInternal(
1728 algorithm,
1729 public_key,
1730 kLongSignature,
1731 sizeof(kLongSignature),
1732 data,
1733 &signature_match));
1734 EXPECT_FALSE(signature_match);
1735
1736 // Ensure can't verify using a private key.
1737 EXPECT_FALSE(VerifySignatureInternal(
1738 algorithm,
1739 private_key,
1740 static_cast<const unsigned char*>(signature.data()),
1741 signature.byteLength(),
1742 data,
1743 &signature_match));
1744
1745 // Ensure can't sign using a public key.
1746 EXPECT_FALSE(SignInternal(algorithm, public_key, data, &signature));
1747
1748 // TODO(padolph): Not sure this kind of test is required here, it might be
eroman 2013/12/20 01:12:50 Doesn't hurt to have it; but you are right, it is
padolph 2013/12/20 01:44:27 Done.
1749 // more appropriate on the Blink side.
1750 // Fail sign with malformed algorithm (no inner hash)
1751 algorithm =
1752 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5);
1753 EXPECT_FALSE(SignInternal(algorithm, private_key, data, &signature));
1754
1755 // TODO(padolph): Not sure this kind of test is required here, it might be
eroman 2013/12/20 01:12:50 Actually currently the blink side is not testing t
padolph 2013/12/20 01:44:27 Done.
1756 // more appropriate on the Blink side.
1757 // Fail sign and verify with incompatible algorithm
1758 algorithm =
1759 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5);
1760 EXPECT_FALSE(SignInternal(algorithm, private_key, data, &signature));
1761 EXPECT_FALSE(VerifySignatureInternal(
1762 algorithm,
1763 public_key,
1764 static_cast<const unsigned char*>(signature.data()),
1765 signature.byteLength(),
1766 data,
1767 &signature_match));
1768
1769 // Some crypto libraries (NSS) can automatically select the RSA SSA inner hash
1770 // based solely on the contents of the input signature data. In the Web Crypto
1771 // implementation, we want the inner hash instead to be specified by the input
1772 // algorithm parameter. To validate this behavior, call Verify with a computed
1773 // signature that used one hash type (SHA-1), but pass in an algorithm with a
1774 // different inner hash type (SHA-256). If the hash type is determined by the
1775 // signature itself (undesired), the verify will pass, while if the hash type
1776 // is specified by the input algorithm (desired), the verify will fail.
1777
1778 // Compute a signature using SHA-1 as the inner hash.
1779 EXPECT_TRUE(SignInternal(CreateRsaAlgorithmWithInnerHash(
1780 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5,
1781 blink::WebCryptoAlgorithmIdSha1),
1782 private_key,
1783 data,
1784 &signature));
1785
1786 // Now verify using an algorithm whose inner hash is SHA-256, not SHA-1. The
1787 // signature should not verify.
1788 // NOTE: public_key was produced by generateKey, and so its associated
1789 // algorithm has WebCryptoRsaKeyGenParams and not WebCryptoRsaSsaParams. Thus
eroman 2013/12/20 01:12:50 Thanks for the reminder: I will change this on th
1790 // it has no inner hash to conflict with the input algorithm.
1791 bool is_match = true;
1792 EXPECT_TRUE(VerifySignatureInternal(
1793 CreateRsaAlgorithmWithInnerHash(
1794 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5,
1795 blink::WebCryptoAlgorithmIdSha256),
1796 public_key,
1797 static_cast<const unsigned char*>(signature.data()),
1798 signature.byteLength(),
1799 data,
1800 &is_match));
1801 EXPECT_FALSE(is_match);
1802 }
1803
1804 TEST_F(WebCryptoImplTest, RsaSignVerifyKnownAnswer) {
1805
1806 // Use the NIST test vectors from Example 1 of
1807 // ftp://ftp.rsa.com/pub/rsalabs/tmp/pkcs1v15sign-vectors.txt
1808 // These vectors are known answers for RSA PKCS#1 v1.5 Signature with a SHA-1
1809 // digest, using a predefined key pair.
1810
1811 // The following key pair is comprised of the SPKI (public key) and PKCS#8
1812 // (private key) representations of the key pair provided in Example 1 of the
1813 // NIST link above.
1814 const std::string public_key_spki_der_hex =
1815 "30819f300d06092a864886f70d010101050003818d0030818902818100a5"
1816 "6e4a0e701017589a5187dc7ea841d156f2ec0e36ad52a44dfeb1e61f7ad9"
1817 "91d8c51056ffedb162b4c0f283a12a88a394dff526ab7291cbb307ceabfc"
1818 "e0b1dfd5cd9508096d5b2b8b6df5d671ef6377c0921cb23c270a70e2598e"
1819 "6ff89d19f105acc2d3f0cb35f29280e1386b6f64c4ef22e1e1f20d0ce8cf"
1820 "fb2249bd9a21370203010001";
1821 const std::string private_key_pkcs8_der_hex =
1822 "30820275020100300d06092a864886f70d01010105000482025f3082025b"
1823 "02010002818100a56e4a0e701017589a5187dc7ea841d156f2ec0e36ad52"
1824 "a44dfeb1e61f7ad991d8c51056ffedb162b4c0f283a12a88a394dff526ab"
1825 "7291cbb307ceabfce0b1dfd5cd9508096d5b2b8b6df5d671ef6377c0921c"
1826 "b23c270a70e2598e6ff89d19f105acc2d3f0cb35f29280e1386b6f64c4ef"
1827 "22e1e1f20d0ce8cffb2249bd9a2137020301000102818033a5042a90b27d"
1828 "4f5451ca9bbbd0b44771a101af884340aef9885f2a4bbe92e894a724ac3c"
1829 "568c8f97853ad07c0266c8c6a3ca0929f1e8f11231884429fc4d9ae55fee"
1830 "896a10ce707c3ed7e734e44727a39574501a532683109c2abacaba283c31"
1831 "b4bd2f53c3ee37e352cee34f9e503bd80c0622ad79c6dcee883547c6a3b3"
1832 "25024100e7e8942720a877517273a356053ea2a1bc0c94aa72d55c6e8629"
1833 "6b2dfc967948c0a72cbccca7eacb35706e09a1df55a1535bd9b3cc34160b"
1834 "3b6dcd3eda8e6443024100b69dca1cf7d4d7ec81e75b90fcca874abcde12"
1835 "3fd2700180aa90479b6e48de8d67ed24f9f19d85ba275874f542cd20dc72"
1836 "3e6963364a1f9425452b269a6799fd024028fa13938655be1f8a159cbaca"
1837 "5a72ea190c30089e19cd274a556f36c4f6e19f554b34c077790427bbdd8d"
1838 "d3ede2448328f385d81b30e8e43b2fffa02786197902401a8b38f398fa71"
1839 "2049898d7fb79ee0a77668791299cdfa09efc0e507acb21ed74301ef5bfd"
1840 "48be455eaeb6e1678255827580a8e4e8e14151d1510a82a3f2e729024027"
1841 "156aba4126d24a81f3a528cbfb27f56886f840a9f6e86e17a44b94fe9319"
1842 "584b8e22fdde1e5a2e3bd8aa5ba8d8584194eb2190acf832b847f13a3d24"
1843 "a79f4d";
1844
1845 // The following data are the input messages and corresponding computed RSA
1846 // PKCS#1 v1.5 signatures from the NIST link above.
1847 struct TestCase {
1848 const std::string message_hex;
1849 const std::string signature_hex;
1850 };
1851
1852 const TestCase kTests[] = {
1853 // PKCS#1 v1.5 Signature Example 1.1
1854 {"cdc87da223d786df3b45e0bbbc721326"
1855 "d1ee2af806cc315475cc6f0d9c66e1b6"
1856 "2371d45ce2392e1ac92844c310102f15"
1857 "6a0d8d52c1f4c40ba3aa65095786cb76"
1858 "9757a6563ba958fed0bcc984e8b517a3"
1859 "d5f515b23b8a41e74aa867693f90dfb0"
1860 "61a6e86dfaaee64472c00e5f20945729"
1861 "cbebe77f06ce78e08f4098fba41f9d61"
1862 "93c0317e8b60d4b6084acb42d29e3808"
1863 "a3bc372d85e331170fcbf7cc72d0b71c"
1864 "296648b3a4d10f416295d0807aa625ca"
1865 "b2744fd9ea8fd223c42537029828bd16"
1866 "be02546f130fd2e33b936d2676e08aed"
1867 "1b73318b750a0167d0",
1868 "6bc3a06656842930a247e30d5864b4d8"
1869 "19236ba7c68965862ad7dbc4e24af28e"
1870 "86bb531f03358be5fb74777c6086f850"
1871 "caef893f0d6fcc2d0c91ec013693b4ea"
1872 "00b80cd49aac4ecb5f8911afe539ada4"
1873 "a8f3823d1d13e472d1490547c659c761"
1874 "7f3d24087ddb6f2b72096167fc097cab"
1875 "18e9a458fcb634cdce8ee35894c484d7"},
1876 // PKCS#1 v1.5 Signature Example 1.2
1877 {"851384cdfe819c22ed6c4ccb30daeb5c"
1878 "f059bc8e1166b7e3530c4c233e2b5f8f"
1879 "71a1cca582d43ecc72b1bca16dfc7013"
1880 "226b9e",
1881 "84fd2ce734ec1da828d0f15bf49a8707"
1882 "c15d05948136de537a3db421384167c8"
1883 "6fae022587ee9e137daee75473826293"
1884 "2d271c744c6d3a189ad4311bdb020492"
1885 "e322fbddc40406ea860d4e8ea2a4084a"
1886 "a98b9622a446756fdb740ddb3d91db76"
1887 "70e211661bbf8709b11c08a70771422d"
1888 "1a12def29f0688a192aebd89e0f896f8"},
1889 // PKCS#1 v1.5 Signature Example1.3
1890 {"a4b159941761c40c6a82f2b80d1b94f5"
1891 "aa2654fd17e12d588864679b54cd04ef"
1892 "8bd03012be8dc37f4b83af7963faff0d"
1893 "fa225477437c48017ff2be8191cf3955"
1894 "fc07356eab3f322f7f620e21d254e5db"
1895 "4324279fe067e0910e2e81ca2cab31c7"
1896 "45e67a54058eb50d993cdb9ed0b4d029"
1897 "c06d21a94ca661c3ce27fae1d6cb20f4"
1898 "564d66ce4767583d0e5f060215b59017"
1899 "be85ea848939127bd8c9c4d47b51056c"
1900 "031cf336f17c9980f3b8f5b9b6878e8b"
1901 "797aa43b882684333e17893fe9caa6aa"
1902 "299f7ed1a18ee2c54864b7b2b99b7261"
1903 "8fb02574d139ef50f019c9eef4169713"
1904 "38e7d470",
1905 "0b1f2e5180e5c7b4b5e672929f664c48"
1906 "96e50c35134b6de4d5a934252a3a245f"
1907 "f48340920e1034b7d5a5b524eb0e1cf1"
1908 "2befef49b27b732d2c19e1c43217d6e1"
1909 "417381111a1d36de6375cf455b3c9812"
1910 "639dbc27600c751994fb61799ecf7da6"
1911 "bcf51540afd0174db4033188556675b1"
1912 "d763360af46feeca5b60f882829ee7b2"},
1913 // PKCS#1 v1.5 Signature Example 1.4
1914 {"bc656747fa9eafb3f0",
1915 "45607ad611cf5747a41ac94d0ffec878"
1916 "bdaf63f6b57a4b088bf36e34e109f840"
1917 "f24b742ada16102dabf951cbc44f8982"
1918 "e94ed4cd09448d20ec0efa73545f80b6"
1919 "5406bed6194a61c340b4ad1568cbb758"
1920 "51049f11af1734964076e02029aee200"
1921 "e40e80be0f4361f69841c4f92a4450a2"
1922 "286d43289b405554c54d25c6ecb584f4"},
1923 // PKCS#1 v1.5 Signature Example 1.5
1924 {"b45581547e5427770c768e8b82b75564"
1925 "e0ea4e9c32594d6bff706544de0a8776"
1926 "c7a80b4576550eee1b2acabc7e8b7d3e"
1927 "f7bb5b03e462c11047eadd00629ae575"
1928 "480ac1470fe046f13a2bf5af17921dc4"
1929 "b0aa8b02bee6334911651d7f8525d10f"
1930 "32b51d33be520d3ddf5a709955a3dfe7"
1931 "8283b9e0ab54046d150c177f037fdccc"
1932 "5be4ea5f68b5e5a38c9d7edcccc4975f"
1933 "455a6909b4",
1934 "54be9d90877515f450279c15b5f61ad6"
1935 "f15ecc95f18cbed82b65b1667a575809"
1936 "587994668044f3bc2ae7f884501f64f0"
1937 "b43f588cfa205a6ab704328c2d4ab92a"
1938 "7ae13440614d3e085f401da9ad28e210"
1939 "5e4a0edb681a6424df047388ce051ee9"
1940 "df7bc2163fe347520ad51ccd51806438"
1941 "3e741acad3cbdc2cb5a7c68e868464c2"},
1942 // PKCS#1 v1.5 Signature Example 1.6
1943 {"10aae9a0ab0b595d0841207b700d48d7"
1944 "5faedde3b775cd6b4cc88ae06e4694ec"
1945 "74ba18f8520d4f5ea69cbbe7cc2beba4"
1946 "3efdc10215ac4eb32dc302a1f53dc6c4"
1947 "352267e7936cfebf7c8d67035784a390"
1948 "9fa859c7b7b59b8e39c5c2349f1886b7"
1949 "05a30267d402f7486ab4f58cad5d69ad"
1950 "b17ab8cd0ce1caf5025af4ae24b1fb87"
1951 "94c6070cc09a51e2f9911311e3877d00"
1952 "44c71c57a993395008806b723ac38373"
1953 "d395481818528c1e7053739282053529"
1954 "510e935cd0fa77b8fa53cc2d474bd4fb"
1955 "3cc5c672d6ffdc90a00f9848712c4bcf"
1956 "e46c60573659b11e6457e861f0f604b6"
1957 "138d144f8ce4e2da73",
1958 "0e6ff63a856b9cbd5dbe423183122047"
1959 "dd39d6f76d1b2310e546fe9ee73b33ef"
1960 "a7c78f9474455c9e5b88cb383aafc369"
1961 "8668e7b7a59a9cbb5b0897b6c5afb7f8"
1962 "bac4b924e98d760a15fc43d2814ab2d5"
1963 "187f79bed9915a93397ebc22a7677506"
1964 "a02e076d3ffdc0441dbd4db00453dc28"
1965 "d830e0573f77b817b505c38b4a4bb5d0"},
1966 // PKCS#1 v1.5 Signature Example 1.7
1967 {"efb5da1b4d1e6d9a5dff92d0184da7e3"
1968 "1f877d1281ddda625664869e8379e67a"
1969 "d3b75eae74a580e9827abd6eb7a002cb"
1970 "5411f5266797768fb8e95ae40e3e8b34"
1971 "66f5ab15d69553952939ec23e61d5849"
1972 "7fac76aa1c0bb5a3cb4a54383587c7bb"
1973 "78d13eefda205443e6ce4365802df55c"
1974 "64713497984e7ca96722b3edf84d56",
1975 "8385d58533a995f72df262b70f40b391"
1976 "ddf515f464b9d2cc2d66398fc05689d8"
1977 "11632946d62eabdca7a31fcf6cd6c981"
1978 "d28bbc29083e4a6d5b2b378ca4e540f0"
1979 "60b96d53ad2693f82178b94e2e2f86b9"
1980 "accfa02025107e062ab7080175684501"
1981 "028f676461d81c008fe4750671649970"
1982 "878fc175cf98e96b2ecbf6874d77dacb"},
1983 // PKCS#1 v1.5 Signature Example 1.8
1984 {"53bb58ce42f1984940552657233b1496"
1985 "9af365c0a561a4132af18af39432280e"
1986 "3e437082434b19231837184f02cf2b2e"
1987 "726bebf74d7ae3256d8b72f3eafdb134"
1988 "d33de06f2991d299d59f5468d43b9958"
1989 "d6a968f5969edbbc6e7185cbc716c7c9"
1990 "45dafa9cc71ddfaaa01094a452ddf5e2"
1991 "407320400bf05ea9729cafbf0600e788"
1992 "07ef9462e3fde32ed7d981a56f4751ef"
1993 "64fb4549910ecc911d728053b3994300"
1994 "4740e6f5821fe8d75c0617bf2c6b24bb"
1995 "fc34013fc95f0dedf5ba297f504fb833"
1996 "da2a436d1d8ff1cc5193e2a64389fced"
1997 "918e7feb6716330f66801db9497549cf"
1998 "1d3bd97cf1bc6255",
1999 "8e1f3d26ec7c6bbb8c54c5d25f312058"
2000 "7803af6d3c2b99a37ced6a3657d4ae54"
2001 "266f63fffde660c866d65d0ab0589e1d"
2002 "12d9ce6054b05c8668ae127171ccaae7"
2003 "f1cd409677f52157b6123ab227f27a00"
2004 "966d1439b42a32169d1070394026fc8b"
2005 "c93545b1ac252d0f7da751c02e33a478"
2006 "31fbd71514c2bbbd3adb6740c0fd68ad"},
2007 // PKCS#1 v1.5 Signature Example 1.9
2008 {"27cadc698450945f204ec3cf8c6cbd8c"
2009 "eb4cc0cbe312274fa96b04deac855160"
2010 "c0e04e4ac5d38210c27c",
2011 "7b63f9223356f35f6117f68c8f822003"
2012 "4fc2384ab5dc6904141f139314d6ee89"
2013 "f54ec6ffd18c413a23c5931c7fbb13c5"
2014 "55ccfd590e0eaa853c8c94d2520cd425"
2015 "0d9a05a193b65dc749b82478af0156ee"
2016 "1de55ddad33ec1f0099cad6c891a3617"
2017 "c7393d05fbfbbb00528a001df0b204eb"
2018 "df1a341090dea89f870a877458427f7b"},
2019 // PKCS#1 v1.5 Signature Example 1.10
2020 {"716407e901b9ef92d761b013fd13eb7a"
2021 "d72aed",
2022 "2a22dbe3774d5b297201b55a0f17f42d"
2023 "ce63b7845cb325cfe951d0badb5c5a14"
2024 "472143d896c86cc339f83671164215ab"
2025 "c97862f2151654e75a3b357c37311b3d"
2026 "7268cab540202e23bee52736f2cd86cc"
2027 "e0c7dbde95e1c600a47395dc5eb0a472"
2028 "153fbc4fb21b643e0c04ae14dd37e97e"
2029 "617a7567c89652219781001ba6f83298"},
2030 // PKCS#1 v1.5 Signature Example 1.11
2031 {"46c24e4103001629c712dd4ce8d747ee"
2032 "595d6c744ccc4f71347d9b8abf49d1b8"
2033 "fb2ef91b95dc899d4c0e3d2997e638f4"
2034 "cf3f68e0498de5aabd13f0dfe02ff26b"
2035 "a4379104e78ffa95ffbd15067ef8cbd7"
2036 "eb7860fecc71abe13d5c720a66851f2d"
2037 "efd4e795054d7bec024bb422a46a7368"
2038 "b56d95b47aebafbeadd612812593a70d"
2039 "b9f96d451ee15edb299308d777f4bb68"
2040 "ed3377c32156b41b7a9c92a14c8b8114"
2041 "4399c56a5a432f4f770aa97da8415d0b"
2042 "da2e813206031e70620031c881d616bf"
2043 "fd5f03bf147c1e73766c26246208",
2044 "12235b0b406126d9d260d447e923a110"
2045 "51fb243079f446fd73a70181d53634d7"
2046 "a0968e4ee27777eda63f6e4a3a91ad59"
2047 "85998a4848da59ce697b24bb332fa2ad"
2048 "9ce462ca4affdc21dab908e8ce15af6e"
2049 "b9105b1abcf39142aa17b34c4c092386"
2050 "a7abbfe028afdbebc14f2ce26fbee5ed"
2051 "eca11502d39a6b7403154843d98a62a7"},
2052 // PKCS#1 v1.5 Signature Example 1.12
2053 {"bc99a932aa16d622bfff79c50b4c4235"
2054 "8673261129e28d6a918ff1b0f1c4f46a"
2055 "d8afa98b0ca0f56f967975b0a29be882"
2056 "e93b6cd3fc33e1faef72e52b2ae0a3f1"
2057 "2024506e25690e902e78298214555653"
2058 "2284cf505789738f4da31fa1333d3af8"
2059 "62b2ba6b6ce7ab4cce6aba",
2060 "872ec5ad4f1846256f17e9936ac50e43"
2061 "e9963ea8c1e76f15879b7874d77d122a"
2062 "609dc8c561145b94bf4ffdffdeb17e6e"
2063 "76ffc6c10c0747f5e37a9f434f5609e7"
2064 "9da5250215a457afdf12c6507cc1551f"
2065 "54a28010595826a2c9b97fa0aa851cc6"
2066 "8b705d7a06d720ba027e4a1c0b019500"
2067 "fb63b78071684dcfa9772700b982dc66"},
2068 // PKCS#1 v1.5 Signature Example 1.13
2069 {"731e172ac063992c5b11ba170dfb23bb"
2070 "000d47ba195329cf278061037381514c"
2071 "146064c5285db130dd5bae98b7722259"
2072 "50eab05d3ea996f6fffb9a8c8622913f"
2073 "279914c89ada4f3dd77666a868bfcbff"
2074 "2b95b7daf453d4e2c9d75beee7f8e709"
2075 "05e4066a4f73aecc67f956aa5a3292b8"
2076 "488c917d317cfdc86253e690381e15ab",
2077 "76204eacc1d63ec1d6ad5bd0692e1a2f"
2078 "686df6e64ca945c77a824de212efa6d9"
2079 "782d81b4591403ff4020620298c07ebd"
2080 "3a8a61c5bf4dad62cbfc4ae6a03937be"
2081 "4b49a216d570fc6e81872937876e27bd"
2082 "19cf601effc30ddca573c9d56cd4569b"
2083 "db4851c450c42cb21e738cdd61027b8b"
2084 "e5e9b410fc46aa3f29e4be9e64451346"},
2085 // PKCS#1 v1.5 Signature Example 1.14
2086 {"0211382683a74d8d2a2cb6a06550563b"
2087 "e1c26ca62821e4ff163b720464fc3a28"
2088 "d91bedddc62749a5538eaf41fbe0c82a"
2089 "77e06ad99383c9e985ffb8a93fd4d7c5"
2090 "8db51ad91ba461d69a8fd7ddabe24967"
2091 "57a0c49122c1a79a85cc0553e8214d03"
2092 "6dfe0185efa0d05860c612fa0882c82d"
2093 "246e5830a67355dff18a2c36b732f988"
2094 "cfedc562264c6254b40fcabb97b76094"
2095 "7568dcd6a17cda6ee8855bddbab93702"
2096 "471aa0cfb1bed2e13118eba1175b73c9"
2097 "6253c108d0b2aba05ab8e17e84392e20"
2098 "085f47404d8365527dc3fb8f2bb48a50"
2099 "038e71361ccf973407",
2100 "525500918331f1042eae0c5c2054aa7f"
2101 "92deb26991b5796634f229daf9b49eb2"
2102 "054d87319f3cfa9b466bd075ef6699ae"
2103 "a4bd4a195a1c52968b5e2b75e092d846"
2104 "ea1b5cc27905a8e1d5e5de0edfdb2139"
2105 "1ebb951864ebd9f0b0ec35b654287136"
2106 "0a317b7ef13ae06af684e38e21b1e19b"
2107 "c7298e5d6fe0013a164bfa25d3e7313d"},
2108 // PKCS#1 v1.5 Signature Example 1.15
2109 {"fc6b700d22583388ab2f8dafcaf1a056"
2110 "20698020da4bae44dafbd0877b501250"
2111 "6dc3181d5c66bf023f348b41fd9f9479"
2112 "5ab96452a4219f2d39d72af359cf1956"
2113 "51c7",
2114 "4452a6cc2626b01e95ab306df0d0cc74"
2115 "84fbab3c22e9703283567f66eadc248d"
2116 "bda58fce7dd0c70cce3f150fca4b369d"
2117 "ff3b6237e2b16281ab55b53fb13089c8"
2118 "5cd265056b3d62a88bfc2135b16791f7"
2119 "fbcab9fd2dc33becb617be419d2c0461"
2120 "42a4d47b338314552edd4b6fe9ce1104"
2121 "ecec4a9958d7331e930fc09bf08a6e64"},
2122 // PKCS#1 v1.5 Signature Example 1.16
2123 {"13ba086d709cfa5fedaa557a89181a61"
2124 "40f2300ed6d7c3febb6cf68abebcbc67"
2125 "8f2bca3dc2330295eec45bb1c4075f3a"
2126 "da987eae88b39c51606cb80429e649d9"
2127 "8acc8441b1f8897db86c5a4ce0abf28b"
2128 "1b81dca3667697b850696b74a5ebd85d"
2129 "ec56c90f8abe513efa857853720be319"
2130 "607921bca947522cd8fac8cace5b827c"
2131 "3e5a129e7ee57f6b84932f14141ac427"
2132 "4e8cbb46e6912b0d3e2177d499d1840c"
2133 "d47d4d7ae0b4cdc4d3",
2134 "1f3b5a87db72a2c97bb3eff2a65a3012"
2135 "68eacd89f42abc1098c1f2de77b0832a"
2136 "65d7815feb35070063f221bb3453bd43"
2137 "4386c9a3fde18e3ca1687fb649e86c51"
2138 "d658619dde5debb86fe15491ff77ab74"
2139 "8373f1be508880d66ea81e870e91cdf1"
2140 "704875c17f0b10103188bc64eef5a355"
2141 "1b414c733670215b1a22702562581ab1"},
2142 // PKCS#1 v1.5 Signature Example 1.17
2143 {"eb1e5935",
2144 "370cb9839ae6074f84b2acd6e6f6b792"
2145 "1b4b523463757f6446716140c4e6c0e7"
2146 "5bec6ad0197ebfa86bf46d094f5f6cd3"
2147 "6dca3a5cc73c8bbb70e2c7c9ab5d964e"
2148 "c8e3dfde481b4a1beffd01b4ad15b31a"
2149 "e7aebb9b70344a9411083165fdf9c375"
2150 "4bbb8b94dd34bd4813dfada1f6937de4"
2151 "267d5597ca09a31e83d7f1a79dd19b5e"},
2152 // PKCS#1 v1.5 Signature Example 1.18
2153 {"6346b153e889c8228209630071c8a577"
2154 "83f368760b8eb908cfc2b276",
2155 "2479c975c5b1ae4c4e940f473a9045b8"
2156 "bf5b0bfca78ec29a38dfbedc8a749b7a"
2157 "2692f7c52d5bc7c831c7232372a00fed"
2158 "3b6b49e760ec99e074ff2eead5134e83"
2159 "05725dfa39212b84bd4b8d80bc8bc17a"
2160 "512823a3beb18fc08e45ed19c26c8177"
2161 "07d67fb05832ef1f12a33e90cd93b8a7"
2162 "80319e2963ca25a2af7b09ad8f595c21"},
2163 // PKCS#1 v1.5 Signature Example 1.19
2164 {"64702db9f825a0f3abc361974659f5e9"
2165 "d30c3aa4f56feac69050c72905e77fe0"
2166 "c22f88a378c21fcf45fe8a5c71730209"
2167 "3929",
2168 "152f3451c858d69594e6567dfb31291c"
2169 "1ee7860b9d15ebd5a5edd276ac3e6f7a"
2170 "8d1480e42b3381d2be023acf7ebbdb28"
2171 "de3d2163ae44259c6df98c335d045b61"
2172 "dac9dba9dbbb4e6ab4a083cd76b580cb"
2173 "e472206a1a9fd60680ceea1a570a29b0"
2174 "881c775eaef5525d6d2f344c28837d0a"
2175 "ca422bbb0f1aba8f6861ae18bd73fe44"},
2176 // PKCS#1 v1.5 Signature Example 1.20
2177 {"941921de4a1c9c1618d6f3ca3c179f6e"
2178 "29bae6ddf9a6a564f929e3ce82cf3265"
2179 "d7837d5e692be8dcc9e86c",
2180 "7076c287fc6fff2b20537435e5a3107c"
2181 "e4da10716186d01539413e609d27d1da"
2182 "6fd952c61f4bab91c045fa4f8683ecc4"
2183 "f8dde74227f773cff3d96db84718c494"
2184 "4b06affeba94b725f1b07d3928b2490a"
2185 "85c2f1abf492a9177a7cd2ea0c966875"
2186 "6f825bbec900fa8ac3824e114387ef57"
2187 "3780ca334882387b94e5aad7a27a28dc"}};
2188
2189 // Import the public key.
2190 blink::WebCryptoAlgorithm algorithm = CreateRsaAlgorithmWithInnerHash(
2191 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5,
2192 blink::WebCryptoAlgorithmIdSha1);
2193 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull();
2194 ASSERT_TRUE(ImportKeyInternal(
2195 blink::WebCryptoKeyFormatSpki,
2196 HexStringToBytes(public_key_spki_der_hex),
2197 algorithm,
2198 true,
2199 blink::WebCryptoKeyUsageVerify,
2200 &public_key));
2201 EXPECT_FALSE(public_key.isNull());
2202 EXPECT_TRUE(public_key.handle());
2203
2204 // Import the private key.
2205 blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull();
2206 ASSERT_TRUE(ImportKeyInternal(
2207 blink::WebCryptoKeyFormatPkcs8,
2208 HexStringToBytes(private_key_pkcs8_der_hex),
2209 algorithm,
2210 true,
2211 blink::WebCryptoKeyUsageSign,
2212 &private_key));
2213 EXPECT_FALSE(private_key.isNull());
2214 EXPECT_TRUE(private_key.handle());
2215
2216 // Validate the signatures are computed and verified as expected.
2217 blink::WebArrayBuffer signature;
2218 for (size_t idx = 0; idx < ARRAYSIZE_UNSAFE(kTests); ++idx) {
2219
2220 SCOPED_TRACE(idx);
2221 const TestCase& test = kTests[idx];
2222 const std::vector<uint8> message = HexStringToBytes(test.message_hex);
2223
2224 signature.reset();
eroman 2013/12/20 01:12:50 Can you delete this line? I believe SignInternal()
2225 ASSERT_TRUE(SignInternal(algorithm, private_key, message, &signature));
2226 ExpectArrayBufferMatchesHex(test.signature_hex, signature);
2227
2228 bool is_match = false;
eroman 2013/12/20 01:12:50 Please remove the initialization.
2229 ASSERT_TRUE(VerifySignatureInternal(
2230 algorithm,
2231 public_key,
2232 HexStringToBytes(test.signature_hex),
2233 message,
2234 &is_match));
2235 EXPECT_TRUE(is_match);
2236 }
2237 }
2238
1624 TEST_F(WebCryptoImplTest, MAYBE(AesKwKeyImport)) { 2239 TEST_F(WebCryptoImplTest, MAYBE(AesKwKeyImport)) {
1625 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); 2240 blink::WebCryptoKey key = blink::WebCryptoKey::createNull();
1626 blink::WebCryptoAlgorithm algorithm = 2241 blink::WebCryptoAlgorithm algorithm =
1627 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdAesKw); 2242 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdAesKw);
1628 2243
1629 // Import a 128-bit Key Encryption Key (KEK) 2244 // Import a 128-bit Key Encryption Key (KEK)
1630 std::string key_raw_hex_in = "025a8cf3f08b4f6c5f33bbc76a471939"; 2245 std::string key_raw_hex_in = "025a8cf3f08b4f6c5f33bbc76a471939";
1631 ASSERT_TRUE(ImportKeyInternal(blink::WebCryptoKeyFormatRaw, 2246 ASSERT_TRUE(ImportKeyInternal(blink::WebCryptoKeyFormatRaw,
1632 HexStringToBytes(key_raw_hex_in), 2247 HexStringToBytes(key_raw_hex_in),
1633 algorithm, 2248 algorithm,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1698 "72d4e475ff34215416c9ad9c8281247a4d730c5f275ac23f376e73e3bce8d7d5a"; 2313 "72d4e475ff34215416c9ad9c8281247a4d730c5f275ac23f376e73e3bce8d7d5a";
1699 EXPECT_FALSE(ImportKeyInternal(blink::WebCryptoKeyFormatRaw, 2314 EXPECT_FALSE(ImportKeyInternal(blink::WebCryptoKeyFormatRaw,
1700 HexStringToBytes(key_raw_hex_in), 2315 HexStringToBytes(key_raw_hex_in),
1701 algorithm, 2316 algorithm,
1702 true, 2317 true,
1703 blink::WebCryptoKeyUsageWrapKey, 2318 blink::WebCryptoKeyUsageWrapKey,
1704 &key)); 2319 &key));
1705 } 2320 }
1706 2321
1707 } // namespace content 2322 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698