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

Side by Side Diff: google_apis/cup/client_update_protocol.h

Issue 15793005: Per discussion, implement the Omaha Client Update Protocol (CUP) in src/crypto. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « google_apis/cup/OWNERS ('k') | google_apis/cup/client_update_protocol.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013 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 GOOGLE_APIS_CUP_CLIENT_UPDATE_PROTOCOL_H_
6 #define GOOGLE_APIS_CUP_CLIENT_UPDATE_PROTOCOL_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/strings/string_piece.h"
14
15 // Client Update Protocol, or CUP, is used by Google Update (Omaha) servers to
16 // ensure freshness and authenticity of update checks over HTTP, without the
17 // overhead of HTTPS -- namely, no PKI, no guarantee of privacy, and no request
18 // replay protection (since update checks are idempotent).
19 //
20 // http://omaha.googlecode.com/svn/wiki/cup.html
21 //
22 // This implementation does not persist client proofs by design.
23 class ClientUpdateProtocol {
24 public:
25 ~ClientUpdateProtocol();
26
27 // Initializes this instance of CUP with a versioned public key. |key_version|
28 // must be non-negative. |public_key| is expected to be a DER-encoded ASN.1
29 // Subject Public Key Info. Returns NULL on failure.
30 static ClientUpdateProtocol* Create(int key_version,
31 const base::StringPiece& public_key);
32
33 // Returns a versioned encrypted secret (v|w) in a URL-safe Base64 encoding.
34 // Add to your URL before calling SignRequest().
35 std::string GetVersionedSecret() const;
36
37 // Generates freshness/authentication data for an outgoing update check.
38 // |url| contains the the URL that the request will be sent to; it should
39 // include GetVersionedSecret() in its query string. This needs to be
40 // formatted in the way that the Omaha server expects: omit the scheme and
41 // any port number. (e.g. "//tools.google.com/service/update2?w=1:abcdef")
42 // |request_body| contains the body of the update check request in UTF-8.
43 //
44 // On success, returns true, and |cp_out| receives a Base64-encoded client
45 // proof, which should be sent in the If-Match HTTP header. On failure,
46 // returns false, and |cp_out| is not modified.
47 //
48 // This method will store internal state in this instance used by calls to
49 // ValidateResponse(); if you need to have multiple update checks in flight,
50 // initialize a separate CUP instance for each one.
51 bool SignRequest(const base::StringPiece& url,
52 const base::StringPiece& request_body,
53 std::string* client_proof);
54
55 // Validates a response given to a update check request previously signed
56 // with SignRequest(). |request_body| contains the body of the response in
57 // UTF-8. |server_cookie| contains the persisted credential cookie provided
58 // by the server. |server_proof| contains the Base64-encoded server proof,
59 // which is passed in the ETag HTTP header. Returns true if the response is
60 // valid.
61 // This method uses internal state that is set by a prior SignRequest() call.
62 bool ValidateResponse(const base::StringPiece& response_body,
63 const base::StringPiece& server_cookie,
64 const base::StringPiece& server_proof);
65
66 // Internal interface to the public key used by ClientUpdateProtocol.
67 // Implemented on a per-platform basis.
68 class CupKeyImpl {
69 public:
70 virtual ~CupKeyImpl() {}
71
72 // Returns the length of the public key's modulus in bytes, 0 on failure.
73 virtual size_t PublicKeyLength() const = 0;
74
75 // Encrypts |key_source| using the loaded public key. Returns the
76 // encrypted result on success, or an empty vector on failure.
77 virtual std::vector<uint8> EncryptKeySource(
78 const std::vector<uint8>& key_source) = 0;
Ryan Sleevi 2013/06/04 18:58:02 You don't need to do this. We just use compile-ti
79 };
80
81 private:
82 friend class CupUnitTest;
83
84 // Constructor is private -- use the Create method above.
85 explicit ClientUpdateProtocol(int key_version);
86
87 // Generates a key source (r) and uses that to fill out |shared_key_| (sk')
88 // and encrypted_key_source_ (w). If |opt_key_source| is non-NULL, the key
89 // source is read from that location instead of being randomly generated.
90 // (Used for unit testing.) Returns true on success.
91 bool BuildSharedKey(size_t public_key_length, const uint8* opt_key_source);
92
93 // The server keeps multiple private keys; a version must be sent so that
94 // the right private key is used to decode the versioned secret. (The CUP
95 // specification calls this "v".)
96 int pub_key_version_;
97
98 // Holds the shared key, which is used to generate an HMAC signature for both
99 // the update check request and the update response. The client builds it
100 // locally, but sends the server an encrypted copy of the key source to
101 // synthesize it on its own. (The CUP specification calls this "sk'".)
102 std::vector<uint8> shared_key_;
103
104 // Holds the original contents of key_source_ that have been encrypted with
105 // the server's public key. The client sends this, along with the version of
106 // the keypair that was used, to the server. The server decrypts it using its
107 // private key to get the contents of key_source_, from which it recreates the
108 // shared key. (The CUP specification calls this "w".)
109 std::vector<uint8> encrypted_key_source_;
110
111 // Holds the hash of the update check request, the URL that it was sent to,
112 // and the versioned secret. This is filled out by a successful call to
113 // SignRequest(), and used by ValidateResponse() to confirm that the server
114 // has successfully decoded the versioned secret and signed the response using
115 // the same shared key as our own. (The CUP specification calls this "hw".)
116 std::vector<uint8> client_challenge_hash_;
117
118 // The public key used to encrypt the key source. (The CUP specification
119 // calls this "pk[v]".)
120 scoped_ptr<CupKeyImpl> public_key_impl_;
121
122 // Helper function to generate an appropriate ClientUpdateProtocolKeyImpl for
123 // this platform and load a public key into it. |public_key| should be a
124 // DER-encoded ASN.1 Subject Public Key Info. Returns a pointer on the heap
125 // (which the caller owns) on success, NULL on failure.
126 static CupKeyImpl* GetCupKeyImpl(const base::StringPiece& public_key);
127
128 DISALLOW_COPY_AND_ASSIGN(ClientUpdateProtocol);
129 };
130
131 #endif // GOOGLE_APIS_CUP_CLIENT_UPDATE_PROTOCOL_H_
132
OLDNEW
« no previous file with comments | « google_apis/cup/OWNERS ('k') | google_apis/cup/client_update_protocol.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698