Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 dict->SetString("alg", "RSA1_5"); | 70 dict->SetString("alg", "RSA1_5"); |
| 71 dict->SetString("use", "enc"); | 71 dict->SetString("use", "enc"); |
| 72 dict->SetBoolean("extractable", false); | 72 dict->SetBoolean("extractable", false); |
| 73 dict->SetString("n", | 73 dict->SetString("n", |
| 74 "qLOyhK-OtQs4cDSoYPFGxJGfMYdjzWxVmMiuSBGh4KvEx-CwgtaTpef87Wdc9GaFEncsDLxk" | 74 "qLOyhK-OtQs4cDSoYPFGxJGfMYdjzWxVmMiuSBGh4KvEx-CwgtaTpef87Wdc9GaFEncsDLxk" |
| 75 "p0LGxjD1M8jMcvYq6DPEC_JYQumEu3i9v5fAEH1VvbZi9cTg-rmEXLUUjvc5LdOq_5OuHmtm" | 75 "p0LGxjD1M8jMcvYq6DPEC_JYQumEu3i9v5fAEH1VvbZi9cTg-rmEXLUUjvc5LdOq_5OuHmtm" |
| 76 "e7PUJHYW1PW6ENTP0ibeiNOfFvs"); | 76 "e7PUJHYW1PW6ENTP0ibeiNOfFvs"); |
| 77 dict->SetString("e", "AQAB"); | 77 dict->SetString("e", "AQAB"); |
| 78 } | 78 } |
| 79 | 79 |
| 80 blink::WebCryptoAlgorithm CreateRsaKeyGenAlgorithm( | 80 #endif // #if !defined(USE_OPENSSL) |
|
eroman
2013/12/19 22:56:38
This will need to be rebased
padolph
2013/12/20 00:03:39
Done.
| |
| 81 | |
| 82 // TODO(padolph): Move to webcrypto_util | |
|
eroman
2013/12/19 22:56:38
This is in webcrypto_util.cc now; could be exposed
padolph
2013/12/20 00:03:39
Done.
| |
| 83 bool IsHashAlgorithm(blink::WebCryptoAlgorithmId alg_id) { | |
| 84 return alg_id == blink::WebCryptoAlgorithmIdSha1 || | |
| 85 alg_id == blink::WebCryptoAlgorithmIdSha224 || | |
| 86 alg_id == blink::WebCryptoAlgorithmIdSha256 || | |
| 87 alg_id == blink::WebCryptoAlgorithmIdSha384 || | |
| 88 alg_id == blink::WebCryptoAlgorithmIdSha512; | |
| 89 } | |
| 90 | |
| 91 blink::WebCryptoAlgorithm CreateRsaAlgorithmWithInnerHash( | |
| 81 blink::WebCryptoAlgorithmId algorithm_id, | 92 blink::WebCryptoAlgorithmId algorithm_id, |
| 82 unsigned modulus_length, | 93 blink::WebCryptoAlgorithmId hash_id) { |
| 83 const std::vector<uint8>& public_exponent) { | 94 DCHECK(algorithm_id == blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 || |
|
eroman
2013/12/19 22:56:38
DCHECK_EQ
padolph
2013/12/20 00:03:39
Not sure how to use that here. I want to ensure th
eroman
2013/12/20 01:12:50
My mistake, didn't notice the ||.
| |
| 84 DCHECK(algorithm_id == blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5 || | |
| 85 algorithm_id == blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 || | |
| 86 algorithm_id == blink::WebCryptoAlgorithmIdRsaOaep); | 95 algorithm_id == blink::WebCryptoAlgorithmIdRsaOaep); |
| 96 DCHECK(IsHashAlgorithm(hash_id)); | |
| 87 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( | 97 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( |
| 88 algorithm_id, | 98 algorithm_id, |
| 89 new blink::WebCryptoRsaKeyGenParams( | 99 new blink::WebCryptoRsaSsaParams(webcrypto::CreateAlgorithm(hash_id))); |
| 90 modulus_length, | |
| 91 webcrypto::Uint8VectorStart(public_exponent), | |
| 92 public_exponent.size())); | |
| 93 } | 100 } |
| 94 | 101 |
| 95 // Determines if two ArrayBuffers have identical content. | 102 // Determines if two ArrayBuffers have identical content. |
| 96 bool ArrayBuffersEqual( | 103 bool ArrayBuffersEqual( |
| 97 const blink::WebArrayBuffer& a, | 104 const blink::WebArrayBuffer& a, |
| 98 const blink::WebArrayBuffer& b) { | 105 const blink::WebArrayBuffer& b) { |
| 99 return a.byteLength() == b.byteLength() && | 106 return a.byteLength() == b.byteLength() && |
| 100 memcmp(a.data(), b.data(), a.byteLength()) == 0; | 107 memcmp(a.data(), b.data(), a.byteLength()) == 0; |
| 101 } | 108 } |
| 102 | 109 |
| 103 // Given a vector of WebArrayBuffers, determines if there are any copies. | 110 // Given a vector of WebArrayBuffers, determines if there are any copies. |
| 104 bool CopiesExist(std::vector<blink::WebArrayBuffer> bufs) { | 111 bool CopiesExist(std::vector<blink::WebArrayBuffer> bufs) { |
| 105 for (size_t i = 0; i < bufs.size(); ++i) { | 112 for (size_t i = 0; i < bufs.size(); ++i) { |
| 106 for (size_t j = i + 1; j < bufs.size(); ++j) { | 113 for (size_t j = i + 1; j < bufs.size(); ++j) { |
| 107 if (ArrayBuffersEqual(bufs[i], bufs[j])) | 114 if (ArrayBuffersEqual(bufs[i], bufs[j])) |
| 108 return true; | 115 return true; |
| 109 } | 116 } |
| 110 } | 117 } |
| 111 return false; | 118 return false; |
| 112 } | 119 } |
| 113 | 120 |
| 114 #endif // #if !defined(USE_OPENSSL) | |
| 115 | |
| 116 } // namespace | 121 } // namespace |
| 117 | 122 |
| 118 class WebCryptoImplTest : public testing::Test { | 123 class WebCryptoImplTest : public testing::Test { |
| 119 protected: | 124 protected: |
| 120 blink::WebCryptoKey ImportSecretKeyFromRawHexString( | 125 blink::WebCryptoKey ImportSecretKeyFromRawHexString( |
| 121 const std::string& key_hex, | 126 const std::string& key_hex, |
| 122 const blink::WebCryptoAlgorithm& algorithm, | 127 const blink::WebCryptoAlgorithm& algorithm, |
| 123 blink::WebCryptoKeyUsageMask usage) { | 128 blink::WebCryptoKeyUsageMask usage) { |
| 124 std::vector<uint8> key_raw = HexStringToBytes(key_hex); | 129 std::vector<uint8> key_raw = HexStringToBytes(key_hex); |
| 125 | 130 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 bool* signature_match) { | 214 bool* signature_match) { |
| 210 return crypto_.VerifySignatureInternal(algorithm, | 215 return crypto_.VerifySignatureInternal(algorithm, |
| 211 key, | 216 key, |
| 212 signature, | 217 signature, |
| 213 signature_size, | 218 signature_size, |
| 214 webcrypto::Uint8VectorStart(data), | 219 webcrypto::Uint8VectorStart(data), |
| 215 data.size(), | 220 data.size(), |
| 216 signature_match); | 221 signature_match); |
| 217 } | 222 } |
| 218 | 223 |
| 224 bool VerifySignatureInternal( | |
| 225 const blink::WebCryptoAlgorithm& algorithm, | |
| 226 const blink::WebCryptoKey& key, | |
| 227 const std::vector<uint8>& signature, | |
| 228 const std::vector<uint8>& data, | |
| 229 bool* signature_match) { | |
| 230 return crypto_.VerifySignatureInternal( | |
| 231 algorithm, | |
| 232 key, | |
| 233 webcrypto::Uint8VectorStart(signature), | |
| 234 signature.size(), | |
| 235 webcrypto::Uint8VectorStart(data), | |
| 236 data.size(), | |
| 237 signature_match); | |
| 238 } | |
| 239 | |
| 219 bool EncryptInternal( | 240 bool EncryptInternal( |
| 220 const blink::WebCryptoAlgorithm& algorithm, | 241 const blink::WebCryptoAlgorithm& algorithm, |
| 221 const blink::WebCryptoKey& key, | 242 const blink::WebCryptoKey& key, |
| 222 const unsigned char* data, | 243 const unsigned char* data, |
| 223 unsigned data_size, | 244 unsigned data_size, |
| 224 blink::WebArrayBuffer* buffer) { | 245 blink::WebArrayBuffer* buffer) { |
| 225 return crypto_.EncryptInternal(algorithm, key, data, data_size, buffer); | 246 return crypto_.EncryptInternal(algorithm, key, data, data_size, buffer); |
| 226 } | 247 } |
| 227 | 248 |
| 228 bool EncryptInternal( | 249 bool EncryptInternal( |
| (...skipping 1066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1295 // Fail with bad modulus. | 1316 // Fail with bad modulus. |
| 1296 algorithm = webcrypto::CreateRsaKeyGenAlgorithm( | 1317 algorithm = webcrypto::CreateRsaKeyGenAlgorithm( |
| 1297 blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, 0, public_exponent); | 1318 blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, 0, public_exponent); |
| 1298 EXPECT_FALSE(GenerateKeyPairInternal( | 1319 EXPECT_FALSE(GenerateKeyPairInternal( |
| 1299 algorithm, extractable, usage_mask, &public_key, &private_key)); | 1320 algorithm, extractable, usage_mask, &public_key, &private_key)); |
| 1300 | 1321 |
| 1301 // Fail with bad exponent: larger than unsigned long. | 1322 // Fail with bad exponent: larger than unsigned long. |
| 1302 unsigned exponent_length = sizeof(unsigned long) + 1; // NOLINT | 1323 unsigned exponent_length = sizeof(unsigned long) + 1; // NOLINT |
| 1303 const std::vector<uint8> long_exponent(exponent_length, 0x01); | 1324 const std::vector<uint8> long_exponent(exponent_length, 0x01); |
| 1304 algorithm = webcrypto::CreateRsaKeyGenAlgorithm( | 1325 algorithm = webcrypto::CreateRsaKeyGenAlgorithm( |
| 1305 blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, modulus_length, long_exponent); | 1326 blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, |
| 1327 modulus_length, | |
| 1328 long_exponent); | |
| 1306 EXPECT_FALSE(GenerateKeyPairInternal( | 1329 EXPECT_FALSE(GenerateKeyPairInternal( |
| 1307 algorithm, extractable, usage_mask, &public_key, &private_key)); | 1330 algorithm, extractable, usage_mask, &public_key, &private_key)); |
| 1308 | 1331 |
| 1309 // Fail with bad exponent: empty. | 1332 // Fail with bad exponent: empty. |
| 1310 const std::vector<uint8> empty_exponent; | 1333 const std::vector<uint8> empty_exponent; |
| 1311 algorithm = webcrypto::CreateRsaKeyGenAlgorithm( | 1334 algorithm = webcrypto::CreateRsaKeyGenAlgorithm( |
| 1312 blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, | 1335 blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, |
| 1313 modulus_length, | 1336 modulus_length, |
| 1314 empty_exponent); | 1337 empty_exponent); |
| 1315 EXPECT_FALSE(GenerateKeyPairInternal( | 1338 EXPECT_FALSE(GenerateKeyPairInternal( |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1379 blink::WebArrayBuffer output; | 1402 blink::WebArrayBuffer output; |
| 1380 EXPECT_FALSE( | 1403 EXPECT_FALSE( |
| 1381 ExportKeyInternal(blink::WebCryptoKeyFormatSpki, private_key, &output)); | 1404 ExportKeyInternal(blink::WebCryptoKeyFormatSpki, private_key, &output)); |
| 1382 } | 1405 } |
| 1383 | 1406 |
| 1384 TEST_F(WebCryptoImplTest, RsaEsRoundTrip) { | 1407 TEST_F(WebCryptoImplTest, RsaEsRoundTrip) { |
| 1385 // Note: using unrealistic short key length here to avoid bogging down tests. | 1408 // Note: using unrealistic short key length here to avoid bogging down tests. |
| 1386 | 1409 |
| 1387 // Create a key pair. | 1410 // Create a key pair. |
| 1388 const unsigned kModulusLength = 256; | 1411 const unsigned kModulusLength = 256; |
| 1389 blink::WebCryptoAlgorithm algorithm = | 1412 blink::WebCryptoAlgorithm algorithm = webcrypto::CreateRsaKeyGenAlgorithm( |
| 1390 CreateRsaKeyGenAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, | 1413 blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, |
| 1391 kModulusLength, | 1414 kModulusLength, |
| 1392 HexStringToBytes("010001")); | 1415 HexStringToBytes("010001")); |
| 1393 const blink::WebCryptoKeyUsageMask usage_mask = | 1416 const blink::WebCryptoKeyUsageMask usage_mask = |
| 1394 blink::WebCryptoKeyUsageEncrypt | blink::WebCryptoKeyUsageDecrypt; | 1417 blink::WebCryptoKeyUsageEncrypt | blink::WebCryptoKeyUsageDecrypt; |
| 1395 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); | 1418 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); |
| 1396 blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); | 1419 blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); |
| 1397 EXPECT_TRUE(GenerateKeyPairInternal( | 1420 EXPECT_TRUE(GenerateKeyPairInternal( |
| 1398 algorithm, false, usage_mask, &public_key, &private_key)); | 1421 algorithm, false, usage_mask, &public_key, &private_key)); |
| 1399 EXPECT_FALSE(public_key.isNull()); | 1422 EXPECT_FALSE(public_key.isNull()); |
| 1400 EXPECT_FALSE(private_key.isNull()); | 1423 EXPECT_FALSE(private_key.isNull()); |
| 1401 | 1424 |
| 1402 // Make a maximum-length data message. RSAES can operate on messages up to | 1425 // Make a maximum-length data message. RSAES can operate on messages up to |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1561 &decrypted_data)); | 1584 &decrypted_data)); |
| 1562 EXPECT_FALSE(decrypted_data.isNull()); | 1585 EXPECT_FALSE(decrypted_data.isNull()); |
| 1563 ExpectArrayBufferMatchesHex(cleartext_hex, decrypted_data); | 1586 ExpectArrayBufferMatchesHex(cleartext_hex, decrypted_data); |
| 1564 } | 1587 } |
| 1565 | 1588 |
| 1566 TEST_F(WebCryptoImplTest, RsaEsFailures) { | 1589 TEST_F(WebCryptoImplTest, RsaEsFailures) { |
| 1567 // Note: using unrealistic short key length here to avoid bogging down tests. | 1590 // Note: using unrealistic short key length here to avoid bogging down tests. |
| 1568 | 1591 |
| 1569 // Create a key pair. | 1592 // Create a key pair. |
| 1570 const unsigned kModulusLength = 256; | 1593 const unsigned kModulusLength = 256; |
| 1571 blink::WebCryptoAlgorithm algorithm = | 1594 blink::WebCryptoAlgorithm algorithm = webcrypto::CreateRsaKeyGenAlgorithm( |
| 1572 CreateRsaKeyGenAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, | 1595 blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, |
| 1573 kModulusLength, | 1596 kModulusLength, |
| 1574 HexStringToBytes("010001")); | 1597 HexStringToBytes("010001")); |
| 1575 const blink::WebCryptoKeyUsageMask usage_mask = | 1598 const blink::WebCryptoKeyUsageMask usage_mask = |
| 1576 blink::WebCryptoKeyUsageEncrypt | blink::WebCryptoKeyUsageDecrypt; | 1599 blink::WebCryptoKeyUsageEncrypt | blink::WebCryptoKeyUsageDecrypt; |
| 1577 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); | 1600 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); |
| 1578 blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); | 1601 blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); |
| 1579 EXPECT_TRUE(GenerateKeyPairInternal( | 1602 EXPECT_TRUE(GenerateKeyPairInternal( |
| 1580 algorithm, false, usage_mask, &public_key, &private_key)); | 1603 algorithm, false, usage_mask, &public_key, &private_key)); |
| 1581 EXPECT_FALSE(public_key.isNull()); | 1604 EXPECT_FALSE(public_key.isNull()); |
| 1582 EXPECT_FALSE(private_key.isNull()); | 1605 EXPECT_FALSE(private_key.isNull()); |
| 1583 | 1606 |
| 1584 // Fail encrypt with a private key. | 1607 // Fail encrypt with a private key. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1629 // Do a successful decrypt with good data just for confirmation. | 1652 // Do a successful decrypt with good data just for confirmation. |
| 1630 EXPECT_TRUE(DecryptInternal( | 1653 EXPECT_TRUE(DecryptInternal( |
| 1631 algorithm, | 1654 algorithm, |
| 1632 private_key, | 1655 private_key, |
| 1633 reinterpret_cast<const unsigned char*>(encrypted_data.data()), | 1656 reinterpret_cast<const unsigned char*>(encrypted_data.data()), |
| 1634 encrypted_data.byteLength(), | 1657 encrypted_data.byteLength(), |
| 1635 &decrypted_data)); | 1658 &decrypted_data)); |
| 1636 ExpectArrayBufferMatchesHex(message_hex_str, decrypted_data); | 1659 ExpectArrayBufferMatchesHex(message_hex_str, decrypted_data); |
| 1637 } | 1660 } |
| 1638 | 1661 |
| 1662 TEST_F(WebCryptoImplTest, RsaSsaSignVerify) { | |
| 1663 | |
| 1664 // Generate an RSA key pair. | |
| 1665 blink::WebCryptoAlgorithm algorithm = webcrypto::CreateRsaKeyGenAlgorithm( | |
| 1666 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | |
| 1667 1024, | |
| 1668 HexStringToBytes("010001")); | |
| 1669 const blink::WebCryptoKeyUsageMask usage_mask = | |
| 1670 blink::WebCryptoKeyUsageSign | blink::WebCryptoKeyUsageVerify; | |
| 1671 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); | |
| 1672 blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); | |
| 1673 EXPECT_TRUE(GenerateKeyPairInternal( | |
| 1674 algorithm, true, usage_mask, &public_key, &private_key)); | |
| 1675 EXPECT_FALSE(public_key.isNull()); | |
| 1676 EXPECT_FALSE(private_key.isNull()); | |
| 1677 | |
| 1678 algorithm = CreateRsaAlgorithmWithInnerHash( | |
| 1679 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | |
| 1680 blink::WebCryptoAlgorithmIdSha1); | |
| 1681 blink::WebArrayBuffer signature; | |
| 1682 bool signature_match = false; | |
| 1683 | |
| 1684 const char* kTestData[] = {"", "00", "010203040506070809"}; | |
| 1685 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestData); ++i) { | |
| 1686 | |
| 1687 SCOPED_TRACE(i); | |
| 1688 | |
| 1689 // Sign data with the private key. | |
| 1690 const std::vector<uint8> data = HexStringToBytes(kTestData[i]); | |
| 1691 ASSERT_TRUE(SignInternal(algorithm, private_key, data, &signature)); | |
| 1692 | |
| 1693 // Verify the signature with the public key. | |
| 1694 signature_match = false; | |
| 1695 EXPECT_TRUE(VerifySignatureInternal( | |
| 1696 algorithm, | |
| 1697 public_key, | |
| 1698 static_cast<const unsigned char*>(signature.data()), | |
| 1699 signature.byteLength(), | |
| 1700 data, | |
| 1701 &signature_match)); | |
| 1702 EXPECT_TRUE(signature_match); | |
| 1703 } | |
| 1704 | |
| 1705 const std::vector<uint8> data = HexStringToBytes("010203040506070809"); | |
| 1706 ASSERT_TRUE(SignInternal(algorithm, private_key, data, &signature)); | |
| 1707 | |
| 1708 // Ensure truncated signature does not verify by passing one less byte. | |
| 1709 signature_match = false; | |
| 1710 EXPECT_TRUE(VerifySignatureInternal( | |
| 1711 algorithm, | |
| 1712 public_key, | |
| 1713 static_cast<const unsigned char*>(signature.data()), | |
| 1714 signature.byteLength() - 1, | |
| 1715 data, | |
| 1716 &signature_match)); | |
| 1717 EXPECT_FALSE(signature_match); | |
| 1718 | |
| 1719 // Ensure corrupted signature does not verify. | |
| 1720 std::vector<uint8> corrupt_sig( | |
| 1721 static_cast<uint8*>(signature.data()), | |
| 1722 static_cast<uint8*>(signature.data()) + signature.byteLength()); | |
| 1723 corrupt_sig[corrupt_sig.size() / 2] ^= 0x1; | |
| 1724 signature_match = false; | |
| 1725 EXPECT_TRUE(VerifySignatureInternal( | |
| 1726 algorithm, | |
| 1727 public_key, | |
| 1728 webcrypto::Uint8VectorStart(corrupt_sig), | |
| 1729 corrupt_sig.size(), | |
| 1730 data, | |
| 1731 &signature_match)); | |
| 1732 EXPECT_FALSE(signature_match); | |
| 1733 | |
| 1734 // Ensure extra long signature does not cause issues and fails. | |
| 1735 const unsigned char kLongSignature[1024] = { 0 }; | |
| 1736 EXPECT_TRUE(VerifySignatureInternal( | |
| 1737 algorithm, | |
| 1738 public_key, | |
| 1739 kLongSignature, | |
| 1740 sizeof(kLongSignature), | |
| 1741 data, | |
| 1742 &signature_match)); | |
| 1743 EXPECT_FALSE(signature_match); | |
| 1744 | |
| 1745 // Ensure can't verify using a private key. | |
| 1746 EXPECT_FALSE(VerifySignatureInternal( | |
| 1747 algorithm, | |
| 1748 private_key, | |
| 1749 static_cast<const unsigned char*>(signature.data()), | |
| 1750 signature.byteLength(), | |
| 1751 data, | |
| 1752 &signature_match)); | |
| 1753 | |
| 1754 // Ensure can't sign using a public key. | |
| 1755 EXPECT_FALSE(SignInternal(algorithm, public_key, data, &signature)); | |
| 1756 | |
| 1757 // TODO(padolph): Not sure this kind of test is required here, it might be | |
| 1758 // more appropriate on the Blink side. | |
| 1759 // Fail sign with malformed algorithm (no inner hash) | |
| 1760 algorithm = | |
| 1761 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5); | |
| 1762 EXPECT_FALSE(SignInternal(algorithm, private_key, data, &signature)); | |
| 1763 | |
| 1764 // TODO(padolph): Not sure this kind of test is required here, it might be | |
| 1765 // more appropriate on the Blink side. | |
| 1766 // Fail sign and verify with incompatible algorithm | |
| 1767 algorithm = | |
| 1768 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5); | |
| 1769 EXPECT_FALSE(SignInternal(algorithm, private_key, data, &signature)); | |
| 1770 EXPECT_FALSE(VerifySignatureInternal( | |
| 1771 algorithm, | |
| 1772 public_key, | |
| 1773 static_cast<const unsigned char*>(signature.data()), | |
| 1774 signature.byteLength(), | |
| 1775 data, | |
| 1776 &signature_match)); | |
| 1777 | |
| 1778 // Some crypto libraries (NSS) can automatically select the RSA SSA inner hash | |
| 1779 // based solely on the contents of the input signature data. In the Web Crypto | |
| 1780 // implementation, we want the inner hash instead to be specified by the input | |
| 1781 // algorithm parameter. To validate this behavior, call Verify with a computed | |
| 1782 // signature that used one hash type (SHA-1), but pass in an algorithm with a | |
| 1783 // different inner hash type (SHA-256). If the hash type is determined by the | |
| 1784 // signature itself (undesired), the verify will pass, while if the hash type | |
| 1785 // is specified by the input algorithm (desired), the verify will fail. | |
| 1786 | |
| 1787 // Compute a signature using SHA-1 as the inner hash. | |
| 1788 EXPECT_TRUE(SignInternal(CreateRsaAlgorithmWithInnerHash( | |
| 1789 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | |
| 1790 blink::WebCryptoAlgorithmIdSha1), | |
| 1791 private_key, | |
| 1792 data, | |
| 1793 &signature)); | |
| 1794 | |
| 1795 // Now verify using an algorithm whose inner hash is SHA-256, not SHA-1. The | |
| 1796 // signature should not verify. | |
| 1797 // NOTE: public_key was produced by generateKey, and so its associated | |
| 1798 // algorithm has WebCryptoRsaKeyGenParams and not WebCryptoRsaSsaParams. Thus | |
| 1799 // it has no inner hash to conflict with the input algorithm. | |
| 1800 bool is_match = true; | |
| 1801 EXPECT_TRUE(VerifySignatureInternal( | |
| 1802 CreateRsaAlgorithmWithInnerHash( | |
| 1803 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | |
| 1804 blink::WebCryptoAlgorithmIdSha256), | |
| 1805 public_key, | |
| 1806 static_cast<const unsigned char*>(signature.data()), | |
| 1807 signature.byteLength(), | |
| 1808 data, | |
| 1809 &is_match)); | |
| 1810 EXPECT_FALSE(is_match); | |
| 1811 } | |
| 1812 | |
| 1813 TEST_F(WebCryptoImplTest, RsaSignVerifyKnownAnswer) { | |
| 1814 | |
| 1815 // Use the NIST test vectors from Example 1 of | |
| 1816 // ftp://ftp.rsa.com/pub/rsalabs/tmp/pkcs1v15sign-vectors.txt | |
| 1817 // These vectors are known answers for RSA PKCS#1 v1.5 Signature with a SHA-1 | |
| 1818 // digest, using a predefined key pair. | |
| 1819 | |
| 1820 // The following key pair is comprised of the SPKI (public key) and PKCS#8 | |
| 1821 // (private key) representations of the key pair provided in Example 1 of the | |
| 1822 // NIST link above. | |
| 1823 const std::string public_key_spki_der_hex = | |
| 1824 "30819f300d06092a864886f70d010101050003818d0030818902818100a5" | |
| 1825 "6e4a0e701017589a5187dc7ea841d156f2ec0e36ad52a44dfeb1e61f7ad9" | |
| 1826 "91d8c51056ffedb162b4c0f283a12a88a394dff526ab7291cbb307ceabfc" | |
| 1827 "e0b1dfd5cd9508096d5b2b8b6df5d671ef6377c0921cb23c270a70e2598e" | |
| 1828 "6ff89d19f105acc2d3f0cb35f29280e1386b6f64c4ef22e1e1f20d0ce8cf" | |
| 1829 "fb2249bd9a21370203010001"; | |
| 1830 const std::string private_key_pkcs8_der_hex = | |
| 1831 "30820275020100300d06092a864886f70d01010105000482025f3082025b" | |
| 1832 "02010002818100a56e4a0e701017589a5187dc7ea841d156f2ec0e36ad52" | |
| 1833 "a44dfeb1e61f7ad991d8c51056ffedb162b4c0f283a12a88a394dff526ab" | |
| 1834 "7291cbb307ceabfce0b1dfd5cd9508096d5b2b8b6df5d671ef6377c0921c" | |
| 1835 "b23c270a70e2598e6ff89d19f105acc2d3f0cb35f29280e1386b6f64c4ef" | |
| 1836 "22e1e1f20d0ce8cffb2249bd9a2137020301000102818033a5042a90b27d" | |
| 1837 "4f5451ca9bbbd0b44771a101af884340aef9885f2a4bbe92e894a724ac3c" | |
| 1838 "568c8f97853ad07c0266c8c6a3ca0929f1e8f11231884429fc4d9ae55fee" | |
| 1839 "896a10ce707c3ed7e734e44727a39574501a532683109c2abacaba283c31" | |
| 1840 "b4bd2f53c3ee37e352cee34f9e503bd80c0622ad79c6dcee883547c6a3b3" | |
| 1841 "25024100e7e8942720a877517273a356053ea2a1bc0c94aa72d55c6e8629" | |
| 1842 "6b2dfc967948c0a72cbccca7eacb35706e09a1df55a1535bd9b3cc34160b" | |
| 1843 "3b6dcd3eda8e6443024100b69dca1cf7d4d7ec81e75b90fcca874abcde12" | |
| 1844 "3fd2700180aa90479b6e48de8d67ed24f9f19d85ba275874f542cd20dc72" | |
| 1845 "3e6963364a1f9425452b269a6799fd024028fa13938655be1f8a159cbaca" | |
| 1846 "5a72ea190c30089e19cd274a556f36c4f6e19f554b34c077790427bbdd8d" | |
| 1847 "d3ede2448328f385d81b30e8e43b2fffa02786197902401a8b38f398fa71" | |
| 1848 "2049898d7fb79ee0a77668791299cdfa09efc0e507acb21ed74301ef5bfd" | |
| 1849 "48be455eaeb6e1678255827580a8e4e8e14151d1510a82a3f2e729024027" | |
| 1850 "156aba4126d24a81f3a528cbfb27f56886f840a9f6e86e17a44b94fe9319" | |
| 1851 "584b8e22fdde1e5a2e3bd8aa5ba8d8584194eb2190acf832b847f13a3d24" | |
| 1852 "a79f4d"; | |
| 1853 | |
| 1854 // The following data are the input messages and corresponding computed RSA | |
| 1855 // PKCS#1 v1.5 signatures from the NIST link above. | |
| 1856 struct TestCase { | |
| 1857 const std::string message_hex; | |
| 1858 const std::string signature_hex; | |
| 1859 }; | |
| 1860 | |
| 1861 const TestCase kTests[] = { | |
| 1862 // PKCS#1 v1.5 Signature Example 1.1 | |
| 1863 {"cdc87da223d786df3b45e0bbbc721326" | |
| 1864 "d1ee2af806cc315475cc6f0d9c66e1b6" | |
| 1865 "2371d45ce2392e1ac92844c310102f15" | |
| 1866 "6a0d8d52c1f4c40ba3aa65095786cb76" | |
| 1867 "9757a6563ba958fed0bcc984e8b517a3" | |
| 1868 "d5f515b23b8a41e74aa867693f90dfb0" | |
| 1869 "61a6e86dfaaee64472c00e5f20945729" | |
| 1870 "cbebe77f06ce78e08f4098fba41f9d61" | |
| 1871 "93c0317e8b60d4b6084acb42d29e3808" | |
| 1872 "a3bc372d85e331170fcbf7cc72d0b71c" | |
| 1873 "296648b3a4d10f416295d0807aa625ca" | |
| 1874 "b2744fd9ea8fd223c42537029828bd16" | |
| 1875 "be02546f130fd2e33b936d2676e08aed" | |
| 1876 "1b73318b750a0167d0", | |
| 1877 "6bc3a06656842930a247e30d5864b4d8" | |
| 1878 "19236ba7c68965862ad7dbc4e24af28e" | |
| 1879 "86bb531f03358be5fb74777c6086f850" | |
| 1880 "caef893f0d6fcc2d0c91ec013693b4ea" | |
| 1881 "00b80cd49aac4ecb5f8911afe539ada4" | |
| 1882 "a8f3823d1d13e472d1490547c659c761" | |
| 1883 "7f3d24087ddb6f2b72096167fc097cab" | |
| 1884 "18e9a458fcb634cdce8ee35894c484d7"}, | |
| 1885 // PKCS#1 v1.5 Signature Example 1.2 | |
| 1886 {"851384cdfe819c22ed6c4ccb30daeb5c" | |
| 1887 "f059bc8e1166b7e3530c4c233e2b5f8f" | |
| 1888 "71a1cca582d43ecc72b1bca16dfc7013" | |
| 1889 "226b9e", | |
| 1890 "84fd2ce734ec1da828d0f15bf49a8707" | |
| 1891 "c15d05948136de537a3db421384167c8" | |
| 1892 "6fae022587ee9e137daee75473826293" | |
| 1893 "2d271c744c6d3a189ad4311bdb020492" | |
| 1894 "e322fbddc40406ea860d4e8ea2a4084a" | |
| 1895 "a98b9622a446756fdb740ddb3d91db76" | |
| 1896 "70e211661bbf8709b11c08a70771422d" | |
| 1897 "1a12def29f0688a192aebd89e0f896f8"}, | |
| 1898 // PKCS#1 v1.5 Signature Example1.3 | |
| 1899 {"a4b159941761c40c6a82f2b80d1b94f5" | |
| 1900 "aa2654fd17e12d588864679b54cd04ef" | |
| 1901 "8bd03012be8dc37f4b83af7963faff0d" | |
| 1902 "fa225477437c48017ff2be8191cf3955" | |
| 1903 "fc07356eab3f322f7f620e21d254e5db" | |
| 1904 "4324279fe067e0910e2e81ca2cab31c7" | |
| 1905 "45e67a54058eb50d993cdb9ed0b4d029" | |
| 1906 "c06d21a94ca661c3ce27fae1d6cb20f4" | |
| 1907 "564d66ce4767583d0e5f060215b59017" | |
| 1908 "be85ea848939127bd8c9c4d47b51056c" | |
| 1909 "031cf336f17c9980f3b8f5b9b6878e8b" | |
| 1910 "797aa43b882684333e17893fe9caa6aa" | |
| 1911 "299f7ed1a18ee2c54864b7b2b99b7261" | |
| 1912 "8fb02574d139ef50f019c9eef4169713" | |
| 1913 "38e7d470", | |
| 1914 "0b1f2e5180e5c7b4b5e672929f664c48" | |
| 1915 "96e50c35134b6de4d5a934252a3a245f" | |
| 1916 "f48340920e1034b7d5a5b524eb0e1cf1" | |
| 1917 "2befef49b27b732d2c19e1c43217d6e1" | |
| 1918 "417381111a1d36de6375cf455b3c9812" | |
| 1919 "639dbc27600c751994fb61799ecf7da6" | |
| 1920 "bcf51540afd0174db4033188556675b1" | |
| 1921 "d763360af46feeca5b60f882829ee7b2"}, | |
| 1922 // PKCS#1 v1.5 Signature Example 1.4 | |
| 1923 {"bc656747fa9eafb3f0", | |
| 1924 "45607ad611cf5747a41ac94d0ffec878" | |
| 1925 "bdaf63f6b57a4b088bf36e34e109f840" | |
| 1926 "f24b742ada16102dabf951cbc44f8982" | |
| 1927 "e94ed4cd09448d20ec0efa73545f80b6" | |
| 1928 "5406bed6194a61c340b4ad1568cbb758" | |
| 1929 "51049f11af1734964076e02029aee200" | |
| 1930 "e40e80be0f4361f69841c4f92a4450a2" | |
| 1931 "286d43289b405554c54d25c6ecb584f4"}, | |
| 1932 // PKCS#1 v1.5 Signature Example 1.5 | |
| 1933 {"b45581547e5427770c768e8b82b75564" | |
| 1934 "e0ea4e9c32594d6bff706544de0a8776" | |
| 1935 "c7a80b4576550eee1b2acabc7e8b7d3e" | |
| 1936 "f7bb5b03e462c11047eadd00629ae575" | |
| 1937 "480ac1470fe046f13a2bf5af17921dc4" | |
| 1938 "b0aa8b02bee6334911651d7f8525d10f" | |
| 1939 "32b51d33be520d3ddf5a709955a3dfe7" | |
| 1940 "8283b9e0ab54046d150c177f037fdccc" | |
| 1941 "5be4ea5f68b5e5a38c9d7edcccc4975f" | |
| 1942 "455a6909b4", | |
| 1943 "54be9d90877515f450279c15b5f61ad6" | |
| 1944 "f15ecc95f18cbed82b65b1667a575809" | |
| 1945 "587994668044f3bc2ae7f884501f64f0" | |
| 1946 "b43f588cfa205a6ab704328c2d4ab92a" | |
| 1947 "7ae13440614d3e085f401da9ad28e210" | |
| 1948 "5e4a0edb681a6424df047388ce051ee9" | |
| 1949 "df7bc2163fe347520ad51ccd51806438" | |
| 1950 "3e741acad3cbdc2cb5a7c68e868464c2"}, | |
| 1951 // PKCS#1 v1.5 Signature Example 1.6 | |
| 1952 {"10aae9a0ab0b595d0841207b700d48d7" | |
| 1953 "5faedde3b775cd6b4cc88ae06e4694ec" | |
| 1954 "74ba18f8520d4f5ea69cbbe7cc2beba4" | |
| 1955 "3efdc10215ac4eb32dc302a1f53dc6c4" | |
| 1956 "352267e7936cfebf7c8d67035784a390" | |
| 1957 "9fa859c7b7b59b8e39c5c2349f1886b7" | |
| 1958 "05a30267d402f7486ab4f58cad5d69ad" | |
| 1959 "b17ab8cd0ce1caf5025af4ae24b1fb87" | |
| 1960 "94c6070cc09a51e2f9911311e3877d00" | |
| 1961 "44c71c57a993395008806b723ac38373" | |
| 1962 "d395481818528c1e7053739282053529" | |
| 1963 "510e935cd0fa77b8fa53cc2d474bd4fb" | |
| 1964 "3cc5c672d6ffdc90a00f9848712c4bcf" | |
| 1965 "e46c60573659b11e6457e861f0f604b6" | |
| 1966 "138d144f8ce4e2da73", | |
| 1967 "0e6ff63a856b9cbd5dbe423183122047" | |
| 1968 "dd39d6f76d1b2310e546fe9ee73b33ef" | |
| 1969 "a7c78f9474455c9e5b88cb383aafc369" | |
| 1970 "8668e7b7a59a9cbb5b0897b6c5afb7f8" | |
| 1971 "bac4b924e98d760a15fc43d2814ab2d5" | |
| 1972 "187f79bed9915a93397ebc22a7677506" | |
| 1973 "a02e076d3ffdc0441dbd4db00453dc28" | |
| 1974 "d830e0573f77b817b505c38b4a4bb5d0"}, | |
| 1975 // PKCS#1 v1.5 Signature Example 1.7 | |
| 1976 {"efb5da1b4d1e6d9a5dff92d0184da7e3" | |
| 1977 "1f877d1281ddda625664869e8379e67a" | |
| 1978 "d3b75eae74a580e9827abd6eb7a002cb" | |
| 1979 "5411f5266797768fb8e95ae40e3e8b34" | |
| 1980 "66f5ab15d69553952939ec23e61d5849" | |
| 1981 "7fac76aa1c0bb5a3cb4a54383587c7bb" | |
| 1982 "78d13eefda205443e6ce4365802df55c" | |
| 1983 "64713497984e7ca96722b3edf84d56", | |
| 1984 "8385d58533a995f72df262b70f40b391" | |
| 1985 "ddf515f464b9d2cc2d66398fc05689d8" | |
| 1986 "11632946d62eabdca7a31fcf6cd6c981" | |
| 1987 "d28bbc29083e4a6d5b2b378ca4e540f0" | |
| 1988 "60b96d53ad2693f82178b94e2e2f86b9" | |
| 1989 "accfa02025107e062ab7080175684501" | |
| 1990 "028f676461d81c008fe4750671649970" | |
| 1991 "878fc175cf98e96b2ecbf6874d77dacb"}, | |
| 1992 // PKCS#1 v1.5 Signature Example 1.8 | |
| 1993 {"53bb58ce42f1984940552657233b1496" | |
| 1994 "9af365c0a561a4132af18af39432280e" | |
| 1995 "3e437082434b19231837184f02cf2b2e" | |
| 1996 "726bebf74d7ae3256d8b72f3eafdb134" | |
| 1997 "d33de06f2991d299d59f5468d43b9958" | |
| 1998 "d6a968f5969edbbc6e7185cbc716c7c9" | |
| 1999 "45dafa9cc71ddfaaa01094a452ddf5e2" | |
| 2000 "407320400bf05ea9729cafbf0600e788" | |
| 2001 "07ef9462e3fde32ed7d981a56f4751ef" | |
| 2002 "64fb4549910ecc911d728053b3994300" | |
| 2003 "4740e6f5821fe8d75c0617bf2c6b24bb" | |
| 2004 "fc34013fc95f0dedf5ba297f504fb833" | |
| 2005 "da2a436d1d8ff1cc5193e2a64389fced" | |
| 2006 "918e7feb6716330f66801db9497549cf" | |
| 2007 "1d3bd97cf1bc6255", | |
| 2008 "8e1f3d26ec7c6bbb8c54c5d25f312058" | |
| 2009 "7803af6d3c2b99a37ced6a3657d4ae54" | |
| 2010 "266f63fffde660c866d65d0ab0589e1d" | |
| 2011 "12d9ce6054b05c8668ae127171ccaae7" | |
| 2012 "f1cd409677f52157b6123ab227f27a00" | |
| 2013 "966d1439b42a32169d1070394026fc8b" | |
| 2014 "c93545b1ac252d0f7da751c02e33a478" | |
| 2015 "31fbd71514c2bbbd3adb6740c0fd68ad"}, | |
| 2016 // PKCS#1 v1.5 Signature Example 1.9 | |
| 2017 {"27cadc698450945f204ec3cf8c6cbd8c" | |
| 2018 "eb4cc0cbe312274fa96b04deac855160" | |
| 2019 "c0e04e4ac5d38210c27c", | |
| 2020 "7b63f9223356f35f6117f68c8f822003" | |
| 2021 "4fc2384ab5dc6904141f139314d6ee89" | |
| 2022 "f54ec6ffd18c413a23c5931c7fbb13c5" | |
| 2023 "55ccfd590e0eaa853c8c94d2520cd425" | |
| 2024 "0d9a05a193b65dc749b82478af0156ee" | |
| 2025 "1de55ddad33ec1f0099cad6c891a3617" | |
| 2026 "c7393d05fbfbbb00528a001df0b204eb" | |
| 2027 "df1a341090dea89f870a877458427f7b"}, | |
| 2028 // PKCS#1 v1.5 Signature Example 1.10 | |
| 2029 {"716407e901b9ef92d761b013fd13eb7a" | |
| 2030 "d72aed", | |
| 2031 "2a22dbe3774d5b297201b55a0f17f42d" | |
| 2032 "ce63b7845cb325cfe951d0badb5c5a14" | |
| 2033 "472143d896c86cc339f83671164215ab" | |
| 2034 "c97862f2151654e75a3b357c37311b3d" | |
| 2035 "7268cab540202e23bee52736f2cd86cc" | |
| 2036 "e0c7dbde95e1c600a47395dc5eb0a472" | |
| 2037 "153fbc4fb21b643e0c04ae14dd37e97e" | |
| 2038 "617a7567c89652219781001ba6f83298"}, | |
| 2039 // PKCS#1 v1.5 Signature Example 1.11 | |
| 2040 {"46c24e4103001629c712dd4ce8d747ee" | |
| 2041 "595d6c744ccc4f71347d9b8abf49d1b8" | |
| 2042 "fb2ef91b95dc899d4c0e3d2997e638f4" | |
| 2043 "cf3f68e0498de5aabd13f0dfe02ff26b" | |
| 2044 "a4379104e78ffa95ffbd15067ef8cbd7" | |
| 2045 "eb7860fecc71abe13d5c720a66851f2d" | |
| 2046 "efd4e795054d7bec024bb422a46a7368" | |
| 2047 "b56d95b47aebafbeadd612812593a70d" | |
| 2048 "b9f96d451ee15edb299308d777f4bb68" | |
| 2049 "ed3377c32156b41b7a9c92a14c8b8114" | |
| 2050 "4399c56a5a432f4f770aa97da8415d0b" | |
| 2051 "da2e813206031e70620031c881d616bf" | |
| 2052 "fd5f03bf147c1e73766c26246208", | |
| 2053 "12235b0b406126d9d260d447e923a110" | |
| 2054 "51fb243079f446fd73a70181d53634d7" | |
| 2055 "a0968e4ee27777eda63f6e4a3a91ad59" | |
| 2056 "85998a4848da59ce697b24bb332fa2ad" | |
| 2057 "9ce462ca4affdc21dab908e8ce15af6e" | |
| 2058 "b9105b1abcf39142aa17b34c4c092386" | |
| 2059 "a7abbfe028afdbebc14f2ce26fbee5ed" | |
| 2060 "eca11502d39a6b7403154843d98a62a7"}, | |
| 2061 // PKCS#1 v1.5 Signature Example 1.12 | |
| 2062 {"bc99a932aa16d622bfff79c50b4c4235" | |
| 2063 "8673261129e28d6a918ff1b0f1c4f46a" | |
| 2064 "d8afa98b0ca0f56f967975b0a29be882" | |
| 2065 "e93b6cd3fc33e1faef72e52b2ae0a3f1" | |
| 2066 "2024506e25690e902e78298214555653" | |
| 2067 "2284cf505789738f4da31fa1333d3af8" | |
| 2068 "62b2ba6b6ce7ab4cce6aba", | |
| 2069 "872ec5ad4f1846256f17e9936ac50e43" | |
| 2070 "e9963ea8c1e76f15879b7874d77d122a" | |
| 2071 "609dc8c561145b94bf4ffdffdeb17e6e" | |
| 2072 "76ffc6c10c0747f5e37a9f434f5609e7" | |
| 2073 "9da5250215a457afdf12c6507cc1551f" | |
| 2074 "54a28010595826a2c9b97fa0aa851cc6" | |
| 2075 "8b705d7a06d720ba027e4a1c0b019500" | |
| 2076 "fb63b78071684dcfa9772700b982dc66"}, | |
| 2077 // PKCS#1 v1.5 Signature Example 1.13 | |
| 2078 {"731e172ac063992c5b11ba170dfb23bb" | |
| 2079 "000d47ba195329cf278061037381514c" | |
| 2080 "146064c5285db130dd5bae98b7722259" | |
| 2081 "50eab05d3ea996f6fffb9a8c8622913f" | |
| 2082 "279914c89ada4f3dd77666a868bfcbff" | |
| 2083 "2b95b7daf453d4e2c9d75beee7f8e709" | |
| 2084 "05e4066a4f73aecc67f956aa5a3292b8" | |
| 2085 "488c917d317cfdc86253e690381e15ab", | |
| 2086 "76204eacc1d63ec1d6ad5bd0692e1a2f" | |
| 2087 "686df6e64ca945c77a824de212efa6d9" | |
| 2088 "782d81b4591403ff4020620298c07ebd" | |
| 2089 "3a8a61c5bf4dad62cbfc4ae6a03937be" | |
| 2090 "4b49a216d570fc6e81872937876e27bd" | |
| 2091 "19cf601effc30ddca573c9d56cd4569b" | |
| 2092 "db4851c450c42cb21e738cdd61027b8b" | |
| 2093 "e5e9b410fc46aa3f29e4be9e64451346"}, | |
| 2094 // PKCS#1 v1.5 Signature Example 1.14 | |
| 2095 {"0211382683a74d8d2a2cb6a06550563b" | |
| 2096 "e1c26ca62821e4ff163b720464fc3a28" | |
| 2097 "d91bedddc62749a5538eaf41fbe0c82a" | |
| 2098 "77e06ad99383c9e985ffb8a93fd4d7c5" | |
| 2099 "8db51ad91ba461d69a8fd7ddabe24967" | |
| 2100 "57a0c49122c1a79a85cc0553e8214d03" | |
| 2101 "6dfe0185efa0d05860c612fa0882c82d" | |
| 2102 "246e5830a67355dff18a2c36b732f988" | |
| 2103 "cfedc562264c6254b40fcabb97b76094" | |
| 2104 "7568dcd6a17cda6ee8855bddbab93702" | |
| 2105 "471aa0cfb1bed2e13118eba1175b73c9" | |
| 2106 "6253c108d0b2aba05ab8e17e84392e20" | |
| 2107 "085f47404d8365527dc3fb8f2bb48a50" | |
| 2108 "038e71361ccf973407", | |
| 2109 "525500918331f1042eae0c5c2054aa7f" | |
| 2110 "92deb26991b5796634f229daf9b49eb2" | |
| 2111 "054d87319f3cfa9b466bd075ef6699ae" | |
| 2112 "a4bd4a195a1c52968b5e2b75e092d846" | |
| 2113 "ea1b5cc27905a8e1d5e5de0edfdb2139" | |
| 2114 "1ebb951864ebd9f0b0ec35b654287136" | |
| 2115 "0a317b7ef13ae06af684e38e21b1e19b" | |
| 2116 "c7298e5d6fe0013a164bfa25d3e7313d"}, | |
| 2117 // PKCS#1 v1.5 Signature Example 1.15 | |
| 2118 {"fc6b700d22583388ab2f8dafcaf1a056" | |
| 2119 "20698020da4bae44dafbd0877b501250" | |
| 2120 "6dc3181d5c66bf023f348b41fd9f9479" | |
| 2121 "5ab96452a4219f2d39d72af359cf1956" | |
| 2122 "51c7", | |
| 2123 "4452a6cc2626b01e95ab306df0d0cc74" | |
| 2124 "84fbab3c22e9703283567f66eadc248d" | |
| 2125 "bda58fce7dd0c70cce3f150fca4b369d" | |
| 2126 "ff3b6237e2b16281ab55b53fb13089c8" | |
| 2127 "5cd265056b3d62a88bfc2135b16791f7" | |
| 2128 "fbcab9fd2dc33becb617be419d2c0461" | |
| 2129 "42a4d47b338314552edd4b6fe9ce1104" | |
| 2130 "ecec4a9958d7331e930fc09bf08a6e64"}, | |
| 2131 // PKCS#1 v1.5 Signature Example 1.16 | |
| 2132 {"13ba086d709cfa5fedaa557a89181a61" | |
| 2133 "40f2300ed6d7c3febb6cf68abebcbc67" | |
| 2134 "8f2bca3dc2330295eec45bb1c4075f3a" | |
| 2135 "da987eae88b39c51606cb80429e649d9" | |
| 2136 "8acc8441b1f8897db86c5a4ce0abf28b" | |
| 2137 "1b81dca3667697b850696b74a5ebd85d" | |
| 2138 "ec56c90f8abe513efa857853720be319" | |
| 2139 "607921bca947522cd8fac8cace5b827c" | |
| 2140 "3e5a129e7ee57f6b84932f14141ac427" | |
| 2141 "4e8cbb46e6912b0d3e2177d499d1840c" | |
| 2142 "d47d4d7ae0b4cdc4d3", | |
| 2143 "1f3b5a87db72a2c97bb3eff2a65a3012" | |
| 2144 "68eacd89f42abc1098c1f2de77b0832a" | |
| 2145 "65d7815feb35070063f221bb3453bd43" | |
| 2146 "4386c9a3fde18e3ca1687fb649e86c51" | |
| 2147 "d658619dde5debb86fe15491ff77ab74" | |
| 2148 "8373f1be508880d66ea81e870e91cdf1" | |
| 2149 "704875c17f0b10103188bc64eef5a355" | |
| 2150 "1b414c733670215b1a22702562581ab1"}, | |
| 2151 // PKCS#1 v1.5 Signature Example 1.17 | |
| 2152 {"eb1e5935", | |
| 2153 "370cb9839ae6074f84b2acd6e6f6b792" | |
| 2154 "1b4b523463757f6446716140c4e6c0e7" | |
| 2155 "5bec6ad0197ebfa86bf46d094f5f6cd3" | |
| 2156 "6dca3a5cc73c8bbb70e2c7c9ab5d964e" | |
| 2157 "c8e3dfde481b4a1beffd01b4ad15b31a" | |
| 2158 "e7aebb9b70344a9411083165fdf9c375" | |
| 2159 "4bbb8b94dd34bd4813dfada1f6937de4" | |
| 2160 "267d5597ca09a31e83d7f1a79dd19b5e"}, | |
| 2161 // PKCS#1 v1.5 Signature Example 1.18 | |
| 2162 {"6346b153e889c8228209630071c8a577" | |
| 2163 "83f368760b8eb908cfc2b276", | |
| 2164 "2479c975c5b1ae4c4e940f473a9045b8" | |
| 2165 "bf5b0bfca78ec29a38dfbedc8a749b7a" | |
| 2166 "2692f7c52d5bc7c831c7232372a00fed" | |
| 2167 "3b6b49e760ec99e074ff2eead5134e83" | |
| 2168 "05725dfa39212b84bd4b8d80bc8bc17a" | |
| 2169 "512823a3beb18fc08e45ed19c26c8177" | |
| 2170 "07d67fb05832ef1f12a33e90cd93b8a7" | |
| 2171 "80319e2963ca25a2af7b09ad8f595c21"}, | |
| 2172 // PKCS#1 v1.5 Signature Example 1.19 | |
| 2173 {"64702db9f825a0f3abc361974659f5e9" | |
| 2174 "d30c3aa4f56feac69050c72905e77fe0" | |
| 2175 "c22f88a378c21fcf45fe8a5c71730209" | |
| 2176 "3929", | |
| 2177 "152f3451c858d69594e6567dfb31291c" | |
| 2178 "1ee7860b9d15ebd5a5edd276ac3e6f7a" | |
| 2179 "8d1480e42b3381d2be023acf7ebbdb28" | |
| 2180 "de3d2163ae44259c6df98c335d045b61" | |
| 2181 "dac9dba9dbbb4e6ab4a083cd76b580cb" | |
| 2182 "e472206a1a9fd60680ceea1a570a29b0" | |
| 2183 "881c775eaef5525d6d2f344c28837d0a" | |
| 2184 "ca422bbb0f1aba8f6861ae18bd73fe44"}, | |
| 2185 // PKCS#1 v1.5 Signature Example 1.20 | |
| 2186 {"941921de4a1c9c1618d6f3ca3c179f6e" | |
| 2187 "29bae6ddf9a6a564f929e3ce82cf3265" | |
| 2188 "d7837d5e692be8dcc9e86c", | |
| 2189 "7076c287fc6fff2b20537435e5a3107c" | |
| 2190 "e4da10716186d01539413e609d27d1da" | |
| 2191 "6fd952c61f4bab91c045fa4f8683ecc4" | |
| 2192 "f8dde74227f773cff3d96db84718c494" | |
| 2193 "4b06affeba94b725f1b07d3928b2490a" | |
| 2194 "85c2f1abf492a9177a7cd2ea0c966875" | |
| 2195 "6f825bbec900fa8ac3824e114387ef57" | |
| 2196 "3780ca334882387b94e5aad7a27a28dc"}}; | |
| 2197 | |
| 2198 // Import the public key. | |
| 2199 blink::WebCryptoAlgorithm algorithm = CreateRsaAlgorithmWithInnerHash( | |
| 2200 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | |
| 2201 blink::WebCryptoAlgorithmIdSha1); | |
| 2202 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); | |
| 2203 ASSERT_TRUE(ImportKeyInternal( | |
| 2204 blink::WebCryptoKeyFormatSpki, | |
| 2205 HexStringToBytes(public_key_spki_der_hex), | |
| 2206 algorithm, | |
| 2207 true, | |
| 2208 blink::WebCryptoKeyUsageVerify, | |
| 2209 &public_key)); | |
| 2210 EXPECT_FALSE(public_key.isNull()); | |
| 2211 EXPECT_TRUE(public_key.handle()); | |
| 2212 | |
| 2213 // Import the private key. | |
| 2214 blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); | |
| 2215 ASSERT_TRUE(ImportKeyInternal( | |
| 2216 blink::WebCryptoKeyFormatPkcs8, | |
| 2217 HexStringToBytes(private_key_pkcs8_der_hex), | |
| 2218 algorithm, | |
| 2219 true, | |
| 2220 blink::WebCryptoKeyUsageSign, | |
| 2221 &private_key)); | |
| 2222 EXPECT_FALSE(private_key.isNull()); | |
| 2223 EXPECT_TRUE(private_key.handle()); | |
| 2224 | |
| 2225 // Validate the signatures are computed and verified as expected. | |
| 2226 blink::WebArrayBuffer signature; | |
| 2227 for (size_t idx = 0; idx < ARRAYSIZE_UNSAFE(kTests); ++idx) { | |
| 2228 | |
| 2229 SCOPED_TRACE(idx); | |
| 2230 const TestCase& test = kTests[idx]; | |
| 2231 const std::vector<uint8> message = HexStringToBytes(test.message_hex); | |
| 2232 | |
| 2233 signature.reset(); | |
| 2234 ASSERT_TRUE(SignInternal(algorithm, private_key, message, &signature)); | |
| 2235 ExpectArrayBufferMatchesHex(test.signature_hex, signature); | |
| 2236 | |
| 2237 bool is_match = false; | |
| 2238 ASSERT_TRUE(VerifySignatureInternal( | |
| 2239 algorithm, | |
| 2240 public_key, | |
| 2241 HexStringToBytes(test.signature_hex), | |
| 2242 message, | |
| 2243 &is_match)); | |
| 2244 EXPECT_TRUE(is_match); | |
| 2245 } | |
| 2246 } | |
| 2247 | |
| 1639 #endif // #if !defined(USE_OPENSSL) | 2248 #endif // #if !defined(USE_OPENSSL) |
| 1640 | 2249 |
| 1641 } // namespace content | 2250 } // namespace content |
| OLD | NEW |