| 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/logging.h" | 8 #include "base/logging.h" |
| 9 #include "chrome/browser/signin/easy_unlock_app_manager.h" | 9 #include "chrome/browser/signin/easy_unlock_app_manager.h" |
| 10 #include "chrome/browser/signin/screenlock_bridge.h" | 10 #include "chrome/browser/signin/proximity_auth_facade.h" |
| 11 #include "components/proximity_auth/screenlock_bridge.h" |
| 11 #include "crypto/encryptor.h" | 12 #include "crypto/encryptor.h" |
| 12 #include "crypto/symmetric_key.h" | 13 #include "crypto/symmetric_key.h" |
| 13 | 14 |
| 14 #if defined(OS_CHROMEOS) | 15 #if defined(OS_CHROMEOS) |
| 15 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h" | 16 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h" |
| 16 #endif | 17 #endif |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 // Decrypts the secret that should be used to login from |wrapped_secret| using | 21 // Decrypts the secret that should be used to login from |wrapped_secret| using |
| (...skipping 22 matching lines...) Expand all Loading... |
| 43 | 44 |
| 44 return secret; | 45 return secret; |
| 45 } | 46 } |
| 46 | 47 |
| 47 void DefaultAuthAttemptFinalizedHandler( | 48 void DefaultAuthAttemptFinalizedHandler( |
| 48 EasyUnlockAuthAttempt::Type auth_attempt_type, | 49 EasyUnlockAuthAttempt::Type auth_attempt_type, |
| 49 bool success, | 50 bool success, |
| 50 const std::string& user_id, | 51 const std::string& user_id, |
| 51 const std::string& key_secret, | 52 const std::string& key_secret, |
| 52 const std::string& key_label) { | 53 const std::string& key_label) { |
| 53 if (!ScreenlockBridge::Get()->IsLocked()) | 54 if (!GetScreenlockBridgeInstance()->IsLocked()) |
| 54 return; | 55 return; |
| 55 | 56 |
| 56 switch (auth_attempt_type) { | 57 switch (auth_attempt_type) { |
| 57 case EasyUnlockAuthAttempt::TYPE_UNLOCK: | 58 case EasyUnlockAuthAttempt::TYPE_UNLOCK: |
| 58 if (success) { | 59 if (success) { |
| 59 ScreenlockBridge::Get()->lock_handler()->Unlock(user_id); | 60 GetScreenlockBridgeInstance()->lock_handler()->Unlock(user_id); |
| 60 } else { | 61 } else { |
| 61 ScreenlockBridge::Get()->lock_handler()->EnableInput(); | 62 GetScreenlockBridgeInstance()->lock_handler()->EnableInput(); |
| 62 } | 63 } |
| 63 return; | 64 return; |
| 64 case EasyUnlockAuthAttempt::TYPE_SIGNIN: | 65 case EasyUnlockAuthAttempt::TYPE_SIGNIN: |
| 65 if (success) { | 66 if (success) { |
| 66 ScreenlockBridge::Get()->lock_handler()->AttemptEasySignin( | 67 GetScreenlockBridgeInstance()->lock_handler()->AttemptEasySignin( |
| 67 user_id, key_secret, key_label); | 68 user_id, key_secret, key_label); |
| 68 } else { | 69 } else { |
| 69 // Attempting signin with an empty secret is equivalent to canceling the | 70 // Attempting signin with an empty secret is equivalent to canceling the |
| 70 // attempt. | 71 // attempt. |
| 71 ScreenlockBridge::Get()->lock_handler()->AttemptEasySignin( | 72 GetScreenlockBridgeInstance()->lock_handler()->AttemptEasySignin( |
| 72 user_id, std::string(), std::string()); | 73 user_id, std::string(), std::string()); |
| 73 } | 74 } |
| 74 return; | 75 return; |
| 75 } | 76 } |
| 76 } | 77 } |
| 77 | 78 |
| 78 } // namespace | 79 } // namespace |
| 79 | 80 |
| 80 EasyUnlockAuthAttempt::EasyUnlockAuthAttempt( | 81 EasyUnlockAuthAttempt::EasyUnlockAuthAttempt( |
| 81 EasyUnlockAppManager* app_manager, | 82 EasyUnlockAppManager* app_manager, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 92 } | 93 } |
| 93 | 94 |
| 94 EasyUnlockAuthAttempt::~EasyUnlockAuthAttempt() { | 95 EasyUnlockAuthAttempt::~EasyUnlockAuthAttempt() { |
| 95 if (state_ == STATE_RUNNING) | 96 if (state_ == STATE_RUNNING) |
| 96 Cancel(user_id_); | 97 Cancel(user_id_); |
| 97 } | 98 } |
| 98 | 99 |
| 99 bool EasyUnlockAuthAttempt::Start() { | 100 bool EasyUnlockAuthAttempt::Start() { |
| 100 DCHECK_EQ(STATE_IDLE, state_); | 101 DCHECK_EQ(STATE_IDLE, state_); |
| 101 | 102 |
| 102 if (!ScreenlockBridge::Get()->IsLocked()) | 103 if (!GetScreenlockBridgeInstance()->IsLocked()) |
| 103 return false; | 104 return false; |
| 104 | 105 |
| 105 ScreenlockBridge::LockHandler::AuthType auth_type = | 106 proximity_auth::ScreenlockBridge::LockHandler::AuthType auth_type = |
| 106 ScreenlockBridge::Get()->lock_handler()->GetAuthType(user_id_); | 107 GetScreenlockBridgeInstance()->lock_handler()->GetAuthType(user_id_); |
| 107 | 108 |
| 108 if (auth_type != ScreenlockBridge::LockHandler::USER_CLICK) { | 109 if (auth_type != proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK) { |
| 109 Cancel(user_id_); | 110 Cancel(user_id_); |
| 110 return false; | 111 return false; |
| 111 } | 112 } |
| 112 | 113 |
| 113 state_ = STATE_RUNNING; | 114 state_ = STATE_RUNNING; |
| 114 | 115 |
| 115 if (!app_manager_->SendAuthAttemptEvent()) { | 116 if (!app_manager_->SendAuthAttemptEvent()) { |
| 116 Cancel(user_id_); | 117 Cancel(user_id_); |
| 117 return false; | 118 return false; |
| 118 } | 119 } |
| 119 | 120 |
| 120 return true; | 121 return true; |
| 121 } | 122 } |
| 122 | 123 |
| 123 void EasyUnlockAuthAttempt::FinalizeUnlock(const std::string& user_id, | 124 void EasyUnlockAuthAttempt::FinalizeUnlock(const std::string& user_id, |
| 124 bool success) { | 125 bool success) { |
| 125 if (state_ != STATE_RUNNING || user_id != user_id_) | 126 if (state_ != STATE_RUNNING || user_id != user_id_) |
| 126 return; | 127 return; |
| 127 | 128 |
| 128 if (!ScreenlockBridge::Get()->IsLocked()) | 129 if (!GetScreenlockBridgeInstance()->IsLocked()) |
| 129 return; | 130 return; |
| 130 | 131 |
| 131 if (type_ != TYPE_UNLOCK) { | 132 if (type_ != TYPE_UNLOCK) { |
| 132 Cancel(user_id_); | 133 Cancel(user_id_); |
| 133 return; | 134 return; |
| 134 } | 135 } |
| 135 | 136 |
| 136 finalized_callback_.Run(type_, success, user_id, std::string(), | 137 finalized_callback_.Run(type_, success, user_id, std::string(), |
| 137 std::string()); | 138 std::string()); |
| 138 state_ = STATE_DONE; | 139 state_ = STATE_DONE; |
| 139 } | 140 } |
| 140 | 141 |
| 141 void EasyUnlockAuthAttempt::FinalizeSignin(const std::string& user_id, | 142 void EasyUnlockAuthAttempt::FinalizeSignin(const std::string& user_id, |
| 142 const std::string& wrapped_secret, | 143 const std::string& wrapped_secret, |
| 143 const std::string& raw_session_key) { | 144 const std::string& raw_session_key) { |
| 144 if (state_ != STATE_RUNNING || user_id != user_id_) | 145 if (state_ != STATE_RUNNING || user_id != user_id_) |
| 145 return; | 146 return; |
| 146 | 147 |
| 147 if (!ScreenlockBridge::Get()->IsLocked()) | 148 if (!GetScreenlockBridgeInstance()->IsLocked()) |
| 148 return; | 149 return; |
| 149 | 150 |
| 150 if (type_ != TYPE_SIGNIN) { | 151 if (type_ != TYPE_SIGNIN) { |
| 151 Cancel(user_id_); | 152 Cancel(user_id_); |
| 152 return; | 153 return; |
| 153 } | 154 } |
| 154 | 155 |
| 155 if (wrapped_secret.empty()) { | 156 if (wrapped_secret.empty()) { |
| 156 Cancel(user_id_); | 157 Cancel(user_id_); |
| 157 return; | 158 return; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 170 state_ = STATE_DONE; | 171 state_ = STATE_DONE; |
| 171 } | 172 } |
| 172 | 173 |
| 173 void EasyUnlockAuthAttempt::Cancel(const std::string& user_id) { | 174 void EasyUnlockAuthAttempt::Cancel(const std::string& user_id) { |
| 174 state_ = STATE_DONE; | 175 state_ = STATE_DONE; |
| 175 | 176 |
| 176 const bool kFailure = false; | 177 const bool kFailure = false; |
| 177 finalized_callback_.Run(type_, kFailure, user_id, std::string(), | 178 finalized_callback_.Run(type_, kFailure, user_id, std::string(), |
| 178 std::string()); | 179 std::string()); |
| 179 } | 180 } |
| OLD | NEW |