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

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

Issue 83483012: [webcrypto] Add RSA private key PKCS#8 import for NSS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes for rsleevi and eroman 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
« no previous file with comments | « content/renderer/webcrypto/webcrypto_impl_nss.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 blink::WebCryptoKeyFormatSpki, 782 blink::WebCryptoKeyFormatSpki,
783 HexStringToBytes(hex_rsa_spki_der), 783 HexStringToBytes(hex_rsa_spki_der),
784 CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5), 784 CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5),
785 false, 785 false,
786 blink::WebCryptoKeyUsageEncrypt, 786 blink::WebCryptoKeyUsageEncrypt,
787 &key)); 787 &key));
788 EXPECT_TRUE(key.handle()); 788 EXPECT_TRUE(key.handle());
789 EXPECT_FALSE(key.extractable()); 789 EXPECT_FALSE(key.extractable());
790 EXPECT_FALSE(ExportKeyInternal(blink::WebCryptoKeyFormatSpki, key, &output)); 790 EXPECT_FALSE(ExportKeyInternal(blink::WebCryptoKeyFormatSpki, key, &output));
791 791
792 // TODO(padolph): Import a RSA SPKI key and verify it works with an operation. 792 // TODO(padolph): Use the imported key for a Known Answer Test (KAT).
793 }
794
795 TEST_F(WebCryptoImplTest, ImportPkcs8) {
796
797 // The following is a DER-encoded PKCS#8 representation of the RSA key from
798 // Example 1 of NIST's "Test vectors for RSA PKCS#1 v1.5 Signature".
799 // ftp://ftp.rsa.com/pub/rsalabs/tmp/pkcs1v15sign-vectors.txt
800 const std::string hex_rsa_pkcs8_der =
801 "30820275020100300D06092A864886F70D01010105000482025F3082025B020100028181"
802 "00A56E4A0E701017589A5187DC7EA841D156F2EC0E36AD52A44DFEB1E61F7AD991D8C510"
803 "56FFEDB162B4C0F283A12A88A394DFF526AB7291CBB307CEABFCE0B1DFD5CD9508096D5B"
804 "2B8B6DF5D671EF6377C0921CB23C270A70E2598E6FF89D19F105ACC2D3F0CB35F29280E1"
805 "386B6F64C4EF22E1E1F20D0CE8CFFB2249BD9A2137020301000102818033A5042A90B27D"
806 "4F5451CA9BBBD0B44771A101AF884340AEF9885F2A4BBE92E894A724AC3C568C8F97853A"
807 "D07C0266C8C6A3CA0929F1E8F11231884429FC4D9AE55FEE896A10CE707C3ED7E734E447"
808 "27A39574501A532683109C2ABACABA283C31B4BD2F53C3EE37E352CEE34F9E503BD80C06"
809 "22AD79C6DCEE883547C6A3B325024100E7E8942720A877517273A356053EA2A1BC0C94AA"
810 "72D55C6E86296B2DFC967948C0A72CBCCCA7EACB35706E09A1DF55A1535BD9B3CC34160B"
811 "3B6DCD3EDA8E6443024100B69DCA1CF7D4D7EC81E75B90FCCA874ABCDE123FD2700180AA"
812 "90479B6E48DE8D67ED24F9F19D85BA275874F542CD20DC723E6963364A1F9425452B269A"
813 "6799FD024028FA13938655BE1F8A159CBACA5A72EA190C30089E19CD274A556F36C4F6E1"
814 "9F554B34C077790427BBDD8DD3EDE2448328F385D81B30E8E43B2FFFA02786197902401A"
815 "8B38F398FA712049898D7FB79EE0A77668791299CDFA09EFC0E507ACB21ED74301EF5BFD"
816 "48BE455EAEB6E1678255827580A8E4E8E14151D1510A82A3F2E729024027156ABA4126D2"
817 "4A81F3A528CBFB27F56886F840A9F6E86E17A44B94FE9319584B8E22FDDE1E5A2E3BD8AA"
818 "5BA8D8584194EB2190ACF832B847F13A3D24A79F4D";
819
820 // Passing case: Import a valid RSA key in PKCS#8 format.
821 blink::WebCryptoKey key = blink::WebCryptoKey::createNull();
822 ASSERT_TRUE(ImportKeyInternal(
823 blink::WebCryptoKeyFormatPkcs8,
824 HexStringToBytes(hex_rsa_pkcs8_der),
825 CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5),
826 true,
827 blink::WebCryptoKeyUsageSign,
828 &key));
829 EXPECT_TRUE(key.handle());
830 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, key.type());
831 EXPECT_TRUE(key.extractable());
832 EXPECT_EQ(blink::WebCryptoKeyUsageSign, key.usages());
833
834 // Failing case: Empty PKCS#8 data
835 EXPECT_FALSE(ImportKeyInternal(
836 blink::WebCryptoKeyFormatPkcs8,
837 std::vector<uint8>(),
838 blink::WebCryptoAlgorithm::createNull(),
839 true,
840 blink::WebCryptoKeyUsageSign,
841 &key));
842
843 // Failing case: Import RSA key with NULL input algorithm. This is not
844 // allowed because the PKCS#8 ASN.1 format for RSA keys is not specific enough
845 // to map to a Web Crypto algorithm.
846 EXPECT_FALSE(ImportKeyInternal(
847 blink::WebCryptoKeyFormatPkcs8,
848 HexStringToBytes(hex_rsa_pkcs8_der),
849 blink::WebCryptoAlgorithm::createNull(),
850 true,
851 blink::WebCryptoKeyUsageSign,
852 &key));
853
854 // Failing case: Bad DER encoding.
855 EXPECT_FALSE(ImportKeyInternal(
856 blink::WebCryptoKeyFormatPkcs8,
857 HexStringToBytes("618333c4cb"),
858 CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5),
859 true,
860 blink::WebCryptoKeyUsageSign,
861 &key));
862
863 // Failing case: Import RSA key but provide an inconsistent input algorithm.
864 EXPECT_FALSE(ImportKeyInternal(
865 blink::WebCryptoKeyFormatPkcs8,
866 HexStringToBytes(hex_rsa_pkcs8_der),
867 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc),
868 true,
869 blink::WebCryptoKeyUsageSign,
870 &key));
871
872 // TODO(padolph): Use the imported key for a Known Answer Test (KAT).
793 } 873 }
794 874
795 TEST_F(WebCryptoImplTest, GenerateKeyPairRsa) { 875 TEST_F(WebCryptoImplTest, GenerateKeyPairRsa) {
796 // Note: using unrealistic short key lengths here to avoid bogging down tests. 876 // Note: using unrealistic short key lengths here to avoid bogging down tests.
797 877
798 // Successful WebCryptoAlgorithmIdRsaEsPkcs1v1_5 key generation. 878 // Successful WebCryptoAlgorithmIdRsaEsPkcs1v1_5 key generation.
799 const unsigned modulus_length = 256; 879 const unsigned modulus_length = 256;
800 const std::vector<uint8> public_exponent = HexStringToBytes("010001"); 880 const std::vector<uint8> public_exponent = HexStringToBytes("010001");
801 blink::WebCryptoAlgorithm algorithm = 881 blink::WebCryptoAlgorithm algorithm =
802 CreateRsaAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, 882 CreateRsaAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5,
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 // since it is expensive to generate an RSA key pair and we already have a 979 // since it is expensive to generate an RSA key pair and we already have a
900 // private key here. 980 // private key here.
901 blink::WebArrayBuffer output; 981 blink::WebArrayBuffer output;
902 EXPECT_FALSE( 982 EXPECT_FALSE(
903 ExportKeyInternal(blink::WebCryptoKeyFormatSpki, private_key, &output)); 983 ExportKeyInternal(blink::WebCryptoKeyFormatSpki, private_key, &output));
904 } 984 }
905 985
906 #endif // #if !defined(USE_OPENSSL) 986 #endif // #if !defined(USE_OPENSSL)
907 987
908 } // namespace content 988 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/webcrypto/webcrypto_impl_nss.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698