| 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 0x00, 0x01, 0x02, 0x03 | 48 0x00, 0x01, 0x02, 0x03 |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 // Key is 0x0405060708090a0b0c0d0e0f10111213, | 51 // Key is 0x0405060708090a0b0c0d0e0f10111213, |
| 52 // base64 equivalent is BAUGBwgJCgsMDQ4PEBESEw. | 52 // base64 equivalent is BAUGBwgJCgsMDQ4PEBESEw. |
| 53 const char kKeyAsJWK[] = | 53 const char kKeyAsJWK[] = |
| 54 "{" | 54 "{" |
| 55 " \"keys\": [" | 55 " \"keys\": [" |
| 56 " {" | 56 " {" |
| 57 " \"kty\": \"oct\"," | 57 " \"kty\": \"oct\"," |
| 58 " \"alg\": \"A128KW\"," |
| 58 " \"kid\": \"AAECAw\"," | 59 " \"kid\": \"AAECAw\"," |
| 59 " \"k\": \"BAUGBwgJCgsMDQ4PEBESEw\"" | 60 " \"k\": \"BAUGBwgJCgsMDQ4PEBESEw\"" |
| 60 " }" | 61 " }" |
| 61 " ]," | 62 " ]," |
| 62 " \"type\": \"temporary\"" | 63 " \"type\": \"temporary\"" |
| 63 "}"; | 64 "}"; |
| 64 | 65 |
| 65 // Same kid as kKeyAsJWK, key to decrypt kEncryptedData2 | 66 // Same kid as kKeyAsJWK, key to decrypt kEncryptedData2 |
| 66 const char kKeyAlternateAsJWK[] = | 67 const char kKeyAlternateAsJWK[] = |
| 67 "{" | 68 "{" |
| 68 " \"keys\": [" | 69 " \"keys\": [" |
| 69 " {" | 70 " {" |
| 70 " \"kty\": \"oct\"," | 71 " \"kty\": \"oct\"," |
| 72 " \"alg\": \"A128KW\"," |
| 71 " \"kid\": \"AAECAw\"," | 73 " \"kid\": \"AAECAw\"," |
| 72 " \"k\": \"FBUWFxgZGhscHR4fICEiIw\"" | 74 " \"k\": \"FBUWFxgZGhscHR4fICEiIw\"" |
| 73 " }" | 75 " }" |
| 74 " ]" | 76 " ]" |
| 75 "}"; | 77 "}"; |
| 76 | 78 |
| 77 const char kWrongKeyAsJWK[] = | 79 const char kWrongKeyAsJWK[] = |
| 78 "{" | 80 "{" |
| 79 " \"keys\": [" | 81 " \"keys\": [" |
| 80 " {" | 82 " {" |
| 81 " \"kty\": \"oct\"," | 83 " \"kty\": \"oct\"," |
| 84 " \"alg\": \"A128KW\"," |
| 82 " \"kid\": \"AAECAw\"," | 85 " \"kid\": \"AAECAw\"," |
| 83 " \"k\": \"7u7u7u7u7u7u7u7u7u7u7g\"" | 86 " \"k\": \"7u7u7u7u7u7u7u7u7u7u7g\"" |
| 84 " }" | 87 " }" |
| 85 " ]" | 88 " ]" |
| 86 "}"; | 89 "}"; |
| 87 | 90 |
| 88 const char kWrongSizedKeyAsJWK[] = | 91 const char kWrongSizedKeyAsJWK[] = |
| 89 "{" | 92 "{" |
| 90 " \"keys\": [" | 93 " \"keys\": [" |
| 91 " {" | 94 " {" |
| 92 " \"kty\": \"oct\"," | 95 " \"kty\": \"oct\"," |
| 96 " \"alg\": \"A128KW\"," |
| 93 " \"kid\": \"AAECAw\"," | 97 " \"kid\": \"AAECAw\"," |
| 94 " \"k\": \"AAECAw\"" | 98 " \"k\": \"AAECAw\"" |
| 95 " }" | 99 " }" |
| 96 " ]" | 100 " ]" |
| 97 "}"; | 101 "}"; |
| 98 | 102 |
| 99 const uint8 kIv[] = { | 103 const uint8 kIv[] = { |
| 100 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, | 104 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, |
| 101 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | 105 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 102 }; | 106 }; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 129 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | 133 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 130 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | 134 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 131 0x10, 0x11, 0x12, 0x13 | 135 0x10, 0x11, 0x12, 0x13 |
| 132 }; | 136 }; |
| 133 | 137 |
| 134 const char kKey2AsJWK[] = | 138 const char kKey2AsJWK[] = |
| 135 "{" | 139 "{" |
| 136 " \"keys\": [" | 140 " \"keys\": [" |
| 137 " {" | 141 " {" |
| 138 " \"kty\": \"oct\"," | 142 " \"kty\": \"oct\"," |
| 143 " \"alg\": \"A128KW\"," |
| 139 " \"kid\": \"AAECAwQFBgcICQoLDA0ODxAREhM\"," | 144 " \"kid\": \"AAECAwQFBgcICQoLDA0ODxAREhM\"," |
| 140 " \"k\": \"FBUWFxgZGhscHR4fICEiIw\"" | 145 " \"k\": \"FBUWFxgZGhscHR4fICEiIw\"" |
| 141 " }" | 146 " }" |
| 142 " ]" | 147 " ]" |
| 143 "}"; | 148 "}"; |
| 144 | 149 |
| 145 // 'k' in bytes is x14x15x16x17x18x19x1ax1bx1cx1dx1ex1fx20x21x22x23 | 150 // 'k' in bytes is x14x15x16x17x18x19x1ax1bx1cx1dx1ex1fx20x21x22x23 |
| 146 | 151 |
| 147 const uint8 kEncryptedData2[] = { | 152 const uint8 kEncryptedData2[] = { |
| 148 0x57, 0x66, 0xf4, 0x12, 0x1a, 0xed, 0xb5, 0x79, | 153 0x57, 0x66, 0xf4, 0x12, 0x1a, 0xed, 0xb5, 0x79, |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS)); | 711 DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS)); |
| 707 } | 712 } |
| 708 | 713 |
| 709 TEST_F(AesDecryptorTest, JWKKey) { | 714 TEST_F(AesDecryptorTest, JWKKey) { |
| 710 std::string session_id = CreateSession(key_id_); | 715 std::string session_id = CreateSession(key_id_); |
| 711 | 716 |
| 712 // Try a simple JWK key (i.e. not in a set) | 717 // Try a simple JWK key (i.e. not in a set) |
| 713 const std::string kJwkSimple = | 718 const std::string kJwkSimple = |
| 714 "{" | 719 "{" |
| 715 " \"kty\": \"oct\"," | 720 " \"kty\": \"oct\"," |
| 721 " \"alg\": \"A128KW\"," |
| 716 " \"kid\": \"AAECAwQFBgcICQoLDA0ODxAREhM\"," | 722 " \"kid\": \"AAECAwQFBgcICQoLDA0ODxAREhM\"," |
| 717 " \"k\": \"FBUWFxgZGhscHR4fICEiIw\"" | 723 " \"k\": \"FBUWFxgZGhscHR4fICEiIw\"" |
| 718 "}"; | 724 "}"; |
| 719 UpdateSessionAndExpect(session_id, kJwkSimple, REJECTED); | 725 UpdateSessionAndExpect(session_id, kJwkSimple, REJECTED); |
| 720 | 726 |
| 721 // Try a key list with multiple entries. | 727 // Try a key list with multiple entries. |
| 722 const std::string kJwksMultipleEntries = | 728 const std::string kJwksMultipleEntries = |
| 723 "{" | 729 "{" |
| 724 " \"keys\": [" | 730 " \"keys\": [" |
| 725 " {" | 731 " {" |
| 726 " \"kty\": \"oct\"," | 732 " \"kty\": \"oct\"," |
| 733 " \"alg\": \"A128KW\"," |
| 727 " \"kid\": \"AAECAwQFBgcICQoLDA0ODxAREhM\"," | 734 " \"kid\": \"AAECAwQFBgcICQoLDA0ODxAREhM\"," |
| 728 " \"k\": \"FBUWFxgZGhscHR4fICEiIw\"" | 735 " \"k\": \"FBUWFxgZGhscHR4fICEiIw\"" |
| 729 " }," | 736 " }," |
| 730 " {" | 737 " {" |
| 731 " \"kty\": \"oct\"," | 738 " \"kty\": \"oct\"," |
| 739 " \"alg\": \"A128KW\"," |
| 732 " \"kid\": \"JCUmJygpKissLS4vMA\"," | 740 " \"kid\": \"JCUmJygpKissLS4vMA\"," |
| 733 " \"k\":\"MTIzNDU2Nzg5Ojs8PT4/QA\"" | 741 " \"k\":\"MTIzNDU2Nzg5Ojs8PT4/QA\"" |
| 734 " }" | 742 " }" |
| 735 " ]" | 743 " ]" |
| 736 "}"; | 744 "}"; |
| 737 UpdateSessionAndExpect(session_id, kJwksMultipleEntries, RESOLVED); | 745 UpdateSessionAndExpect(session_id, kJwksMultipleEntries, RESOLVED); |
| 738 | 746 |
| 739 // Try a key with no spaces and some \n plus additional fields. | 747 // Try a key with no spaces and some \n plus additional fields. |
| 740 const std::string kJwksNoSpaces = | 748 const std::string kJwksNoSpaces = |
| 741 "\n\n{\"something\":1,\"keys\":[{\n\n\"kty\":\"oct\",\"alg\":\"A128KW\"," | 749 "\n\n{\"something\":1,\"keys\":[{\n\n\"kty\":\"oct\",\"alg\":\"A128KW\"," |
| (...skipping 24 matching lines...) Expand all Loading... |
| 766 | 774 |
| 767 // Try with 'keys' a list of integers. | 775 // Try with 'keys' a list of integers. |
| 768 UpdateSessionAndExpect(session_id, "{ \"keys\": [ 1, 2, 3 ] }", REJECTED); | 776 UpdateSessionAndExpect(session_id, "{ \"keys\": [ 1, 2, 3 ] }", REJECTED); |
| 769 | 777 |
| 770 // Try padding(=) at end of 'k' base64 string. | 778 // Try padding(=) at end of 'k' base64 string. |
| 771 const std::string kJwksWithPaddedKey = | 779 const std::string kJwksWithPaddedKey = |
| 772 "{" | 780 "{" |
| 773 " \"keys\": [" | 781 " \"keys\": [" |
| 774 " {" | 782 " {" |
| 775 " \"kty\": \"oct\"," | 783 " \"kty\": \"oct\"," |
| 784 " \"alg\": \"A128KW\"," |
| 776 " \"kid\": \"AAECAw\"," | 785 " \"kid\": \"AAECAw\"," |
| 777 " \"k\": \"BAUGBwgJCgsMDQ4PEBESEw==\"" | 786 " \"k\": \"BAUGBwgJCgsMDQ4PEBESEw==\"" |
| 778 " }" | 787 " }" |
| 779 " ]" | 788 " ]" |
| 780 "}"; | 789 "}"; |
| 781 UpdateSessionAndExpect(session_id, kJwksWithPaddedKey, REJECTED); | 790 UpdateSessionAndExpect(session_id, kJwksWithPaddedKey, REJECTED); |
| 782 | 791 |
| 783 // Try padding(=) at end of 'kid' base64 string. | 792 // Try padding(=) at end of 'kid' base64 string. |
| 784 const std::string kJwksWithPaddedKeyId = | 793 const std::string kJwksWithPaddedKeyId = |
| 785 "{" | 794 "{" |
| 786 " \"keys\": [" | 795 " \"keys\": [" |
| 787 " {" | 796 " {" |
| 788 " \"kty\": \"oct\"," | 797 " \"kty\": \"oct\"," |
| 798 " \"alg\": \"A128KW\"," |
| 789 " \"kid\": \"AAECAw==\"," | 799 " \"kid\": \"AAECAw==\"," |
| 790 " \"k\": \"BAUGBwgJCgsMDQ4PEBESEw\"" | 800 " \"k\": \"BAUGBwgJCgsMDQ4PEBESEw\"" |
| 791 " }" | 801 " }" |
| 792 " ]" | 802 " ]" |
| 793 "}"; | 803 "}"; |
| 794 UpdateSessionAndExpect(session_id, kJwksWithPaddedKeyId, REJECTED); | 804 UpdateSessionAndExpect(session_id, kJwksWithPaddedKeyId, REJECTED); |
| 795 | 805 |
| 796 // Try a key with invalid base64 encoding. | 806 // Try a key with invalid base64 encoding. |
| 797 const std::string kJwksWithInvalidBase64 = | 807 const std::string kJwksWithInvalidBase64 = |
| 798 "{" | 808 "{" |
| 799 " \"keys\": [" | 809 " \"keys\": [" |
| 800 " {" | 810 " {" |
| 801 " \"kty\": \"oct\"," | 811 " \"kty\": \"oct\"," |
| 812 " \"alg\": \"A128KW\"," |
| 802 " \"kid\": \"!@#$%^&*()\"," | 813 " \"kid\": \"!@#$%^&*()\"," |
| 803 " \"k\": \"BAUGBwgJCgsMDQ4PEBESEw\"" | 814 " \"k\": \"BAUGBwgJCgsMDQ4PEBESEw\"" |
| 804 " }" | 815 " }" |
| 805 " ]" | 816 " ]" |
| 806 "}"; | 817 "}"; |
| 807 UpdateSessionAndExpect(session_id, kJwksWithInvalidBase64, REJECTED); | 818 UpdateSessionAndExpect(session_id, kJwksWithInvalidBase64, REJECTED); |
| 808 | 819 |
| 809 // Try a 3-byte 'kid' where no base64 padding is required. | 820 // Try a 3-byte 'kid' where no base64 padding is required. |
| 810 // |kJwksMultipleEntries| above has 2 'kid's that require 1 and 2 padding | 821 // |kJwksMultipleEntries| above has 2 'kid's that require 1 and 2 padding |
| 811 // bytes. Note that 'k' has to be 16 bytes, so it will always require padding. | 822 // bytes. Note that 'k' has to be 16 bytes, so it will always require padding. |
| 812 const std::string kJwksWithNoPadding = | 823 const std::string kJwksWithNoPadding = |
| 813 "{" | 824 "{" |
| 814 " \"keys\": [" | 825 " \"keys\": [" |
| 815 " {" | 826 " {" |
| 816 " \"kty\": \"oct\"," | 827 " \"kty\": \"oct\"," |
| 828 " \"alg\": \"A128KW\"," |
| 817 " \"kid\": \"Kiss\"," | 829 " \"kid\": \"Kiss\"," |
| 818 " \"k\": \"BAUGBwgJCgsMDQ4PEBESEw\"" | 830 " \"k\": \"BAUGBwgJCgsMDQ4PEBESEw\"" |
| 819 " }" | 831 " }" |
| 820 " ]" | 832 " ]" |
| 821 "}"; | 833 "}"; |
| 822 UpdateSessionAndExpect(session_id, kJwksWithNoPadding, RESOLVED); | 834 UpdateSessionAndExpect(session_id, kJwksWithNoPadding, RESOLVED); |
| 823 | 835 |
| 824 // Empty key id. | 836 // Empty key id. |
| 825 const std::string kJwksWithEmptyKeyId = | 837 const std::string kJwksWithEmptyKeyId = |
| 826 "{" | 838 "{" |
| 827 " \"keys\": [" | 839 " \"keys\": [" |
| 828 " {" | 840 " {" |
| 829 " \"kty\": \"oct\"," | 841 " \"kty\": \"oct\"," |
| 842 " \"alg\": \"A128KW\"," |
| 830 " \"kid\": \"\"," | 843 " \"kid\": \"\"," |
| 831 " \"k\": \"BAUGBwgJCgsMDQ4PEBESEw\"" | 844 " \"k\": \"BAUGBwgJCgsMDQ4PEBESEw\"" |
| 832 " }" | 845 " }" |
| 833 " ]" | 846 " ]" |
| 834 "}"; | 847 "}"; |
| 835 UpdateSessionAndExpect(session_id, kJwksWithEmptyKeyId, REJECTED); | 848 UpdateSessionAndExpect(session_id, kJwksWithEmptyKeyId, REJECTED); |
| 836 CloseSession(session_id); | 849 CloseSession(session_id); |
| 837 } | 850 } |
| 838 | 851 |
| 839 } // namespace media | 852 } // namespace media |
| OLD | NEW |