| 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/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 <CommonCrypto/CommonHMAC.h> |
| 9 #include <launch.h> | 9 #include <launch.h> |
| 10 #import <PreferencePanes/PreferencePanes.h> | 10 #import <PreferencePanes/PreferencePanes.h> |
| 11 #import <SecurityInterface/SFAuthorizationView.h> | 11 #import <SecurityInterface/SFAuthorizationView.h> |
| 12 #include <unistd.h> | 12 #include <unistd.h> |
| 13 | 13 |
| 14 #include <fstream> | 14 #include <fstream> |
| 15 | 15 |
| 16 #include "base/eintr_wrapper.h" | 16 #include "base/eintr_wrapper.h" |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/mac/authorization_util.h" | 18 #include "base/mac/authorization_util.h" |
| 19 #include "base/mac/foundation_util.h" | 19 #include "base/mac/foundation_util.h" |
| 20 #include "base/mac/launchd.h" | 20 #include "base/mac/launchd.h" |
| 21 #include "base/mac/mac_logging.h" | 21 #include "base/mac/mac_logging.h" |
| 22 #include "base/mac/scoped_launch_data.h" | 22 #include "base/mac/scoped_launch_data.h" |
| 23 #include "base/memory/scoped_ptr.h" | 23 #include "base/memory/scoped_ptr.h" |
| 24 #include "base/stringprintf.h" | 24 #include "base/stringprintf.h" |
| 25 #include "base/sys_string_conversions.h" | 25 #include "base/sys_string_conversions.h" |
| 26 #include "remoting/host/host_config.h" | 26 #include "remoting/host/host_config.h" |
| 27 #import "remoting/host/me2me_preference_pane_confirm_pin.h" |
| 28 #import "remoting/host/me2me_preference_pane_disable.h" |
| 27 #include "third_party/jsoncpp/source/include/json/reader.h" | 29 #include "third_party/jsoncpp/source/include/json/reader.h" |
| 28 #include "third_party/jsoncpp/source/include/json/writer.h" | 30 #include "third_party/jsoncpp/source/include/json/writer.h" |
| 29 #include "third_party/modp_b64/modp_b64.h" | 31 #include "third_party/modp_b64/modp_b64.h" |
| 30 | 32 |
| 31 namespace { | 33 namespace { |
| 32 // The name of the Remoting Host service that is registered with launchd. | 34 // The name of the Remoting Host service that is registered with launchd. |
| 33 #define kServiceName "org.chromium.chromoting" | 35 #define kServiceName "org.chromium.chromoting" |
| 34 | 36 |
| 35 // Use separate named notifications for success and failure because sandboxed | 37 // Use separate named notifications for success and failure because sandboxed |
| 36 // components can't include a dictionary when sending distributed notifications. | 38 // components can't include a dictionary when sending distributed notifications. |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 } | 147 } |
| 146 | 148 |
| 147 } // namespace remoting | 149 } // namespace remoting |
| 148 | 150 |
| 149 @implementation Me2MePreferencePane | 151 @implementation Me2MePreferencePane |
| 150 | 152 |
| 151 - (void)mainViewDidLoad { | 153 - (void)mainViewDidLoad { |
| 152 [authorization_view_ setDelegate:self]; | 154 [authorization_view_ setDelegate:self]; |
| 153 [authorization_view_ setString:kAuthorizationRightExecute]; | 155 [authorization_view_ setString:kAuthorizationRightExecute]; |
| 154 [authorization_view_ setAutoupdate:YES]; | 156 [authorization_view_ setAutoupdate:YES]; |
| 157 confirm_pin_view_ = [[Me2MePreferencePaneConfirmPin alloc] init]; |
| 158 [confirm_pin_view_ setDelegate:self]; |
| 159 disable_view_ = [[Me2MePreferencePaneDisable alloc] init]; |
| 160 [disable_view_ setDelegate:self]; |
| 155 } | 161 } |
| 156 | 162 |
| 157 - (void)willSelect { | 163 - (void)willSelect { |
| 158 have_new_config_ = NO; | 164 have_new_config_ = NO; |
| 159 | 165 |
| 160 NSDistributedNotificationCenter* center = | 166 NSDistributedNotificationCenter* center = |
| 161 [NSDistributedNotificationCenter defaultCenter]; | 167 [NSDistributedNotificationCenter defaultCenter]; |
| 162 [center addObserver:self | 168 [center addObserver:self |
| 163 selector:@selector(onNewConfigFile:) | 169 selector:@selector(onNewConfigFile:) |
| 164 name:@kServiceName | 170 name:@kServiceName |
| (...skipping 17 matching lines...) Expand all Loading... |
| 182 [center removeObserver:self]; | 188 [center removeObserver:self]; |
| 183 | 189 |
| 184 [service_status_timer_ invalidate]; | 190 [service_status_timer_ invalidate]; |
| 185 [service_status_timer_ release]; | 191 [service_status_timer_ release]; |
| 186 service_status_timer_ = nil; | 192 service_status_timer_ = nil; |
| 187 if (have_new_config_) { | 193 if (have_new_config_) { |
| 188 [self notifyPlugin: kUpdateFailedNotificationName]; | 194 [self notifyPlugin: kUpdateFailedNotificationName]; |
| 189 } | 195 } |
| 190 } | 196 } |
| 191 | 197 |
| 192 - (void)onApply:(id)sender { | 198 - (void)applyConfiguration:(id)sender |
| 199 pin:(NSString*)pin { |
| 193 if (!have_new_config_) { | 200 if (!have_new_config_) { |
| 194 // It shouldn't be possible to hit the button if there is no config to | 201 // It shouldn't be possible to hit the button if there is no config to |
| 195 // apply, but check anyway just in case it happens somehow. | 202 // apply, but check anyway just in case it happens somehow. |
| 196 return; | 203 return; |
| 197 } | 204 } |
| 198 | 205 |
| 199 // Ensure the authorization token is up-to-date before using it. | 206 // Ensure the authorization token is up-to-date before using it. |
| 200 [self updateAuthorizationStatus]; | 207 [self updateAuthorizationStatus]; |
| 201 [self updateUI]; | 208 [self updateUI]; |
| 202 | 209 |
| 203 std::string pin = base::SysNSStringToUTF8([pin_ stringValue]); | 210 std::string pin_utf8 = base::SysNSStringToUTF8(pin); |
| 204 std::string host_id, host_secret_hash; | 211 std::string host_id, host_secret_hash; |
| 205 bool result = (config_->GetString(remoting::kHostIdConfigPath, &host_id) && | 212 bool result = (config_->GetString(remoting::kHostIdConfigPath, &host_id) && |
| 206 config_->GetString(remoting::kHostSecretHashConfigPath, | 213 config_->GetString(remoting::kHostSecretHashConfigPath, |
| 207 &host_secret_hash)); | 214 &host_secret_hash)); |
| 208 DCHECK(result); | 215 DCHECK(result); |
| 209 if (!IsPinValid(pin, host_id, host_secret_hash)) { | 216 if (!IsPinValid(pin_utf8, host_id, host_secret_hash)) { |
| 210 [self showIncorrectPinMessage]; | 217 [self showIncorrectPinMessage]; |
| 211 return; | 218 return; |
| 212 } | 219 } |
| 213 | 220 |
| 214 [self applyNewServiceConfig]; | 221 [self applyNewServiceConfig]; |
| 215 [self updateUI]; | 222 [self updateUI]; |
| 216 } | 223 } |
| 217 | 224 |
| 218 - (void)onDisable:(id)sender { | 225 - (void)onDisable:(id)sender { |
| 219 // Ensure the authorization token is up-to-date before using it. | 226 // Ensure the authorization token is up-to-date before using it. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 } | 296 } |
| 290 remove(file.c_str()); | 297 remove(file.c_str()); |
| 291 if (!IsConfigValid(new_config_.get())) { | 298 if (!IsConfigValid(new_config_.get())) { |
| 292 LOG(ERROR) << "Invalid configuration data read."; | 299 LOG(ERROR) << "Invalid configuration data read."; |
| 293 [self showError]; | 300 [self showError]; |
| 294 return; | 301 return; |
| 295 } | 302 } |
| 296 | 303 |
| 297 config_.swap(new_config_); | 304 config_.swap(new_config_); |
| 298 have_new_config_ = YES; | 305 have_new_config_ = YES; |
| 306 |
| 307 [confirm_pin_view_ resetPin]; |
| 299 } | 308 } |
| 300 | 309 |
| 301 - (void)updateUI { | 310 - (void)updateUI { |
| 302 // TODO(lambroslambrou): These strings should be localized. | 311 if (have_new_config_) { |
| 303 #ifdef OFFICIAL_BUILD | 312 [box_ setContentView:[confirm_pin_view_ view]]; |
| 304 NSString* name = @"Chrome Remote Desktop"; | 313 } else { |
| 305 #else | 314 [box_ setContentView:[disable_view_ view]]; |
| 306 NSString* name = @"Chromoting"; | 315 } |
| 307 #endif | 316 |
| 317 // TODO(lambroslambrou): Show "enabled" and "disabled" in bold font. |
| 308 NSString* message; | 318 NSString* message; |
| 309 if (is_service_running_) { | 319 if (is_service_running_) { |
| 310 message = [NSString stringWithFormat:@"%@ is enabled", name]; | 320 if (have_new_config_) { |
| 321 message = @"Please confirm your new PIN."; |
| 322 } else { |
| 323 message = @"Remote connections to this computer are enabled."; |
| 324 } |
| 311 } else { | 325 } else { |
| 312 message = [NSString stringWithFormat:@"%@ is disabled", name]; | 326 if (have_new_config_) { |
| 327 message = @"Remote connections to this computer are disabled. To enable " |
| 328 "remote connections you must confirm your PIN."; |
| 329 } else { |
| 330 message = @"Remote connections to this computer are disabled."; |
| 331 } |
| 313 } | 332 } |
| 314 [status_message_ setStringValue:message]; | 333 [status_message_ setStringValue:message]; |
| 315 | 334 |
| 316 std::string email; | 335 std::string email; |
| 317 if (config_.get()) { | 336 if (config_.get()) { |
| 318 bool result = config_->GetString(remoting::kXmppLoginConfigPath, &email); | 337 bool result = config_->GetString(remoting::kXmppLoginConfigPath, &email); |
| 319 | 338 |
| 320 // The config has already been checked by |IsConfigValid|. | 339 // The config has already been checked by |IsConfigValid|. |
| 321 DCHECK(result); | 340 DCHECK(result); |
| 322 } | 341 } |
| 323 [email_ setStringValue:base::SysUTF8ToNSString(email)]; | |
| 324 | 342 |
| 325 [disable_button_ setEnabled:(is_pane_unlocked_ && is_service_running_)]; | 343 [disable_view_ setEnabled:(is_pane_unlocked_ && is_service_running_)]; |
| 326 [pin_instruction_message_ setEnabled:have_new_config_]; | 344 [confirm_pin_view_ setEnabled:is_pane_unlocked_]; |
| 327 [email_ setEnabled:have_new_config_]; | 345 [confirm_pin_view_ setEmail:base::SysUTF8ToNSString(email)]; |
| 328 [pin_ setEnabled:have_new_config_]; | 346 NSString* applyButtonText = is_service_running_ ? @"Confirm" : @"Enable"; |
| 329 [apply_button_ setEnabled:(is_pane_unlocked_ && have_new_config_)]; | 347 [confirm_pin_view_ setButtonText:applyButtonText]; |
| 330 } | 348 } |
| 331 | 349 |
| 332 - (void)showError { | 350 - (void)showError { |
| 333 NSAlert* alert = [[NSAlert alloc] init]; | 351 NSAlert* alert = [[NSAlert alloc] init]; |
| 334 [alert setMessageText:@"An unexpected error occurred."]; | 352 [alert setMessageText:@"An unexpected error occurred."]; |
| 335 [alert setInformativeText:@"Check the system log for more information."]; | 353 [alert setInformativeText:@"Check the system log for more information."]; |
| 336 [alert setAlertStyle:NSWarningAlertStyle]; | 354 [alert setAlertStyle:NSWarningAlertStyle]; |
| 337 [alert beginSheetModalForWindow:[[self mainView] window] | 355 [alert beginSheetModalForWindow:[[self mainView] window] |
| 338 modalDelegate:nil | 356 modalDelegate:nil |
| 339 didEndSelector:nil | 357 didEndSelector:nil |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 - (void)notifyPlugin:(const char*)message { | 512 - (void)notifyPlugin:(const char*)message { |
| 495 NSDistributedNotificationCenter* center = | 513 NSDistributedNotificationCenter* center = |
| 496 [NSDistributedNotificationCenter defaultCenter]; | 514 [NSDistributedNotificationCenter defaultCenter]; |
| 497 NSString* name = [NSString stringWithUTF8String:message]; | 515 NSString* name = [NSString stringWithUTF8String:message]; |
| 498 [center postNotificationName:name | 516 [center postNotificationName:name |
| 499 object:nil | 517 object:nil |
| 500 userInfo:nil]; | 518 userInfo:nil]; |
| 501 } | 519 } |
| 502 | 520 |
| 503 @end | 521 @end |
| OLD | NEW |