OLD | NEW |
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 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 TEST(WebCryptoRsaSsaTest, GenerateKeyPairRsa) { | 311 TEST(WebCryptoRsaSsaTest, GenerateKeyPairRsa) { |
312 // Note: using unrealistic short key lengths here to avoid bogging down tests. | 312 // Note: using unrealistic short key lengths here to avoid bogging down tests. |
313 | 313 |
314 // Successful WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 key generation (sha256) | 314 // Successful WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 key generation (sha256) |
315 const unsigned int modulus_length = 256; | 315 const unsigned int modulus_length = 256; |
316 const std::vector<uint8_t> public_exponent = HexStringToBytes("010001"); | 316 const std::vector<uint8_t> public_exponent = HexStringToBytes("010001"); |
317 blink::WebCryptoAlgorithm algorithm = CreateRsaHashedKeyGenAlgorithm( | 317 blink::WebCryptoAlgorithm algorithm = CreateRsaHashedKeyGenAlgorithm( |
318 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 318 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
319 blink::WebCryptoAlgorithmIdSha256, modulus_length, public_exponent); | 319 blink::WebCryptoAlgorithmIdSha256, modulus_length, public_exponent); |
320 bool extractable = true; | 320 bool extractable = true; |
321 const blink::WebCryptoKeyUsageMask usages = 0; | 321 const blink::WebCryptoKeyUsageMask public_usages = |
| 322 blink::WebCryptoKeyUsageVerify; |
| 323 const blink::WebCryptoKeyUsageMask private_usages = |
| 324 blink::WebCryptoKeyUsageSign; |
| 325 const blink::WebCryptoKeyUsageMask usages = public_usages | private_usages; |
322 blink::WebCryptoKey public_key; | 326 blink::WebCryptoKey public_key; |
323 blink::WebCryptoKey private_key; | 327 blink::WebCryptoKey private_key; |
324 | 328 |
325 EXPECT_EQ(Status::Success(), GenerateKeyPair(algorithm, extractable, usages, | 329 EXPECT_EQ(Status::Success(), GenerateKeyPair(algorithm, extractable, usages, |
326 &public_key, &private_key)); | 330 &public_key, &private_key)); |
327 EXPECT_FALSE(public_key.isNull()); | 331 ASSERT_FALSE(public_key.isNull()); |
328 EXPECT_FALSE(private_key.isNull()); | 332 ASSERT_FALSE(private_key.isNull()); |
329 EXPECT_EQ(blink::WebCryptoKeyTypePublic, public_key.type()); | 333 EXPECT_EQ(blink::WebCryptoKeyTypePublic, public_key.type()); |
330 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, private_key.type()); | 334 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, private_key.type()); |
331 EXPECT_EQ(modulus_length, | 335 EXPECT_EQ(modulus_length, |
332 public_key.algorithm().rsaHashedParams()->modulusLengthBits()); | 336 public_key.algorithm().rsaHashedParams()->modulusLengthBits()); |
333 EXPECT_EQ(modulus_length, | 337 EXPECT_EQ(modulus_length, |
334 private_key.algorithm().rsaHashedParams()->modulusLengthBits()); | 338 private_key.algorithm().rsaHashedParams()->modulusLengthBits()); |
335 EXPECT_EQ(blink::WebCryptoAlgorithmIdSha256, | 339 EXPECT_EQ(blink::WebCryptoAlgorithmIdSha256, |
336 public_key.algorithm().rsaHashedParams()->hash().id()); | 340 public_key.algorithm().rsaHashedParams()->hash().id()); |
337 EXPECT_EQ(blink::WebCryptoAlgorithmIdSha256, | 341 EXPECT_EQ(blink::WebCryptoAlgorithmIdSha256, |
338 private_key.algorithm().rsaHashedParams()->hash().id()); | 342 private_key.algorithm().rsaHashedParams()->hash().id()); |
339 EXPECT_TRUE(public_key.extractable()); | 343 EXPECT_TRUE(public_key.extractable()); |
340 EXPECT_EQ(extractable, private_key.extractable()); | 344 EXPECT_EQ(extractable, private_key.extractable()); |
341 EXPECT_EQ(usages, public_key.usages()); | 345 EXPECT_EQ(public_usages, public_key.usages()); |
342 EXPECT_EQ(usages, private_key.usages()); | 346 EXPECT_EQ(private_usages, private_key.usages()); |
343 | 347 |
344 // Try exporting the generated key pair, and then re-importing to verify that | 348 // Try exporting the generated key pair, and then re-importing to verify that |
345 // the exported data was valid. | 349 // the exported data was valid. |
346 std::vector<uint8_t> public_key_spki; | 350 std::vector<uint8_t> public_key_spki; |
347 EXPECT_EQ(Status::Success(), ExportKey(blink::WebCryptoKeyFormatSpki, | 351 EXPECT_EQ(Status::Success(), ExportKey(blink::WebCryptoKeyFormatSpki, |
348 public_key, &public_key_spki)); | 352 public_key, &public_key_spki)); |
349 | 353 |
350 if (SupportsRsaPrivateKeyImport()) { | 354 if (SupportsRsaPrivateKeyImport()) { |
351 public_key = blink::WebCryptoKey::createNull(); | 355 public_key = blink::WebCryptoKey::createNull(); |
352 EXPECT_EQ( | 356 ASSERT_EQ( |
353 Status::Success(), | 357 Status::Success(), |
354 ImportKey(blink::WebCryptoKeyFormatSpki, CryptoData(public_key_spki), | 358 ImportKey(blink::WebCryptoKeyFormatSpki, CryptoData(public_key_spki), |
355 CreateRsaHashedImportAlgorithm( | 359 CreateRsaHashedImportAlgorithm( |
356 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 360 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
357 blink::WebCryptoAlgorithmIdSha256), | 361 blink::WebCryptoAlgorithmIdSha256), |
358 true, usages, &public_key)); | 362 true, public_usages, &public_key)); |
359 EXPECT_EQ(modulus_length, | 363 EXPECT_EQ(modulus_length, |
360 public_key.algorithm().rsaHashedParams()->modulusLengthBits()); | 364 public_key.algorithm().rsaHashedParams()->modulusLengthBits()); |
361 | 365 |
362 std::vector<uint8_t> private_key_pkcs8; | 366 std::vector<uint8_t> private_key_pkcs8; |
363 EXPECT_EQ(Status::Success(), ExportKey(blink::WebCryptoKeyFormatPkcs8, | 367 EXPECT_EQ(Status::Success(), ExportKey(blink::WebCryptoKeyFormatPkcs8, |
364 private_key, &private_key_pkcs8)); | 368 private_key, &private_key_pkcs8)); |
365 private_key = blink::WebCryptoKey::createNull(); | 369 private_key = blink::WebCryptoKey::createNull(); |
366 EXPECT_EQ( | 370 ASSERT_EQ( |
367 Status::Success(), | 371 Status::Success(), |
368 ImportKey(blink::WebCryptoKeyFormatPkcs8, CryptoData(private_key_pkcs8), | 372 ImportKey(blink::WebCryptoKeyFormatPkcs8, CryptoData(private_key_pkcs8), |
369 CreateRsaHashedImportAlgorithm( | 373 CreateRsaHashedImportAlgorithm( |
370 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 374 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
371 blink::WebCryptoAlgorithmIdSha256), | 375 blink::WebCryptoAlgorithmIdSha256), |
372 true, usages, &private_key)); | 376 true, private_usages, &private_key)); |
373 EXPECT_EQ(modulus_length, | 377 EXPECT_EQ(modulus_length, |
374 private_key.algorithm().rsaHashedParams()->modulusLengthBits()); | 378 private_key.algorithm().rsaHashedParams()->modulusLengthBits()); |
375 } | 379 } |
376 | 380 |
377 // Fail with bad modulus. | 381 // Fail with bad modulus. |
378 algorithm = CreateRsaHashedKeyGenAlgorithm( | 382 algorithm = CreateRsaHashedKeyGenAlgorithm( |
379 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 383 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
380 blink::WebCryptoAlgorithmIdSha256, 0, public_exponent); | 384 blink::WebCryptoAlgorithmIdSha256, 0, public_exponent); |
381 EXPECT_EQ(Status::ErrorGenerateRsaUnsupportedModulus(), | 385 EXPECT_EQ(Status::ErrorGenerateRsaUnsupportedModulus(), |
382 GenerateKeyPair(algorithm, extractable, usages, &public_key, | 386 GenerateKeyPair(algorithm, extractable, usages, &public_key, |
(...skipping 25 matching lines...) Expand all Loading... |
408 blink::WebCryptoAlgorithmIdSha256, modulus_length, | 412 blink::WebCryptoAlgorithmIdSha256, modulus_length, |
409 exponent_with_leading_zeros); | 413 exponent_with_leading_zeros); |
410 EXPECT_EQ(Status::ErrorGenerateKeyPublicExponent(), | 414 EXPECT_EQ(Status::ErrorGenerateKeyPublicExponent(), |
411 GenerateKeyPair(algorithm, extractable, usages, &public_key, | 415 GenerateKeyPair(algorithm, extractable, usages, &public_key, |
412 &private_key)); | 416 &private_key)); |
413 | 417 |
414 // Key generation success using exponent with leading zeros. | 418 // Key generation success using exponent with leading zeros. |
415 exponent_with_leading_zeros.insert(exponent_with_leading_zeros.end(), | 419 exponent_with_leading_zeros.insert(exponent_with_leading_zeros.end(), |
416 public_exponent.begin(), | 420 public_exponent.begin(), |
417 public_exponent.end()); | 421 public_exponent.end()); |
418 algorithm = CreateRsaHashedKeyGenAlgorithm( | 422 algorithm = |
419 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 423 CreateRsaHashedKeyGenAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
420 blink::WebCryptoAlgorithmIdSha256, modulus_length, | 424 blink::WebCryptoAlgorithmIdSha256, |
421 exponent_with_leading_zeros); | 425 modulus_length, |
| 426 exponent_with_leading_zeros); |
422 EXPECT_EQ(Status::Success(), GenerateKeyPair(algorithm, extractable, usages, | 427 EXPECT_EQ(Status::Success(), GenerateKeyPair(algorithm, extractable, usages, |
423 &public_key, &private_key)); | 428 &public_key, &private_key)); |
424 EXPECT_FALSE(public_key.isNull()); | 429 EXPECT_FALSE(public_key.isNull()); |
425 EXPECT_FALSE(private_key.isNull()); | 430 EXPECT_FALSE(private_key.isNull()); |
426 EXPECT_EQ(blink::WebCryptoKeyTypePublic, public_key.type()); | 431 EXPECT_EQ(blink::WebCryptoKeyTypePublic, public_key.type()); |
427 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, private_key.type()); | 432 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, private_key.type()); |
428 EXPECT_TRUE(public_key.extractable()); | 433 EXPECT_TRUE(public_key.extractable()); |
429 EXPECT_EQ(extractable, private_key.extractable()); | 434 EXPECT_EQ(extractable, private_key.extractable()); |
430 EXPECT_EQ(usages, public_key.usages()); | 435 EXPECT_EQ(public_usages, public_key.usages()); |
431 EXPECT_EQ(usages, private_key.usages()); | 436 EXPECT_EQ(private_usages, private_key.usages()); |
432 | 437 |
433 // Successful WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 key generation (sha1) | 438 // Successful WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 key generation (sha1) |
434 algorithm = CreateRsaHashedKeyGenAlgorithm( | 439 algorithm = |
435 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 440 CreateRsaHashedKeyGenAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
436 blink::WebCryptoAlgorithmIdSha1, modulus_length, public_exponent); | 441 blink::WebCryptoAlgorithmIdSha1, |
437 EXPECT_EQ(Status::Success(), GenerateKeyPair(algorithm, false, usages, | 442 modulus_length, |
438 &public_key, &private_key)); | 443 public_exponent); |
| 444 EXPECT_EQ( |
| 445 Status::Success(), |
| 446 GenerateKeyPair(algorithm, false, usages, &public_key, &private_key)); |
439 EXPECT_FALSE(public_key.isNull()); | 447 EXPECT_FALSE(public_key.isNull()); |
440 EXPECT_FALSE(private_key.isNull()); | 448 EXPECT_FALSE(private_key.isNull()); |
441 EXPECT_EQ(blink::WebCryptoKeyTypePublic, public_key.type()); | 449 EXPECT_EQ(blink::WebCryptoKeyTypePublic, public_key.type()); |
442 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, private_key.type()); | 450 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, private_key.type()); |
443 EXPECT_EQ(modulus_length, | 451 EXPECT_EQ(modulus_length, |
444 public_key.algorithm().rsaHashedParams()->modulusLengthBits()); | 452 public_key.algorithm().rsaHashedParams()->modulusLengthBits()); |
445 EXPECT_EQ(modulus_length, | 453 EXPECT_EQ(modulus_length, |
446 private_key.algorithm().rsaHashedParams()->modulusLengthBits()); | 454 private_key.algorithm().rsaHashedParams()->modulusLengthBits()); |
447 EXPECT_EQ(blink::WebCryptoAlgorithmIdSha1, | 455 EXPECT_EQ(blink::WebCryptoAlgorithmIdSha1, |
448 public_key.algorithm().rsaHashedParams()->hash().id()); | 456 public_key.algorithm().rsaHashedParams()->hash().id()); |
449 EXPECT_EQ(blink::WebCryptoAlgorithmIdSha1, | 457 EXPECT_EQ(blink::WebCryptoAlgorithmIdSha1, |
450 private_key.algorithm().rsaHashedParams()->hash().id()); | 458 private_key.algorithm().rsaHashedParams()->hash().id()); |
451 // Even though "extractable" was set to false, the public key remains | 459 // Even though "extractable" was set to false, the public key remains |
452 // extractable. | 460 // extractable. |
453 EXPECT_TRUE(public_key.extractable()); | 461 EXPECT_TRUE(public_key.extractable()); |
454 EXPECT_FALSE(private_key.extractable()); | 462 EXPECT_FALSE(private_key.extractable()); |
455 EXPECT_EQ(usages, public_key.usages()); | 463 EXPECT_EQ(public_usages, public_key.usages()); |
456 EXPECT_EQ(usages, private_key.usages()); | 464 EXPECT_EQ(private_usages, private_key.usages()); |
457 | 465 |
458 // Exporting a private key as SPKI format doesn't make sense. However this | 466 // Exporting a private key as SPKI format doesn't make sense. However this |
459 // will first fail because the key is not extractable. | 467 // will first fail because the key is not extractable. |
460 std::vector<uint8_t> output; | 468 std::vector<uint8_t> output; |
461 EXPECT_EQ(Status::ErrorKeyNotExtractable(), | 469 EXPECT_EQ(Status::ErrorKeyNotExtractable(), |
462 ExportKey(blink::WebCryptoKeyFormatSpki, private_key, &output)); | 470 ExportKey(blink::WebCryptoKeyFormatSpki, private_key, &output)); |
463 | 471 |
464 // Re-generate an extractable private_key and try to export it as SPKI format. | 472 // Re-generate an extractable private_key and try to export it as SPKI format. |
465 // This should fail since spki is for public keys. | 473 // This should fail since spki is for public keys. |
466 EXPECT_EQ(Status::Success(), GenerateKeyPair(algorithm, true, usages, | 474 EXPECT_EQ(Status::Success(), GenerateKeyPair(algorithm, true, usages, |
(...skipping 14 matching lines...) Expand all Loading... |
481 | 489 |
482 const std::vector<uint8_t> public_exponent = HexStringToBytes("010001"); | 490 const std::vector<uint8_t> public_exponent = HexStringToBytes("010001"); |
483 | 491 |
484 for (size_t i = 0; i < arraysize(kBadModulusBits); ++i) { | 492 for (size_t i = 0; i < arraysize(kBadModulusBits); ++i) { |
485 const unsigned int modulus_length_bits = kBadModulusBits[i]; | 493 const unsigned int modulus_length_bits = kBadModulusBits[i]; |
486 blink::WebCryptoAlgorithm algorithm = CreateRsaHashedKeyGenAlgorithm( | 494 blink::WebCryptoAlgorithm algorithm = CreateRsaHashedKeyGenAlgorithm( |
487 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 495 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
488 blink::WebCryptoAlgorithmIdSha256, modulus_length_bits, | 496 blink::WebCryptoAlgorithmIdSha256, modulus_length_bits, |
489 public_exponent); | 497 public_exponent); |
490 bool extractable = true; | 498 bool extractable = true; |
491 const blink::WebCryptoKeyUsageMask usages = 0; | 499 const blink::WebCryptoKeyUsageMask usages = blink::WebCryptoKeyUsageSign; |
492 blink::WebCryptoKey public_key; | 500 blink::WebCryptoKey public_key; |
493 blink::WebCryptoKey private_key; | 501 blink::WebCryptoKey private_key; |
494 | 502 |
495 EXPECT_EQ(Status::ErrorGenerateRsaUnsupportedModulus(), | 503 EXPECT_EQ(Status::ErrorGenerateRsaUnsupportedModulus(), |
496 GenerateKeyPair(algorithm, extractable, usages, &public_key, | 504 GenerateKeyPair(algorithm, extractable, usages, &public_key, |
497 &private_key)); | 505 &private_key)); |
498 } | 506 } |
499 } | 507 } |
500 | 508 |
501 // Try generating RSA key pairs using unsupported public exponents. Only | 509 // Try generating RSA key pairs using unsupported public exponents. Only |
(...skipping 15 matching lines...) Expand all Loading... |
517 SCOPED_TRACE(i); | 525 SCOPED_TRACE(i); |
518 blink::WebCryptoAlgorithm algorithm = CreateRsaHashedKeyGenAlgorithm( | 526 blink::WebCryptoAlgorithm algorithm = CreateRsaHashedKeyGenAlgorithm( |
519 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 527 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
520 blink::WebCryptoAlgorithmIdSha256, modulus_length, | 528 blink::WebCryptoAlgorithmIdSha256, modulus_length, |
521 HexStringToBytes(kPublicExponents[i])); | 529 HexStringToBytes(kPublicExponents[i])); |
522 | 530 |
523 blink::WebCryptoKey public_key; | 531 blink::WebCryptoKey public_key; |
524 blink::WebCryptoKey private_key; | 532 blink::WebCryptoKey private_key; |
525 | 533 |
526 EXPECT_EQ(Status::ErrorGenerateKeyPublicExponent(), | 534 EXPECT_EQ(Status::ErrorGenerateKeyPublicExponent(), |
527 GenerateKeyPair(algorithm, true, 0, &public_key, &private_key)); | 535 GenerateKeyPair(algorithm, true, blink::WebCryptoKeyUsageSign, |
| 536 &public_key, &private_key)); |
528 } | 537 } |
529 } | 538 } |
530 | 539 |
531 TEST(WebCryptoRsaSsaTest, SignVerifyFailures) { | 540 TEST(WebCryptoRsaSsaTest, SignVerifyFailures) { |
532 if (!SupportsRsaPrivateKeyImport()) | 541 if (!SupportsRsaPrivateKeyImport()) |
533 return; | 542 return; |
534 | 543 |
535 // Import a key pair. | 544 // Import a key pair. |
536 blink::WebCryptoAlgorithm import_algorithm = | 545 blink::WebCryptoAlgorithm import_algorithm = |
537 CreateRsaHashedImportAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 546 CreateRsaHashedImportAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 801 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
793 blink::WebCryptoAlgorithmIdSha256, | 802 blink::WebCryptoAlgorithmIdSha256, |
794 modulus_length, public_exponent), | 803 modulus_length, public_exponent), |
795 true, blink::WebCryptoKeyUsageSign, &public_key, | 804 true, blink::WebCryptoKeyUsageSign, &public_key, |
796 &private_key)); | 805 &private_key)); |
797 | 806 |
798 EXPECT_EQ(0, public_key.usages()); | 807 EXPECT_EQ(0, public_key.usages()); |
799 EXPECT_EQ(blink::WebCryptoKeyUsageSign, private_key.usages()); | 808 EXPECT_EQ(blink::WebCryptoKeyUsageSign, private_key.usages()); |
800 } | 809 } |
801 | 810 |
| 811 TEST(WebCryptoRsaSsaTest, GenerateKeyPairEmptyUsages) { |
| 812 const unsigned int modulus_length = 256; |
| 813 const std::vector<uint8_t> public_exponent = HexStringToBytes("010001"); |
| 814 |
| 815 blink::WebCryptoKey public_key; |
| 816 blink::WebCryptoKey private_key; |
| 817 |
| 818 ASSERT_EQ(Status::ErrorCreateKeyEmptyUsages(), |
| 819 GenerateKeyPair(CreateRsaHashedKeyGenAlgorithm( |
| 820 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
| 821 blink::WebCryptoAlgorithmIdSha256, |
| 822 modulus_length, public_exponent), |
| 823 true, 0, &public_key, &private_key)); |
| 824 } |
| 825 |
802 TEST(WebCryptoRsaSsaTest, ImportExportJwkRsaPublicKey) { | 826 TEST(WebCryptoRsaSsaTest, ImportExportJwkRsaPublicKey) { |
803 struct TestCase { | 827 struct TestCase { |
804 const blink::WebCryptoAlgorithmId hash; | 828 const blink::WebCryptoAlgorithmId hash; |
805 const blink::WebCryptoKeyUsageMask usage; | 829 const blink::WebCryptoKeyUsageMask usage; |
806 const char* const jwk_alg; | 830 const char* const jwk_alg; |
807 }; | 831 }; |
808 const TestCase kTests[] = { | 832 const TestCase kTests[] = { |
809 {blink::WebCryptoAlgorithmIdSha1, blink::WebCryptoKeyUsageVerify, "RS1"}, | 833 {blink::WebCryptoAlgorithmIdSha1, blink::WebCryptoKeyUsageVerify, "RS1"}, |
810 {blink::WebCryptoAlgorithmIdSha256, | 834 {blink::WebCryptoAlgorithmIdSha256, |
811 blink::WebCryptoKeyUsageVerify, | 835 blink::WebCryptoKeyUsageVerify, |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
942 | 966 |
943 const base::DictionaryValue* test; | 967 const base::DictionaryValue* test; |
944 ASSERT_TRUE(tests->GetDictionary(test_index, &test)); | 968 ASSERT_TRUE(tests->GetDictionary(test_index, &test)); |
945 | 969 |
946 blink::WebCryptoKeyFormat key_format = GetKeyFormatFromJsonTestCase(test); | 970 blink::WebCryptoKeyFormat key_format = GetKeyFormatFromJsonTestCase(test); |
947 std::vector<uint8_t> key_data = | 971 std::vector<uint8_t> key_data = |
948 GetKeyDataFromJsonTestCase(test, key_format); | 972 GetKeyDataFromJsonTestCase(test, key_format); |
949 std::string test_error; | 973 std::string test_error; |
950 ASSERT_TRUE(test->GetString("error", &test_error)); | 974 ASSERT_TRUE(test->GetString("error", &test_error)); |
951 | 975 |
| 976 blink::WebCryptoKeyUsageMask usages = blink::WebCryptoKeyUsageSign; |
| 977 if (key_format == blink::WebCryptoKeyFormatSpki) |
| 978 usages = blink::WebCryptoKeyUsageVerify; |
952 blink::WebCryptoKey key; | 979 blink::WebCryptoKey key; |
953 Status status = ImportKey(key_format, CryptoData(key_data), | 980 Status status = ImportKey(key_format, CryptoData(key_data), |
954 CreateRsaHashedImportAlgorithm( | 981 CreateRsaHashedImportAlgorithm( |
955 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 982 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
956 blink::WebCryptoAlgorithmIdSha256), | 983 blink::WebCryptoAlgorithmIdSha256), |
957 true, 0, &key); | 984 true, usages, &key); |
958 EXPECT_EQ(test_error, StatusToString(status)); | 985 EXPECT_EQ(test_error, StatusToString(status)); |
959 } | 986 } |
960 } | 987 } |
961 | 988 |
962 } // namespace | 989 } // namespace |
963 | 990 |
964 } // namespace webcrypto | 991 } // namespace webcrypto |
965 | 992 |
966 } // namespace content | 993 } // namespace content |
OLD | NEW |