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 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); |
| 1626 blink::WebCryptoAlgorithm algorithm = |
| 1627 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdAesKw); |
| 1628 |
| 1629 // Import a 128-bit Key Encryption Key (KEK) |
| 1630 std::string key_raw_hex_in = "025a8cf3f08b4f6c5f33bbc76a471939"; |
| 1631 ASSERT_TRUE(ImportKeyInternal(blink::WebCryptoKeyFormatRaw, |
| 1632 HexStringToBytes(key_raw_hex_in), |
| 1633 algorithm, |
| 1634 true, |
| 1635 blink::WebCryptoKeyUsageWrapKey, |
| 1636 &key)); |
| 1637 blink::WebArrayBuffer key_raw_out; |
| 1638 EXPECT_TRUE(ExportKeyInternal(blink::WebCryptoKeyFormatRaw, |
| 1639 key, |
| 1640 &key_raw_out)); |
| 1641 ExpectArrayBufferMatchesHex(key_raw_hex_in, key_raw_out); |
| 1642 |
| 1643 // Import a 192-bit KEK |
| 1644 key_raw_hex_in = "c0192c6466b2370decbb62b2cfef4384544ffeb4d2fbc103"; |
| 1645 ASSERT_TRUE(ImportKeyInternal(blink::WebCryptoKeyFormatRaw, |
| 1646 HexStringToBytes(key_raw_hex_in), |
| 1647 algorithm, |
| 1648 true, |
| 1649 blink::WebCryptoKeyUsageWrapKey, |
| 1650 &key)); |
| 1651 EXPECT_TRUE(ExportKeyInternal(blink::WebCryptoKeyFormatRaw, |
| 1652 key, |
| 1653 &key_raw_out)); |
| 1654 ExpectArrayBufferMatchesHex(key_raw_hex_in, key_raw_out); |
| 1655 |
| 1656 // Import a 256-bit Key Encryption Key (KEK) |
| 1657 key_raw_hex_in = |
| 1658 "e11fe66380d90fa9ebefb74e0478e78f95664d0c67ca20ce4a0b5842863ac46f"; |
| 1659 ASSERT_TRUE(ImportKeyInternal(blink::WebCryptoKeyFormatRaw, |
| 1660 HexStringToBytes(key_raw_hex_in), |
| 1661 algorithm, |
| 1662 true, |
| 1663 blink::WebCryptoKeyUsageWrapKey, |
| 1664 &key)); |
| 1665 EXPECT_TRUE(ExportKeyInternal(blink::WebCryptoKeyFormatRaw, |
| 1666 key, |
| 1667 &key_raw_out)); |
| 1668 ExpectArrayBufferMatchesHex(key_raw_hex_in, key_raw_out); |
| 1669 |
| 1670 // Fail import of 0 length key |
| 1671 EXPECT_FALSE(ImportKeyInternal(blink::WebCryptoKeyFormatRaw, |
| 1672 HexStringToBytes(""), |
| 1673 algorithm, |
| 1674 true, |
| 1675 blink::WebCryptoKeyUsageWrapKey, |
| 1676 &key)); |
| 1677 |
| 1678 // Fail import of 124-bit KEK |
| 1679 key_raw_hex_in = "3e4566a2bdaa10cb68134fa66c15ddb"; |
| 1680 EXPECT_FALSE(ImportKeyInternal(blink::WebCryptoKeyFormatRaw, |
| 1681 HexStringToBytes(key_raw_hex_in), |
| 1682 algorithm, |
| 1683 true, |
| 1684 blink::WebCryptoKeyUsageWrapKey, |
| 1685 &key)); |
| 1686 |
| 1687 // Fail import of 200-bit KEK |
| 1688 key_raw_hex_in = "0a1d88608a5ad9fec64f1ada269ebab4baa2feeb8d95638c0e"; |
| 1689 EXPECT_FALSE(ImportKeyInternal(blink::WebCryptoKeyFormatRaw, |
| 1690 HexStringToBytes(key_raw_hex_in), |
| 1691 algorithm, |
| 1692 true, |
| 1693 blink::WebCryptoKeyUsageWrapKey, |
| 1694 &key)); |
| 1695 |
| 1696 // Fail import of 260-bit KEK |
| 1697 key_raw_hex_in = |
| 1698 "72d4e475ff34215416c9ad9c8281247a4d730c5f275ac23f376e73e3bce8d7d5a"; |
| 1699 EXPECT_FALSE(ImportKeyInternal(blink::WebCryptoKeyFormatRaw, |
| 1700 HexStringToBytes(key_raw_hex_in), |
| 1701 algorithm, |
| 1702 true, |
| 1703 blink::WebCryptoKeyUsageWrapKey, |
| 1704 &key)); |
| 1705 } |
| 1706 |
1621 } // namespace content | 1707 } // namespace content |
OLD | NEW |