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

Side by Side Diff: remoting/host/me2me_preference_pane.mm

Issue 10384140: Use system crypto in pref-pane IsPinValid() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix DEPS Created 8 years, 7 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/DEPS ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/me2me_preference_pane.h" 5 #import "remoting/host/me2me_preference_pane.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 #include <CommonCrypto/CommonHMAC.h>
8 #include <launch.h> 9 #include <launch.h>
9 #import <PreferencePanes/PreferencePanes.h> 10 #import <PreferencePanes/PreferencePanes.h>
10 #import <SecurityInterface/SFAuthorizationView.h> 11 #import <SecurityInterface/SFAuthorizationView.h>
11 12
12 #include "base/eintr_wrapper.h" 13 #include "base/eintr_wrapper.h"
13 #include "base/file_path.h" 14 #include "base/file_path.h"
14 #include "base/file_util.h" 15 #include "base/file_util.h"
15 #include "base/logging.h" 16 #include "base/logging.h"
16 #include "base/mac/authorization_util.h" 17 #include "base/mac/authorization_util.h"
17 #include "base/mac/foundation_util.h" 18 #include "base/mac/foundation_util.h"
18 #include "base/mac/launchd.h" 19 #include "base/mac/launchd.h"
19 #include "base/mac/mac_logging.h" 20 #include "base/mac/mac_logging.h"
20 #include "base/mac/scoped_launch_data.h" 21 #include "base/mac/scoped_launch_data.h"
21 #include "base/memory/scoped_ptr.h" 22 #include "base/memory/scoped_ptr.h"
22 #include "base/stringprintf.h" 23 #include "base/stringprintf.h"
23 #include "base/sys_string_conversions.h" 24 #include "base/sys_string_conversions.h"
24 #include "remoting/host/host_config.h" 25 #include "remoting/host/host_config.h"
25 #include "remoting/host/json_host_config.h" 26 #include "remoting/host/json_host_config.h"
26 #include "remoting/protocol/me2me_host_authenticator_factory.h" 27 #include "third_party/modp_b64/modp_b64.h"
27 28
28 namespace { 29 namespace {
29 // The name of the Remoting Host service that is registered with launchd. 30 // The name of the Remoting Host service that is registered with launchd.
30 #define kServiceName "org.chromium.chromoting" 31 #define kServiceName "org.chromium.chromoting"
31 #define kConfigDir "/Library/PrivilegedHelperTools/" 32 #define kConfigDir "/Library/PrivilegedHelperTools/"
32 33
33 // This helper script is executed as root. It is passed a command-line option 34 // This helper script is executed as root. It is passed a command-line option
34 // (--enable or --disable), which causes it to create or remove a file that 35 // (--enable or --disable), which causes it to create or remove a file that
35 // informs the host's launch script of whether the host is enabled or disabled. 36 // informs the host's launch script of whether the host is enabled or disabled.
36 const char kHelperTool[] = kConfigDir kServiceName ".me2me.sh"; 37 const char kHelperTool[] = kConfigDir kServiceName ".me2me.sh";
37 38
38 bool GetTemporaryConfigFilePath(FilePath* path) { 39 bool GetTemporaryConfigFilePath(FilePath* path) {
39 if (!file_util::GetTempDir(path)) 40 if (!file_util::GetTempDir(path))
40 return false; 41 return false;
41 *path = path->Append(kServiceName ".json"); 42 *path = path->Append(kServiceName ".json");
42 return true; 43 return true;
43 } 44 }
44 45
45 bool IsConfigValid(const remoting::JsonHostConfig* config) { 46 bool IsConfigValid(const remoting::JsonHostConfig* config) {
46 std::string value; 47 std::string value;
47 return (config->GetString(remoting::kHostIdConfigPath, &value) && 48 return (config->GetString(remoting::kHostIdConfigPath, &value) &&
48 config->GetString(remoting::kHostSecretHashConfigPath, &value) && 49 config->GetString(remoting::kHostSecretHashConfigPath, &value) &&
49 config->GetString(remoting::kXmppLoginConfigPath, &value)); 50 config->GetString(remoting::kXmppLoginConfigPath, &value));
50 } 51 }
51 52
52 bool IsPinValid(const std::string& pin, const std::string& host_id, 53 bool IsPinValid(const std::string& pin, const std::string& host_id,
53 const std::string& host_secret_hash) { 54 const std::string& host_secret_hash) {
54 remoting::protocol::SharedSecretHash hash; 55 // TODO(lambroslambrou): Once the "base" target supports building for 64-bit
55 if (!hash.Parse(host_secret_hash)) { 56 // on Mac OS X, remove this code and replace it with |VerifyHostPinHash()|
56 LOG(ERROR) << "Invalid host_secret_hash."; 57 // from host/pin_hash.h.
58 size_t separator = host_secret_hash.find(':');
59 if (separator == std::string::npos)
60 return false;
61
62 std::string method = host_secret_hash.substr(0, separator);
63 if (method != "hmac") {
64 LOG(ERROR) << "Authentication method '" << method << "' not supported";
57 return false; 65 return false;
58 } 66 }
59 std::string result = 67
60 remoting::protocol::AuthenticationMethod::ApplyHashFunction( 68 std::string hash_base64 = host_secret_hash.substr(separator + 1);
61 hash.hash_function, host_id, pin); 69
62 return result == hash.value; 70 // Convert |hash_base64| to |hash|, based on code from base/base64.cc.
71 int hash_base64_size = static_cast<int>(hash_base64.size());
72 std::string hash;
73 hash.resize(modp_b64_decode_len(hash_base64_size));
Ryan Sleevi 2012/05/16 03:10:34 Security? You don't check if hash.empty() before a
Lambros 2012/05/16 18:48:57 Ah, good point! I lifted this from base/base64.cc
Ryan Sleevi 2012/05/16 19:26:14 Ah, looks like modp_b64_decode_len will always ret
Wez 2012/05/16 20:09:27 Sufficiently subtle that a short comment to explai
74 int hash_size = modp_b64_decode(&(hash[0]), hash_base64.data(),
75 hash_base64_size);
76 if (hash_size < 0) {
77 LOG(ERROR) << "Failed to parse host_secret_hash";
78 return false;
79 }
80 hash.resize(hash_size);
81
82 std::string computed_hash;
83 computed_hash.resize(CC_SHA256_DIGEST_LENGTH);
84
85 CCHmac(kCCHmacAlgSHA256,
86 host_id.data(), host_id.size(),
87 pin.data(), pin.size(),
88 &(computed_hash[0]));
89
90 return computed_hash == hash;
Ryan Sleevi 2012/05/16 03:10:34 Security? This is not a constant time comparison,
Lambros 2012/05/16 18:48:57 Thanks. At the moment, the hash is already readab
Ryan Sleevi 2012/05/16 19:26:14 Nope, should be fine then.
Wez 2012/05/16 20:09:27 Again, as discussed offline, a short comment to ex
63 } 91 }
64 92
65 } // namespace 93 } // namespace
66 94
67 95
68 @implementation Me2MePreferencePane 96 @implementation Me2MePreferencePane
69 97
70 - (void)mainViewDidLoad { 98 - (void)mainViewDidLoad {
71 [authorization_view_ setDelegate:self]; 99 [authorization_view_ setDelegate:self];
72 [authorization_view_ setString:kAuthorizationRightExecute]; 100 [authorization_view_ setString:kAuthorizationRightExecute];
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 int error = launch_data_get_errno(response.get()); 422 int error = launch_data_get_errno(response.get());
395 if (error) { 423 if (error) {
396 LOG(ERROR) << "launchd returned error: " << error; 424 LOG(ERROR) << "launchd returned error: " << error;
397 [self showError]; 425 [self showError];
398 return NO; 426 return NO;
399 } 427 }
400 return YES; 428 return YES;
401 } 429 }
402 430
403 @end 431 @end
OLDNEW
« no previous file with comments | « remoting/host/DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698