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

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

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/OWNERS ('k') | components/client_update_protocol/ecdsa.cc » ('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 #ifndef COMPONENTS_UPDATE_CLIENT_CLIENT_UPDATE_PROTOCOL_ECDSA_H_ 5 #ifndef COMPONENTS_CLIENT_UPDATE_PROTOCOL_ECDSA_H_
6 #define COMPONENTS_UPDATE_CLIENT_CLIENT_UPDATE_PROTOCOL_ECDSA_H_ 6 #define COMPONENTS_CLIENT_UPDATE_PROTOCOL_ECDSA_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/strings/string_piece.h" 14 #include "base/strings/string_piece.h"
15 15
16 namespace update_client { 16 namespace client_update_protocol {
17 17
18 // Client Update Protocol v2, or CUP-ECDSA, is used by Google Update (Omaha) 18 // Client Update Protocol v2, or CUP-ECDSA, is used by Google Update (Omaha)
19 // servers to ensure freshness and authenticity of update checks over HTTP, 19 // servers to ensure freshness and authenticity of server responses over HTTP,
20 // without the overhead of HTTPS -- namely, no PKI, no guarantee of privacy, 20 // without the overhead of HTTPS -- namely, no PKI, no guarantee of privacy, and
21 // and no request replay protection (since update checks are idempotent). 21 // no request replay protection.
22 // 22 //
23 // CUP-ECDSA relies on a single signing operation using ECDSA with SHA-256, 23 // CUP-ECDSA relies on a single signing operation using ECDSA with SHA-256,
24 // instead of the original CUP which used HMAC-SHA1 with a random signing key 24 // instead of the original CUP which used HMAC-SHA1 with a random signing key
25 // encrypted using RSA. 25 // encrypted using RSA.
26 // 26 //
27 // Each ClientUpdateProtocolEcdsa object represents a single update check in 27 // Each |Ecdsa| object represents a single network ping in flight -- a call to
28 // flight -- a call to SignRequest() generates internal state that will be used 28 // SignRequest() generates internal state that will be used by
29 // by ValidateResponse(). 29 // ValidateResponse().
30 class ClientUpdateProtocolEcdsa { 30 class Ecdsa {
31 public: 31 public:
32 ~ClientUpdateProtocolEcdsa(); 32 ~Ecdsa();
33 33
34 // Initializes this instance of CUP-ECDSA with a versioned public key. 34 // Initializes this instance of CUP-ECDSA with a versioned public key.
35 // |key_version| must be non-negative. |public_key| is expected to be a 35 // |key_version| must be non-negative. |public_key| is expected to be a
36 // DER-encoded ASN.1 SubjectPublicKeyInfo containing an ECDSA public key. 36 // DER-encoded ASN.1 SubjectPublicKeyInfo containing an ECDSA public key.
37 // Returns a NULL pointer on failure. 37 // Returns a NULL pointer on failure.
38 static scoped_ptr<ClientUpdateProtocolEcdsa> Create( 38 static scoped_ptr<Ecdsa> Create(int key_version,
39 int key_version, 39 const base::StringPiece& public_key);
40 const base::StringPiece& public_key);
41 40
42 // Generates freshness/authentication data for an outgoing update check. 41 // Generates freshness/authentication data for an outgoing ping.
43 // |request_body| contains the body of the update check request in UTF-8. 42 // |request_body| contains the body of the ping in UTF-8. On return,
44 // On return, |query_params| contains a set of query parameters (in UTF-8) 43 // |query_params| contains a set of query parameters (in UTF-8) to be appended
45 // to be appended to the URL. 44 // to the URL.
46 // 45 //
47 // This method will store internal state in this instance used by calls to 46 // This method will store internal state in this instance used by calls to
48 // ValidateResponse(); if you need to have multiple update checks in flight, 47 // ValidateResponse(); if you need to have multiple pings in flight,
49 // initialize a separate CUP-ECDSA instance for each one. 48 // initialize a separate CUP-ECDSA instance for each one.
50 void SignRequest(const base::StringPiece& request_body, 49 void SignRequest(const base::StringPiece& request_body,
51 std::string* query_params); 50 std::string* query_params);
52 51
53 // Validates a response given to a update check request previously signed 52 // Validates a response given to a ping previously signed with
54 // with SignRequest(). |response_body| contains the body of the response in 53 // SignRequest(). |response_body| contains the body of the response in
55 // UTF-8. |server_proof| contains the ECDSA signature and observed request 54 // UTF-8. |server_proof| contains the ECDSA signature and observed request
56 // hash, which is passed in the ETag HTTP header. Returns true if the 55 // hash, which is passed in the ETag HTTP header. Returns true if the response
57 // response is valid and the observed request hash matches the sent hash. 56 // is valid and the observed request hash matches the sent hash. This method
58 // This method uses internal state that is set by a prior SignRequest() call. 57 // uses internal state that is set by a prior SignRequest() call.
59 bool ValidateResponse(const base::StringPiece& response_body, 58 bool ValidateResponse(const base::StringPiece& response_body,
60 const base::StringPiece& server_etag); 59 const base::StringPiece& server_etag);
61 60
62 private: 61 private:
63 friend class CupEcdsaTest; 62 friend class CupEcdsaTest;
64 63
65 ClientUpdateProtocolEcdsa(int key_version, 64 Ecdsa(int key_version, const base::StringPiece& public_key);
66 const base::StringPiece& public_key);
67 65
68 // The server keeps multiple signing keys; a version must be sent so that 66 // The server keeps multiple signing keys; a version must be sent so that
69 // the correct signing key is used to sign the assembled message. 67 // the correct signing key is used to sign the assembled message.
70 const int pub_key_version_; 68 const int pub_key_version_;
71 69
72 // The ECDSA public key to use for verifying response signatures. 70 // The ECDSA public key to use for verifying response signatures.
73 const std::vector<uint8_t> public_key_; 71 const std::vector<uint8_t> public_key_;
74 72
75 // The SHA-256 hash of the XML request. This is modified on each call to 73 // The SHA-256 hash of the XML request. This is modified on each call to
76 // SignRequest(), and checked by ValidateResponse(). 74 // SignRequest(), and checked by ValidateResponse().
77 std::vector<uint8_t> request_hash_; 75 std::vector<uint8_t> request_hash_;
78 76
79 // The query string containing key version and nonce in UTF-8 form. This is 77 // The query string containing key version and nonce in UTF-8 form. This is
80 // modified on each call to SignRequest(), and checked by ValidateResponse(). 78 // modified on each call to SignRequest(), and checked by ValidateResponse().
81 std::string request_query_cup2key_; 79 std::string request_query_cup2key_;
82 80
83 DISALLOW_IMPLICIT_CONSTRUCTORS(ClientUpdateProtocolEcdsa); 81 DISALLOW_IMPLICIT_CONSTRUCTORS(Ecdsa);
84 }; 82 };
85 83
86 } // namespace update_client 84 } // namespace client_update_protocol
87 85
88 #endif // COMPONENTS_UPDATE_CLIENT_CLIENT_UPDATE_PROTOCOL_ECDSA_H_ 86 #endif // COMPONENTS_CLIENT_UPDATE_PROTOCOL_ECDSA_H_
OLDNEW
« no previous file with comments | « components/client_update_protocol/OWNERS ('k') | components/client_update_protocol/ecdsa.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698