| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/renderer/webcrypto/webcrypto_impl.h" | 5 #include "content/renderer/webcrypto/webcrypto_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 std::vector<uint8> MakeJsonVector(const std::string& json_string) { | 42 std::vector<uint8> MakeJsonVector(const std::string& json_string) { |
| 43 return std::vector<uint8>(json_string.begin(), json_string.end()); | 43 return std::vector<uint8>(json_string.begin(), json_string.end()); |
| 44 } | 44 } |
| 45 | 45 |
| 46 std::vector<uint8> MakeJsonVector(const base::DictionaryValue& dict) { | 46 std::vector<uint8> MakeJsonVector(const base::DictionaryValue& dict) { |
| 47 std::string json; | 47 std::string json; |
| 48 base::JSONWriter::Write(&dict, &json); | 48 base::JSONWriter::Write(&dict, &json); |
| 49 return MakeJsonVector(json); | 49 return MakeJsonVector(json); |
| 50 } | 50 } |
| 51 | 51 |
| 52 // Helper for ImportJwkBadJwk; restores JWK JSON dictionary to a good state | 52 // Helper for ImportJwkFailures and ImportJwkOctFailures. Restores the JWK JSON |
| 53 void RestoreDictionaryForImportBadJwkTest(base::DictionaryValue* dict) { | 53 // dictionary to a good state |
| 54 void RestoreJwkOctDictionary(base::DictionaryValue* dict) { |
| 54 dict->Clear(); | 55 dict->Clear(); |
| 55 dict->SetString("kty", "oct"); | 56 dict->SetString("kty", "oct"); |
| 56 dict->SetString("alg", "A128CBC"); | 57 dict->SetString("alg", "A128CBC"); |
| 57 dict->SetString("use", "enc"); | 58 dict->SetString("use", "enc"); |
| 58 dict->SetBoolean("extractable", false); | 59 dict->SetBoolean("extractable", false); |
| 59 dict->SetString("k", "GADWrMRHwQfoNaXU5fZvTg=="); | 60 dict->SetString("k", "GADWrMRHwQfoNaXU5fZvTg=="); |
| 60 } | 61 } |
| 62 |
| 61 #if !defined(USE_OPENSSL) | 63 #if !defined(USE_OPENSSL) |
| 62 | 64 |
| 65 // Helper for ImportJwkRsaFailures. Restores the JWK JSON |
| 66 // dictionary to a good state |
| 67 void RestoreJwkRsaDictionary(base::DictionaryValue* dict) { |
| 68 dict->Clear(); |
| 69 dict->SetString("kty", "RSA"); |
| 70 dict->SetString("alg", "RSA1_5"); |
| 71 dict->SetString("use", "enc"); |
| 72 dict->SetBoolean("extractable", false); |
| 73 dict->SetString("n", |
| 74 "qLOyhK-OtQs4cDSoYPFGxJGfMYdjzWxVmMiuSBGh4KvEx-CwgtaTpef87Wdc9GaFEncsDLxk" |
| 75 "p0LGxjD1M8jMcvYq6DPEC_JYQumEu3i9v5fAEH1VvbZi9cTg-rmEXLUUjvc5LdOq_5OuHmtm" |
| 76 "e7PUJHYW1PW6ENTP0ibeiNOfFvs"); |
| 77 dict->SetString("e", "AQAB"); |
| 78 } |
| 79 |
| 63 blink::WebCryptoAlgorithm CreateRsaKeyGenAlgorithm( | 80 blink::WebCryptoAlgorithm CreateRsaKeyGenAlgorithm( |
| 64 blink::WebCryptoAlgorithmId algorithm_id, | 81 blink::WebCryptoAlgorithmId algorithm_id, |
| 65 unsigned modulus_length, | 82 unsigned modulus_length, |
| 66 const std::vector<uint8>& public_exponent) { | 83 const std::vector<uint8>& public_exponent) { |
| 67 DCHECK(algorithm_id == blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5 || | 84 DCHECK(algorithm_id == blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5 || |
| 68 algorithm_id == blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 || | 85 algorithm_id == blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 || |
| 69 algorithm_id == blink::WebCryptoAlgorithmIdRsaOaep); | 86 algorithm_id == blink::WebCryptoAlgorithmIdRsaOaep); |
| 70 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( | 87 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( |
| 71 algorithm_id, | 88 algorithm_id, |
| 72 new blink::WebCryptoRsaKeyGenParams( | 89 new blink::WebCryptoRsaKeyGenParams( |
| (...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 blink::WebCryptoKeyFormatRaw, | 717 blink::WebCryptoKeyFormatRaw, |
| 701 HexStringToBytes("00000000000000000000"), | 718 HexStringToBytes("00000000000000000000"), |
| 702 blink::WebCryptoAlgorithm::createNull(), | 719 blink::WebCryptoAlgorithm::createNull(), |
| 703 true, | 720 true, |
| 704 blink::WebCryptoKeyUsageEncrypt, | 721 blink::WebCryptoKeyUsageEncrypt, |
| 705 &key)); | 722 &key)); |
| 706 } | 723 } |
| 707 | 724 |
| 708 #endif //#if !defined(USE_OPENSSL) | 725 #endif //#if !defined(USE_OPENSSL) |
| 709 | 726 |
| 710 TEST_F(WebCryptoImplTest, ImportJwkBadJwk) { | 727 TEST_F(WebCryptoImplTest, ImportJwkFailures) { |
| 711 | 728 |
| 712 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); | 729 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); |
| 713 blink::WebCryptoAlgorithm algorithm = | 730 blink::WebCryptoAlgorithm algorithm = |
| 714 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc); | 731 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc); |
| 715 blink::WebCryptoKeyUsageMask usage_mask = blink::WebCryptoKeyUsageEncrypt; | 732 blink::WebCryptoKeyUsageMask usage_mask = blink::WebCryptoKeyUsageEncrypt; |
| 716 | 733 |
| 717 // Baseline pass: each test below breaks a single item, so we start with a | 734 // Baseline pass: each test below breaks a single item, so we start with a |
| 718 // passing case to make sure each failure is caused by the isolated break. | 735 // passing case to make sure each failure is caused by the isolated break. |
| 719 // Each breaking subtest below resets the dictionary to this passing case when | 736 // Each breaking subtest below resets the dictionary to this passing case when |
| 720 // complete. | 737 // complete. |
| 721 base::DictionaryValue dict; | 738 base::DictionaryValue dict; |
| 722 RestoreDictionaryForImportBadJwkTest(&dict); | 739 RestoreJwkOctDictionary(&dict); |
| 723 std::vector<uint8> json_vec = MakeJsonVector(dict); | 740 EXPECT_TRUE(ImportKeyJwk( |
| 724 EXPECT_TRUE(ImportKeyJwk(json_vec, algorithm, false, usage_mask, &key)); | 741 MakeJsonVector(dict), algorithm, false, usage_mask, &key)); |
| 725 | 742 |
| 726 // Fail on empty JSON. | 743 // Fail on empty JSON. |
| 727 EXPECT_FALSE( | 744 EXPECT_FALSE(ImportKeyJwk( |
| 728 ImportKeyJwk(MakeJsonVector(""), algorithm, false, usage_mask, &key)); | 745 MakeJsonVector(""), algorithm, false, usage_mask, &key)); |
| 729 | 746 |
| 730 // Fail on invalid JSON. | 747 // Fail on invalid JSON. |
| 731 const std::vector<uint8> bad_json_vec = MakeJsonVector( | 748 const std::vector<uint8> bad_json_vec = MakeJsonVector( |
| 732 "{" | 749 "{" |
| 733 "\"kty\" : \"oct\"," | 750 "\"kty\" : \"oct\"," |
| 734 "\"alg\" : \"HS256\"," | 751 "\"alg\" : \"HS256\"," |
| 735 "\"use\" : " | 752 "\"use\" : " |
| 736 ); | 753 ); |
| 737 EXPECT_FALSE(ImportKeyJwk(bad_json_vec, algorithm, false, usage_mask, &key)); | 754 EXPECT_FALSE(ImportKeyJwk(bad_json_vec, algorithm, false, usage_mask, &key)); |
| 738 | 755 |
| 739 // Fail on JWK alg present but unrecognized. | 756 // Fail on JWK alg present but unrecognized. |
| 740 dict.SetString("alg", "A127CBC"); | 757 dict.SetString("alg", "A127CBC"); |
| 741 json_vec = MakeJsonVector(dict); | 758 EXPECT_FALSE(ImportKeyJwk( |
| 742 EXPECT_FALSE(ImportKeyJwk(json_vec, algorithm, false, usage_mask, &key)); | 759 MakeJsonVector(dict), algorithm, false, usage_mask, &key)); |
| 743 RestoreDictionaryForImportBadJwkTest(&dict); | 760 RestoreJwkOctDictionary(&dict); |
| 744 | 761 |
| 745 // Fail on both JWK and input algorithm missing. | 762 // Fail on both JWK and input algorithm missing. |
| 746 dict.Remove("alg", NULL); | 763 dict.Remove("alg", NULL); |
| 747 json_vec = MakeJsonVector(dict); | 764 EXPECT_FALSE(ImportKeyJwk(MakeJsonVector(dict), |
| 748 EXPECT_FALSE(ImportKeyJwk(json_vec, | |
| 749 blink::WebCryptoAlgorithm::createNull(), | 765 blink::WebCryptoAlgorithm::createNull(), |
| 750 false, | 766 false, |
| 751 usage_mask, | 767 usage_mask, |
| 752 &key)); | 768 &key)); |
| 753 RestoreDictionaryForImportBadJwkTest(&dict); | 769 RestoreJwkOctDictionary(&dict); |
| 754 | 770 |
| 755 // Fail on invalid kty. | 771 // Fail on invalid kty. |
| 756 dict.SetString("kty", "foo"); | 772 dict.SetString("kty", "foo"); |
| 757 json_vec = MakeJsonVector(dict); | 773 EXPECT_FALSE(ImportKeyJwk( |
| 758 EXPECT_FALSE(ImportKeyJwk(json_vec, algorithm, false, usage_mask, &key)); | 774 MakeJsonVector(dict), algorithm, false, usage_mask, &key)); |
| 759 RestoreDictionaryForImportBadJwkTest(&dict); | 775 RestoreJwkOctDictionary(&dict); |
| 760 | 776 |
| 761 // Fail on missing kty. | 777 // Fail on missing kty. |
| 762 dict.Remove("kty", NULL); | 778 dict.Remove("kty", NULL); |
| 763 json_vec = MakeJsonVector(dict); | 779 EXPECT_FALSE(ImportKeyJwk( |
| 764 EXPECT_FALSE(ImportKeyJwk(json_vec, algorithm, false, usage_mask, &key)); | 780 MakeJsonVector(dict), algorithm, false, usage_mask, &key)); |
| 765 RestoreDictionaryForImportBadJwkTest(&dict); | 781 RestoreJwkOctDictionary(&dict); |
| 766 | 782 |
| 767 // Fail on invalid use. | 783 // Fail on invalid use. |
| 768 dict.SetString("use", "foo"); | 784 dict.SetString("use", "foo"); |
| 769 json_vec = MakeJsonVector(dict); | 785 EXPECT_FALSE(ImportKeyJwk( |
| 770 EXPECT_FALSE(ImportKeyJwk(json_vec, algorithm, false, usage_mask, &key)); | 786 MakeJsonVector(dict), algorithm, false, usage_mask, &key)); |
| 771 RestoreDictionaryForImportBadJwkTest(&dict); | 787 RestoreJwkOctDictionary(&dict); |
| 788 } |
| 772 | 789 |
| 773 // Fail on missing k when kty = "oct". | 790 TEST_F(WebCryptoImplTest, ImportJwkOctFailures) { |
| 791 |
| 792 base::DictionaryValue dict; |
| 793 RestoreJwkOctDictionary(&dict); |
| 794 blink::WebCryptoAlgorithm algorithm = |
| 795 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc); |
| 796 blink::WebCryptoKeyUsageMask usage_mask = blink::WebCryptoKeyUsageEncrypt; |
| 797 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); |
| 798 |
| 799 // Baseline pass. |
| 800 EXPECT_TRUE(ImportKeyJwk( |
| 801 MakeJsonVector(dict), algorithm, false, usage_mask, &key)); |
| 802 EXPECT_EQ(algorithm.id(), key.algorithm().id()); |
| 803 EXPECT_FALSE(key.extractable()); |
| 804 EXPECT_EQ(blink::WebCryptoKeyUsageEncrypt, key.usages()); |
| 805 EXPECT_EQ(blink::WebCryptoKeyTypeSecret, key.type()); |
| 806 |
| 807 // The following are specific failure cases for when kty = "oct". |
| 808 |
| 809 // Fail on missing k. |
| 774 dict.Remove("k", NULL); | 810 dict.Remove("k", NULL); |
| 775 json_vec = MakeJsonVector(dict); | 811 EXPECT_FALSE(ImportKeyJwk( |
| 776 EXPECT_FALSE(ImportKeyJwk(json_vec, algorithm, false, usage_mask, &key)); | 812 MakeJsonVector(dict), algorithm, false, usage_mask, &key)); |
| 777 RestoreDictionaryForImportBadJwkTest(&dict); | 813 RestoreJwkOctDictionary(&dict); |
| 778 | 814 |
| 779 // Fail on bad b64 encoding for k. | 815 // Fail on bad b64 encoding for k. |
| 780 dict.SetString("k", "Qk3f0DsytU8lfza2au #$% Htaw2xpop9GYyTuH0p5GghxTI="); | 816 dict.SetString("k", "Qk3f0DsytU8lfza2au #$% Htaw2xpop9GYyTuH0p5GghxTI="); |
| 781 json_vec = MakeJsonVector(dict); | 817 EXPECT_FALSE(ImportKeyJwk( |
| 782 EXPECT_FALSE(ImportKeyJwk(json_vec, algorithm, false, usage_mask, &key)); | 818 MakeJsonVector(dict), algorithm, false, usage_mask, &key)); |
| 783 RestoreDictionaryForImportBadJwkTest(&dict); | 819 RestoreJwkOctDictionary(&dict); |
| 784 | 820 |
| 785 // Fail on empty k. | 821 // Fail on empty k. |
| 786 dict.SetString("k", ""); | 822 dict.SetString("k", ""); |
| 787 json_vec = MakeJsonVector(dict); | 823 EXPECT_FALSE(ImportKeyJwk( |
| 788 EXPECT_FALSE(ImportKeyJwk(json_vec, algorithm, false, usage_mask, &key)); | 824 MakeJsonVector(dict), algorithm, false, usage_mask, &key)); |
| 789 RestoreDictionaryForImportBadJwkTest(&dict); | 825 RestoreJwkOctDictionary(&dict); |
| 790 | 826 |
| 791 // Fail on k actual length (120 bits) inconsistent with the embedded JWK alg | 827 // Fail on k actual length (120 bits) inconsistent with the embedded JWK alg |
| 792 // value (128) for an AES key. | 828 // value (128) for an AES key. |
| 793 dict.SetString("k", "AVj42h0Y5aqGtE3yluKL"); | 829 dict.SetString("k", "AVj42h0Y5aqGtE3yluKL"); |
| 794 json_vec = MakeJsonVector(dict); | 830 EXPECT_FALSE(ImportKeyJwk( |
| 795 EXPECT_FALSE(ImportKeyJwk(json_vec, algorithm, false, usage_mask, &key)); | 831 MakeJsonVector(dict), algorithm, false, usage_mask, &key)); |
| 796 RestoreDictionaryForImportBadJwkTest(&dict); | 832 RestoreJwkOctDictionary(&dict); |
| 833 } |
| 797 | 834 |
| 798 // TODO(padolph) RSA public key bad data: | 835 #if !defined(USE_OPENSSL) |
| 799 // Missing n or e when kty = "RSA" | 836 |
| 800 // Bad encoding for n or e | 837 TEST_F(WebCryptoImplTest, ImportJwkRsaFailures) { |
| 801 // Size check on n?? | 838 |
| 802 // Value check on e?? | 839 base::DictionaryValue dict; |
| 840 RestoreJwkRsaDictionary(&dict); |
| 841 blink::WebCryptoAlgorithm algorithm = |
| 842 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5); |
| 843 blink::WebCryptoKeyUsageMask usage_mask = blink::WebCryptoKeyUsageEncrypt; |
| 844 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); |
| 845 |
| 846 // An RSA public key JWK _must_ have an "n" (modulus) and an "e" (exponent) |
| 847 // entry, while an RSA private key must have those plus at least a "d" |
| 848 // (private exponent) entry. |
| 849 // See http://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-18, |
| 850 // section 6.3. |
| 851 |
| 852 // Baseline pass. |
| 853 EXPECT_TRUE(ImportKeyJwk( |
| 854 MakeJsonVector(dict), algorithm, false, usage_mask, &key)); |
| 855 EXPECT_EQ(algorithm.id(), key.algorithm().id()); |
| 856 EXPECT_FALSE(key.extractable()); |
| 857 EXPECT_EQ(blink::WebCryptoKeyUsageEncrypt, key.usages()); |
| 858 EXPECT_EQ(blink::WebCryptoKeyTypePublic, key.type()); |
| 859 |
| 860 // The following are specific failure cases for when kty = "RSA". |
| 861 |
| 862 // Fail if either "n" or "e" is not present or malformed. |
| 863 const std::string kKtyParmName[] = {"n", "e"}; |
| 864 for (size_t idx = 0; idx < ARRAYSIZE_UNSAFE(kKtyParmName); ++idx) { |
| 865 |
| 866 // Fail on missing parameter. |
| 867 dict.Remove(kKtyParmName[idx], NULL); |
| 868 EXPECT_FALSE(ImportKeyJwk( |
| 869 MakeJsonVector(dict), algorithm, false, usage_mask, &key)); |
| 870 RestoreJwkRsaDictionary(&dict); |
| 871 |
| 872 // Fail on bad b64 parameter encoding. |
| 873 dict.SetString(kKtyParmName[idx], "Qk3f0DsytU8lfza2au #$% Htaw2xpop9yTuH0"); |
| 874 EXPECT_FALSE(ImportKeyJwk( |
| 875 MakeJsonVector(dict), algorithm, false, usage_mask, &key)); |
| 876 RestoreJwkRsaDictionary(&dict); |
| 877 |
| 878 // Fail on empty parameter. |
| 879 dict.SetString(kKtyParmName[idx], ""); |
| 880 EXPECT_FALSE(ImportKeyJwk( |
| 881 MakeJsonVector(dict), algorithm, false, usage_mask, &key)); |
| 882 RestoreJwkRsaDictionary(&dict); |
| 883 } |
| 884 |
| 885 // Fail if "d" parameter is present, implying the JWK is a private key, which |
| 886 // is not supported. |
| 887 dict.SetString("d", "Qk3f0Dsyt"); |
| 888 EXPECT_FALSE(ImportKeyJwk( |
| 889 MakeJsonVector(dict), algorithm, false, usage_mask, &key)); |
| 890 RestoreJwkRsaDictionary(&dict); |
| 803 } | 891 } |
| 804 | 892 |
| 893 #endif // #if !defined(USE_OPENSSL) |
| 894 |
| 805 TEST_F(WebCryptoImplTest, ImportJwkInputConsistency) { | 895 TEST_F(WebCryptoImplTest, ImportJwkInputConsistency) { |
| 806 // The Web Crypto spec says that if a JWK value is present, but is | 896 // The Web Crypto spec says that if a JWK value is present, but is |
| 807 // inconsistent with the input value, the operation must fail. | 897 // inconsistent with the input value, the operation must fail. |
| 808 | 898 |
| 809 // Consistency rules when JWK value is not present: Inputs should be used. | 899 // Consistency rules when JWK value is not present: Inputs should be used. |
| 810 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); | 900 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); |
| 811 bool extractable = false; | 901 bool extractable = false; |
| 812 blink::WebCryptoAlgorithm algorithm = | 902 blink::WebCryptoAlgorithm algorithm = |
| 813 webcrypto::CreateHmacAlgorithmByHashId(blink::WebCryptoAlgorithmIdSha256); | 903 webcrypto::CreateHmacAlgorithmByHashId(blink::WebCryptoAlgorithmIdSha256); |
| 814 blink::WebCryptoKeyUsageMask usage_mask = blink::WebCryptoKeyUsageVerify; | 904 blink::WebCryptoKeyUsageMask usage_mask = blink::WebCryptoKeyUsageVerify; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 EXPECT_FALSE(ImportKeyJwk( | 987 EXPECT_FALSE(ImportKeyJwk( |
| 898 json_vec, algorithm, extractable, blink::WebCryptoKeyUsageEncrypt, &key)); | 988 json_vec, algorithm, extractable, blink::WebCryptoKeyUsageEncrypt, &key)); |
| 899 | 989 |
| 900 // Fail: Input usage_mask (encrypt|sign|verify) is not a subset of the JWK | 990 // Fail: Input usage_mask (encrypt|sign|verify) is not a subset of the JWK |
| 901 // value (sign|verify) | 991 // value (sign|verify) |
| 902 usage_mask = blink::WebCryptoKeyUsageEncrypt | blink::WebCryptoKeyUsageSign | | 992 usage_mask = blink::WebCryptoKeyUsageEncrypt | blink::WebCryptoKeyUsageSign | |
| 903 blink::WebCryptoKeyUsageVerify; | 993 blink::WebCryptoKeyUsageVerify; |
| 904 EXPECT_FALSE( | 994 EXPECT_FALSE( |
| 905 ImportKeyJwk(json_vec, algorithm, extractable, usage_mask, &key)); | 995 ImportKeyJwk(json_vec, algorithm, extractable, usage_mask, &key)); |
| 906 usage_mask = blink::WebCryptoKeyUsageSign | blink::WebCryptoKeyUsageVerify; | 996 usage_mask = blink::WebCryptoKeyUsageSign | blink::WebCryptoKeyUsageVerify; |
| 997 |
| 998 // TODO(padolph): kty vs alg consistency tests: Depending on the kty value, |
| 999 // only certain alg values are permitted. For example, when kty = "RSA" alg |
| 1000 // must be of the RSA family, or when kty = "oct" alg must be symmetric |
| 1001 // algorithm. |
| 907 } | 1002 } |
| 908 | 1003 |
| 909 TEST_F(WebCryptoImplTest, ImportJwkHappy) { | 1004 TEST_F(WebCryptoImplTest, ImportJwkHappy) { |
| 910 | 1005 |
| 911 // This test verifies the happy path of JWK import, including the application | 1006 // This test verifies the happy path of JWK import, including the application |
| 912 // of the imported key material. | 1007 // of the imported key material. |
| 913 | 1008 |
| 914 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); | 1009 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); |
| 915 bool extractable = false; | 1010 bool extractable = false; |
| 916 blink::WebCryptoAlgorithm algorithm = | 1011 blink::WebCryptoAlgorithm algorithm = |
| (...skipping 21 matching lines...) Expand all Loading... |
| 938 | 1033 |
| 939 blink::WebArrayBuffer output; | 1034 blink::WebArrayBuffer output; |
| 940 | 1035 |
| 941 ASSERT_TRUE(SignInternal(algorithm, key, message_raw, &output)); | 1036 ASSERT_TRUE(SignInternal(algorithm, key, message_raw, &output)); |
| 942 | 1037 |
| 943 const std::string mac_raw = | 1038 const std::string mac_raw = |
| 944 "769f00d3e6a6cc1fb426a14a4f76c6462e6149726e0dee0ec0cf97a16605ac8b"; | 1039 "769f00d3e6a6cc1fb426a14a4f76c6462e6149726e0dee0ec0cf97a16605ac8b"; |
| 945 | 1040 |
| 946 ExpectArrayBufferMatchesHex(mac_raw, output); | 1041 ExpectArrayBufferMatchesHex(mac_raw, output); |
| 947 | 1042 |
| 948 // TODO(padolph) | 1043 // TODO(padolph): Import an RSA public key JWK and use it |
| 949 // Import an RSA public key JWK and use it | |
| 950 } | 1044 } |
| 951 | 1045 |
| 952 #if !defined(USE_OPENSSL) | 1046 #if !defined(USE_OPENSSL) |
| 953 | 1047 |
| 954 TEST_F(WebCryptoImplTest, ImportExportSpki) { | 1048 TEST_F(WebCryptoImplTest, ImportExportSpki) { |
| 955 // openssl genrsa -out pair.pem 2048 | 1049 // openssl genrsa -out pair.pem 2048 |
| 956 // openssl rsa -in pair.pem -out pubkey.der -outform DER -pubout | 1050 // openssl rsa -in pair.pem -out pubkey.der -outform DER -pubout |
| 957 // xxd -p pubkey.der | 1051 // xxd -p pubkey.der |
| 958 const std::string hex_rsa_spki_der = | 1052 const std::string hex_rsa_spki_der = |
| 959 "30820122300d06092a864886f70d01010105000382010f003082010a0282" | 1053 "30820122300d06092a864886f70d01010105000382010f003082010a0282" |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1481 private_key, | 1575 private_key, |
| 1482 reinterpret_cast<const unsigned char*>(encrypted_data.data()), | 1576 reinterpret_cast<const unsigned char*>(encrypted_data.data()), |
| 1483 encrypted_data.byteLength(), | 1577 encrypted_data.byteLength(), |
| 1484 &decrypted_data)); | 1578 &decrypted_data)); |
| 1485 ExpectArrayBufferMatchesHex(message_hex_str, decrypted_data); | 1579 ExpectArrayBufferMatchesHex(message_hex_str, decrypted_data); |
| 1486 } | 1580 } |
| 1487 | 1581 |
| 1488 #endif // #if !defined(USE_OPENSSL) | 1582 #endif // #if !defined(USE_OPENSSL) |
| 1489 | 1583 |
| 1490 } // namespace content | 1584 } // namespace content |
| OLD | NEW |