| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 callback.Run(std::string() /* no public key */, kErrorInternal); | 42 callback.Run(std::string() /* no public key */, kErrorInternal); |
| 43 } | 43 } |
| 44 | 44 |
| 45 // Callback used by |PlatformKeysService::Sign|. | 45 // Callback used by |PlatformKeysService::Sign|. |
| 46 // Is called with the old validity of |public_key_spki_der| (or false if an | 46 // Is called with the old validity of |public_key_spki_der| (or false if an |
| 47 // error occurred during reading the StateStore). If allowed, starts the actual | 47 // error occurred during reading the StateStore). If allowed, starts the actual |
| 48 // signing operation which will call back |callback|. If not allowed, calls | 48 // signing operation which will call back |callback|. If not allowed, calls |
| 49 // |callback| with an error. | 49 // |callback| with an error. |
| 50 void CheckValidityAndSign(const std::string& token_id, | 50 void CheckValidityAndSign(const std::string& token_id, |
| 51 const std::string& public_key_spki_der, | 51 const std::string& public_key_spki_der, |
| 52 platform_keys::HashAlgorithm hash_algorithm, |
| 52 const std::string& data, | 53 const std::string& data, |
| 53 const PlatformKeysService::SignCallback& callback, | 54 const PlatformKeysService::SignCallback& callback, |
| 54 content::BrowserContext* browser_context, | 55 content::BrowserContext* browser_context, |
| 55 bool key_is_valid) { | 56 bool key_is_valid) { |
| 56 if (!key_is_valid) { | 57 if (!key_is_valid) { |
| 57 callback.Run(std::string() /* no signature */, | 58 callback.Run(std::string() /* no signature */, |
| 58 kErrorKeyNotAllowedForSigning); | 59 kErrorKeyNotAllowedForSigning); |
| 59 return; | 60 return; |
| 60 } | 61 } |
| 61 platform_keys::subtle::Sign( | 62 platform_keys::subtle::Sign(token_id, |
| 62 token_id, public_key_spki_der, data, callback, browser_context); | 63 public_key_spki_der, |
| 64 hash_algorithm, |
| 65 data, |
| 66 callback, |
| 67 browser_context); |
| 63 } | 68 } |
| 64 | 69 |
| 65 } // namespace | 70 } // namespace |
| 66 | 71 |
| 67 PlatformKeysService::PlatformKeysService( | 72 PlatformKeysService::PlatformKeysService( |
| 68 content::BrowserContext* browser_context, | 73 content::BrowserContext* browser_context, |
| 69 extensions::StateStore* state_store) | 74 extensions::StateStore* state_store) |
| 70 : browser_context_(browser_context), | 75 : browser_context_(browser_context), |
| 71 state_store_(state_store), | 76 state_store_(state_store), |
| 72 weak_factory_(this) { | 77 weak_factory_(this) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 87 modulus_length, | 92 modulus_length, |
| 88 base::Bind(&PlatformKeysService::GenerateRSAKeyCallback, | 93 base::Bind(&PlatformKeysService::GenerateRSAKeyCallback, |
| 89 weak_factory_.GetWeakPtr(), | 94 weak_factory_.GetWeakPtr(), |
| 90 extension_id, | 95 extension_id, |
| 91 callback), | 96 callback), |
| 92 browser_context_); | 97 browser_context_); |
| 93 } | 98 } |
| 94 | 99 |
| 95 void PlatformKeysService::Sign(const std::string& token_id, | 100 void PlatformKeysService::Sign(const std::string& token_id, |
| 96 const std::string& public_key_spki_der, | 101 const std::string& public_key_spki_der, |
| 102 platform_keys::HashAlgorithm hash_algorithm, |
| 97 const std::string& data, | 103 const std::string& data, |
| 98 const std::string& extension_id, | 104 const std::string& extension_id, |
| 99 const SignCallback& callback) { | 105 const SignCallback& callback) { |
| 100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 101 ReadValidityAndInvalidateKey(extension_id, | 107 ReadValidityAndInvalidateKey(extension_id, |
| 102 public_key_spki_der, | 108 public_key_spki_der, |
| 103 base::Bind(&CheckValidityAndSign, | 109 base::Bind(&CheckValidityAndSign, |
| 104 token_id, | 110 token_id, |
| 105 public_key_spki_der, | 111 public_key_spki_der, |
| 112 hash_algorithm, |
| 106 data, | 113 data, |
| 107 callback, | 114 callback, |
| 108 browser_context_)); | 115 browser_context_)); |
| 109 } | 116 } |
| 110 | 117 |
| 111 void PlatformKeysService::RegisterPublicKey( | 118 void PlatformKeysService::RegisterPublicKey( |
| 112 const std::string& extension_id, | 119 const std::string& extension_id, |
| 113 const std::string& public_key_spki_der, | 120 const std::string& public_key_spki_der, |
| 114 const base::Callback<void(bool)>& callback) { | 121 const base::Callback<void(bool)>& callback) { |
| 115 GetPlatformKeysOfExtension( | 122 GetPlatformKeysOfExtension( |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 base::ListValue* keys = NULL; | 222 base::ListValue* keys = NULL; |
| 216 if (!value->GetAsList(&keys)) { | 223 if (!value->GetAsList(&keys)) { |
| 217 LOG(ERROR) << "Found a value of wrong type."; | 224 LOG(ERROR) << "Found a value of wrong type."; |
| 218 value.reset(); | 225 value.reset(); |
| 219 } | 226 } |
| 220 ignore_result(value.release()); | 227 ignore_result(value.release()); |
| 221 callback.Run(make_scoped_ptr(keys)); | 228 callback.Run(make_scoped_ptr(keys)); |
| 222 } | 229 } |
| 223 | 230 |
| 224 } // namespace chromeos | 231 } // namespace chromeos |
| OLD | NEW |