| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "remoting/host/verify_config_window_win.h" | 5 #include "remoting/host/verify_config_window_win.h" |
| 6 | 6 |
| 7 #include <atlbase.h> | 7 #include <atlbase.h> |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "remoting/host/elevated_controller_resource.h" | 14 #include "remoting/host/elevated_controller_resource.h" |
| 15 #include "remoting/host/pin_hash.h" |
| 15 #include "remoting/protocol/authentication_method.h" | 16 #include "remoting/protocol/authentication_method.h" |
| 16 | 17 |
| 17 namespace remoting { | 18 namespace remoting { |
| 18 | 19 |
| 19 VerifyConfigWindowWin::VerifyConfigWindowWin(const std::string& email, | 20 VerifyConfigWindowWin::VerifyConfigWindowWin(const std::string& email, |
| 20 const std::string& host_id, const std::string& host_secret_hash) | 21 const std::string& host_id, const std::string& host_secret_hash) |
| 21 : hwnd_(NULL), | 22 : hwnd_(NULL), |
| 22 email_(email), | 23 email_(email), |
| 23 host_id_(host_id), | 24 host_id_(host_id), |
| 24 host_secret_hash_(host_secret_hash) { | 25 host_secret_hash_(host_secret_hash) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 } | 111 } |
| 111 } | 112 } |
| 112 | 113 |
| 113 bool VerifyConfigWindowWin::VerifyHostSecretHash() { | 114 bool VerifyConfigWindowWin::VerifyHostSecretHash() { |
| 114 const int kMaxPinLength = 256; | 115 const int kMaxPinLength = 256; |
| 115 // TODO(simonmorris): Use ATL's string class, if it's more convenient. | 116 // TODO(simonmorris): Use ATL's string class, if it's more convenient. |
| 116 scoped_array<WCHAR> pinWSTR(new WCHAR[kMaxPinLength]); | 117 scoped_array<WCHAR> pinWSTR(new WCHAR[kMaxPinLength]); |
| 117 HWND hwndPin = GetDlgItem(hwnd_, IDC_PIN); | 118 HWND hwndPin = GetDlgItem(hwnd_, IDC_PIN); |
| 118 CHECK(hwndPin); | 119 CHECK(hwndPin); |
| 119 GetWindowText(hwndPin, pinWSTR.get(), kMaxPinLength); | 120 GetWindowText(hwndPin, pinWSTR.get(), kMaxPinLength); |
| 120 | |
| 121 // TODO(simonmorris): This code was copied from host_script_object.cc. | |
| 122 // Refactor to use PinIsValid(), from CL 10008092. | |
| 123 std::string pin(UTF16ToUTF8(pinWSTR.get())); | 121 std::string pin(UTF16ToUTF8(pinWSTR.get())); |
| 124 std::string hash = protocol::AuthenticationMethod::ApplyHashFunction( | 122 return VerifyHostPinHash(host_secret_hash_, host_id_, pin); |
| 125 protocol::AuthenticationMethod::HMAC_SHA256, host_id_, pin); | |
| 126 std::string hash_base64; | |
| 127 bool base64_result = base::Base64Encode(hash, &hash_base64); | |
| 128 if (!base64_result) { | |
| 129 LOG(FATAL) << "Base64Encode failed"; | |
| 130 return false; | |
| 131 } | |
| 132 hash_base64 = "hmac:" + hash_base64; | |
| 133 | |
| 134 return (hash_base64 == host_secret_hash_); | |
| 135 } | 123 } |
| 136 | 124 |
| 137 } // namespace remoting | 125 } // namespace remoting |
| OLD | NEW |