OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/extensions/api/gcd_private/privet_v3_session.h" | 5 #include "chrome/browser/extensions/api/gcd_private/privet_v3_session.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 // Key will be verified below, using HMAC. | 349 // Key will be verified below, using HMAC. |
350 const std::string& key = spake_->GetUnverifiedKey(); | 350 const std::string& key = spake_->GetUnverifiedKey(); |
351 if (!hmac.Init(reinterpret_cast<const unsigned char*>(key.c_str()), | 351 if (!hmac.Init(reinterpret_cast<const unsigned char*>(key.c_str()), |
352 key.size()) || | 352 key.size()) || |
353 !hmac.Verify(fingerprint, signature)) { | 353 !hmac.Verify(fingerprint, signature)) { |
354 LOG(ERROR) << "Verification failed: " << response; | 354 LOG(ERROR) << "Verification failed: " << response; |
355 return callback.Run(Result::STATUS_BADPAIRINGCODEERROR); | 355 return callback.Run(Result::STATUS_BADPAIRINGCODEERROR); |
356 } | 356 } |
357 | 357 |
358 std::string auth_code(hmac.DigestLength(), ' '); | 358 std::string auth_code(hmac.DigestLength(), ' '); |
359 if (!hmac.Sign(session_id_, | 359 if (!hmac.Sign(session_id_, reinterpret_cast<unsigned char*>( |
360 reinterpret_cast<unsigned char*>(string_as_array(&auth_code)), | 360 base::string_as_array(&auth_code)), |
361 auth_code.size())) { | 361 auth_code.size())) { |
362 LOG(FATAL) << "Signing failed"; | 362 LOG(FATAL) << "Signing failed"; |
363 return callback.Run(Result::STATUS_SESSIONERROR); | 363 return callback.Run(Result::STATUS_SESSIONERROR); |
364 } | 364 } |
365 | 365 |
366 VLOG(1) << "Expected certificate: " << fingerprint; | 366 VLOG(1) << "Expected certificate: " << fingerprint; |
367 context_getter_->AddPairedHost( | 367 context_getter_->AddPairedHost( |
368 host_port_.host(), hash, | 368 host_port_.host(), hash, |
369 base::Bind(&PrivetV3Session::OnPairedHostAddedToContext, | 369 base::Bind(&PrivetV3Session::OnPairedHostAddedToContext, |
370 weak_ptr_factory_.GetWeakPtr(), auth_code, callback)); | 370 weak_ptr_factory_.GetWeakPtr(), auth_code, callback)); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 // Only session with pairing in process needs to be canceled. Paired sessions | 507 // Only session with pairing in process needs to be canceled. Paired sessions |
508 // (in https mode) does not need to be canceled. | 508 // (in https mode) does not need to be canceled. |
509 if (session_id_.empty() || use_https_) | 509 if (session_id_.empty() || use_https_) |
510 return; | 510 return; |
511 base::DictionaryValue input; | 511 base::DictionaryValue input; |
512 input.SetString(kPrivetV3KeySessionId, session_id_); | 512 input.SetString(kPrivetV3KeySessionId, session_id_); |
513 StartPostRequest(kPrivetV3PairingCancelPath, input, MessageCallback()); | 513 StartPostRequest(kPrivetV3PairingCancelPath, input, MessageCallback()); |
514 } | 514 } |
515 | 515 |
516 } // namespace extensions | 516 } // namespace extensions |
OLD | NEW |