Chromium Code Reviews| 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/platform_keys/platform_keys_service.h" | 5 #include "chrome/browser/chromeos/platform_keys/platform_keys_service.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/chromeos/platform_keys/platform_keys.h" | 10 #include "chrome/browser/chromeos/platform_keys/platform_keys.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 browser_context); | 63 browser_context); |
| 64 } | 64 } |
| 65 | 65 |
| 66 } // namespace | 66 } // namespace |
| 67 | 67 |
| 68 PlatformKeysService::PlatformKeysService( | 68 PlatformKeysService::PlatformKeysService( |
| 69 content::BrowserContext* browser_context, | 69 content::BrowserContext* browser_context, |
| 70 extensions::StateStore* state_store) | 70 extensions::StateStore* state_store) |
| 71 : browser_context_(browser_context), | 71 : browser_context_(browser_context), |
| 72 state_store_(state_store), | 72 state_store_(state_store), |
| 73 permission_check_disabled_(false), | |
| 73 weak_factory_(this) { | 74 weak_factory_(this) { |
| 74 DCHECK(state_store); | 75 DCHECK(state_store); |
| 75 } | 76 } |
| 76 | 77 |
| 77 PlatformKeysService::~PlatformKeysService() { | 78 PlatformKeysService::~PlatformKeysService() { |
| 78 } | 79 } |
| 79 | 80 |
| 81 void PlatformKeysService::DisablePermissionCheckForTesting() { | |
| 82 permission_check_disabled_ = true; | |
| 83 } | |
| 84 | |
| 80 void PlatformKeysService::GenerateRSAKey(const std::string& token_id, | 85 void PlatformKeysService::GenerateRSAKey(const std::string& token_id, |
| 81 unsigned int modulus_length, | 86 unsigned int modulus_length, |
| 82 const std::string& extension_id, | 87 const std::string& extension_id, |
| 83 const GenerateKeyCallback& callback) { | 88 const GenerateKeyCallback& callback) { |
| 84 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 85 | 90 |
| 86 platform_keys::subtle::GenerateRSAKey( | 91 platform_keys::subtle::GenerateRSAKey( |
| 87 token_id, | 92 token_id, |
| 88 modulus_length, | 93 modulus_length, |
| 89 base::Bind(&PlatformKeysService::GenerateRSAKeyCallback, | 94 base::Bind(&PlatformKeysService::GenerateRSAKeyCallback, |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 | 211 |
| 207 void PlatformKeysService::InvalidateKey( | 212 void PlatformKeysService::InvalidateKey( |
| 208 const std::string& extension_id, | 213 const std::string& extension_id, |
| 209 const std::string& public_key_spki_der, | 214 const std::string& public_key_spki_der, |
| 210 const base::Callback<void(bool)>& callback, | 215 const base::Callback<void(bool)>& callback, |
| 211 scoped_ptr<base::ListValue> platform_keys) { | 216 scoped_ptr<base::ListValue> platform_keys) { |
| 212 scoped_ptr<base::StringValue> key_value( | 217 scoped_ptr<base::StringValue> key_value( |
| 213 GetPublicKeyValue(public_key_spki_der)); | 218 GetPublicKeyValue(public_key_spki_der)); |
| 214 | 219 |
| 215 size_t index = 0; | 220 size_t index = 0; |
| 216 if (!platform_keys->Remove(*key_value, &index)) { | 221 if (!platform_keys->Remove(*key_value, &index) && |
| 222 !permission_check_disabled_) { | |
|
Ryan Sleevi
2015/02/03 01:44:50
I've read this code multiple times and I'm still c
pneubeck (no reviews)
2015/02/03 20:15:00
reordered to make it clearer.
| |
| 217 // The key is not found, so it's not valid to use it for signing. | 223 // The key is not found, so it's not valid to use it for signing. |
| 218 callback.Run(false); | 224 callback.Run(false); |
| 219 return; | 225 return; |
| 220 } | 226 } |
| 221 | 227 |
| 222 SetPlatformKeysOfExtension(extension_id, platform_keys.Pass()); | 228 SetPlatformKeysOfExtension(extension_id, platform_keys.Pass()); |
| 223 callback.Run(true); | 229 callback.Run(true); |
| 224 } | 230 } |
| 225 | 231 |
| 226 void PlatformKeysService::GotPlatformKeysOfExtension( | 232 void PlatformKeysService::GotPlatformKeysOfExtension( |
| 227 const std::string& extension_id, | 233 const std::string& extension_id, |
| 228 const GetPlatformKeysCallback& callback, | 234 const GetPlatformKeysCallback& callback, |
| 229 scoped_ptr<base::Value> value) { | 235 scoped_ptr<base::Value> value) { |
| 230 if (!value) | 236 if (!value) |
| 231 value.reset(new base::ListValue); | 237 value.reset(new base::ListValue); |
| 232 | 238 |
| 233 base::ListValue* keys = NULL; | 239 base::ListValue* keys = NULL; |
| 234 if (!value->GetAsList(&keys)) { | 240 if (!value->GetAsList(&keys)) { |
| 235 LOG(ERROR) << "Found a value of wrong type."; | 241 LOG(ERROR) << "Found a value of wrong type."; |
| 236 | 242 |
| 237 keys = new base::ListValue; | 243 keys = new base::ListValue; |
| 238 value.reset(keys); | 244 value.reset(keys); |
| 239 } | 245 } |
| 240 | 246 |
| 241 ignore_result(value.release()); | 247 ignore_result(value.release()); |
| 242 callback.Run(make_scoped_ptr(keys)); | 248 callback.Run(make_scoped_ptr(keys)); |
| 243 } | 249 } |
| 244 | 250 |
| 245 } // namespace chromeos | 251 } // namespace chromeos |
| OLD | NEW |