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 <windows.h> | |
8 | |
9 #include "base/base64.h" | |
10 #include "base/compiler_specific.h" | |
11 #include "base/logging.h" | |
12 #include "base/utf_string_conversions.h" | |
13 #include "remoting/host/elevated_controller_resource.h" | |
14 #include "remoting/protocol/authentication_method.h" | |
15 // TODO(garykac): Lots of duplicated code in this file and | |
16 // disconnect_window_win.cc. These global floating windows are temporary so | |
17 // they should be deleted soon. If we need to expand this then we should | |
18 // create a class with the shared code. | |
19 | |
20 // HINSTANCE from WinMain. This is needed to find our dialog resource. | |
21 // This is defined in elevated_controller_module_win.cc | |
22 extern HINSTANCE g_hInstance; | |
23 | |
24 namespace remoting { | |
25 | |
26 VerifyConfigWindowWin::VerifyConfigWindowWin(const std::string& email, | |
alexeypa (please no reviews)
2012/04/12 21:20:41
Broken indentation
simonmorris
2012/04/12 22:11:44
Done.
| |
27 const std::string& host_id, const std::string& host_secret_hash) | |
28 : hwnd_(NULL), | |
29 email_(email), | |
30 host_id_(host_id), | |
31 host_secret_hash_(host_secret_hash) { | |
32 } | |
33 | |
34 VerifyConfigWindowWin::~VerifyConfigWindowWin() { | |
35 EndDialog(); | |
36 } | |
37 | |
38 int VerifyConfigWindowWin::Run() { | |
39 return DialogBoxParam(g_hInstance, MAKEINTRESOURCE(IDD_VERIFY_CONFIG_DIALOG), | |
40 NULL, (DLGPROC)DialogProc, (LPARAM)this); | |
41 } | |
42 | |
43 BOOL CALLBACK VerifyConfigWindowWin::DialogProc(HWND hwnd, UINT msg, | |
44 WPARAM wParam, LPARAM lParam) { | |
45 VerifyConfigWindowWin* win = NULL; | |
46 if (msg == WM_INITDIALOG) { | |
alexeypa (please no reviews)
2012/04/12 21:20:41
Using dialog classes from ATL should help you to g
simonmorris
2012/04/12 22:11:44
I've added a TODO to the header file. Given the ti
| |
47 win = reinterpret_cast<VerifyConfigWindowWin*>(lParam); | |
48 CHECK(win); | |
49 SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)win); | |
50 } else { | |
51 LONG_PTR lp = GetWindowLongPtr(hwnd, DWLP_USER); | |
52 win = reinterpret_cast<VerifyConfigWindowWin*>(lp); | |
53 } | |
54 if (win == NULL) | |
55 return FALSE; | |
56 return win->OnDialogMessage(hwnd, msg, wParam, lParam); | |
57 } | |
58 | |
59 BOOL VerifyConfigWindowWin::OnDialogMessage(HWND hwnd, UINT msg, | |
60 WPARAM wParam, LPARAM lParam) { | |
61 switch (msg) { | |
62 case WM_INITDIALOG: | |
alexeypa (please no reviews)
2012/04/12 21:20:41
It can be much more readable ATL message handles m
simonmorris
2012/04/12 22:11:44
Added a TODO.
| |
63 hwnd_ = hwnd; | |
64 InitDialog(); | |
65 return TRUE; | |
66 case WM_DESTROY: | |
67 ::EndDialog(hwnd, 0); | |
68 case WM_COMMAND: | |
69 switch (LOWORD(wParam)) { | |
70 case IDOK: | |
71 ::EndDialog(hwnd, VerifyHostSecretHash()); | |
72 hwnd_ = NULL; | |
73 return TRUE; | |
74 case IDCANCEL: | |
75 ::EndDialog(hwnd, 0); | |
76 hwnd_ = NULL; | |
77 return TRUE; | |
78 } | |
79 } | |
80 return FALSE; | |
81 } | |
82 | |
83 void VerifyConfigWindowWin::InitDialog() { | |
84 // TODO(simonmorris): Get these strings from the host, for l10n. | |
85 SetWindowText(hwnd_, L"Chrome Remote Desktop"); | |
alexeypa (please no reviews)
2012/04/12 21:20:41
Why are we doing this? Shouldn't this come from th
simonmorris
2012/04/12 22:11:44
The string code here is only intended to be good e
| |
86 | |
87 HWND hwndOk = GetDlgItem(hwnd_, IDOK); | |
88 CHECK(hwndOk); | |
89 SetWindowText(hwndOk, L"OK"); | |
90 | |
91 HWND hwndCancel = GetDlgItem(hwnd_, IDCANCEL); | |
92 CHECK(hwndCancel); | |
93 SetWindowText(hwndCancel, L"Cancel"); | |
94 | |
95 HWND hwndMessage = GetDlgItem(hwnd_, IDC_MESSAGE); | |
96 CHECK(hwndMessage); | |
97 SetWindowText(hwndMessage, L"To confirm that your Chrome Remote Desktop " | |
98 L"should be accessible by this account, please enter your PIN below."); | |
99 | |
100 HWND hwndEmail = GetDlgItem(hwnd_, IDC_EMAIL); | |
101 CHECK(hwndEmail); | |
102 SetWindowText(hwndEmail, UTF8ToUTF16(email_).c_str()); | |
103 | |
104 HWND hwndPin = GetDlgItem(hwnd_, IDC_PIN); | |
105 CHECK(hwndPin); | |
106 SetFocus(hwndPin); | |
107 } | |
108 | |
109 void VerifyConfigWindowWin::EndDialog() { | |
110 if (hwnd_) { | |
111 ::EndDialog(hwnd_, 0); | |
112 hwnd_ = NULL; | |
113 } | |
114 } | |
115 | |
116 bool VerifyConfigWindowWin::VerifyHostSecretHash() { | |
117 const int kMaxPinLength = 256; | |
118 scoped_array<WCHAR> pinWSTR(new WCHAR[kMaxPinLength]); | |
alexeypa (please no reviews)
2012/04/12 21:20:41
ATL has a string class which will be more convenie
simonmorris
2012/04/12 22:11:44
Added a TODO.
| |
119 HWND hwndPin = GetDlgItem(hwnd_, IDC_PIN); | |
120 CHECK(hwndPin); | |
121 GetWindowText(hwndPin, pinWSTR.get(), kMaxPinLength); | |
122 | |
123 // TODO(simonmorris): This code was copied from host_script_object.cc. | |
124 // Refactor. | |
125 std::string pin(UTF16ToUTF8(pinWSTR.get())); | |
126 std::string hash = protocol::AuthenticationMethod::ApplyHashFunction( | |
127 protocol::AuthenticationMethod::HMAC_SHA256, host_id_, pin); | |
128 std::string hash_base64; | |
129 bool base64_result = base::Base64Encode(hash, &hash_base64); | |
130 if (!base64_result) { | |
131 LOG(FATAL) << "Base64Encode failed"; | |
132 } | |
133 hash_base64 = "hmac:" + hash_base64; | |
134 | |
135 return (hash_base64 == host_secret_hash_); | |
136 } | |
137 | |
138 } // namespace remoting | |
OLD | NEW |