Chromium Code Reviews| 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 #include "chrome/browser/chromeos/cros/cert_library.h" | 5 #include "chrome/browser/chromeos/cros/cert_library.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/chromeos/chromeos_version.h" | 9 #include "base/chromeos/chromeos_version.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 190 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 191 return server_certs_; | 191 return server_certs_; |
| 192 } | 192 } |
| 193 | 193 |
| 194 virtual const CertList& GetCACertificates() const OVERRIDE { | 194 virtual const CertList& GetCACertificates() const OVERRIDE { |
| 195 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 195 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 196 return server_ca_certs_; | 196 return server_ca_certs_; |
| 197 } | 197 } |
| 198 | 198 |
| 199 virtual std::string EncryptToken(const std::string& token) OVERRIDE { | 199 virtual std::string EncryptToken(const std::string& token) OVERRIDE { |
| 200 #ifndef NDEBUG | |
|
Joao da Silva
2013/01/11 16:45:07
Is this meant to stay in?
zel
2013/01/11 19:51:16
Yes it is going to stay in. While we develop on Li
Joao da Silva
2013/01/11 20:13:15
Ah, I see now. IsRunningOnChromeOS() may be a more
zel
2013/01/11 20:54:20
Done.
| |
| 201 return token; | |
| 202 #else | |
| 200 if (!LoadSupplementalUserKey()) { | 203 if (!LoadSupplementalUserKey()) { |
| 201 LOG(WARNING) << "Supplemental user key is not available for encrypt."; | 204 LOG(WARNING) << "Supplemental user key is not available for encrypt."; |
| 202 return std::string(); | 205 return std::string(); |
| 203 } | 206 } |
| 204 crypto::Encryptor encryptor; | 207 crypto::Encryptor encryptor; |
| 205 if (!encryptor.Init(supplemental_user_key_.get(), crypto::Encryptor::CTR, | 208 if (!encryptor.Init(supplemental_user_key_.get(), crypto::Encryptor::CTR, |
| 206 std::string())) { | 209 std::string())) { |
| 207 LOG(WARNING) << "Failed to initialize Encryptor."; | 210 LOG(WARNING) << "Failed to initialize Encryptor."; |
| 208 return std::string(); | 211 return std::string(); |
| 209 } | 212 } |
| 210 std::string salt = | 213 std::string salt = |
| 211 CrosLibrary::Get()->GetCryptohomeLibrary()->GetSystemSalt(); | 214 CrosLibrary::Get()->GetCryptohomeLibrary()->GetSystemSalt(); |
| 212 std::string nonce = salt.substr(0, kKeySize); | 215 std::string nonce = salt.substr(0, kKeySize); |
| 213 std::string encoded_token; | 216 std::string encoded_token; |
| 214 CHECK(encryptor.SetCounter(nonce)); | 217 CHECK(encryptor.SetCounter(nonce)); |
| 215 if (!encryptor.Encrypt(token, &encoded_token)) { | 218 if (!encryptor.Encrypt(token, &encoded_token)) { |
| 216 LOG(WARNING) << "Failed to encrypt token."; | 219 LOG(WARNING) << "Failed to encrypt token."; |
| 217 return std::string(); | 220 return std::string(); |
| 218 } | 221 } |
| 219 | 222 |
| 220 return StringToLowerASCII(base::HexEncode( | 223 return StringToLowerASCII(base::HexEncode( |
| 221 reinterpret_cast<const void*>(encoded_token.data()), | 224 reinterpret_cast<const void*>(encoded_token.data()), |
| 222 encoded_token.size())); | 225 encoded_token.size())); |
| 226 #endif | |
| 223 } | 227 } |
| 224 | 228 |
| 225 virtual std::string DecryptToken( | 229 virtual std::string DecryptToken( |
| 226 const std::string& encrypted_token_hex) OVERRIDE { | 230 const std::string& encrypted_token_hex) OVERRIDE { |
| 231 #ifndef NDEBUG | |
| 232 return encrypted_token_hex; | |
| 233 #else | |
| 227 if (!LoadSupplementalUserKey()) { | 234 if (!LoadSupplementalUserKey()) { |
| 228 LOG(WARNING) << "Supplemental user key is not available for decrypt."; | 235 LOG(WARNING) << "Supplemental user key is not available for decrypt."; |
| 229 return std::string(); | 236 return std::string(); |
| 230 } | 237 } |
| 231 return DecryptTokenWithKey(supplemental_user_key_.get(), | 238 return DecryptTokenWithKey(supplemental_user_key_.get(), |
| 232 CrosLibrary::Get()->GetCryptohomeLibrary()->GetSystemSalt(), | 239 CrosLibrary::Get()->GetCryptohomeLibrary()->GetSystemSalt(), |
| 233 encrypted_token_hex); | 240 encrypted_token_hex); |
| 241 #endif | |
| 234 } | 242 } |
| 235 | 243 |
| 236 // net::CertDatabase::Observer implementation. Observer added on UI thread. | 244 // net::CertDatabase::Observer implementation. Observer added on UI thread. |
| 237 virtual void OnCertTrustChanged(const net::X509Certificate* cert) OVERRIDE { | 245 virtual void OnCertTrustChanged(const net::X509Certificate* cert) OVERRIDE { |
| 238 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 246 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 239 } | 247 } |
| 240 | 248 |
| 241 virtual void OnCertAdded(const net::X509Certificate* cert) OVERRIDE { | 249 virtual void OnCertAdded(const net::X509Certificate* cert) OVERRIDE { |
| 242 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 250 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 243 // Only load certificates if we have completed an initial request. | 251 // Only load certificates if we have completed an initial request. |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 599 net::X509Certificate* cert = GetCertificateAt(index); | 607 net::X509Certificate* cert = GetCertificateAt(index); |
| 600 net::X509Certificate::OSCertHandle cert_handle = cert->os_cert_handle(); | 608 net::X509Certificate::OSCertHandle cert_handle = cert->os_cert_handle(); |
| 601 std::string id = x509_certificate_model::GetPkcs11Id(cert_handle); | 609 std::string id = x509_certificate_model::GetPkcs11Id(cert_handle); |
| 602 if (id == pkcs11_id) | 610 if (id == pkcs11_id) |
| 603 return index; | 611 return index; |
| 604 } | 612 } |
| 605 return -1; // Not found. | 613 return -1; // Not found. |
| 606 } | 614 } |
| 607 | 615 |
| 608 } // chromeos | 616 } // chromeos |
| OLD | NEW |