Chromium Code Reviews| 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 #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 update checks 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, |
| 21 // and no request replay protection (since update checks are idempotent). | 21 // and no request replay protection (since update checks are idempotent). |
| 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 update check in |
|
Sorin Jianu
2016/03/16 22:22:47
idea: fix the terminology so that it refers to pro
mab
2016/03/16 22:50:35
Good idea. I rewrote all the instances I could fi
Sorin Jianu
2016/03/16 23:05:54
Acknowledged.
| |
| 28 // flight -- a call to SignRequest() generates internal state that will be used | 28 // flight -- a call to SignRequest() generates internal state that will be used |
| 29 // by ValidateResponse(). | 29 // by ValidateResponse(). |
| 30 class ClientUpdateProtocolEcdsa { | 30 class Ecdsa { |
|
Sorin Jianu
2016/03/16 22:22:47
Maybe rename to EcdsaSigner?
mab
2016/03/16 22:50:35
That's a bit tricky: as documented on |SignRequest
Sorin Jianu
2016/03/16 23:05:54
Acknowledged.
| |
| 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 update check. |
| 43 // |request_body| contains the body of the update check request in UTF-8. | 42 // |request_body| contains the body of the update check request in UTF-8. |
| 44 // On return, |query_params| contains a set of query parameters (in UTF-8) | 43 // On return, |query_params| contains a set of query parameters (in UTF-8) |
| 45 // to be appended to the URL. | 44 // to be appended 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 update checks 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 update check request previously signed |
| 54 // with SignRequest(). |response_body| contains the body of the response in | 53 // with 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 |
| 57 // response is valid and the observed request hash matches the sent hash. | 56 // response is valid and the observed request hash matches the sent hash. |
| 58 // This method uses internal state that is set by a prior SignRequest() call. | 57 // This method 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 update_client |
| 87 | 85 |
| 88 #endif // COMPONENTS_UPDATE_CLIENT_CLIENT_UPDATE_PROTOCOL_ECDSA_H_ | 86 #endif // COMPONENTS_CLIENT_UPDATE_PROTOCOL_ECDSA_H_ |
| OLD | NEW |