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 // TODO(garykac): Lots of duplicated code in this file and | |
17 // disconnect_window_win.cc. These global floating windows are temporary so | |
18 // they should be deleted soon. If we need to expand this then we should | |
19 // create a class with the shared code. | |
Jamie
2012/04/13 16:40:03
Is this comment still true?
simonmorris
2012/04/13 16:48:03
No: the aim is now to use ATL instead.
Done.
| |
20 | |
21 namespace remoting { | |
22 | |
23 VerifyConfigWindowWin::VerifyConfigWindowWin(const std::string& email, | |
24 const std::string& host_id, const std::string& host_secret_hash) | |
25 : hwnd_(NULL), | |
26 email_(email), | |
27 host_id_(host_id), | |
28 host_secret_hash_(host_secret_hash) { | |
29 } | |
30 | |
31 VerifyConfigWindowWin::~VerifyConfigWindowWin() { | |
32 EndDialog(); | |
33 } | |
34 | |
35 int VerifyConfigWindowWin::Run() { | |
36 // TODO(simonmorris): Provide a handle of a parent window for this dialog. | |
37 return DialogBoxParam(ATL::_AtlBaseModule.GetModuleInstance(), | |
38 MAKEINTRESOURCE(IDD_VERIFY_CONFIG_DIALOG), | |
39 NULL, | |
40 (DLGPROC)DialogProc, | |
41 (LPARAM)this); | |
42 } | |
43 | |
44 BOOL CALLBACK VerifyConfigWindowWin::DialogProc(HWND hwnd, UINT msg, | |
45 WPARAM wParam, LPARAM lParam) { | |
46 VerifyConfigWindowWin* win = NULL; | |
47 if (msg == WM_INITDIALOG) { | |
48 win = reinterpret_cast<VerifyConfigWindowWin*>(lParam); | |
49 CHECK(win); | |
50 SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)win); | |
51 } else { | |
52 LONG_PTR lp = GetWindowLongPtr(hwnd, DWLP_USER); | |
53 win = reinterpret_cast<VerifyConfigWindowWin*>(lp); | |
54 } | |
55 if (win == NULL) | |
56 return FALSE; | |
57 return win->OnDialogMessage(hwnd, msg, wParam, lParam); | |
58 } | |
59 | |
60 BOOL VerifyConfigWindowWin::OnDialogMessage(HWND hwnd, UINT msg, | |
61 WPARAM wParam, LPARAM lParam) { | |
62 switch (msg) { | |
63 case WM_INITDIALOG: | |
64 hwnd_ = hwnd; | |
65 InitDialog(); | |
66 return TRUE; | |
67 case WM_DESTROY: | |
68 ::EndDialog(hwnd, 0); | |
69 case WM_COMMAND: | |
70 switch (LOWORD(wParam)) { | |
71 case IDOK: | |
72 ::EndDialog(hwnd, VerifyHostSecretHash()); | |
73 hwnd_ = NULL; | |
74 return TRUE; | |
75 case IDCANCEL: | |
76 ::EndDialog(hwnd, 0); | |
77 hwnd_ = NULL; | |
78 return TRUE; | |
79 } | |
80 } | |
81 return FALSE; | |
82 } | |
83 | |
84 void VerifyConfigWindowWin::InitDialog() { | |
85 // TODO(simonmorris): Get these strings from the host, for l10n. | |
Jamie
2012/04/13 16:40:03
We'll need to do something for l10n, but getting t
simonmorris
2012/04/13 16:48:03
Done.
| |
86 SetWindowText(hwnd_, L"Chrome Remote Desktop"); | |
87 | |
88 HWND hwndOk = GetDlgItem(hwnd_, IDOK); | |
89 CHECK(hwndOk); | |
90 SetWindowText(hwndOk, L"OK"); | |
91 | |
92 HWND hwndCancel = GetDlgItem(hwnd_, IDCANCEL); | |
93 CHECK(hwndCancel); | |
94 SetWindowText(hwndCancel, L"Cancel"); | |
95 | |
96 HWND hwndMessage = GetDlgItem(hwnd_, IDC_MESSAGE); | |
97 CHECK(hwndMessage); | |
98 SetWindowText(hwndMessage, L"To confirm that your Chrome Remote Desktop " | |
99 L"should be accessible by this account, please enter your PIN below."); | |
100 | |
101 HWND hwndEmail = GetDlgItem(hwnd_, IDC_EMAIL); | |
102 CHECK(hwndEmail); | |
103 SetWindowText(hwndEmail, UTF8ToUTF16(email_).c_str()); | |
104 | |
105 HWND hwndPin = GetDlgItem(hwnd_, IDC_PIN); | |
106 CHECK(hwndPin); | |
107 SetFocus(hwndPin); | |
108 } | |
109 | |
110 void VerifyConfigWindowWin::EndDialog() { | |
111 if (hwnd_) { | |
112 ::EndDialog(hwnd_, 0); | |
113 hwnd_ = NULL; | |
114 } | |
115 } | |
116 | |
117 bool VerifyConfigWindowWin::VerifyHostSecretHash() { | |
118 const int kMaxPinLength = 256; | |
119 // TODO(simonmorris): Use ATL's string class, if it's more convenient. | |
120 scoped_array<WCHAR> pinWSTR(new WCHAR[kMaxPinLength]); | |
121 HWND hwndPin = GetDlgItem(hwnd_, IDC_PIN); | |
122 CHECK(hwndPin); | |
123 GetWindowText(hwndPin, pinWSTR.get(), kMaxPinLength); | |
124 | |
125 // TODO(simonmorris): This code was copied from host_script_object.cc. | |
126 // Refactor to use PinIsValid(), from CL 10008092. | |
127 std::string pin(UTF16ToUTF8(pinWSTR.get())); | |
128 std::string hash = protocol::AuthenticationMethod::ApplyHashFunction( | |
129 protocol::AuthenticationMethod::HMAC_SHA256, host_id_, pin); | |
130 std::string hash_base64; | |
131 bool base64_result = base::Base64Encode(hash, &hash_base64); | |
132 if (!base64_result) { | |
133 LOG(FATAL) << "Base64Encode failed"; | |
Jamie
2012/04/13 16:40:03
I think a "return false" here would help readabili
simonmorris
2012/04/13 16:48:03
Done.
| |
134 } | |
135 hash_base64 = "hmac:" + hash_base64; | |
136 | |
137 return (hash_base64 == host_secret_hash_); | |
138 } | |
139 | |
140 } // namespace remoting | |
OLD | NEW |