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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 | 337 |
338 // Successful WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 key generation (sha256) | 338 // Successful WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 key generation (sha256) |
339 const unsigned int modulus_length = 256; | 339 const unsigned int modulus_length = 256; |
340 const std::vector<uint8_t> public_exponent = HexStringToBytes("010001"); | 340 const std::vector<uint8_t> public_exponent = HexStringToBytes("010001"); |
341 blink::WebCryptoAlgorithm algorithm = | 341 blink::WebCryptoAlgorithm algorithm = |
342 CreateRsaHashedKeyGenAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 342 CreateRsaHashedKeyGenAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
343 blink::WebCryptoAlgorithmIdSha256, | 343 blink::WebCryptoAlgorithmIdSha256, |
344 modulus_length, | 344 modulus_length, |
345 public_exponent); | 345 public_exponent); |
346 bool extractable = true; | 346 bool extractable = true; |
347 const blink::WebCryptoKeyUsageMask usages = 0; | 347 const blink::WebCryptoKeyUsageMask public_usages = |
| 348 blink::WebCryptoKeyUsageVerify; |
| 349 const blink::WebCryptoKeyUsageMask private_usages = |
| 350 blink::WebCryptoKeyUsageSign; |
| 351 const blink::WebCryptoKeyUsageMask usages = public_usages | private_usages; |
348 blink::WebCryptoKey public_key; | 352 blink::WebCryptoKey public_key; |
349 blink::WebCryptoKey private_key; | 353 blink::WebCryptoKey private_key; |
350 | 354 |
351 EXPECT_EQ(Status::Success(), | 355 EXPECT_EQ(Status::Success(), GenerateKeyPair(algorithm, extractable, usages, |
352 GenerateKeyPair( | 356 &public_key, &private_key)); |
353 algorithm, extractable, usages, &public_key, &private_key)); | 357 ASSERT_FALSE(public_key.isNull()); |
354 EXPECT_FALSE(public_key.isNull()); | 358 ASSERT_FALSE(private_key.isNull()); |
355 EXPECT_FALSE(private_key.isNull()); | |
356 EXPECT_EQ(blink::WebCryptoKeyTypePublic, public_key.type()); | 359 EXPECT_EQ(blink::WebCryptoKeyTypePublic, public_key.type()); |
357 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, private_key.type()); | 360 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, private_key.type()); |
358 EXPECT_EQ(modulus_length, | 361 EXPECT_EQ(modulus_length, |
359 public_key.algorithm().rsaHashedParams()->modulusLengthBits()); | 362 public_key.algorithm().rsaHashedParams()->modulusLengthBits()); |
360 EXPECT_EQ(modulus_length, | 363 EXPECT_EQ(modulus_length, |
361 private_key.algorithm().rsaHashedParams()->modulusLengthBits()); | 364 private_key.algorithm().rsaHashedParams()->modulusLengthBits()); |
362 EXPECT_EQ(blink::WebCryptoAlgorithmIdSha256, | 365 EXPECT_EQ(blink::WebCryptoAlgorithmIdSha256, |
363 public_key.algorithm().rsaHashedParams()->hash().id()); | 366 public_key.algorithm().rsaHashedParams()->hash().id()); |
364 EXPECT_EQ(blink::WebCryptoAlgorithmIdSha256, | 367 EXPECT_EQ(blink::WebCryptoAlgorithmIdSha256, |
365 private_key.algorithm().rsaHashedParams()->hash().id()); | 368 private_key.algorithm().rsaHashedParams()->hash().id()); |
366 EXPECT_TRUE(public_key.extractable()); | 369 EXPECT_TRUE(public_key.extractable()); |
367 EXPECT_EQ(extractable, private_key.extractable()); | 370 EXPECT_EQ(extractable, private_key.extractable()); |
368 EXPECT_EQ(usages, public_key.usages()); | 371 EXPECT_EQ(public_usages, public_key.usages()); |
369 EXPECT_EQ(usages, private_key.usages()); | 372 EXPECT_EQ(private_usages, private_key.usages()); |
370 | 373 |
371 // Try exporting the generated key pair, and then re-importing to verify that | 374 // Try exporting the generated key pair, and then re-importing to verify that |
372 // the exported data was valid. | 375 // the exported data was valid. |
373 std::vector<uint8_t> public_key_spki; | 376 std::vector<uint8_t> public_key_spki; |
374 EXPECT_EQ( | 377 EXPECT_EQ( |
375 Status::Success(), | 378 Status::Success(), |
376 ExportKey(blink::WebCryptoKeyFormatSpki, public_key, &public_key_spki)); | 379 ExportKey(blink::WebCryptoKeyFormatSpki, public_key, &public_key_spki)); |
377 | 380 |
378 if (SupportsRsaPrivateKeyImport()) { | 381 if (SupportsRsaPrivateKeyImport()) { |
379 public_key = blink::WebCryptoKey::createNull(); | 382 public_key = blink::WebCryptoKey::createNull(); |
380 EXPECT_EQ(Status::Success(), | 383 ASSERT_EQ( |
381 ImportKey(blink::WebCryptoKeyFormatSpki, | 384 Status::Success(), |
382 CryptoData(public_key_spki), | 385 ImportKey(blink::WebCryptoKeyFormatSpki, CryptoData(public_key_spki), |
383 CreateRsaHashedImportAlgorithm( | 386 CreateRsaHashedImportAlgorithm( |
384 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 387 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
385 blink::WebCryptoAlgorithmIdSha256), | 388 blink::WebCryptoAlgorithmIdSha256), |
386 true, | 389 true, public_usages, &public_key)); |
387 usages, | |
388 &public_key)); | |
389 EXPECT_EQ(modulus_length, | 390 EXPECT_EQ(modulus_length, |
390 public_key.algorithm().rsaHashedParams()->modulusLengthBits()); | 391 public_key.algorithm().rsaHashedParams()->modulusLengthBits()); |
391 | 392 |
392 std::vector<uint8_t> private_key_pkcs8; | 393 std::vector<uint8_t> private_key_pkcs8; |
393 EXPECT_EQ( | 394 EXPECT_EQ( |
394 Status::Success(), | 395 Status::Success(), |
395 ExportKey( | 396 ExportKey( |
396 blink::WebCryptoKeyFormatPkcs8, private_key, &private_key_pkcs8)); | 397 blink::WebCryptoKeyFormatPkcs8, private_key, &private_key_pkcs8)); |
397 private_key = blink::WebCryptoKey::createNull(); | 398 private_key = blink::WebCryptoKey::createNull(); |
398 EXPECT_EQ(Status::Success(), | 399 ASSERT_EQ( |
399 ImportKey(blink::WebCryptoKeyFormatPkcs8, | 400 Status::Success(), |
400 CryptoData(private_key_pkcs8), | 401 ImportKey(blink::WebCryptoKeyFormatPkcs8, CryptoData(private_key_pkcs8), |
401 CreateRsaHashedImportAlgorithm( | 402 CreateRsaHashedImportAlgorithm( |
402 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 403 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
403 blink::WebCryptoAlgorithmIdSha256), | 404 blink::WebCryptoAlgorithmIdSha256), |
404 true, | 405 true, private_usages, &private_key)); |
405 usages, | |
406 &private_key)); | |
407 EXPECT_EQ(modulus_length, | 406 EXPECT_EQ(modulus_length, |
408 private_key.algorithm().rsaHashedParams()->modulusLengthBits()); | 407 private_key.algorithm().rsaHashedParams()->modulusLengthBits()); |
409 } | 408 } |
410 | 409 |
411 // Fail with bad modulus. | 410 // Fail with bad modulus. |
412 algorithm = | 411 algorithm = |
413 CreateRsaHashedKeyGenAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 412 CreateRsaHashedKeyGenAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
414 blink::WebCryptoAlgorithmIdSha256, | 413 blink::WebCryptoAlgorithmIdSha256, |
415 0, | 414 0, |
416 public_exponent); | 415 public_exponent); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 | 453 |
455 // Key generation success using exponent with leading zeros. | 454 // Key generation success using exponent with leading zeros. |
456 exponent_with_leading_zeros.insert(exponent_with_leading_zeros.end(), | 455 exponent_with_leading_zeros.insert(exponent_with_leading_zeros.end(), |
457 public_exponent.begin(), | 456 public_exponent.begin(), |
458 public_exponent.end()); | 457 public_exponent.end()); |
459 algorithm = | 458 algorithm = |
460 CreateRsaHashedKeyGenAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 459 CreateRsaHashedKeyGenAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
461 blink::WebCryptoAlgorithmIdSha256, | 460 blink::WebCryptoAlgorithmIdSha256, |
462 modulus_length, | 461 modulus_length, |
463 exponent_with_leading_zeros); | 462 exponent_with_leading_zeros); |
464 EXPECT_EQ(Status::Success(), | 463 EXPECT_EQ(Status::Success(), GenerateKeyPair(algorithm, extractable, usages, |
465 GenerateKeyPair( | 464 &public_key, &private_key)); |
466 algorithm, extractable, usages, &public_key, &private_key)); | |
467 EXPECT_FALSE(public_key.isNull()); | 465 EXPECT_FALSE(public_key.isNull()); |
468 EXPECT_FALSE(private_key.isNull()); | 466 EXPECT_FALSE(private_key.isNull()); |
469 EXPECT_EQ(blink::WebCryptoKeyTypePublic, public_key.type()); | 467 EXPECT_EQ(blink::WebCryptoKeyTypePublic, public_key.type()); |
470 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, private_key.type()); | 468 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, private_key.type()); |
471 EXPECT_TRUE(public_key.extractable()); | 469 EXPECT_TRUE(public_key.extractable()); |
472 EXPECT_EQ(extractable, private_key.extractable()); | 470 EXPECT_EQ(extractable, private_key.extractable()); |
473 EXPECT_EQ(usages, public_key.usages()); | 471 EXPECT_EQ(public_usages, public_key.usages()); |
474 EXPECT_EQ(usages, private_key.usages()); | 472 EXPECT_EQ(private_usages, private_key.usages()); |
475 | 473 |
476 // Successful WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 key generation (sha1) | 474 // Successful WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 key generation (sha1) |
477 algorithm = | 475 algorithm = |
478 CreateRsaHashedKeyGenAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 476 CreateRsaHashedKeyGenAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
479 blink::WebCryptoAlgorithmIdSha1, | 477 blink::WebCryptoAlgorithmIdSha1, |
480 modulus_length, | 478 modulus_length, |
481 public_exponent); | 479 public_exponent); |
482 EXPECT_EQ( | 480 EXPECT_EQ( |
483 Status::Success(), | 481 Status::Success(), |
484 GenerateKeyPair(algorithm, false, usages, &public_key, &private_key)); | 482 GenerateKeyPair(algorithm, false, usages, &public_key, &private_key)); |
485 EXPECT_FALSE(public_key.isNull()); | 483 EXPECT_FALSE(public_key.isNull()); |
486 EXPECT_FALSE(private_key.isNull()); | 484 EXPECT_FALSE(private_key.isNull()); |
487 EXPECT_EQ(blink::WebCryptoKeyTypePublic, public_key.type()); | 485 EXPECT_EQ(blink::WebCryptoKeyTypePublic, public_key.type()); |
488 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, private_key.type()); | 486 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, private_key.type()); |
489 EXPECT_EQ(modulus_length, | 487 EXPECT_EQ(modulus_length, |
490 public_key.algorithm().rsaHashedParams()->modulusLengthBits()); | 488 public_key.algorithm().rsaHashedParams()->modulusLengthBits()); |
491 EXPECT_EQ(modulus_length, | 489 EXPECT_EQ(modulus_length, |
492 private_key.algorithm().rsaHashedParams()->modulusLengthBits()); | 490 private_key.algorithm().rsaHashedParams()->modulusLengthBits()); |
493 EXPECT_EQ(blink::WebCryptoAlgorithmIdSha1, | 491 EXPECT_EQ(blink::WebCryptoAlgorithmIdSha1, |
494 public_key.algorithm().rsaHashedParams()->hash().id()); | 492 public_key.algorithm().rsaHashedParams()->hash().id()); |
495 EXPECT_EQ(blink::WebCryptoAlgorithmIdSha1, | 493 EXPECT_EQ(blink::WebCryptoAlgorithmIdSha1, |
496 private_key.algorithm().rsaHashedParams()->hash().id()); | 494 private_key.algorithm().rsaHashedParams()->hash().id()); |
497 // Even though "extractable" was set to false, the public key remains | 495 // Even though "extractable" was set to false, the public key remains |
498 // extractable. | 496 // extractable. |
499 EXPECT_TRUE(public_key.extractable()); | 497 EXPECT_TRUE(public_key.extractable()); |
500 EXPECT_FALSE(private_key.extractable()); | 498 EXPECT_FALSE(private_key.extractable()); |
501 EXPECT_EQ(usages, public_key.usages()); | 499 EXPECT_EQ(public_usages, public_key.usages()); |
502 EXPECT_EQ(usages, private_key.usages()); | 500 EXPECT_EQ(private_usages, private_key.usages()); |
503 | 501 |
504 // Exporting a private key as SPKI format doesn't make sense. However this | 502 // Exporting a private key as SPKI format doesn't make sense. However this |
505 // will first fail because the key is not extractable. | 503 // will first fail because the key is not extractable. |
506 std::vector<uint8_t> output; | 504 std::vector<uint8_t> output; |
507 EXPECT_EQ(Status::ErrorKeyNotExtractable(), | 505 EXPECT_EQ(Status::ErrorKeyNotExtractable(), |
508 ExportKey(blink::WebCryptoKeyFormatSpki, private_key, &output)); | 506 ExportKey(blink::WebCryptoKeyFormatSpki, private_key, &output)); |
509 | 507 |
510 // Re-generate an extractable private_key and try to export it as SPKI format. | 508 // Re-generate an extractable private_key and try to export it as SPKI format. |
511 // This should fail since spki is for public keys. | 509 // This should fail since spki is for public keys. |
512 EXPECT_EQ( | 510 EXPECT_EQ(Status::Success(), GenerateKeyPair(algorithm, true, usages, |
513 Status::Success(), | 511 &public_key, &private_key)); |
514 GenerateKeyPair(algorithm, true, usages, &public_key, &private_key)); | |
515 EXPECT_EQ(Status::ErrorUnexpectedKeyType(), | 512 EXPECT_EQ(Status::ErrorUnexpectedKeyType(), |
516 ExportKey(blink::WebCryptoKeyFormatSpki, private_key, &output)); | 513 ExportKey(blink::WebCryptoKeyFormatSpki, private_key, &output)); |
517 } | 514 } |
518 | 515 |
519 TEST(WebCryptoRsaSsaTest, GenerateKeyPairRsaBadModulusLength) { | 516 TEST(WebCryptoRsaSsaTest, GenerateKeyPairRsaBadModulusLength) { |
520 const unsigned int kBadModulusBits[] = { | 517 const unsigned int kBadModulusBits[] = { |
521 0, | 518 0, |
522 248, // Too small. | 519 248, // Too small. |
523 257, // Not a multiple of 8. | 520 257, // Not a multiple of 8. |
524 1023, // Not a multiple of 8. | 521 1023, // Not a multiple of 8. |
525 0xFFFFFFFF, // Too big. | 522 0xFFFFFFFF, // Too big. |
526 16384 + 8, // 16384 is the maxmimum length that NSS succeeds for. | 523 16384 + 8, // 16384 is the maxmimum length that NSS succeeds for. |
527 }; | 524 }; |
528 | 525 |
529 const std::vector<uint8_t> public_exponent = HexStringToBytes("010001"); | 526 const std::vector<uint8_t> public_exponent = HexStringToBytes("010001"); |
530 | 527 |
531 for (size_t i = 0; i < arraysize(kBadModulusBits); ++i) { | 528 for (size_t i = 0; i < arraysize(kBadModulusBits); ++i) { |
532 const unsigned int modulus_length_bits = kBadModulusBits[i]; | 529 const unsigned int modulus_length_bits = kBadModulusBits[i]; |
533 blink::WebCryptoAlgorithm algorithm = CreateRsaHashedKeyGenAlgorithm( | 530 blink::WebCryptoAlgorithm algorithm = CreateRsaHashedKeyGenAlgorithm( |
534 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 531 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
535 blink::WebCryptoAlgorithmIdSha256, | 532 blink::WebCryptoAlgorithmIdSha256, |
536 modulus_length_bits, | 533 modulus_length_bits, |
537 public_exponent); | 534 public_exponent); |
538 bool extractable = true; | 535 bool extractable = true; |
539 const blink::WebCryptoKeyUsageMask usages = 0; | 536 const blink::WebCryptoKeyUsageMask usages = blink::WebCryptoKeyUsageSign; |
540 blink::WebCryptoKey public_key; | 537 blink::WebCryptoKey public_key; |
541 blink::WebCryptoKey private_key; | 538 blink::WebCryptoKey private_key; |
542 | 539 |
543 EXPECT_EQ(Status::ErrorGenerateRsaUnsupportedModulus(), | 540 EXPECT_EQ(Status::ErrorGenerateRsaUnsupportedModulus(), |
544 GenerateKeyPair( | 541 GenerateKeyPair( |
545 algorithm, extractable, usages, &public_key, &private_key)); | 542 algorithm, extractable, usages, &public_key, &private_key)); |
546 } | 543 } |
547 } | 544 } |
548 | 545 |
549 // Try generating RSA key pairs using unsupported public exponents. Only | 546 // Try generating RSA key pairs using unsupported public exponents. Only |
(...skipping 14 matching lines...) Expand all Loading... |
564 blink::WebCryptoAlgorithm algorithm = CreateRsaHashedKeyGenAlgorithm( | 561 blink::WebCryptoAlgorithm algorithm = CreateRsaHashedKeyGenAlgorithm( |
565 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 562 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
566 blink::WebCryptoAlgorithmIdSha256, | 563 blink::WebCryptoAlgorithmIdSha256, |
567 modulus_length, | 564 modulus_length, |
568 HexStringToBytes(kPublicExponents[i])); | 565 HexStringToBytes(kPublicExponents[i])); |
569 | 566 |
570 blink::WebCryptoKey public_key; | 567 blink::WebCryptoKey public_key; |
571 blink::WebCryptoKey private_key; | 568 blink::WebCryptoKey private_key; |
572 | 569 |
573 EXPECT_EQ(Status::ErrorGenerateKeyPublicExponent(), | 570 EXPECT_EQ(Status::ErrorGenerateKeyPublicExponent(), |
574 GenerateKeyPair(algorithm, true, 0, &public_key, &private_key)); | 571 GenerateKeyPair(algorithm, true, blink::WebCryptoKeyUsageSign, |
| 572 &public_key, &private_key)); |
575 } | 573 } |
576 } | 574 } |
577 | 575 |
578 TEST(WebCryptoRsaSsaTest, SignVerifyFailures) { | 576 TEST(WebCryptoRsaSsaTest, SignVerifyFailures) { |
579 if (!SupportsRsaPrivateKeyImport()) | 577 if (!SupportsRsaPrivateKeyImport()) |
580 return; | 578 return; |
581 | 579 |
582 // Import a key pair. | 580 // Import a key pair. |
583 blink::WebCryptoAlgorithm import_algorithm = | 581 blink::WebCryptoAlgorithm import_algorithm = |
584 CreateRsaHashedImportAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 582 CreateRsaHashedImportAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 public_exponent), | 883 public_exponent), |
886 true, | 884 true, |
887 blink::WebCryptoKeyUsageSign, | 885 blink::WebCryptoKeyUsageSign, |
888 &public_key, | 886 &public_key, |
889 &private_key)); | 887 &private_key)); |
890 | 888 |
891 EXPECT_EQ(0, public_key.usages()); | 889 EXPECT_EQ(0, public_key.usages()); |
892 EXPECT_EQ(blink::WebCryptoKeyUsageSign, private_key.usages()); | 890 EXPECT_EQ(blink::WebCryptoKeyUsageSign, private_key.usages()); |
893 } | 891 } |
894 | 892 |
| 893 TEST(WebCryptoRsaSsaTest, GenerateKeyPairEmptyUsages) { |
| 894 const unsigned int modulus_length = 256; |
| 895 const std::vector<uint8_t> public_exponent = HexStringToBytes("010001"); |
| 896 |
| 897 blink::WebCryptoKey public_key; |
| 898 blink::WebCryptoKey private_key; |
| 899 |
| 900 ASSERT_EQ(Status::ErrorCreateKeyEmptyUsages(), |
| 901 GenerateKeyPair(CreateRsaHashedKeyGenAlgorithm( |
| 902 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
| 903 blink::WebCryptoAlgorithmIdSha256, |
| 904 modulus_length, public_exponent), |
| 905 true, 0, &public_key, &private_key)); |
| 906 } |
| 907 |
895 TEST(WebCryptoRsaSsaTest, ImportExportJwkRsaPublicKey) { | 908 TEST(WebCryptoRsaSsaTest, ImportExportJwkRsaPublicKey) { |
896 struct TestCase { | 909 struct TestCase { |
897 const blink::WebCryptoAlgorithmId hash; | 910 const blink::WebCryptoAlgorithmId hash; |
898 const blink::WebCryptoKeyUsageMask usage; | 911 const blink::WebCryptoKeyUsageMask usage; |
899 const char* const jwk_alg; | 912 const char* const jwk_alg; |
900 }; | 913 }; |
901 const TestCase kTests[] = { | 914 const TestCase kTests[] = { |
902 {blink::WebCryptoAlgorithmIdSha1, blink::WebCryptoKeyUsageVerify, "RS1"}, | 915 {blink::WebCryptoAlgorithmIdSha1, blink::WebCryptoKeyUsageVerify, "RS1"}, |
903 {blink::WebCryptoAlgorithmIdSha256, blink::WebCryptoKeyUsageVerify, | 916 {blink::WebCryptoAlgorithmIdSha256, blink::WebCryptoKeyUsageVerify, |
904 "RS256"}, | 917 "RS256"}, |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1044 | 1057 |
1045 const base::DictionaryValue* test; | 1058 const base::DictionaryValue* test; |
1046 ASSERT_TRUE(tests->GetDictionary(test_index, &test)); | 1059 ASSERT_TRUE(tests->GetDictionary(test_index, &test)); |
1047 | 1060 |
1048 blink::WebCryptoKeyFormat key_format = GetKeyFormatFromJsonTestCase(test); | 1061 blink::WebCryptoKeyFormat key_format = GetKeyFormatFromJsonTestCase(test); |
1049 std::vector<uint8_t> key_data = | 1062 std::vector<uint8_t> key_data = |
1050 GetKeyDataFromJsonTestCase(test, key_format); | 1063 GetKeyDataFromJsonTestCase(test, key_format); |
1051 std::string test_error; | 1064 std::string test_error; |
1052 ASSERT_TRUE(test->GetString("error", &test_error)); | 1065 ASSERT_TRUE(test->GetString("error", &test_error)); |
1053 | 1066 |
| 1067 blink::WebCryptoKeyUsageMask usages = blink::WebCryptoKeyUsageSign; |
| 1068 if (key_format == blink::WebCryptoKeyFormatSpki) |
| 1069 usages = blink::WebCryptoKeyUsageVerify; |
1054 blink::WebCryptoKey key; | 1070 blink::WebCryptoKey key; |
1055 Status status = ImportKey(key_format, CryptoData(key_data), | 1071 Status status = ImportKey(key_format, CryptoData(key_data), |
1056 CreateRsaHashedImportAlgorithm( | 1072 CreateRsaHashedImportAlgorithm( |
1057 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 1073 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
1058 blink::WebCryptoAlgorithmIdSha256), | 1074 blink::WebCryptoAlgorithmIdSha256), |
1059 true, 0, &key); | 1075 true, usages, &key); |
1060 EXPECT_EQ(test_error, StatusToString(status)); | 1076 EXPECT_EQ(test_error, StatusToString(status)); |
1061 } | 1077 } |
1062 } | 1078 } |
1063 | 1079 |
1064 } // namespace | 1080 } // namespace |
1065 | 1081 |
1066 } // namespace webcrypto | 1082 } // namespace webcrypto |
1067 | 1083 |
1068 } // namespace content | 1084 } // namespace content |
OLD | NEW |