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