| 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/chromeos/login/easy_unlock/easy_unlock_create_keys_oper
ation.h" | 5 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_create_keys_oper
ation.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 callback_.Run(false); | 146 callback_.Run(false); |
| 147 return; | 147 return; |
| 148 } | 148 } |
| 149 | 149 |
| 150 esk_ = esk; | 150 esk_ = esk; |
| 151 GeneratePayload(); | 151 GeneratePayload(); |
| 152 } | 152 } |
| 153 | 153 |
| 154 void EasyUnlockCreateKeysOperation::ChallengeCreator::GeneratePayload() { | 154 void EasyUnlockCreateKeysOperation::ChallengeCreator::GeneratePayload() { |
| 155 // Work around to get HeaderAndBody bytes to use as challenge payload. | 155 // Work around to get HeaderAndBody bytes to use as challenge payload. |
| 156 EasyUnlockClient::CreateSecureMessageOptions options; |
| 157 options.key = esk_; |
| 158 // TODO(xiyuan, tbarzic): Wrap in a GenericPublicKey proto. |
| 159 options.verification_key_id = tpm_pub_key_; |
| 160 options.encryption_type = easy_unlock::kEncryptionTypeAES256CBC; |
| 161 options.signature_type = easy_unlock::kSignatureTypeHMACSHA256; |
| 162 |
| 156 easy_unlock_client_->CreateSecureMessage( | 163 easy_unlock_client_->CreateSecureMessage( |
| 157 session_key_, | 164 session_key_, |
| 158 esk_, | 165 options, |
| 159 std::string(), // associated data | |
| 160 std::string(), // public meta | |
| 161 tpm_pub_key_, // TODO(xiyuan): Wrap in a GenericPublicKey proto. | |
| 162 std::string(), // decryption key id | |
| 163 easy_unlock::kEncryptionTypeAES256CBC, | |
| 164 easy_unlock::kSignatureTypeHMACSHA256, | |
| 165 base::Bind(&ChallengeCreator::OnPayloadMessageGenerated, | 166 base::Bind(&ChallengeCreator::OnPayloadMessageGenerated, |
| 166 weak_ptr_factory_.GetWeakPtr())); | 167 weak_ptr_factory_.GetWeakPtr())); |
| 167 } | 168 } |
| 168 | 169 |
| 169 void | 170 void |
| 170 EasyUnlockCreateKeysOperation::ChallengeCreator::OnPayloadMessageGenerated( | 171 EasyUnlockCreateKeysOperation::ChallengeCreator::OnPayloadMessageGenerated( |
| 171 const std::string& payload_message) { | 172 const std::string& payload_message) { |
| 173 EasyUnlockClient::UnwrapSecureMessageOptions options; |
| 174 options.key = esk_; |
| 175 options.encryption_type = easy_unlock::kEncryptionTypeAES256CBC; |
| 176 options.signature_type = easy_unlock::kSignatureTypeHMACSHA256; |
| 177 |
| 172 easy_unlock_client_->UnwrapSecureMessage( | 178 easy_unlock_client_->UnwrapSecureMessage( |
| 173 payload_message, | 179 payload_message, |
| 174 esk_, | 180 options, |
| 175 std::string(), // associated data | |
| 176 easy_unlock::kEncryptionTypeAES256CBC, | |
| 177 easy_unlock::kSignatureTypeHMACSHA256, | |
| 178 base::Bind(&ChallengeCreator::OnPayloadGenerated, | 181 base::Bind(&ChallengeCreator::OnPayloadGenerated, |
| 179 weak_ptr_factory_.GetWeakPtr())); | 182 weak_ptr_factory_.GetWeakPtr())); |
| 180 } | 183 } |
| 181 | 184 |
| 182 void EasyUnlockCreateKeysOperation::ChallengeCreator::OnPayloadGenerated( | 185 void EasyUnlockCreateKeysOperation::ChallengeCreator::OnPayloadGenerated( |
| 183 const std::string& payload) { | 186 const std::string& payload) { |
| 184 if (payload.empty()) { | 187 if (payload.empty()) { |
| 185 LOG(ERROR) << "Easy unlock failed to generate challenge payload."; | 188 LOG(ERROR) << "Easy unlock failed to generate challenge payload."; |
| 186 callback_.Run(false); | 189 callback_.Run(false); |
| 187 return; | 190 return; |
| 188 } | 191 } |
| 189 | 192 |
| 193 EasyUnlockClient::CreateSecureMessageOptions options; |
| 194 options.key = esk_; |
| 195 options.decryption_key_id = ec_public_key_; |
| 196 options.encryption_type = easy_unlock::kEncryptionTypeAES256CBC; |
| 197 options.signature_type = easy_unlock::kSignatureTypeHMACSHA256; |
| 198 |
| 190 easy_unlock_client_->CreateSecureMessage( | 199 easy_unlock_client_->CreateSecureMessage( |
| 191 payload, | 200 payload, |
| 192 esk_, | 201 options, |
| 193 std::string(), // associated data | |
| 194 std::string(), // public meta | |
| 195 std::string(), // verification key id | |
| 196 ec_public_key_, // decryption key id | |
| 197 easy_unlock::kEncryptionTypeAES256CBC, | |
| 198 easy_unlock::kSignatureTypeHMACSHA256, | |
| 199 base::Bind(&ChallengeCreator::OnChallengeGenerated, | 202 base::Bind(&ChallengeCreator::OnChallengeGenerated, |
| 200 weak_ptr_factory_.GetWeakPtr())); | 203 weak_ptr_factory_.GetWeakPtr())); |
| 201 } | 204 } |
| 202 | 205 |
| 203 void EasyUnlockCreateKeysOperation::ChallengeCreator::OnChallengeGenerated( | 206 void EasyUnlockCreateKeysOperation::ChallengeCreator::OnChallengeGenerated( |
| 204 const std::string& challenge) { | 207 const std::string& challenge) { |
| 205 if (challenge.empty()) { | 208 if (challenge.empty()) { |
| 206 LOG(ERROR) << "Easy unlock failed to generate challenge."; | 209 LOG(ERROR) << "Easy unlock failed to generate challenge."; |
| 207 callback_.Run(false); | 210 callback_.Run(false); |
| 208 return; | 211 return; |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 LOG(ERROR) << "Easy unlock failed to create key, code=" << return_code; | 357 LOG(ERROR) << "Easy unlock failed to create key, code=" << return_code; |
| 355 callback_.Run(false); | 358 callback_.Run(false); |
| 356 return; | 359 return; |
| 357 } | 360 } |
| 358 | 361 |
| 359 ++key_creation_index_; | 362 ++key_creation_index_; |
| 360 CreateKeyForDeviceAtIndex(key_creation_index_); | 363 CreateKeyForDeviceAtIndex(key_creation_index_); |
| 361 } | 364 } |
| 362 | 365 |
| 363 } // namespace chromeos | 366 } // namespace chromeos |
| OLD | NEW |