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

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: 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 | « no previous file | 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 size_t separator = host_secret_hash.find(':');
Jamie 2012/05/14 17:37:49 Would it be possible to define a local class with
Lambros 2012/05/14 19:58:34 The SharedSecretHash/AuthenticationMethod interfac
55 if (!hash.Parse(host_secret_hash)) { 56 if (separator == std::string::npos)
56 LOG(ERROR) << "Invalid host_secret_hash."; 57 return false;
58
59 std::string method = host_secret_hash.substr(0, separator);
60 if (method != "hmac") {
61 LOG(ERROR) << "Authentication method '" << method << "' not supported";
57 return false; 62 return false;
58 } 63 }
59 std::string result = 64
60 remoting::protocol::AuthenticationMethod::ApplyHashFunction( 65 std::string hash_base64 = host_secret_hash.substr(separator + 1);
61 hash.hash_function, host_id, pin); 66
62 return result == hash.value; 67 // Convert |hash_base64| to |hash|, based on code from base/base64.cc.
68 int hash_base64_size = static_cast<int>(hash_base64.size());
69 std::string hash;
70 hash.resize(modp_b64_decode_len(hash_base64_size));
71 int hash_size = modp_b64_decode(&(hash[0]), hash_base64.data(),
72 hash_base64_size);
73 if (hash_size < 0) {
74 LOG(ERROR) << "Failed to parse host_secret_hash";
75 return false;
76 }
77 hash.resize(hash_size);
78
79 std::string computed_hash;
80 computed_hash.resize(32);
dcaiafa 2012/05/14 15:04:43 s/32/CC_SHA256_DIGEST_LENGTH/
Lambros 2012/05/14 19:58:34 Thanks for that! Done.
81
82 CCHmac(kCCHmacAlgSHA256,
83 host_id.data(), host_id.size(),
84 pin.data(), pin.size(),
85 &(computed_hash[0]));
86
87 return computed_hash == hash;
63 } 88 }
64 89
65 } // namespace 90 } // namespace
66 91
67 92
68 @implementation Me2MePreferencePane 93 @implementation Me2MePreferencePane
69 94
70 - (void)mainViewDidLoad { 95 - (void)mainViewDidLoad {
71 [authorization_view_ setDelegate:self]; 96 [authorization_view_ setDelegate:self];
72 [authorization_view_ setString:kAuthorizationRightExecute]; 97 [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()); 419 int error = launch_data_get_errno(response.get());
395 if (error) { 420 if (error) {
396 LOG(ERROR) << "launchd returned error: " << error; 421 LOG(ERROR) << "launchd returned error: " << error;
397 [self showError]; 422 [self showError];
398 return NO; 423 return NO;
399 } 424 }
400 return YES; 425 return YES;
401 } 426 }
402 427
403 @end 428 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698