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 #import "remoting/host/mac/me2me_preference_pane.h" | 5 #import "remoting/host/mac/me2me_preference_pane.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 #include <CommonCrypto/CommonHMAC.h> | 8 #include <CommonCrypto/CommonHMAC.h> |
9 #include <errno.h> | 9 #include <errno.h> |
10 #include <launch.h> | 10 #include <launch.h> |
11 #import <PreferencePanes/PreferencePanes.h> | 11 #import <PreferencePanes/PreferencePanes.h> |
12 #import <SecurityInterface/SFAuthorizationView.h> | 12 #import <SecurityInterface/SFAuthorizationView.h> |
13 #include <stddef.h> | 13 #include <stddef.h> |
14 #include <stdlib.h> | 14 #include <stdlib.h> |
15 #include <unistd.h> | 15 #include <unistd.h> |
16 | 16 |
17 #include <fstream> | 17 #include <fstream> |
18 | 18 |
19 #include "base/mac/scoped_launch_data.h" | 19 #include "base/mac/scoped_launch_data.h" |
20 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
21 #include "base/posix/eintr_wrapper.h" | 21 #include "base/posix/eintr_wrapper.h" |
22 #include "remoting/host/constants_mac.h" | 22 #include "remoting/host/constants_mac.h" |
23 #include "remoting/host/host_config.h" | 23 #include "remoting/host/host_config.h" |
24 #include "remoting/host/pin_hash.h" | |
24 #import "remoting/host/mac/me2me_preference_pane_confirm_pin.h" | 25 #import "remoting/host/mac/me2me_preference_pane_confirm_pin.h" |
25 #import "remoting/host/mac/me2me_preference_pane_disable.h" | 26 #import "remoting/host/mac/me2me_preference_pane_disable.h" |
26 #include "third_party/jsoncpp/source/include/json/reader.h" | 27 #include "third_party/jsoncpp/source/include/json/reader.h" |
27 #include "third_party/jsoncpp/source/include/json/writer.h" | 28 #include "third_party/jsoncpp/source/include/json/writer.h" |
28 #include "third_party/modp_b64/modp_b64.h" | |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
32 bool GetTemporaryConfigFilePath(std::string* path) { | 32 bool GetTemporaryConfigFilePath(std::string* path) { |
33 NSString* filename = NSTemporaryDirectory(); | 33 NSString* filename = NSTemporaryDirectory(); |
34 if (filename == nil) | 34 if (filename == nil) |
35 return false; | 35 return false; |
36 | 36 |
37 *path = [[NSString stringWithFormat:@"%@/%s", | 37 *path = [[NSString stringWithFormat:@"%@/%s", |
38 filename, remoting::kHostConfigFileName] UTF8String]; | 38 filename, remoting::kHostConfigFileName] UTF8String]; |
39 return true; | 39 return true; |
40 } | 40 } |
41 | 41 |
42 bool IsConfigValid(const remoting::JsonHostConfig* config) { | 42 bool IsConfigValid(const remoting::JsonHostConfig* config) { |
43 std::string value; | 43 std::string value; |
44 return (config->GetString(remoting::kHostIdConfigPath, &value) && | 44 return (config->GetString(remoting::kHostIdConfigPath, &value) && |
45 config->GetString(remoting::kHostSecretHashConfigPath, &value) && | 45 config->GetString(remoting::kHostSecretHashConfigPath, &value) && |
46 config->GetString(remoting::kXmppLoginConfigPath, &value)); | 46 config->GetString(remoting::kXmppLoginConfigPath, &value)); |
47 } | 47 } |
48 | 48 |
49 bool IsPinValid(const std::string& pin, const std::string& host_id, | |
50 const std::string& host_secret_hash) { | |
51 // TODO(lambroslambrou): Once the "base" target supports building for 64-bit | |
52 // on Mac OS X, remove this code and replace it with |VerifyHostPinHash()| | |
53 // from host/pin_hash.h. | |
54 size_t separator = host_secret_hash.find(':'); | |
55 if (separator == std::string::npos) | |
56 return false; | |
57 | |
58 std::string method = host_secret_hash.substr(0, separator); | |
59 if (method != "hmac") { | |
60 NSLog(@"Authentication method '%s' not supported", method.c_str()); | |
61 return false; | |
62 } | |
63 | |
64 std::string hash_base64 = host_secret_hash.substr(separator + 1); | |
65 | |
66 // Convert |hash_base64| to |hash|, based on code from base/base64.cc. | |
67 int hash_base64_size = static_cast<int>(hash_base64.size()); | |
68 std::string hash; | |
69 hash.resize(modp_b64_decode_len(hash_base64_size)); | |
70 | |
71 // modp_b64_decode_len() returns at least 1, so hash[0] is safe here. | |
72 int hash_size = modp_b64_decode(&(hash[0]), hash_base64.data(), | |
73 hash_base64_size); | |
74 if (hash_size < 0) { | |
75 NSLog(@"Failed to parse host_secret_hash"); | |
76 return false; | |
77 } | |
78 hash.resize(hash_size); | |
79 | |
80 std::string computed_hash; | |
81 computed_hash.resize(CC_SHA256_DIGEST_LENGTH); | |
82 | |
83 CCHmac(kCCHmacAlgSHA256, | |
84 host_id.data(), host_id.size(), | |
85 pin.data(), pin.size(), | |
86 &(computed_hash[0])); | |
87 | |
88 // Normally, a constant-time comparison function would be used, but it is | |
89 // unnecessary here as the "secret" is already readable by the user | |
90 // supplying input to this routine. | |
91 return computed_hash == hash; | |
92 } | |
93 | |
94 } // namespace | 49 } // namespace |
95 | 50 |
96 // These methods are copied from base/mac, but with the logging changed to use | 51 // These methods are copied from base/mac, but with the logging changed to use |
97 // NSLog(). | 52 // NSLog(). |
98 // | 53 // |
99 // TODO(lambroslambrou): Once the "base" target supports building for 64-bit | 54 // TODO(lambroslambrou): Once the "base" target supports building for 64-bit |
100 // on Mac OS X, remove these implementations and use the ones in base/mac. | 55 // on Mac OS X, remove these implementations and use the ones in base/mac. |
101 namespace base { | 56 namespace base { |
102 namespace mac { | 57 namespace mac { |
103 | 58 |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
334 | 289 |
335 std::string pin_utf8 = [pin UTF8String]; | 290 std::string pin_utf8 = [pin UTF8String]; |
336 std::string host_id, host_secret_hash; | 291 std::string host_id, host_secret_hash; |
337 bool result = (config_->GetString(remoting::kHostIdConfigPath, &host_id) && | 292 bool result = (config_->GetString(remoting::kHostIdConfigPath, &host_id) && |
338 config_->GetString(remoting::kHostSecretHashConfigPath, | 293 config_->GetString(remoting::kHostSecretHashConfigPath, |
339 &host_secret_hash)); | 294 &host_secret_hash)); |
340 if (!result) { | 295 if (!result) { |
341 [self showError]; | 296 [self showError]; |
342 return; | 297 return; |
343 } | 298 } |
344 if (!IsPinValid(pin_utf8, host_id, host_secret_hash)) { | 299 if (!remoting::VerifyHostPinHash(pin_utf8, host_id, host_secret_hash)) { |
nicholss
2016/02/03 22:33:45
The arguments are flipped here. I will have a CL t
| |
345 [self showIncorrectPinMessage]; | 300 [self showIncorrectPinMessage]; |
346 return; | 301 return; |
347 } | 302 } |
348 | 303 |
349 [self applyNewServiceConfig]; | 304 [self applyNewServiceConfig]; |
350 [self updateUI]; | 305 [self updateUI]; |
351 } | 306 } |
352 | 307 |
353 - (void)onDisable:(id)sender { | 308 - (void)onDisable:(id)sender { |
354 // Ensure the authorization token is up-to-date before using it. | 309 // Ensure the authorization token is up-to-date before using it. |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
754 NSArray* arguments = [NSArray arrayWithObjects:@"--relaunch-prefpane", nil]; | 709 NSArray* arguments = [NSArray arrayWithObjects:@"--relaunch-prefpane", nil]; |
755 [task setLaunchPath:command]; | 710 [task setLaunchPath:command]; |
756 [task setArguments:arguments]; | 711 [task setArguments:arguments]; |
757 [task setStandardInput:[NSPipe pipe]]; | 712 [task setStandardInput:[NSPipe pipe]]; |
758 [task launch]; | 713 [task launch]; |
759 [task release]; | 714 [task release]; |
760 [NSApp terminate:nil]; | 715 [NSApp terminate:nil]; |
761 } | 716 } |
762 | 717 |
763 @end | 718 @end |
OLD | NEW |