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

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

Issue 668313002: Reject JWK key import when key_ops contains duplicate values. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove heap-allocated std::set Created 6 years, 1 month 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/child/webcrypto/status.cc ('k') | content/child/webcrypto/webcrypto_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/stl_util.h" 5 #include "base/stl_util.h"
6 #include "content/child/webcrypto/algorithm_dispatch.h" 6 #include "content/child/webcrypto/algorithm_dispatch.h"
7 #include "content/child/webcrypto/crypto_data.h" 7 #include "content/child/webcrypto/crypto_data.h"
8 #include "content/child/webcrypto/status.h" 8 #include "content/child/webcrypto/status.h"
9 #include "content/child/webcrypto/test/test_helpers.h" 9 #include "content/child/webcrypto/test/test_helpers.h"
10 #include "content/child/webcrypto/webcrypto_util.h" 10 #include "content/child/webcrypto/webcrypto_util.h"
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 dict, 395 dict,
396 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc), 396 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc),
397 false, 397 false,
398 blink::WebCryptoKeyUsageDecrypt | blink::WebCryptoKeyUsageEncrypt, 398 blink::WebCryptoKeyUsageDecrypt | blink::WebCryptoKeyUsageEncrypt,
399 &key)); 399 &key));
400 400
401 EXPECT_EQ(blink::WebCryptoKeyUsageEncrypt | blink::WebCryptoKeyUsageDecrypt, 401 EXPECT_EQ(blink::WebCryptoKeyUsageEncrypt | blink::WebCryptoKeyUsageDecrypt,
402 key.usages()); 402 key.usages());
403 } 403 }
404 404
405 // Tests that importing a JWK containing duplicate key_ops values fails.
406 TEST(WebCryptoAesCbcTest, ImportKeyJwkDuplicateKeyOps) {
407 blink::WebCryptoKey key;
408 base::DictionaryValue dict;
409 dict.SetString("kty", "oct");
410 dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg==");
411 // key_ops will be owned by |dict|.
412 base::ListValue* key_ops = new base::ListValue;
413 dict.Set("key_ops", key_ops);
414
415 // The "encrypt" operation appears twice.
416 key_ops->AppendString("encrypt");
417 key_ops->AppendString("decrypt");
418 key_ops->AppendString("encrypt");
419
420 EXPECT_EQ(Status::ErrorJwkDuplicateKeyOps(),
421 ImportKeyJwkFromDict(
422 dict, CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc), false,
423 0, &key));
424 }
425
426 // Tests that importing a JWK containing duplicate key_ops values fails.
427 TEST(WebCryptoAesCbcTest, ImportKeyJwkDuplicateUnrecognizedKeyOps) {
428 blink::WebCryptoKey key;
429 base::DictionaryValue dict;
430 dict.SetString("kty", "oct");
431 dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg==");
432 // key_ops will be owned by |dict|.
433 base::ListValue* key_ops = new base::ListValue;
434 dict.Set("key_ops", key_ops);
435
436 // The (unknown) "foopy" operation appears twice.
437 key_ops->AppendString("foopy");
438 key_ops->AppendString("decrypt");
439 key_ops->AppendString("foopy");
440
441 EXPECT_EQ(Status::ErrorJwkDuplicateKeyOps(),
442 ImportKeyJwkFromDict(
443 dict, CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc), false,
444 0, &key));
445 }
446
405 // Test failure if input usage is NOT a strict subset of the JWK usage. 447 // Test failure if input usage is NOT a strict subset of the JWK usage.
406 TEST(WebCryptoAesCbcTest, ImportKeyJwkKeyOpsNotSuperset) { 448 TEST(WebCryptoAesCbcTest, ImportKeyJwkKeyOpsNotSuperset) {
407 blink::WebCryptoKey key; 449 blink::WebCryptoKey key;
408 base::DictionaryValue dict; 450 base::DictionaryValue dict;
409 dict.SetString("kty", "oct"); 451 dict.SetString("kty", "oct");
410 dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg=="); 452 dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg==");
411 base::ListValue* key_ops = new base::ListValue; 453 base::ListValue* key_ops = new base::ListValue;
412 dict.Set("key_ops", key_ops); // Takes ownership. 454 dict.Set("key_ops", key_ops); // Takes ownership.
413 455
414 key_ops->AppendString("encrypt"); 456 key_ops->AppendString("encrypt");
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 1074
1033 EXPECT_NE(public_key_spki, wrapped_public_key); 1075 EXPECT_NE(public_key_spki, wrapped_public_key);
1034 EXPECT_NE(private_key_pkcs8, wrapped_private_key); 1076 EXPECT_NE(private_key_pkcs8, wrapped_private_key);
1035 } 1077 }
1036 1078
1037 } // namespace 1079 } // namespace
1038 1080
1039 } // namespace webcrypto 1081 } // namespace webcrypto
1040 1082
1041 } // namespace content 1083 } // namespace content
OLDNEW
« no previous file with comments | « content/child/webcrypto/status.cc ('k') | content/child/webcrypto/webcrypto_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698