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

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
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 // Forward declare types for NSS/OpenSSL.
Ryan Sleevi 2013/06/06 19:59:10 comment nit: You're not using OpenSSL ATM, so lets
Ryan Myers (chromium) 2013/06/06 21:09:10 Done.
16 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX)
17 typedef struct SECKEYPublicKeyStr SECKEYPublicKey;
18 #endif
19
20 // Client Update Protocol, or CUP, is used by Google Update (Omaha) servers to
21 // ensure freshness and authenticity of update checks over HTTP, without the
22 // overhead of HTTPS -- namely, no PKI, no guarantee of privacy, and no request
23 // replay protection (since update checks are idempotent).
24 //
25 // http://omaha.googlecode.com/svn/wiki/cup.html
26 //
27 // This implementation does not persist client proofs by design.
28 class ClientUpdateProtocol {
29 public:
30 ~ClientUpdateProtocol();
31
32 // Initializes this instance of CUP with a versioned public key. |key_version|
33 // must be non-negative. |public_key| is expected to be a DER-encoded ASN.1
34 // Subject Public Key Info. Returns NULL on failure.
35 static ClientUpdateProtocol* Create(int key_version,
Ryan Sleevi 2013/06/06 19:59:10 Chromium style is to prefer returning scoped_ptr<C
Ryan Myers (chromium) 2013/06/06 21:09:10 Done.
36 const base::StringPiece& public_key);
37
38 // Returns a versioned encrypted secret (v|w) in a URL-safe Base64 encoding.
39 // Add to your URL before calling SignRequest().
40 std::string GetVersionedSecret() const;
41
42 // Generates freshness/authentication data for an outgoing update check.
43 // |url| contains the the URL that the request will be sent to; it should
44 // include GetVersionedSecret() in its query string. This needs to be
45 // formatted in the way that the Omaha server expects: omit the scheme and
46 // any port number. (e.g. "//tools.google.com/service/update2?w=1:abcdef")
47 // |request_body| contains the body of the update check request in UTF-8.
48 //
49 // On success, returns true, and |cp_out| receives a Base64-encoded client
Ryan Sleevi 2013/06/06 19:59:10 s/cp_out/client_proof/
Ryan Myers (chromium) 2013/06/06 21:09:10 Done.
50 // proof, which should be sent in the If-Match HTTP header. On failure,
51 // returns false, and |cp_out| is not modified.
52 //
53 // This method will store internal state in this instance used by calls to
54 // ValidateResponse(); if you need to have multiple update checks in flight,
55 // initialize a separate CUP instance for each one.
Ryan Sleevi 2013/06/06 19:59:10 This last bit seems better moved to the class leve
Ryan Myers (chromium) 2013/06/06 21:09:10 Done.
Ryan Myers (chromium) 2013/06/06 21:09:10 Done.
56 bool SignRequest(const base::StringPiece& url,
57 const base::StringPiece& request_body,
58 std::string* client_proof);
59
60 // Validates a response given to a update check request previously signed
61 // with SignRequest(). |request_body| contains the body of the response in
Ryan Sleevi 2013/06/06 19:59:10 comment/OCD nit: Either use only a single space be
62 // UTF-8. |server_cookie| contains the persisted credential cookie provided
63 // by the server. |server_proof| contains the Base64-encoded server proof,
64 // which is passed in the ETag HTTP header. Returns true if the response is
65 // valid.
66 // This method uses internal state that is set by a prior SignRequest() call.
67 bool ValidateResponse(const base::StringPiece& response_body,
68 const base::StringPiece& server_cookie,
69 const base::StringPiece& server_proof);
70
71 private:
72 friend class CupUnitTest;
Ryan Sleevi 2013/06/06 19:59:10 naming nit: The vast majority of our tests omit th
Ryan Myers (chromium) 2013/06/06 21:09:10 Done.
73
74 // Constructor is private -- use the Create method above.
Ryan Sleevi 2013/06/06 19:59:10 comment nit: Seems a superfluous comment.
Ryan Myers (chromium) 2013/06/06 21:09:10 Done.
75 explicit ClientUpdateProtocol(int key_version);
76
77 // Decodes |public_key| into the appropriate internal structures. Returns
78 // the length of the public key (modulus) in bytes, or 0 on failure.
79 bool LoadPublicKey(const base::StringPiece& public_key);
80
81 // Returns the size of the public key in bytes, or 0 on failure.
82 size_t PublicKeyLength();
83
84 // Helper function for BuildSharedKey() -- encrypts |key_source| (r) using
85 // the loaded public key, filling out |encrypted_key_source_| (w).
86 // Returns true on success.
87 bool EncryptKeySource(const std::vector<uint8>& key_source);
88
89 // Generates a key source (r) and uses that to fill out |shared_key_| (sk')
90 // and encrypted_key_source_ (w). If |opt_key_source| is non-NULL, the key
91 // source is read from that location instead of being randomly generated.
92 // (Used for unit testing.) Returns true on success.
93 bool BuildSharedKey(size_t public_key_length, const uint8* opt_key_source);
Ryan Sleevi 2013/06/06 19:59:10 style/design: I would encourage two different call
Ryan Myers (chromium) 2013/06/06 21:09:10 Done.
94
95 // The server keeps multiple private keys; a version must be sent so that
96 // the right private key is used to decode the versioned secret. (The CUP
97 // specification calls this "v".)
98 int pub_key_version_;
99
100 // Holds the shared key, which is used to generate an HMAC signature for both
101 // the update check request and the update response. The client builds it
102 // locally, but sends the server an encrypted copy of the key source to
103 // synthesize it on its own. (The CUP specification calls this "sk'".)
104 std::vector<uint8> shared_key_;
105
106 // Holds the original contents of key_source_ that have been encrypted with
107 // the server's public key. The client sends this, along with the version of
108 // the keypair that was used, to the server. The server decrypts it using its
109 // private key to get the contents of key_source_, from which it recreates the
110 // shared key. (The CUP specification calls this "w".)
111 std::vector<uint8> encrypted_key_source_;
112
113 // Holds the hash of the update check request, the URL that it was sent to,
114 // and the versioned secret. This is filled out by a successful call to
115 // SignRequest(), and used by ValidateResponse() to confirm that the server
116 // has successfully decoded the versioned secret and signed the response using
117 // the same shared key as our own. (The CUP specification calls this "hw".)
118 std::vector<uint8> client_challenge_hash_;
119
120 // The public key used to encrypt the key source. (The CUP specification
121 // calls this "pk[v]".)
122 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX)
123 SECKEYPublicKey* public_key_;
124 #endif
125
126 DISALLOW_COPY_AND_ASSIGN(ClientUpdateProtocol);
Ryan Sleevi 2013/06/06 19:59:10 nit: DISALLOW_IMPLICIT_CONSTRUCTORS
Ryan Myers (chromium) 2013/06/06 21:09:10 Done.
127 };
128
129 #endif // GOOGLE_APIS_CUP_CLIENT_UPDATE_PROTOCOL_H_
130
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698