Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: remoting/host/verify_config_window_win.cc

Issue 10071025: [Chromoting] Make the Windows host controller ask the user to confirm host registration. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review. Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/host/verify_config_window_win.h ('k') | remoting/remoting.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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_instance;
23
24 namespace remoting {
25
26 VerifyConfigWindowWin::VerifyConfigWindowWin(const std::string& email,
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_instance, 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) {
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:
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");
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 // TODO(simonmorris): Use ATL's string class, if it's more convenient.
119 scoped_array<WCHAR> pinWSTR(new WCHAR[kMaxPinLength]);
120 HWND hwndPin = GetDlgItem(hwnd_, IDC_PIN);
121 CHECK(hwndPin);
122 GetWindowText(hwndPin, pinWSTR.get(), kMaxPinLength);
123
124 // TODO(simonmorris): This code was copied from host_script_object.cc.
125 // Refactor.
Wez 2012/04/12 22:06:28 See PinIsValid in lambroslambrou@'s CL 10008092.
simonmorris 2012/04/12 22:14:48 Duly noted.
126 std::string pin(UTF16ToUTF8(pinWSTR.get()));
127 std::string hash = protocol::AuthenticationMethod::ApplyHashFunction(
128 protocol::AuthenticationMethod::HMAC_SHA256, host_id_, pin);
129 std::string hash_base64;
130 bool base64_result = base::Base64Encode(hash, &hash_base64);
131 if (!base64_result) {
132 LOG(FATAL) << "Base64Encode failed";
133 }
134 hash_base64 = "hmac:" + hash_base64;
135
136 return (hash_base64 == host_secret_hash_);
137 }
138
139 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/verify_config_window_win.h ('k') | remoting/remoting.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698