| 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/ownership/owner_settings_service_chromeos.h" | 5 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" |
| 6 | 6 |
| 7 #include <keyhi.h> | 7 #include <keyhi.h> |
| 8 #include <stdint.h> |
| 8 | 9 |
| 9 #include <algorithm> | 10 #include <algorithm> |
| 10 #include <string> | 11 #include <string> |
| 11 | 12 |
| 12 #include "base/bind.h" | 13 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
| 14 #include "base/callback.h" | 15 #include "base/callback.h" |
| 15 #include "base/command_line.h" | 16 #include "base/command_line.h" |
| 16 #include "base/prefs/pref_service.h" | 17 #include "base/prefs/pref_service.h" |
| 17 #include "base/threading/thread_checker.h" | 18 #include "base/threading/thread_checker.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 FROM_HERE, | 95 FROM_HERE, |
| 95 base::Bind(callback, public_key, private_key)); | 96 base::Bind(callback, public_key, private_key)); |
| 96 } | 97 } |
| 97 | 98 |
| 98 void LoadPrivateKey( | 99 void LoadPrivateKey( |
| 99 const scoped_refptr<OwnerKeyUtil>& owner_key_util, | 100 const scoped_refptr<OwnerKeyUtil>& owner_key_util, |
| 100 const std::string username_hash, | 101 const std::string username_hash, |
| 101 const base::Callback<void(const scoped_refptr<PublicKey>& public_key, | 102 const base::Callback<void(const scoped_refptr<PublicKey>& public_key, |
| 102 const scoped_refptr<PrivateKey>& private_key)>& | 103 const scoped_refptr<PrivateKey>& private_key)>& |
| 103 callback) { | 104 callback) { |
| 104 std::vector<uint8> public_key_data; | 105 std::vector<uint8_t> public_key_data; |
| 105 scoped_refptr<PublicKey> public_key; | 106 scoped_refptr<PublicKey> public_key; |
| 106 if (!owner_key_util->ImportPublicKey(&public_key_data)) { | 107 if (!owner_key_util->ImportPublicKey(&public_key_data)) { |
| 107 scoped_refptr<PrivateKey> private_key; | 108 scoped_refptr<PrivateKey> private_key; |
| 108 BrowserThread::PostTask(BrowserThread::UI, | 109 BrowserThread::PostTask(BrowserThread::UI, |
| 109 FROM_HERE, | 110 FROM_HERE, |
| 110 base::Bind(callback, public_key, private_key)); | 111 base::Bind(callback, public_key, private_key)); |
| 111 return; | 112 return; |
| 112 } | 113 } |
| 113 public_key = new PublicKey(); | 114 public_key = new PublicKey(); |
| 114 public_key->data().swap(public_key_data); | 115 public_key->data().swap(public_key_data); |
| 115 bool rv = BrowserThread::PostTask(BrowserThread::IO, | 116 bool rv = BrowserThread::PostTask(BrowserThread::IO, |
| 116 FROM_HERE, | 117 FROM_HERE, |
| 117 base::Bind(&LoadPrivateKeyByPublicKey, | 118 base::Bind(&LoadPrivateKeyByPublicKey, |
| 118 owner_key_util, | 119 owner_key_util, |
| 119 public_key, | 120 public_key, |
| 120 username_hash, | 121 username_hash, |
| 121 callback)); | 122 callback)); |
| 122 if (!rv) { | 123 if (!rv) { |
| 123 // IO thread doesn't exists in unit tests, but it's safe to use NSS from | 124 // IO thread doesn't exists in unit tests, but it's safe to use NSS from |
| 124 // BlockingPool in unit tests. | 125 // BlockingPool in unit tests. |
| 125 LoadPrivateKeyByPublicKey( | 126 LoadPrivateKeyByPublicKey( |
| 126 owner_key_util, public_key, username_hash, callback); | 127 owner_key_util, public_key, username_hash, callback); |
| 127 } | 128 } |
| 128 } | 129 } |
| 129 | 130 |
| 130 bool DoesPrivateKeyExistAsyncHelper( | 131 bool DoesPrivateKeyExistAsyncHelper( |
| 131 const scoped_refptr<OwnerKeyUtil>& owner_key_util) { | 132 const scoped_refptr<OwnerKeyUtil>& owner_key_util) { |
| 132 std::vector<uint8> public_key; | 133 std::vector<uint8_t> public_key; |
| 133 if (!owner_key_util->ImportPublicKey(&public_key)) | 134 if (!owner_key_util->ImportPublicKey(&public_key)) |
| 134 return false; | 135 return false; |
| 135 crypto::ScopedSECKEYPrivateKey key = | 136 crypto::ScopedSECKEYPrivateKey key = |
| 136 crypto::FindNSSKeyFromPublicKeyInfo(public_key); | 137 crypto::FindNSSKeyFromPublicKeyInfo(public_key); |
| 137 return key && SECKEY_GetPrivateKeyType(key.get()) == rsaKey; | 138 return key && SECKEY_GetPrivateKeyType(key.get()) == rsaKey; |
| 138 } | 139 } |
| 139 | 140 |
| 140 // Checks whether NSS slots with private key are mounted or | 141 // Checks whether NSS slots with private key are mounted or |
| 141 // not. Responds via |callback|. | 142 // not. Responds via |callback|. |
| 142 void DoesPrivateKeyExistAsync( | 143 void DoesPrivateKeyExistAsync( |
| (...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 std::vector<OnManagementSettingsSetCallback> callbacks; | 815 std::vector<OnManagementSettingsSetCallback> callbacks; |
| 815 pending_management_settings_callbacks_.swap(callbacks); | 816 pending_management_settings_callbacks_.swap(callbacks); |
| 816 for (const auto& callback : callbacks) { | 817 for (const auto& callback : callbacks) { |
| 817 if (!callback.is_null()) | 818 if (!callback.is_null()) |
| 818 callback.Run(success); | 819 callback.Run(success); |
| 819 } | 820 } |
| 820 StorePendingChanges(); | 821 StorePendingChanges(); |
| 821 } | 822 } |
| 822 | 823 |
| 823 } // namespace chromeos | 824 } // namespace chromeos |
| OLD | NEW |