Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "remoting/host/verify_config_window_win.h" | |
| 6 | |
| 7 #include <atlbase.h> | |
| 8 #include <windows.h> | |
| 9 | |
| 10 #include "base/base64.h" | |
| 11 #include "base/compiler_specific.h" | |
| 12 #include "base/logging.h" | |
| 13 #include "base/utf_string_conversions.h" | |
| 14 #include "remoting/host/elevated_controller_resource.h" | |
| 15 #include "remoting/protocol/authentication_method.h" | |
| 16 | |
| 17 namespace remoting { | |
| 18 | |
| 19 VerifyConfigWindowWin::VerifyConfigWindowWin(const std::string& email, | |
| 20 const std::string& host_id, const std::string& host_secret_hash) | |
| 21 : hwnd_(NULL), | |
| 22 email_(email), | |
| 23 host_id_(host_id), | |
| 24 host_secret_hash_(host_secret_hash) { | |
| 25 } | |
| 26 | |
| 27 VerifyConfigWindowWin::~VerifyConfigWindowWin() { | |
| 28 EndDialog(); | |
| 29 } | |
| 30 | |
| 31 bool VerifyConfigWindowWin::Run() { | |
| 32 // TODO(simonmorris): Provide a handle of a parent window for this dialog. | |
| 33 return (DialogBoxParam(ATL::_AtlBaseModule.GetModuleInstance(), | |
| 34 MAKEINTRESOURCE(IDD_VERIFY_CONFIG_DIALOG), | |
| 35 NULL, | |
| 36 (DLGPROC)DialogProc, | |
| 37 (LPARAM)this) != 0); | |
| 38 } | |
| 39 | |
| 40 BOOL CALLBACK VerifyConfigWindowWin::DialogProc(HWND hwnd, UINT msg, | |
| 41 WPARAM wParam, LPARAM lParam) { | |
| 42 VerifyConfigWindowWin* win = NULL; | |
| 43 if (msg == WM_INITDIALOG) { | |
| 44 win = reinterpret_cast<VerifyConfigWindowWin*>(lParam); | |
| 45 CHECK(win); | |
| 46 SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)win); | |
| 47 } else { | |
| 48 LONG_PTR lp = GetWindowLongPtr(hwnd, DWLP_USER); | |
| 49 win = reinterpret_cast<VerifyConfigWindowWin*>(lp); | |
| 50 } | |
| 51 if (win == NULL) | |
| 52 return FALSE; | |
| 53 return win->OnDialogMessage(hwnd, msg, wParam, lParam); | |
| 54 } | |
| 55 | |
| 56 BOOL VerifyConfigWindowWin::OnDialogMessage(HWND hwnd, UINT msg, | |
| 57 WPARAM wParam, LPARAM lParam) { | |
| 58 switch (msg) { | |
| 59 case WM_INITDIALOG: | |
| 60 hwnd_ = hwnd; | |
| 61 InitDialog(); | |
| 62 return TRUE; | |
| 63 case WM_DESTROY: | |
| 64 ::EndDialog(hwnd, 0); | |
| 65 case WM_COMMAND: | |
| 66 switch (LOWORD(wParam)) { | |
| 67 case IDOK: | |
| 68 ::EndDialog(hwnd, VerifyHostSecretHash()); | |
| 69 hwnd_ = NULL; | |
| 70 return TRUE; | |
| 71 case IDCANCEL: | |
| 72 ::EndDialog(hwnd, 0); | |
| 73 hwnd_ = NULL; | |
| 74 return TRUE; | |
| 75 } | |
| 76 } | |
| 77 return FALSE; | |
| 78 } | |
| 79 | |
| 80 void VerifyConfigWindowWin::InitDialog() { | |
| 81 // TODO(simonmorris): l10n. | |
| 82 SetWindowText(hwnd_, L"Chrome Remote Desktop"); | |
| 83 | |
| 84 HWND hwndOk = GetDlgItem(hwnd_, IDOK); | |
| 85 CHECK(hwndOk); | |
| 86 SetWindowText(hwndOk, L"OK"); | |
| 87 | |
| 88 HWND hwndCancel = GetDlgItem(hwnd_, IDCANCEL); | |
| 89 CHECK(hwndCancel); | |
| 90 SetWindowText(hwndCancel, L"Cancel"); | |
| 91 | |
| 92 HWND hwndMessage = GetDlgItem(hwnd_, IDC_MESSAGE); | |
| 93 CHECK(hwndMessage); | |
| 94 SetWindowText(hwndMessage, L"To confirm that your Chrome Remote Desktop " | |
| 95 L"should be accessible by this account, please enter your PIN below."); | |
| 96 | |
| 97 HWND hwndEmail = GetDlgItem(hwnd_, IDC_EMAIL); | |
| 98 CHECK(hwndEmail); | |
| 99 SetWindowText(hwndEmail, UTF8ToUTF16(email_).c_str()); | |
| 100 | |
| 101 HWND hwndPin = GetDlgItem(hwnd_, IDC_PIN); | |
| 102 CHECK(hwndPin); | |
| 103 SetFocus(hwndPin); | |
| 104 } | |
| 105 | |
| 106 void VerifyConfigWindowWin::EndDialog() { | |
| 107 if (hwnd_) { | |
| 108 ::EndDialog(hwnd_, 0); | |
| 109 hwnd_ = NULL; | |
| 110 } | |
| 111 } | |
| 112 | |
| 113 bool VerifyConfigWindowWin::VerifyHostSecretHash() { | |
| 114 const int kMaxPinLength = 256; | |
| 115 // TODO(simonmorris): Use ATL's string class, if it's more convenient. | |
| 116 scoped_array<WCHAR> pinWSTR(new WCHAR[kMaxPinLength]); | |
| 117 HWND hwndPin = GetDlgItem(hwnd_, IDC_PIN); | |
| 118 CHECK(hwndPin); | |
| 119 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. | |
|
Wez
2012/04/13 20:23:41
If you pass in the DictionaryValue containing the
| |
| 123 std::string pin(UTF16ToUTF8(pinWSTR.get())); | |
| 124 std::string hash = protocol::AuthenticationMethod::ApplyHashFunction( | |
| 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 } | |
| 136 | |
| 137 } // namespace remoting | |
| OLD | NEW |