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

Side by Side Diff: content/child/webcrypto/test/rsa_ssa_unittest.cc

Issue 777403004: [WebCrypto] Throw syntaxError if keyUsage is empty in ImportKey (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated issues in ecdh tests and other review comments. Created 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/logging.h" 5 #include "base/logging.h"
6 #include "base/stl_util.h" 6 #include "base/stl_util.h"
7 #include "content/child/webcrypto/algorithm_dispatch.h" 7 #include "content/child/webcrypto/algorithm_dispatch.h"
8 #include "content/child/webcrypto/crypto_data.h" 8 #include "content/child/webcrypto/crypto_data.h"
9 #include "content/child/webcrypto/status.h" 9 #include "content/child/webcrypto/status.h"
10 #include "content/child/webcrypto/test/test_helpers.h" 10 #include "content/child/webcrypto/test/test_helpers.h"
(...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 blink::WebCryptoKey private_key; 816 blink::WebCryptoKey private_key;
817 817
818 ASSERT_EQ(Status::ErrorCreateKeyEmptyUsages(), 818 ASSERT_EQ(Status::ErrorCreateKeyEmptyUsages(),
819 GenerateKeyPair(CreateRsaHashedKeyGenAlgorithm( 819 GenerateKeyPair(CreateRsaHashedKeyGenAlgorithm(
820 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, 820 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5,
821 blink::WebCryptoAlgorithmIdSha256, 821 blink::WebCryptoAlgorithmIdSha256,
822 modulus_length, public_exponent), 822 modulus_length, public_exponent),
823 true, 0, &public_key, &private_key)); 823 true, 0, &public_key, &private_key));
824 } 824 }
825 825
826 TEST(WebCryptoRsaSsaTest, ImportKeyEmptyUsages) {
827 if (!SupportsRsaPrivateKeyImport())
828 return;
829
830 blink::WebCryptoKey public_key;
831 blink::WebCryptoKey private_key;
832
833 // Public without usage does not throw an error.
834 ASSERT_EQ(Status::Success(),
835 ImportKey(blink::WebCryptoKeyFormatSpki,
836 CryptoData(HexStringToBytes(kPublicKeySpkiDerHex)),
837 CreateRsaHashedImportAlgorithm(
838 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5,
839 blink::WebCryptoAlgorithmIdSha256),
840 true, 0, &public_key));
841 EXPECT_EQ(0, public_key.usages());
842
843 // Private empty usage will throw an error.
844 ASSERT_EQ(Status::ErrorCreateKeyEmptyUsages(),
845 ImportKey(blink::WebCryptoKeyFormatPkcs8,
846 CryptoData(HexStringToBytes(kPrivateKeyPkcs8DerHex)),
847 CreateRsaHashedImportAlgorithm(
848 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5,
849 blink::WebCryptoAlgorithmIdSha1),
850 true, 0, &private_key));
851
852 std::vector<uint8_t> public_jwk;
853 ASSERT_EQ(Status::Success(),
854 ExportKey(blink::WebCryptoKeyFormatJwk, public_key, &public_jwk));
855
856 ASSERT_EQ(Status::Success(),
857 ImportKey(blink::WebCryptoKeyFormatJwk,
858 CryptoData(public_jwk),
859 CreateRsaHashedImportAlgorithm(
860 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5,
861 blink::WebCryptoAlgorithmIdSha256),
862 true, 0, &public_key));
863 EXPECT_EQ(0, public_key.usages());
864
865 // With correct usage to get correct imported private_key
866 std::vector<uint8_t> private_jwk;
867 ImportKey(blink::WebCryptoKeyFormatPkcs8,
868 CryptoData(HexStringToBytes(kPrivateKeyPkcs8DerHex)),
869 CreateRsaHashedImportAlgorithm(
870 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5,
871 blink::WebCryptoAlgorithmIdSha1),
872 true, blink::WebCryptoKeyUsageSign, &private_key);
873
874 ASSERT_EQ(Status::Success(),
875 ExportKey(blink::WebCryptoKeyFormatJwk, private_key, &private_jwk));
876
877 ASSERT_EQ(Status::ErrorCreateKeyEmptyUsages(),
878 ImportKey(blink::WebCryptoKeyFormatJwk,
879 CryptoData(private_jwk),
880 CreateRsaHashedImportAlgorithm(
881 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5,
882 blink::WebCryptoAlgorithmIdSha1),
883 true, 0, &private_key));
884 }
885
826 TEST(WebCryptoRsaSsaTest, ImportExportJwkRsaPublicKey) { 886 TEST(WebCryptoRsaSsaTest, ImportExportJwkRsaPublicKey) {
827 struct TestCase { 887 struct TestCase {
828 const blink::WebCryptoAlgorithmId hash; 888 const blink::WebCryptoAlgorithmId hash;
829 const blink::WebCryptoKeyUsageMask usage; 889 const blink::WebCryptoKeyUsageMask usage;
830 const char* const jwk_alg; 890 const char* const jwk_alg;
831 }; 891 };
832 const TestCase kTests[] = { 892 const TestCase kTests[] = {
833 {blink::WebCryptoAlgorithmIdSha1, blink::WebCryptoKeyUsageVerify, "RS1"}, 893 {blink::WebCryptoAlgorithmIdSha1, blink::WebCryptoKeyUsageVerify, "RS1"},
834 {blink::WebCryptoAlgorithmIdSha256, 894 {blink::WebCryptoAlgorithmIdSha256,
835 blink::WebCryptoKeyUsageVerify, 895 blink::WebCryptoKeyUsageVerify,
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 true, usages, &key); 1044 true, usages, &key);
985 EXPECT_EQ(test_error, StatusToString(status)); 1045 EXPECT_EQ(test_error, StatusToString(status));
986 } 1046 }
987 } 1047 }
988 1048
989 } // namespace 1049 } // namespace
990 1050
991 } // namespace webcrypto 1051 } // namespace webcrypto
992 1052
993 } // namespace content 1053 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698