| 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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 } | 178 } |
| 179 | 179 |
| 180 scoped_ptr<base::StringValue> key_value( | 180 scoped_ptr<base::StringValue> key_value( |
| 181 GetPublicKeyValue(public_key_spki_der)); | 181 GetPublicKeyValue(public_key_spki_der)); |
| 182 | 182 |
| 183 DCHECK(platform_keys->end() == platform_keys->Find(*key_value)) | 183 DCHECK(platform_keys->end() == platform_keys->Find(*key_value)) |
| 184 << "Keys are assumed to be generated and not to be registered multiple " | 184 << "Keys are assumed to be generated and not to be registered multiple " |
| 185 "times."; | 185 "times."; |
| 186 platform_keys->Append(key_value.release()); | 186 platform_keys->Append(key_value.release()); |
| 187 | 187 |
| 188 state_store_->SetExtensionValue(extension_id, | 188 state_store_->SetExtensionValue( |
| 189 kStateStorePlatformKeys, | 189 extension_id, kStateStorePlatformKeys, platform_keys.Pass()); |
| 190 platform_keys.PassAs<base::Value>()); | |
| 191 callback.Run(true); | 190 callback.Run(true); |
| 192 } | 191 } |
| 193 | 192 |
| 194 void PlatformKeysService::InvalidateKey( | 193 void PlatformKeysService::InvalidateKey( |
| 195 const std::string& extension_id, | 194 const std::string& extension_id, |
| 196 const std::string& public_key_spki_der, | 195 const std::string& public_key_spki_der, |
| 197 const base::Callback<void(bool)>& callback, | 196 const base::Callback<void(bool)>& callback, |
| 198 scoped_ptr<base::ListValue> platform_keys) { | 197 scoped_ptr<base::ListValue> platform_keys) { |
| 199 scoped_ptr<base::StringValue> key_value( | 198 scoped_ptr<base::StringValue> key_value( |
| 200 GetPublicKeyValue(public_key_spki_der)); | 199 GetPublicKeyValue(public_key_spki_der)); |
| 201 | 200 |
| 202 size_t index = 0; | 201 size_t index = 0; |
| 203 if (!platform_keys->Remove(*key_value, &index)) { | 202 if (!platform_keys->Remove(*key_value, &index)) { |
| 204 // The key is not found, so it's not valid to use it for signing. | 203 // The key is not found, so it's not valid to use it for signing. |
| 205 callback.Run(false); | 204 callback.Run(false); |
| 206 return; | 205 return; |
| 207 } | 206 } |
| 208 | 207 |
| 209 state_store_->SetExtensionValue(extension_id, | 208 state_store_->SetExtensionValue( |
| 210 kStateStorePlatformKeys, | 209 extension_id, kStateStorePlatformKeys, platform_keys.Pass()); |
| 211 platform_keys.PassAs<base::Value>()); | |
| 212 callback.Run(true); | 210 callback.Run(true); |
| 213 } | 211 } |
| 214 | 212 |
| 215 void PlatformKeysService::GotPlatformKeysOfExtension( | 213 void PlatformKeysService::GotPlatformKeysOfExtension( |
| 216 const std::string& extension_id, | 214 const std::string& extension_id, |
| 217 const GetPlatformKeysCallback& callback, | 215 const GetPlatformKeysCallback& callback, |
| 218 scoped_ptr<base::Value> value) { | 216 scoped_ptr<base::Value> value) { |
| 219 if (!value) | 217 if (!value) |
| 220 value.reset(new base::ListValue); | 218 value.reset(new base::ListValue); |
| 221 | 219 |
| 222 base::ListValue* keys = NULL; | 220 base::ListValue* keys = NULL; |
| 223 if (!value->GetAsList(&keys)) { | 221 if (!value->GetAsList(&keys)) { |
| 224 LOG(ERROR) << "Found a value of wrong type."; | 222 LOG(ERROR) << "Found a value of wrong type."; |
| 225 value.reset(); | 223 value.reset(); |
| 226 } | 224 } |
| 227 ignore_result(value.release()); | 225 ignore_result(value.release()); |
| 228 callback.Run(make_scoped_ptr(keys)); | 226 callback.Run(make_scoped_ptr(keys)); |
| 229 } | 227 } |
| 230 | 228 |
| 231 } // namespace chromeos | 229 } // namespace chromeos |
| OLD | NEW |