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

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

Issue 1835823002: network_time_tracker: add temporary time protocol. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: scoped_refptr Created 4 years, 7 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
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 "components/client_update_protocol/ecdsa.h" 5 #include "components/client_update_protocol/ecdsa.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 std::unique_ptr<Ecdsa> Ecdsa::Create(int key_version, 93 std::unique_ptr<Ecdsa> Ecdsa::Create(int key_version,
94 const base::StringPiece& public_key) { 94 const base::StringPiece& public_key) {
95 DCHECK_GT(key_version, 0); 95 DCHECK_GT(key_version, 0);
96 DCHECK(!public_key.empty()); 96 DCHECK(!public_key.empty());
97 97
98 return base::WrapUnique(new Ecdsa(key_version, public_key)); 98 return base::WrapUnique(new Ecdsa(key_version, public_key));
99 } 99 }
100 100
101 void Ecdsa::SignRequest(const base::StringPiece& request_body, 101 void Ecdsa::SignRequest(const base::StringPiece& request_body,
102 std::string* query_params) { 102 std::string* query_params) {
103 DCHECK(!request_body.empty());
104 DCHECK(query_params); 103 DCHECK(query_params);
105 104
106 // Generate a random nonce to use for freshness, build the cup2key query 105 // Generate a random nonce to use for freshness, build the cup2key query
107 // string, and compute the SHA-256 hash of the request body. Set these 106 // string, and compute the SHA-256 hash of the request body. Set these
108 // two pieces of data aside to use during ValidateResponse(). 107 // two pieces of data aside to use during ValidateResponse().
109 uint32_t nonce = 0; 108 uint32_t nonce = 0;
110 crypto::RandBytes(&nonce, sizeof(nonce)); 109 crypto::RandBytes(&nonce, sizeof(nonce));
111 request_query_cup2key_ = base::StringPrintf("%d:%u", pub_key_version_, nonce); 110 request_query_cup2key_ = base::StringPrintf("%d:%u", pub_key_version_, nonce);
112 request_hash_ = SHA256HashStr(request_body); 111 request_hash_ = SHA256HashStr(request_body);
113 112
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 // * The signature was modified 177 // * The signature was modified
179 // * The buffer that the server signed does not match the buffer that the 178 // * The buffer that the server signed does not match the buffer that the
180 // client assembled -- implying that either request body or response body 179 // client assembled -- implying that either request body or response body
181 // was modified, or a different nonce value was used. 180 // was modified, or a different nonce value was used.
182 verifier.VerifyUpdate(&signed_message_hash.front(), 181 verifier.VerifyUpdate(&signed_message_hash.front(),
183 static_cast<int>(signed_message_hash.size())); 182 static_cast<int>(signed_message_hash.size()));
184 return verifier.VerifyFinal(); 183 return verifier.VerifyFinal();
185 } 184 }
186 185
187 } // namespace client_update_protocol 186 } // namespace client_update_protocol
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698