| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "chrome/browser/signin/easy_unlock_auth_attempt.h" | 5 #include "chrome/browser/signin/easy_unlock_auth_attempt.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "chrome/browser/signin/easy_unlock_app_manager.h" | 10 #include "chrome/browser/signin/easy_unlock_app_manager.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 std::string secret; | 42 std::string secret; |
| 43 if (!encryptor.Decrypt(wrapped_secret, &secret)) | 43 if (!encryptor.Decrypt(wrapped_secret, &secret)) |
| 44 return std::string(); | 44 return std::string(); |
| 45 | 45 |
| 46 return secret; | 46 return secret; |
| 47 } | 47 } |
| 48 | 48 |
| 49 void DefaultAuthAttemptFinalizedHandler( | 49 void DefaultAuthAttemptFinalizedHandler( |
| 50 EasyUnlockAuthAttempt::Type auth_attempt_type, | 50 EasyUnlockAuthAttempt::Type auth_attempt_type, |
| 51 bool success, | 51 bool success, |
| 52 const std::string& user_id, | 52 const AccountId& account_id, |
| 53 const std::string& key_secret, | 53 const std::string& key_secret, |
| 54 const std::string& key_label) { | 54 const std::string& key_label) { |
| 55 if (!proximity_auth::ScreenlockBridge::Get()->IsLocked()) | 55 if (!proximity_auth::ScreenlockBridge::Get()->IsLocked()) |
| 56 return; | 56 return; |
| 57 | 57 |
| 58 switch (auth_attempt_type) { | 58 switch (auth_attempt_type) { |
| 59 case EasyUnlockAuthAttempt::TYPE_UNLOCK: | 59 case EasyUnlockAuthAttempt::TYPE_UNLOCK: |
| 60 if (success) { | 60 if (success) { |
| 61 proximity_auth::ScreenlockBridge::Get()->lock_handler()->Unlock( | 61 proximity_auth::ScreenlockBridge::Get()->lock_handler()->Unlock( |
| 62 user_id); | 62 account_id); |
| 63 } else { | 63 } else { |
| 64 proximity_auth::ScreenlockBridge::Get()->lock_handler()->EnableInput(); | 64 proximity_auth::ScreenlockBridge::Get()->lock_handler()->EnableInput(); |
| 65 } | 65 } |
| 66 return; | 66 return; |
| 67 case EasyUnlockAuthAttempt::TYPE_SIGNIN: | 67 case EasyUnlockAuthAttempt::TYPE_SIGNIN: |
| 68 if (success) { | 68 if (success) { |
| 69 proximity_auth::ScreenlockBridge::Get() | 69 proximity_auth::ScreenlockBridge::Get() |
| 70 ->lock_handler() | 70 ->lock_handler() |
| 71 ->AttemptEasySignin(user_id, key_secret, key_label); | 71 ->AttemptEasySignin(account_id, key_secret, key_label); |
| 72 } else { | 72 } else { |
| 73 // Attempting signin with an empty secret is equivalent to canceling the | 73 // Attempting signin with an empty secret is equivalent to canceling the |
| 74 // attempt. | 74 // attempt. |
| 75 proximity_auth::ScreenlockBridge::Get() | 75 proximity_auth::ScreenlockBridge::Get() |
| 76 ->lock_handler() | 76 ->lock_handler() |
| 77 ->AttemptEasySignin(user_id, std::string(), std::string()); | 77 ->AttemptEasySignin(account_id, std::string(), std::string()); |
| 78 } | 78 } |
| 79 return; | 79 return; |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 | 82 |
| 83 } // namespace | 83 } // namespace |
| 84 | 84 |
| 85 EasyUnlockAuthAttempt::EasyUnlockAuthAttempt( | 85 EasyUnlockAuthAttempt::EasyUnlockAuthAttempt( |
| 86 EasyUnlockAppManager* app_manager, | 86 EasyUnlockAppManager* app_manager, |
| 87 const std::string& user_id, | 87 const AccountId& account_id, |
| 88 Type type, | 88 Type type, |
| 89 const FinalizedCallback& finalized_callback) | 89 const FinalizedCallback& finalized_callback) |
| 90 : app_manager_(app_manager), | 90 : app_manager_(app_manager), |
| 91 state_(STATE_IDLE), | 91 state_(STATE_IDLE), |
| 92 user_id_(user_id), | 92 account_id_(account_id), |
| 93 type_(type), | 93 type_(type), |
| 94 finalized_callback_(finalized_callback) { | 94 finalized_callback_(finalized_callback) { |
| 95 if (finalized_callback_.is_null()) | 95 if (finalized_callback_.is_null()) |
| 96 finalized_callback_ = base::Bind(&DefaultAuthAttemptFinalizedHandler); | 96 finalized_callback_ = base::Bind(&DefaultAuthAttemptFinalizedHandler); |
| 97 } | 97 } |
| 98 | 98 |
| 99 EasyUnlockAuthAttempt::~EasyUnlockAuthAttempt() { | 99 EasyUnlockAuthAttempt::~EasyUnlockAuthAttempt() { |
| 100 if (state_ == STATE_RUNNING) | 100 if (state_ == STATE_RUNNING) |
| 101 Cancel(user_id_); | 101 Cancel(account_id_); |
| 102 } | 102 } |
| 103 | 103 |
| 104 bool EasyUnlockAuthAttempt::Start() { | 104 bool EasyUnlockAuthAttempt::Start() { |
| 105 DCHECK_EQ(STATE_IDLE, state_); | 105 DCHECK_EQ(STATE_IDLE, state_); |
| 106 | 106 |
| 107 if (!proximity_auth::ScreenlockBridge::Get()->IsLocked()) | 107 if (!proximity_auth::ScreenlockBridge::Get()->IsLocked()) |
| 108 return false; | 108 return false; |
| 109 | 109 |
| 110 proximity_auth::ScreenlockBridge::LockHandler::AuthType auth_type = | 110 proximity_auth::ScreenlockBridge::LockHandler::AuthType auth_type = |
| 111 proximity_auth::ScreenlockBridge::Get()->lock_handler()->GetAuthType( | 111 proximity_auth::ScreenlockBridge::Get()->lock_handler()->GetAuthType( |
| 112 user_id_); | 112 account_id_); |
| 113 | 113 |
| 114 if (auth_type != proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK) { | 114 if (auth_type != proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK) { |
| 115 Cancel(user_id_); | 115 Cancel(account_id_); |
| 116 return false; | 116 return false; |
| 117 } | 117 } |
| 118 | 118 |
| 119 state_ = STATE_RUNNING; | 119 state_ = STATE_RUNNING; |
| 120 | 120 |
| 121 // We need this workaround for ProximityAuthSystem, since we don't load the | 121 // We need this workaround for ProximityAuthSystem, since we don't load the |
| 122 // full background app anymore. The call to | 122 // full background app anymore. The call to |
| 123 // |app_manager_->SendAuthAttemptEvent()| returns false, as there is no | 123 // |app_manager_->SendAuthAttemptEvent()| returns false, as there is no |
| 124 // observer registered for the |screenlock::OnAuthAttempted| event. As a | 124 // observer registered for the |screenlock::OnAuthAttempted| event. As a |
| 125 // result, the auth attempt will always fail. | 125 // result, the auth attempt will always fail. |
| 126 // TODO(sacomoto): Clean this up when the background app is not needed | 126 // TODO(sacomoto): Clean this up when the background app is not needed |
| 127 // anymore. | 127 // anymore. |
| 128 if (!app_manager_->SendAuthAttemptEvent() && | 128 if (!app_manager_->SendAuthAttemptEvent() && |
| 129 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 129 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 130 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery)) { | 130 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery)) { |
| 131 Cancel(user_id_); | 131 Cancel(account_id_); |
| 132 return false; | 132 return false; |
| 133 } | 133 } |
| 134 | 134 |
| 135 return true; | 135 return true; |
| 136 } | 136 } |
| 137 | 137 |
| 138 void EasyUnlockAuthAttempt::FinalizeUnlock(const std::string& user_id, | 138 void EasyUnlockAuthAttempt::FinalizeUnlock(const AccountId& account_id, |
| 139 bool success) { | 139 bool success) { |
| 140 if (state_ != STATE_RUNNING || user_id != user_id_) | 140 if (state_ != STATE_RUNNING || account_id != account_id_) |
| 141 return; | 141 return; |
| 142 | 142 |
| 143 if (!proximity_auth::ScreenlockBridge::Get()->IsLocked()) | 143 if (!proximity_auth::ScreenlockBridge::Get()->IsLocked()) |
| 144 return; | 144 return; |
| 145 | 145 |
| 146 if (type_ != TYPE_UNLOCK) { | 146 if (type_ != TYPE_UNLOCK) { |
| 147 Cancel(user_id_); | 147 Cancel(account_id_); |
| 148 return; | 148 return; |
| 149 } | 149 } |
| 150 | 150 |
| 151 finalized_callback_.Run(type_, success, user_id, std::string(), | 151 finalized_callback_.Run(type_, success, account_id, std::string(), |
| 152 std::string()); | 152 std::string()); |
| 153 state_ = STATE_DONE; | 153 state_ = STATE_DONE; |
| 154 } | 154 } |
| 155 | 155 |
| 156 void EasyUnlockAuthAttempt::FinalizeSignin(const std::string& user_id, | 156 void EasyUnlockAuthAttempt::FinalizeSignin(const AccountId& account_id, |
| 157 const std::string& wrapped_secret, | 157 const std::string& wrapped_secret, |
| 158 const std::string& raw_session_key) { | 158 const std::string& raw_session_key) { |
| 159 if (state_ != STATE_RUNNING || user_id != user_id_) | 159 if (state_ != STATE_RUNNING || account_id != account_id_) |
| 160 return; | 160 return; |
| 161 | 161 |
| 162 if (!proximity_auth::ScreenlockBridge::Get()->IsLocked()) | 162 if (!proximity_auth::ScreenlockBridge::Get()->IsLocked()) |
| 163 return; | 163 return; |
| 164 | 164 |
| 165 if (type_ != TYPE_SIGNIN) { | 165 if (type_ != TYPE_SIGNIN) { |
| 166 Cancel(user_id_); | 166 Cancel(account_id_); |
| 167 return; | 167 return; |
| 168 } | 168 } |
| 169 | 169 |
| 170 if (wrapped_secret.empty()) { | 170 if (wrapped_secret.empty()) { |
| 171 Cancel(user_id_); | 171 Cancel(account_id_); |
| 172 return; | 172 return; |
| 173 } | 173 } |
| 174 | 174 |
| 175 std::string unwrapped_secret = UnwrapSecret(wrapped_secret, raw_session_key); | 175 std::string unwrapped_secret = UnwrapSecret(wrapped_secret, raw_session_key); |
| 176 | 176 |
| 177 std::string key_label; | 177 std::string key_label; |
| 178 #if defined(OS_CHROMEOS) | 178 #if defined(OS_CHROMEOS) |
| 179 key_label = chromeos::EasyUnlockKeyManager::GetKeyLabel(0u); | 179 key_label = chromeos::EasyUnlockKeyManager::GetKeyLabel(0u); |
| 180 #endif // defined(OS_CHROMEOS) | 180 #endif // defined(OS_CHROMEOS) |
| 181 | 181 |
| 182 const bool kSuccess = true; | 182 const bool kSuccess = true; |
| 183 finalized_callback_.Run(type_, kSuccess, user_id, unwrapped_secret, | 183 finalized_callback_.Run(type_, kSuccess, account_id, unwrapped_secret, |
| 184 key_label); | 184 key_label); |
| 185 state_ = STATE_DONE; | 185 state_ = STATE_DONE; |
| 186 } | 186 } |
| 187 | 187 |
| 188 void EasyUnlockAuthAttempt::Cancel(const std::string& user_id) { | 188 void EasyUnlockAuthAttempt::Cancel(const AccountId& account_id) { |
| 189 state_ = STATE_DONE; | 189 state_ = STATE_DONE; |
| 190 | 190 |
| 191 const bool kFailure = false; | 191 const bool kFailure = false; |
| 192 finalized_callback_.Run(type_, kFailure, user_id, std::string(), | 192 finalized_callback_.Run(type_, kFailure, account_id, std::string(), |
| 193 std::string()); | 193 std::string()); |
| 194 } | 194 } |
| OLD | NEW |