| 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/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/extensions/api/screenlock_private/screenlock_private_ap
i.h" | 8 #include "chrome/browser/extensions/api/screenlock_private/screenlock_private_ap
i.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/signin/screenlock_bridge.h" | 10 #include "chrome/browser/signin/signin_screen_bridge.h" |
| 11 #include "crypto/encryptor.h" | 11 #include "crypto/encryptor.h" |
| 12 #include "crypto/symmetric_key.h" | 12 #include "crypto/symmetric_key.h" |
| 13 | 13 |
| 14 | 14 |
| 15 #if defined(OS_CHROMEOS) | 15 #if defined(OS_CHROMEOS) |
| 16 #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" |
| 17 #endif | 17 #endif |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 } | 60 } |
| 61 | 61 |
| 62 EasyUnlockAuthAttempt::~EasyUnlockAuthAttempt() { | 62 EasyUnlockAuthAttempt::~EasyUnlockAuthAttempt() { |
| 63 if (state_ == STATE_RUNNING) | 63 if (state_ == STATE_RUNNING) |
| 64 Cancel(user_id_); | 64 Cancel(user_id_); |
| 65 } | 65 } |
| 66 | 66 |
| 67 bool EasyUnlockAuthAttempt::Start(const std::string& user_id) { | 67 bool EasyUnlockAuthAttempt::Start(const std::string& user_id) { |
| 68 DCHECK(state_ == STATE_IDLE); | 68 DCHECK(state_ == STATE_IDLE); |
| 69 | 69 |
| 70 if (!ScreenlockBridge::Get()->IsLocked()) | 70 if (!SigninScreenBridge::Get()->IsLocked()) |
| 71 return false; | 71 return false; |
| 72 | 72 |
| 73 if (user_id != user_id_) { | 73 if (user_id != user_id_) { |
| 74 Cancel(user_id); | 74 Cancel(user_id); |
| 75 return false; | 75 return false; |
| 76 } | 76 } |
| 77 | 77 |
| 78 ScreenlockBridge::LockHandler::AuthType auth_type = | 78 SigninScreenBridge::LockHandler::AuthType auth_type = |
| 79 ScreenlockBridge::Get()->lock_handler()->GetAuthType(user_id); | 79 SigninScreenBridge::Get()->lock_handler()->GetAuthType(user_id); |
| 80 | 80 |
| 81 if (auth_type != ScreenlockBridge::LockHandler::USER_CLICK) { | 81 if (auth_type != SigninScreenBridge::LockHandler::USER_CLICK) { |
| 82 Cancel(user_id); | 82 Cancel(user_id); |
| 83 return false; | 83 return false; |
| 84 } | 84 } |
| 85 | 85 |
| 86 state_ = STATE_RUNNING; | 86 state_ = STATE_RUNNING; |
| 87 | 87 |
| 88 // TODO(tbarzic): Replace this with an easyUnlockPrivate event that will | 88 // TODO(tbarzic): Replace this with an easyUnlockPrivate event that will |
| 89 // report more context to the app (e.g. user id, whether the attempt is for | 89 // report more context to the app (e.g. user id, whether the attempt is for |
| 90 // signin or unlock). | 90 // signin or unlock). |
| 91 extensions::ScreenlockPrivateEventRouter* router = | 91 extensions::ScreenlockPrivateEventRouter* router = |
| 92 extensions::ScreenlockPrivateEventRouter::GetFactoryInstance()->Get( | 92 extensions::ScreenlockPrivateEventRouter::GetFactoryInstance()->Get( |
| 93 profile_); | 93 profile_); |
| 94 return router->OnAuthAttempted(auth_type, ""); | 94 return router->OnAuthAttempted(auth_type, ""); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void EasyUnlockAuthAttempt::FinalizeUnlock(const std::string& user_id, | 97 void EasyUnlockAuthAttempt::FinalizeUnlock(const std::string& user_id, |
| 98 bool success) { | 98 bool success) { |
| 99 if (state_ != STATE_RUNNING || user_id != user_id_) | 99 if (state_ != STATE_RUNNING || user_id != user_id_) |
| 100 return; | 100 return; |
| 101 | 101 |
| 102 if (type_ != TYPE_UNLOCK) { | 102 if (type_ != TYPE_UNLOCK) { |
| 103 Cancel(user_id_); | 103 Cancel(user_id_); |
| 104 return; | 104 return; |
| 105 } | 105 } |
| 106 | 106 |
| 107 if (!ScreenlockBridge::Get()->IsLocked()) | 107 if (!SigninScreenBridge::Get()->IsLocked()) |
| 108 return; | 108 return; |
| 109 | 109 |
| 110 if (success) { | 110 if (success) { |
| 111 ScreenlockBridge::Get()->lock_handler()->Unlock(user_id_); | 111 SigninScreenBridge::Get()->lock_handler()->Unlock(user_id_); |
| 112 } else { | 112 } else { |
| 113 ScreenlockBridge::Get()->lock_handler()->EnableInput(); | 113 SigninScreenBridge::Get()->lock_handler()->EnableInput(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 state_ = STATE_DONE; | 116 state_ = STATE_DONE; |
| 117 } | 117 } |
| 118 | 118 |
| 119 void EasyUnlockAuthAttempt::FinalizeSignin(const std::string& user_id, | 119 void EasyUnlockAuthAttempt::FinalizeSignin(const std::string& user_id, |
| 120 const std::string& wrapped_secret, | 120 const std::string& wrapped_secret, |
| 121 const std::string& raw_session_key) { | 121 const std::string& raw_session_key) { |
| 122 if (state_ != STATE_RUNNING || user_id != user_id_) | 122 if (state_ != STATE_RUNNING || user_id != user_id_) |
| 123 return; | 123 return; |
| 124 | 124 |
| 125 if (type_ != TYPE_SIGNIN) { | 125 if (type_ != TYPE_SIGNIN) { |
| 126 Cancel(user_id_); | 126 Cancel(user_id_); |
| 127 return; | 127 return; |
| 128 } | 128 } |
| 129 | 129 |
| 130 if (!ScreenlockBridge::Get()->IsLocked()) | 130 if (!SigninScreenBridge::Get()->IsLocked()) |
| 131 return; | 131 return; |
| 132 | 132 |
| 133 | 133 |
| 134 std::string unwrapped_secret = UnwrapSecret(wrapped_secret, raw_session_key); | 134 std::string unwrapped_secret = UnwrapSecret(wrapped_secret, raw_session_key); |
| 135 | 135 |
| 136 // If secret is not set, set it to an arbitrary value, otherwise there will | 136 // If secret is not set, set it to an arbitrary value, otherwise there will |
| 137 // be no authenitcation attempt and the ui will get stuck. | 137 // be no authenitcation attempt and the ui will get stuck. |
| 138 // TODO(tbarzic): Find a better way to handle this case. | 138 // TODO(tbarzic): Find a better way to handle this case. |
| 139 if (unwrapped_secret.empty()) | 139 if (unwrapped_secret.empty()) |
| 140 unwrapped_secret = kStubSecret; | 140 unwrapped_secret = kStubSecret; |
| 141 | 141 |
| 142 std::string key_label; | 142 std::string key_label; |
| 143 #if defined(OS_CHROMEOS) | 143 #if defined(OS_CHROMEOS) |
| 144 key_label = chromeos::EasyUnlockKeyManager::GetKeyLabel(0u); | 144 key_label = chromeos::EasyUnlockKeyManager::GetKeyLabel(0u); |
| 145 #endif // defined(OS_CHROMEOS) | 145 #endif // defined(OS_CHROMEOS) |
| 146 | 146 |
| 147 ScreenlockBridge::Get()->lock_handler()->AttemptUserClickLogin( | 147 SigninScreenBridge::Get()->lock_handler()->AttemptUserClickLogin( |
| 148 user_id, | 148 user_id, |
| 149 unwrapped_secret, | 149 unwrapped_secret, |
| 150 key_label); | 150 key_label); |
| 151 state_ = STATE_DONE; | 151 state_ = STATE_DONE; |
| 152 } | 152 } |
| 153 | 153 |
| 154 void EasyUnlockAuthAttempt::Cancel(const std::string& user_id) { | 154 void EasyUnlockAuthAttempt::Cancel(const std::string& user_id) { |
| 155 if (type_ == TYPE_UNLOCK) | 155 if (type_ == TYPE_UNLOCK) |
| 156 FinalizeUnlock(user_id, false); | 156 FinalizeUnlock(user_id, false); |
| 157 else | 157 else |
| 158 FinalizeSignin(user_id, "", ""); | 158 FinalizeSignin(user_id, "", ""); |
| 159 state_ = STATE_DONE; | 159 state_ = STATE_DONE; |
| 160 } | 160 } |
| OLD | NEW |