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

Side by Side Diff: components/proximity_auth/device_to_device_responder_operations.cc

Issue 2502343003: Moved //components/proximity_auth/cryptauth to //components/cryptauth. (Closed)
Patch Set: Fixed proto #includes. Created 4 years, 1 month 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "components/proximity_auth/device_to_device_responder_operations.h" 5 #include "components/proximity_auth/device_to_device_responder_operations.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "components/proximity_auth/cryptauth/proto/cryptauth_api.pb.h" 9 #include "components/cryptauth/proto/cryptauth_api.pb.h"
10 #include "components/proximity_auth/cryptauth/proto/securemessage.pb.h" 10 #include "components/cryptauth/proto/securemessage.pb.h"
11 #include "components/proximity_auth/cryptauth/secure_message_delegate.h" 11 #include "components/cryptauth/secure_message_delegate.h"
12 #include "components/proximity_auth/logging/logging.h" 12 #include "components/proximity_auth/logging/logging.h"
13 13
14 namespace proximity_auth { 14 namespace proximity_auth {
15 15
16 namespace { 16 namespace {
17 17
18 // TODO(tengs): Due to a bug with the ChromeOS secure message daemon, we cannot 18 // TODO(tengs): Due to a bug with the ChromeOS secure message daemon, we cannot
19 // create SecureMessages with empty payloads. To workaround this bug, this value 19 // create SecureMessages with empty payloads. To workaround this bug, this value
20 // is put into the payload if it would otherwise be empty. 20 // is put into the payload if it would otherwise be empty.
21 // See crbug.com/512894. 21 // See crbug.com/512894.
(...skipping 19 matching lines...) Expand all
41 } 41 }
42 42
43 // Helper struct containing all the context needed to create the [Responder 43 // Helper struct containing all the context needed to create the [Responder
44 // Auth] message. 44 // Auth] message.
45 struct CreateResponderAuthMessageContext { 45 struct CreateResponderAuthMessageContext {
46 std::string hello_message; 46 std::string hello_message;
47 std::string session_public_key; 47 std::string session_public_key;
48 std::string session_private_key; 48 std::string session_private_key;
49 std::string persistent_private_key; 49 std::string persistent_private_key;
50 std::string persistent_symmetric_key; 50 std::string persistent_symmetric_key;
51 SecureMessageDelegate* secure_message_delegate; 51 cryptauth::SecureMessageDelegate* secure_message_delegate;
52 DeviceToDeviceResponderOperations::MessageCallback callback; 52 DeviceToDeviceResponderOperations::MessageCallback callback;
53 std::string hello_public_key; 53 std::string hello_public_key;
54 std::string middle_message; 54 std::string middle_message;
55 }; 55 };
56 56
57 // Forward declarations of functions used to create the [Responder Auth] 57 // Forward declarations of functions used to create the [Responder Auth]
58 // message, declared in order in which they are called during the creation flow. 58 // message, declared in order in which they are called during the creation flow.
59 void OnHelloMessageValidatedForResponderAuth( 59 void OnHelloMessageValidatedForResponderAuth(
60 CreateResponderAuthMessageContext context, 60 CreateResponderAuthMessageContext context,
61 bool hello_message_validated, 61 bool hello_message_validated,
(...skipping 19 matching lines...) Expand all
81 return; 81 return;
82 } 82 }
83 83
84 context.hello_public_key = hello_public_key; 84 context.hello_public_key = hello_public_key;
85 85
86 // Create the inner most wrapped message of [Responder Auth]. 86 // Create the inner most wrapped message of [Responder Auth].
87 cryptauth::GcmMetadata gcm_metadata; 87 cryptauth::GcmMetadata gcm_metadata;
88 gcm_metadata.set_type(cryptauth::UNLOCK_KEY_SIGNED_CHALLENGE); 88 gcm_metadata.set_type(cryptauth::UNLOCK_KEY_SIGNED_CHALLENGE);
89 gcm_metadata.set_version(kGcmMetadataVersion); 89 gcm_metadata.set_version(kGcmMetadataVersion);
90 90
91 SecureMessageDelegate::CreateOptions create_options; 91 cryptauth::SecureMessageDelegate::CreateOptions create_options;
92 create_options.encryption_scheme = securemessage::NONE; 92 create_options.encryption_scheme = securemessage::NONE;
93 create_options.signature_scheme = securemessage::ECDSA_P256_SHA256; 93 create_options.signature_scheme = securemessage::ECDSA_P256_SHA256;
94 gcm_metadata.SerializeToString(&create_options.public_metadata); 94 gcm_metadata.SerializeToString(&create_options.public_metadata);
95 create_options.associated_data = context.hello_message; 95 create_options.associated_data = context.hello_message;
96 96
97 context.secure_message_delegate->CreateSecureMessage( 97 context.secure_message_delegate->CreateSecureMessage(
98 kPayloadFiller, context.persistent_private_key, create_options, 98 kPayloadFiller, context.persistent_private_key, create_options,
99 base::Bind(&OnInnerMessageCreatedForResponderAuth, context)); 99 base::Bind(&OnInnerMessageCreatedForResponderAuth, context));
100 } 100 }
101 101
102 // Called after the inner-most layer of [Responder Auth] is created. 102 // Called after the inner-most layer of [Responder Auth] is created.
103 void OnInnerMessageCreatedForResponderAuth( 103 void OnInnerMessageCreatedForResponderAuth(
104 CreateResponderAuthMessageContext context, 104 CreateResponderAuthMessageContext context,
105 const std::string& inner_message) { 105 const std::string& inner_message) {
106 if (inner_message.empty()) { 106 if (inner_message.empty()) {
107 PA_LOG(INFO) << "Failed to create middle message for [Responder Auth]"; 107 PA_LOG(INFO) << "Failed to create middle message for [Responder Auth]";
108 context.callback.Run(std::string()); 108 context.callback.Run(std::string());
109 return; 109 return;
110 } 110 }
111 111
112 // Create the middle message. 112 // Create the middle message.
113 SecureMessageDelegate::CreateOptions create_options; 113 cryptauth::SecureMessageDelegate::CreateOptions create_options;
114 create_options.encryption_scheme = securemessage::AES_256_CBC; 114 create_options.encryption_scheme = securemessage::AES_256_CBC;
115 create_options.signature_scheme = securemessage::HMAC_SHA256; 115 create_options.signature_scheme = securemessage::HMAC_SHA256;
116 create_options.associated_data = context.hello_message; 116 create_options.associated_data = context.hello_message;
117 context.secure_message_delegate->CreateSecureMessage( 117 context.secure_message_delegate->CreateSecureMessage(
118 inner_message, context.persistent_symmetric_key, create_options, 118 inner_message, context.persistent_symmetric_key, create_options,
119 base::Bind(&OnMiddleMessageCreatedForResponderAuth, context)); 119 base::Bind(&OnMiddleMessageCreatedForResponderAuth, context));
120 } 120 }
121 121
122 // Called after the middle layer of [Responder Auth] is created. 122 // Called after the middle layer of [Responder Auth] is created.
123 void OnMiddleMessageCreatedForResponderAuth( 123 void OnMiddleMessageCreatedForResponderAuth(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 context.callback.Run(std::string()); 161 context.callback.Run(std::string());
162 return; 162 return;
163 } 163 }
164 164
165 // Create the outer most message, wrapping the other messages created 165 // Create the outer most message, wrapping the other messages created
166 // previously. 166 // previously.
167 securemessage::DeviceToDeviceMessage device_to_device_message; 167 securemessage::DeviceToDeviceMessage device_to_device_message;
168 device_to_device_message.set_message(context.middle_message); 168 device_to_device_message.set_message(context.middle_message);
169 device_to_device_message.set_sequence_number(1); 169 device_to_device_message.set_sequence_number(1);
170 170
171 SecureMessageDelegate::CreateOptions create_options; 171 cryptauth::SecureMessageDelegate::CreateOptions create_options;
172 create_options.encryption_scheme = securemessage::AES_256_CBC; 172 create_options.encryption_scheme = securemessage::AES_256_CBC;
173 create_options.signature_scheme = securemessage::HMAC_SHA256; 173 create_options.signature_scheme = securemessage::HMAC_SHA256;
174 create_options.public_metadata = gcm_metadata.SerializeAsString(); 174 create_options.public_metadata = gcm_metadata.SerializeAsString();
175 responder_hello.SerializeToString(&create_options.decryption_key_id); 175 responder_hello.SerializeToString(&create_options.decryption_key_id);
176 176
177 context.secure_message_delegate->CreateSecureMessage( 177 context.secure_message_delegate->CreateSecureMessage(
178 device_to_device_message.SerializeAsString(), session_symmetric_key, 178 device_to_device_message.SerializeAsString(), session_symmetric_key,
179 create_options, context.callback); 179 create_options, context.callback);
180 } 180 }
181 181
182 // Helper struct containing all the context needed to validate the [Initiator 182 // Helper struct containing all the context needed to validate the [Initiator
183 // Auth] message. 183 // Auth] message.
184 struct ValidateInitiatorAuthMessageContext { 184 struct ValidateInitiatorAuthMessageContext {
185 std::string persistent_symmetric_key; 185 std::string persistent_symmetric_key;
186 std::string responder_auth_message; 186 std::string responder_auth_message;
187 SecureMessageDelegate* secure_message_delegate; 187 cryptauth::SecureMessageDelegate* secure_message_delegate;
188 DeviceToDeviceResponderOperations::ValidationCallback callback; 188 DeviceToDeviceResponderOperations::ValidationCallback callback;
189 }; 189 };
190 190
191 // Called after the inner-most layer of [Initiator Auth] is unwrapped. 191 // Called after the inner-most layer of [Initiator Auth] is unwrapped.
192 void OnInnerMessageUnwrappedForInitiatorAuth( 192 void OnInnerMessageUnwrappedForInitiatorAuth(
193 const ValidateInitiatorAuthMessageContext& context, 193 const ValidateInitiatorAuthMessageContext& context,
194 bool verified, 194 bool verified,
195 const std::string& payload, 195 const std::string& payload,
196 const securemessage::Header& header) { 196 const securemessage::Header& header) {
197 if (!verified) 197 if (!verified)
(...skipping 16 matching lines...) Expand all
214 // Parse the decrypted payload. 214 // Parse the decrypted payload.
215 securemessage::DeviceToDeviceMessage device_to_device_message; 215 securemessage::DeviceToDeviceMessage device_to_device_message;
216 if (!device_to_device_message.ParseFromString(payload) || 216 if (!device_to_device_message.ParseFromString(payload) ||
217 device_to_device_message.sequence_number() != 2) { 217 device_to_device_message.sequence_number() != 2) {
218 PA_LOG(INFO) << "Failed to validate DeviceToDeviceMessage payload."; 218 PA_LOG(INFO) << "Failed to validate DeviceToDeviceMessage payload.";
219 context.callback.Run(false); 219 context.callback.Run(false);
220 return; 220 return;
221 } 221 }
222 222
223 // Unwrap the inner message of [Initiator Auth]. 223 // Unwrap the inner message of [Initiator Auth].
224 SecureMessageDelegate::UnwrapOptions unwrap_options; 224 cryptauth::SecureMessageDelegate::UnwrapOptions unwrap_options;
225 unwrap_options.encryption_scheme = securemessage::AES_256_CBC; 225 unwrap_options.encryption_scheme = securemessage::AES_256_CBC;
226 unwrap_options.signature_scheme = securemessage::HMAC_SHA256; 226 unwrap_options.signature_scheme = securemessage::HMAC_SHA256;
227 unwrap_options.associated_data = context.responder_auth_message; 227 unwrap_options.associated_data = context.responder_auth_message;
228 context.secure_message_delegate->UnwrapSecureMessage( 228 context.secure_message_delegate->UnwrapSecureMessage(
229 device_to_device_message.message(), context.persistent_symmetric_key, 229 device_to_device_message.message(), context.persistent_symmetric_key,
230 unwrap_options, 230 unwrap_options,
231 base::Bind(&OnInnerMessageUnwrappedForInitiatorAuth, context)); 231 base::Bind(&OnInnerMessageUnwrappedForInitiatorAuth, context));
232 } 232 }
233 233
234 } // namespace 234 } // namespace
235 235
236 // static 236 // static
237 void DeviceToDeviceResponderOperations::ValidateHelloMessage( 237 void DeviceToDeviceResponderOperations::ValidateHelloMessage(
238 const std::string& hello_message, 238 const std::string& hello_message,
239 const std::string& persistent_symmetric_key, 239 const std::string& persistent_symmetric_key,
240 SecureMessageDelegate* secure_message_delegate, 240 cryptauth::SecureMessageDelegate* secure_message_delegate,
241 const ValidateHelloCallback& callback) { 241 const ValidateHelloCallback& callback) {
242 // The [Hello] message has the structure: 242 // The [Hello] message has the structure:
243 // { 243 // {
244 // header: <session_public_key>, 244 // header: <session_public_key>,
245 // Sig(<session_public_key>, persistent_symmetric_key) 245 // Sig(<session_public_key>, persistent_symmetric_key)
246 // payload: "" 246 // payload: ""
247 // } 247 // }
248 SecureMessageDelegate::UnwrapOptions unwrap_options; 248 cryptauth::SecureMessageDelegate::UnwrapOptions unwrap_options;
249 unwrap_options.encryption_scheme = securemessage::NONE; 249 unwrap_options.encryption_scheme = securemessage::NONE;
250 unwrap_options.signature_scheme = securemessage::HMAC_SHA256; 250 unwrap_options.signature_scheme = securemessage::HMAC_SHA256;
251 secure_message_delegate->UnwrapSecureMessage( 251 secure_message_delegate->UnwrapSecureMessage(
252 hello_message, persistent_symmetric_key, unwrap_options, 252 hello_message, persistent_symmetric_key, unwrap_options,
253 base::Bind(&OnHelloMessageUnwrapped, callback)); 253 base::Bind(&OnHelloMessageUnwrapped, callback));
254 } 254 }
255 255
256 // static 256 // static
257 void DeviceToDeviceResponderOperations::CreateResponderAuthMessage( 257 void DeviceToDeviceResponderOperations::CreateResponderAuthMessage(
258 const std::string& hello_message, 258 const std::string& hello_message,
259 const std::string& session_public_key, 259 const std::string& session_public_key,
260 const std::string& session_private_key, 260 const std::string& session_private_key,
261 const std::string& persistent_private_key, 261 const std::string& persistent_private_key,
262 const std::string& persistent_symmetric_key, 262 const std::string& persistent_symmetric_key,
263 SecureMessageDelegate* secure_message_delegate, 263 cryptauth::SecureMessageDelegate* secure_message_delegate,
264 const MessageCallback& callback) { 264 const MessageCallback& callback) {
265 // The [Responder Auth] message has the structure: 265 // The [Responder Auth] message has the structure:
266 // { 266 // {
267 // header: <responder_public_key>, 267 // header: <responder_public_key>,
268 // Sig(<responder_public_key> + payload1, 268 // Sig(<responder_public_key> + payload1,
269 // session_symmetric_key), 269 // session_symmetric_key),
270 // payload1: Enc({ 270 // payload1: Enc({
271 // header: Sig(payload2 + <hello_message>, persistent_symmetric_key), 271 // header: Sig(payload2 + <hello_message>, persistent_symmetric_key),
272 // payload2: { 272 // payload2: {
273 // sequence_number: 1, 273 // sequence_number: 1,
(...skipping 19 matching lines...) Expand all
293 hello_message, persistent_symmetric_key, secure_message_delegate, 293 hello_message, persistent_symmetric_key, secure_message_delegate,
294 base::Bind(&OnHelloMessageValidatedForResponderAuth, context)); 294 base::Bind(&OnHelloMessageValidatedForResponderAuth, context));
295 } 295 }
296 296
297 // static 297 // static
298 void DeviceToDeviceResponderOperations::ValidateInitiatorAuthMessage( 298 void DeviceToDeviceResponderOperations::ValidateInitiatorAuthMessage(
299 const std::string& initiator_auth_message, 299 const std::string& initiator_auth_message,
300 const std::string& session_symmetric_key, 300 const std::string& session_symmetric_key,
301 const std::string& persistent_symmetric_key, 301 const std::string& persistent_symmetric_key,
302 const std::string& responder_auth_message, 302 const std::string& responder_auth_message,
303 SecureMessageDelegate* secure_message_delegate, 303 cryptauth::SecureMessageDelegate* secure_message_delegate,
304 const ValidationCallback& callback) { 304 const ValidationCallback& callback) {
305 // The [Initiator Auth] message has the structure: 305 // The [Initiator Auth] message has the structure:
306 // { 306 // {
307 // header: Sig(payload1, session_symmetric_key) 307 // header: Sig(payload1, session_symmetric_key)
308 // payload1: Enc({ 308 // payload1: Enc({
309 // sequence_number: 2, 309 // sequence_number: 2,
310 // body: { 310 // body: {
311 // header: Sig(payload2 + responder_auth_message, 311 // header: Sig(payload2 + responder_auth_message,
312 // persistent_symmetric_key) 312 // persistent_symmetric_key)
313 // payload2: "" 313 // payload2: ""
314 // } 314 // }
315 // }, session_symmetric_key) 315 // }, session_symmetric_key)
316 // } 316 // }
317 ValidateInitiatorAuthMessageContext context = { 317 ValidateInitiatorAuthMessageContext context = {
318 persistent_symmetric_key, responder_auth_message, secure_message_delegate, 318 persistent_symmetric_key, responder_auth_message, secure_message_delegate,
319 callback}; 319 callback};
320 320
321 SecureMessageDelegate::UnwrapOptions unwrap_options; 321 cryptauth::SecureMessageDelegate::UnwrapOptions unwrap_options;
322 unwrap_options.encryption_scheme = securemessage::AES_256_CBC; 322 unwrap_options.encryption_scheme = securemessage::AES_256_CBC;
323 unwrap_options.signature_scheme = securemessage::HMAC_SHA256; 323 unwrap_options.signature_scheme = securemessage::HMAC_SHA256;
324 secure_message_delegate->UnwrapSecureMessage( 324 secure_message_delegate->UnwrapSecureMessage(
325 initiator_auth_message, session_symmetric_key, unwrap_options, 325 initiator_auth_message, session_symmetric_key, unwrap_options,
326 base::Bind(&OnOuterMessageUnwrappedForInitiatorAuth, context)); 326 base::Bind(&OnOuterMessageUnwrappedForInitiatorAuth, context));
327 } 327 }
328 328
329 } // proximity_auth 329 } // proximity_auth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698