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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); | 115 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); |
| 116 bool extractable = true; | 116 bool extractable = true; |
| 117 EXPECT_TRUE(crypto_.ImportKeyInternal(blink::WebCryptoKeyFormatRaw, | 117 EXPECT_TRUE(crypto_.ImportKeyInternal(blink::WebCryptoKeyFormatRaw, |
| 118 webcrypto::Uint8VectorStart(key_raw), | 118 webcrypto::Uint8VectorStart(key_raw), |
| 119 key_raw.size(), | 119 key_raw.size(), |
| 120 algorithm, | 120 algorithm, |
| 121 extractable, | 121 extractable, |
| 122 usage, | 122 usage, |
| 123 &key)); | 123 &key)); |
| 124 | 124 |
| 125 EXPECT_EQ(blink::WebCryptoKeyTypeSecret, key.type()); | |
| 126 EXPECT_FALSE(key.isNull()); | 125 EXPECT_FALSE(key.isNull()); |
| 127 EXPECT_TRUE(key.handle()); | 126 EXPECT_TRUE(key.handle()); |
| 127 EXPECT_EQ(blink::WebCryptoKeyTypeSecret, key.type()); | |
| 128 EXPECT_EQ(algorithm.id(), key.algorithm().id()); | |
| 129 EXPECT_EQ(extractable, key.extractable()); | |
| 130 EXPECT_EQ(usage, key.usages()); | |
| 128 return key; | 131 return key; |
| 129 } | 132 } |
| 130 | 133 |
| 131 // Forwarding methods to gain access to protected methods of | 134 // Forwarding methods to gain access to protected methods of |
| 132 // WebCryptoImpl. | 135 // WebCryptoImpl. |
| 133 | 136 |
| 134 bool DigestInternal( | 137 bool DigestInternal( |
| 135 const blink::WebCryptoAlgorithm& algorithm, | 138 const blink::WebCryptoAlgorithm& algorithm, |
| 136 const std::vector<uint8>& data, | 139 const std::vector<uint8>& data, |
| 137 blink::WebArrayBuffer* buffer) { | 140 blink::WebArrayBuffer* buffer) { |
| (...skipping 1473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1611 // Do a successful decrypt with good data just for confirmation. | 1614 // Do a successful decrypt with good data just for confirmation. |
| 1612 EXPECT_TRUE(DecryptInternal( | 1615 EXPECT_TRUE(DecryptInternal( |
| 1613 algorithm, | 1616 algorithm, |
| 1614 private_key, | 1617 private_key, |
| 1615 reinterpret_cast<const unsigned char*>(encrypted_data.data()), | 1618 reinterpret_cast<const unsigned char*>(encrypted_data.data()), |
| 1616 encrypted_data.byteLength(), | 1619 encrypted_data.byteLength(), |
| 1617 &decrypted_data)); | 1620 &decrypted_data)); |
| 1618 ExpectArrayBufferMatchesHex(message_hex_str, decrypted_data); | 1621 ExpectArrayBufferMatchesHex(message_hex_str, decrypted_data); |
| 1619 } | 1622 } |
| 1620 | 1623 |
| 1624 TEST_F(WebCryptoImplTest, MAYBE(AesKwKeyImport)) { | |
| 1625 | |
|
eroman
2013/12/18 02:10:30
Can you delete this extra line?
padolph
2013/12/18 03:21:41
Done.
| |
| 1626 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); | |
| 1627 blink::WebCryptoAlgorithm algorithm = | |
| 1628 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdAesKw); | |
| 1629 | |
| 1630 // Import a 128-bit Key Encryption Key (KEK) | |
| 1631 std::string key_raw_hex_in = "025a8cf3f08b4f6c5f33bbc76a471939"; | |
| 1632 ASSERT_TRUE(ImportKeyInternal(blink::WebCryptoKeyFormatRaw, | |
| 1633 HexStringToBytes(key_raw_hex_in), | |
| 1634 algorithm, | |
| 1635 true, | |
| 1636 blink::WebCryptoKeyUsageWrapKey, | |
| 1637 &key)); | |
| 1638 blink::WebArrayBuffer key_raw_out; | |
| 1639 EXPECT_TRUE(ExportKeyInternal(blink::WebCryptoKeyFormatRaw, | |
| 1640 key, | |
| 1641 &key_raw_out)); | |
| 1642 ExpectArrayBufferMatchesHex(key_raw_hex_in, key_raw_out); | |
| 1643 | |
| 1644 // Import a 192-bit KEK | |
| 1645 key_raw_hex_in = "c0192c6466b2370decbb62b2cfef4384544ffeb4d2fbc103"; | |
| 1646 ASSERT_TRUE(ImportKeyInternal(blink::WebCryptoKeyFormatRaw, | |
| 1647 HexStringToBytes(key_raw_hex_in), | |
| 1648 algorithm, | |
| 1649 true, | |
| 1650 blink::WebCryptoKeyUsageWrapKey, | |
| 1651 &key)); | |
| 1652 EXPECT_TRUE(ExportKeyInternal(blink::WebCryptoKeyFormatRaw, | |
| 1653 key, | |
| 1654 &key_raw_out)); | |
| 1655 ExpectArrayBufferMatchesHex(key_raw_hex_in, key_raw_out); | |
| 1656 | |
| 1657 // Import a 256-bit Key Encryption Key (KEK) | |
| 1658 key_raw_hex_in = | |
| 1659 "e11fe66380d90fa9ebefb74e0478e78f95664d0c67ca20ce4a0b5842863ac46f"; | |
| 1660 ASSERT_TRUE(ImportKeyInternal(blink::WebCryptoKeyFormatRaw, | |
| 1661 HexStringToBytes(key_raw_hex_in), | |
| 1662 algorithm, | |
| 1663 true, | |
| 1664 blink::WebCryptoKeyUsageWrapKey, | |
| 1665 &key)); | |
| 1666 EXPECT_TRUE(ExportKeyInternal(blink::WebCryptoKeyFormatRaw, | |
| 1667 key, | |
| 1668 &key_raw_out)); | |
| 1669 ExpectArrayBufferMatchesHex(key_raw_hex_in, key_raw_out); | |
| 1670 | |
| 1671 // Fail import of 0 length key | |
| 1672 EXPECT_FALSE(ImportKeyInternal(blink::WebCryptoKeyFormatRaw, | |
| 1673 HexStringToBytes(""), | |
| 1674 algorithm, | |
| 1675 true, | |
| 1676 blink::WebCryptoKeyUsageWrapKey, | |
| 1677 &key)); | |
| 1678 | |
| 1679 // Fail import of 124-bit KEK | |
| 1680 key_raw_hex_in = "3e4566a2bdaa10cb68134fa66c15ddb"; | |
| 1681 EXPECT_FALSE(ImportKeyInternal(blink::WebCryptoKeyFormatRaw, | |
| 1682 HexStringToBytes(key_raw_hex_in), | |
| 1683 algorithm, | |
| 1684 true, | |
| 1685 blink::WebCryptoKeyUsageWrapKey, | |
| 1686 &key)); | |
| 1687 | |
| 1688 // Fail import of 200-bit KEK | |
| 1689 key_raw_hex_in = "0a1d88608a5ad9fec64f1ada269ebab4baa2feeb8d95638c0e"; | |
| 1690 EXPECT_FALSE(ImportKeyInternal(blink::WebCryptoKeyFormatRaw, | |
| 1691 HexStringToBytes(key_raw_hex_in), | |
| 1692 algorithm, | |
| 1693 true, | |
| 1694 blink::WebCryptoKeyUsageWrapKey, | |
| 1695 &key)); | |
| 1696 | |
| 1697 // Fail import of 260-bit KEK | |
| 1698 key_raw_hex_in = | |
| 1699 "72d4e475ff34215416c9ad9c8281247a4d730c5f275ac23f376e73e3bce8d7d5a"; | |
| 1700 EXPECT_FALSE(ImportKeyInternal(blink::WebCryptoKeyFormatRaw, | |
| 1701 HexStringToBytes(key_raw_hex_in), | |
| 1702 algorithm, | |
| 1703 true, | |
| 1704 blink::WebCryptoKeyUsageWrapKey, | |
| 1705 &key)); | |
| 1706 } | |
| 1707 | |
| 1621 } // namespace content | 1708 } // namespace content |
| OLD | NEW |