| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_UPDATE_CLIENT_CLIENT_UPDATE_PROTOCOL_ECDSA_H_ | |
| 6 #define COMPONENTS_UPDATE_CLIENT_CLIENT_UPDATE_PROTOCOL_ECDSA_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include <string> | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/strings/string_piece.h" | |
| 15 | |
| 16 namespace update_client { | |
| 17 | |
| 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, | |
| 20 // without the overhead of HTTPS -- namely, no PKI, no guarantee of privacy, | |
| 21 // and no request replay protection (since update checks are idempotent). | |
| 22 // | |
| 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 | |
| 25 // encrypted using RSA. | |
| 26 // | |
| 27 // Each ClientUpdateProtocolEcdsa object represents a single update check in | |
| 28 // flight -- a call to SignRequest() generates internal state that will be used | |
| 29 // by ValidateResponse(). | |
| 30 class ClientUpdateProtocolEcdsa { | |
| 31 public: | |
| 32 ~ClientUpdateProtocolEcdsa(); | |
| 33 | |
| 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 | |
| 36 // DER-encoded ASN.1 SubjectPublicKeyInfo containing an ECDSA public key. | |
| 37 // Returns a NULL pointer on failure. | |
| 38 static scoped_ptr<ClientUpdateProtocolEcdsa> Create( | |
| 39 int key_version, | |
| 40 const base::StringPiece& public_key); | |
| 41 | |
| 42 // Generates freshness/authentication data for an outgoing update check. | |
| 43 // |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) | |
| 45 // to be appended to the URL. | |
| 46 // | |
| 47 // 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, | |
| 49 // initialize a separate CUP-ECDSA instance for each one. | |
| 50 void SignRequest(const base::StringPiece& request_body, | |
| 51 std::string* query_params); | |
| 52 | |
| 53 // Validates a response given to a update check request previously signed | |
| 54 // with SignRequest(). |response_body| contains the body of the response in | |
| 55 // 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 | |
| 57 // 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. | |
| 59 bool ValidateResponse(const base::StringPiece& response_body, | |
| 60 const base::StringPiece& server_etag); | |
| 61 | |
| 62 private: | |
| 63 friend class CupEcdsaTest; | |
| 64 | |
| 65 ClientUpdateProtocolEcdsa(int key_version, | |
| 66 const base::StringPiece& public_key); | |
| 67 | |
| 68 // 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. | |
| 70 const int pub_key_version_; | |
| 71 | |
| 72 // The ECDSA public key to use for verifying response signatures. | |
| 73 const std::vector<uint8_t> public_key_; | |
| 74 | |
| 75 // The SHA-256 hash of the XML request. This is modified on each call to | |
| 76 // SignRequest(), and checked by ValidateResponse(). | |
| 77 std::vector<uint8_t> request_hash_; | |
| 78 | |
| 79 // 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(). | |
| 81 std::string request_query_cup2key_; | |
| 82 | |
| 83 DISALLOW_IMPLICIT_CONSTRUCTORS(ClientUpdateProtocolEcdsa); | |
| 84 }; | |
| 85 | |
| 86 } // namespace update_client | |
| 87 | |
| 88 #endif // COMPONENTS_UPDATE_CLIENT_CLIENT_UPDATE_PROTOCOL_ECDSA_H_ | |
| OLD | NEW |