Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(789)

Side by Side Diff: components/client_update_protocol/ecdsa_unittest.cc

Issue 1805263002: Move CUP to new component client_update_protocol (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sorin review 1 Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/client_update_protocol/ecdsa.cc ('k') | components/components.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <limits> 7 #include <limits>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/strings/string_piece.h" 12 #include "base/strings/string_piece.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "components/update_client/client_update_protocol_ecdsa.h" 14 #include "components/client_update_protocol/ecdsa.h"
15 #include "crypto/random.h" 15 #include "crypto/random.h"
16 #include "crypto/secure_util.h" 16 #include "crypto/secure_util.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 namespace update_client { 19 namespace client_update_protocol {
20 20
21 namespace { 21 namespace {
22 22
23 std::string GetPublicKeyForTesting() { 23 std::string GetPublicKeyForTesting() {
24 // How to generate this key: 24 // How to generate this key:
25 // openssl ecparam -genkey -name prime256v1 -out ecpriv.pem 25 // openssl ecparam -genkey -name prime256v1 -out ecpriv.pem
26 // openssl ec -in ecpriv.pem -pubout -out ecpub.pem 26 // openssl ec -in ecpriv.pem -pubout -out ecpub.pem
27 27
28 static const char kCupEcdsaTestKey_Base64[] = 28 static const char kCupEcdsaTestKey_Base64[] =
29 "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEJNOjKyN6UHyUGkGow+xCmQthQXUo" 29 "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEJNOjKyN6UHyUGkGow+xCmQthQXUo"
30 "9sd7RIXSpVIM768UlbGb/5JrnISjSYejCc/pxQooI6mJTzWL3pZb5TA1DA=="; 30 "9sd7RIXSpVIM768UlbGb/5JrnISjSYejCc/pxQooI6mJTzWL3pZb5TA1DA==";
31 31
32 std::string result; 32 std::string result;
33 if (!base::Base64Decode(std::string(kCupEcdsaTestKey_Base64), &result)) 33 if (!base::Base64Decode(std::string(kCupEcdsaTestKey_Base64), &result))
34 return std::string(); 34 return std::string();
35 35
36 return result; 36 return result;
37 } 37 }
38 38
39 } // end namespace 39 } // end namespace
40 40
41 class CupEcdsaTest : public testing::Test { 41 class CupEcdsaTest : public testing::Test {
42 protected: 42 protected:
43 void SetUp() override { 43 void SetUp() override {
44 cup_ = ClientUpdateProtocolEcdsa::Create(8, GetPublicKeyForTesting()); 44 cup_ = Ecdsa::Create(8, GetPublicKeyForTesting());
45 ASSERT_TRUE(cup_.get()); 45 ASSERT_TRUE(cup_.get());
46 } 46 }
47 47
48 void OverrideNonce(uint32_t nonce) { 48 void OverrideNonce(uint32_t nonce) {
49 cup_->request_query_cup2key_ = 49 cup_->request_query_cup2key_ =
50 base::StringPrintf("%d:%u", cup_->pub_key_version_, nonce); 50 base::StringPrintf("%d:%u", cup_->pub_key_version_, nonce);
51 } 51 }
52 52
53 ClientUpdateProtocolEcdsa& CUP() { return *cup_.get(); } 53 Ecdsa& CUP() { return *cup_.get(); }
54 54
55 private: 55 private:
56 scoped_ptr<ClientUpdateProtocolEcdsa> cup_; 56 scoped_ptr<Ecdsa> cup_;
57 }; 57 };
58 58
59 TEST_F(CupEcdsaTest, SignRequest) { 59 TEST_F(CupEcdsaTest, SignRequest) {
60 static const char kRequest[] = "TestSequenceForCupEcdsaUnitTest"; 60 static const char kRequest[] = "TestSequenceForCupEcdsaUnitTest";
61 static const char kRequestHash[] = 61 static const char kRequestHash[] =
62 "&cup2hreq=" 62 "&cup2hreq="
63 "cde1f7dc1311ed96813057ca321c2f5a17ea2c9c776ee0eb31965f7985a3074a"; 63 "cde1f7dc1311ed96813057ca321c2f5a17ea2c9c776ee0eb31965f7985a3074a";
64 static const char kKeyId[] = "cup2key=8:"; 64 static const char kKeyId[] = "cup2key=8:";
65 65
66 std::string query; 66 std::string query;
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 288
289 // Failure case: Request/response are intact, but the signature is invalid 289 // Failure case: Request/response are intact, but the signature is invalid
290 // because it was signed against a different nonce (67890). 290 // because it was signed against a different nonce (67890).
291 EXPECT_FALSE(CUP().ValidateResponse( 291 EXPECT_FALSE(CUP().ValidateResponse(
292 "Response_A", 292 "Response_A",
293 "3046022100d3bbb1fb4451c8e04a07fe95404cc39121ed0e0bc084f87de19d52eee50a97" 293 "3046022100d3bbb1fb4451c8e04a07fe95404cc39121ed0e0bc084f87de19d52eee50a97"
294 "bf022100dd7d41d467be2af98d9116b0c7ba09740d54578c02a02f74da5f089834be3403" 294 "bf022100dd7d41d467be2af98d9116b0c7ba09740d54578c02a02f74da5f089834be3403"
295 ":2727bc2b3c33feb6800a830f4055901dd87d65a84184c5fbeb3f816db0a243f5")); 295 ":2727bc2b3c33feb6800a830f4055901dd87d65a84184c5fbeb3f816db0a243f5"));
296 } 296 }
297 297
298 } // namespace update_client 298 } // namespace client_update_protocol
OLDNEW
« no previous file with comments | « components/client_update_protocol/ecdsa.cc ('k') | components/components.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698