OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/common/origin_trials/trial_token_validator.h" | 5 #include "content/common/origin_trials/trial_token_validator.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 // 0x16, 0xab, 0xb4, 0x86, 0xea, 0xf3, 0x35, 0xc6, 0xca | 41 // 0x16, 0xab, 0xb4, 0x86, 0xea, 0xf3, 0x35, 0xc6, 0xca |
42 const uint8_t kTestPublicKey2[] = { | 42 const uint8_t kTestPublicKey2[] = { |
43 0x50, 0x07, 0x4d, 0x76, 0x55, 0x56, 0x42, 0x17, 0x2d, 0x8a, 0x9c, | 43 0x50, 0x07, 0x4d, 0x76, 0x55, 0x56, 0x42, 0x17, 0x2d, 0x8a, 0x9c, |
44 0x47, 0x96, 0x25, 0xda, 0x70, 0xaa, 0xb9, 0xfd, 0x53, 0x5d, 0x51, | 44 0x47, 0x96, 0x25, 0xda, 0x70, 0xaa, 0xb9, 0xfd, 0x53, 0x5d, 0x51, |
45 0x3e, 0x16, 0xab, 0xb4, 0x86, 0xea, 0xf3, 0x35, 0xc6, 0xca, | 45 0x3e, 0x16, 0xab, 0xb4, 0x86, 0xea, 0xf3, 0x35, 0xc6, 0xca, |
46 }; | 46 }; |
47 | 47 |
48 // This is a good trial token, signed with the above test private key. | 48 // This is a good trial token, signed with the above test private key. |
49 // TODO(iclelland): This token expires in 2033. Update it or find a way | 49 // TODO(iclelland): This token expires in 2033. Update it or find a way |
50 // to autogenerate it before then. | 50 // to autogenerate it before then. |
| 51 // Generate this token with the command (in tools/origin_trials): |
| 52 // generate_token.py valid.example.com Frobulate --expire-timestamp=2000000000 |
51 const char kSampleToken[] = | 53 const char kSampleToken[] = |
52 "1|w694328Rl8l2vd96nkbAumpwvOOnvhWTj9/pfBRkvcWMDAsmiMEhZGEPzdBRy5Yao6il5qC" | 54 "AuR/1mg+/w5ROLN54Ok20rApK3opgR7Tq9ZfzhATQmnCa+BtPA1RRw4Nigf336r+" |
53 "OyS6Ah7uuHf7JAQ==|https://valid.example.com|Frobulate|2000000000"; | 55 "O4fM3Sa+MEd+5JcIgSZafw8AAABZeyJvcmlnaW4iOiAiaHR0cHM6Ly92YWxpZC5l" |
| 56 "eGFtcGxlLmNvbTo0NDMiLCAiZmVhdHVyZSI6ICJGcm9idWxhdGUiLCAiZXhwaXJ5" |
| 57 "IjogMjAwMDAwMDAwMH0="; |
54 | 58 |
55 // The token should be valid for this origin and for this feature. | 59 // The token should be valid for this origin and for this feature. |
56 const char kAppropriateOrigin[] = "https://valid.example.com"; | 60 const char kAppropriateOrigin[] = "https://valid.example.com"; |
57 const char kAppropriateFeatureName[] = "Frobulate"; | 61 const char kAppropriateFeatureName[] = "Frobulate"; |
58 | 62 |
59 const char kInappropriateFeatureName[] = "Grokalyze"; | 63 const char kInappropriateFeatureName[] = "Grokalyze"; |
60 const char kInappropriateOrigin[] = "https://invalid.example.com"; | 64 const char kInappropriateOrigin[] = "https://invalid.example.com"; |
61 const char kInsecureOrigin[] = "http://valid.example.com"; | 65 const char kInsecureOrigin[] = "http://valid.example.com"; |
62 | 66 |
63 // Well-formed trial token with an invalid signature. | 67 // Well-formed trial token with an invalid signature. |
| 68 // This token is a corruption of the above valid token. |
64 const char kInvalidSignatureToken[] = | 69 const char kInvalidSignatureToken[] = |
65 "1|CO8hDne98QeFeOJ0DbRZCBN3uE0nyaPgaLlkYhSWnbRoDfEAg+TXELaYfQPfEvKYFauBg/h" | 70 "AuR/1mg+/w5ROLN54Ok20rApK3opgR7Tq9ZfzhATQmnCa+BtPA1RRw4Nigf336r+" |
66 "nxmba765hz0mXMc==|https://valid.example.com|Frobulate|2000000000"; | 71 "RrOtlAwa0gPqqn+A8GTD3AQAAABZeyJvcmlnaW4iOiAiaHR0cHM6Ly92YWxpZC5l" |
| 72 "eGFtcGxlLmNvbTo0NDMiLCAiZmVhdHVyZSI6ICJGcm9idWxhdGUiLCAiZXhwaXJ5" |
| 73 "IjogMjAwMDAwMDAwMH0="; |
67 | 74 |
68 // Well-formed, but expired, trial token. (Expired in 2001) | 75 // Well-formed, but expired, trial token. (Expired in 2001) |
| 76 // Generate this token with the command (in tools/origin_trials): |
| 77 // generate_token.py valid.example.com Frobulate --expire-timestamp=1000000000 |
69 const char kExpiredToken[] = | 78 const char kExpiredToken[] = |
70 "1|Vtzq/H0qMxsMXPThIgGEvI13d3Fd8K3W11/0E+FrJJXqBpx6n/dFkeFkEUsPaP3KeT8PCPF" | 79 "AmHPUIXMaXe9jWW8kJeDFXolVjT93p4XMnK4+jMYd2pjqtFcYB1bUmdD8PunQKM+" |
71 "1zpZ7kVgWYRLpAA==|https://valid.example.com|Frobulate|1000000000"; | 80 "RrOtlAwa0gPqqn+A8GTD3AQAAABZeyJvcmlnaW4iOiAiaHR0cHM6Ly92YWxpZC5l" |
| 81 "eGFtcGxlLmNvbTo0NDMiLCAiZmVhdHVyZSI6ICJGcm9idWxhdGUiLCAiZXhwaXJ5" |
| 82 "IjogMTAwMDAwMDAwMH0="; |
72 | 83 |
73 const char kUnparsableToken[] = "abcde"; | 84 const char kUnparsableToken[] = "abcde"; |
74 | 85 |
75 class TestContentClient : public ContentClient { | 86 class TestContentClient : public ContentClient { |
76 public: | 87 public: |
77 base::StringPiece GetOriginTrialPublicKey() override { | 88 base::StringPiece GetOriginTrialPublicKey() override { |
78 return base::StringPiece(reinterpret_cast<const char*>(key_), | 89 return base::StringPiece(reinterpret_cast<const char*>(key_), |
79 arraysize(kTestPublicKey)); | 90 arraysize(kTestPublicKey)); |
80 } | 91 } |
81 void SetOriginTrialPublicKey(const uint8_t* key) { key_ = key; } | 92 void SetOriginTrialPublicKey(const uint8_t* key) { key_ = key; } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 kExpiredToken, appropriate_origin_, kAppropriateFeatureName)); | 151 kExpiredToken, appropriate_origin_, kAppropriateFeatureName)); |
141 } | 152 } |
142 | 153 |
143 TEST_F(TrialTokenValidatorTest, ValidateValidTokenWithIncorrectKey) { | 154 TEST_F(TrialTokenValidatorTest, ValidateValidTokenWithIncorrectKey) { |
144 SetPublicKey(kTestPublicKey2); | 155 SetPublicKey(kTestPublicKey2); |
145 EXPECT_FALSE(TrialTokenValidator::ValidateToken( | 156 EXPECT_FALSE(TrialTokenValidator::ValidateToken( |
146 kSampleToken, appropriate_origin_, kAppropriateFeatureName)); | 157 kSampleToken, appropriate_origin_, kAppropriateFeatureName)); |
147 } | 158 } |
148 | 159 |
149 } // namespace content | 160 } // namespace content |
OLD | NEW |