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

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: 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) {
eroman 2014/12/09 21:04:46 Could you also add the same sort of test to ecdh_u
Habib Virji 2014/12/15 18:48:55 Added test.
827 blink::WebCryptoKey key;
828 // Public without usage does not throw error.
829 ASSERT_EQ(Status::Success(),
830 ImportKey(blink::WebCryptoKeyFormatSpki,
831 CryptoData(HexStringToBytes(kPublicKeySpkiDerHex)),
832 CreateRsaHashedImportAlgorithm(
833 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5,
834 blink::WebCryptoAlgorithmIdSha256),
835 true, 0, &key));
836 // Private key usage will generate error.
eroman 2014/12/09 21:04:46 Could you add two more tests for JWK: (1) Import
Habib Virji 2014/12/15 18:48:55 Done. Have done export key and import key as jwk.
837 ASSERT_EQ(Status::ErrorImportKeyEmptyUsages(),
838 ImportKey(blink::WebCryptoKeyFormatPkcs8,
839 CryptoData(HexStringToBytes(kPrivateKeyPkcs8DerHex)),
840 CreateRsaHashedImportAlgorithm(
841 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5,
842 blink::WebCryptoAlgorithmIdSha1),
843 true, 0, &key));
844
845 }
846
826 TEST(WebCryptoRsaSsaTest, ImportExportJwkRsaPublicKey) { 847 TEST(WebCryptoRsaSsaTest, ImportExportJwkRsaPublicKey) {
827 struct TestCase { 848 struct TestCase {
828 const blink::WebCryptoAlgorithmId hash; 849 const blink::WebCryptoAlgorithmId hash;
829 const blink::WebCryptoKeyUsageMask usage; 850 const blink::WebCryptoKeyUsageMask usage;
830 const char* const jwk_alg; 851 const char* const jwk_alg;
831 }; 852 };
832 const TestCase kTests[] = { 853 const TestCase kTests[] = {
833 {blink::WebCryptoAlgorithmIdSha1, blink::WebCryptoKeyUsageVerify, "RS1"}, 854 {blink::WebCryptoAlgorithmIdSha1, blink::WebCryptoKeyUsageVerify, "RS1"},
834 {blink::WebCryptoAlgorithmIdSha256, 855 {blink::WebCryptoAlgorithmIdSha256,
835 blink::WebCryptoKeyUsageVerify, 856 blink::WebCryptoKeyUsageVerify,
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 true, usages, &key); 1005 true, usages, &key);
985 EXPECT_EQ(test_error, StatusToString(status)); 1006 EXPECT_EQ(test_error, StatusToString(status));
986 } 1007 }
987 } 1008 }
988 1009
989 } // namespace 1010 } // namespace
990 1011
991 } // namespace webcrypto 1012 } // namespace webcrypto
992 1013
993 } // namespace content 1014 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698