OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "crypto/nss_key_util.h" | 5 #include "crypto/nss_key_util.h" |
6 | 6 |
7 #include <cryptohi.h> | 7 #include <cryptohi.h> |
8 #include <keyhi.h> | 8 #include <keyhi.h> |
9 #include <pk11pub.h> | 9 #include <pk11pub.h> |
10 #include <stdint.h> | 10 #include <stdint.h> |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 AutoSECMODListReadLock auto_lock; | 130 AutoSECMODListReadLock auto_lock; |
131 const SECMODModuleList* head = SECMOD_GetDefaultModuleList(); | 131 const SECMODModuleList* head = SECMOD_GetDefaultModuleList(); |
132 for (const SECMODModuleList* item = head; item != nullptr; | 132 for (const SECMODModuleList* item = head; item != nullptr; |
133 item = item->next) { | 133 item = item->next) { |
134 int slot_count = item->module->loaded ? item->module->slotCount : 0; | 134 int slot_count = item->module->loaded ? item->module->slotCount : 0; |
135 for (int i = 0; i < slot_count; i++) { | 135 for (int i = 0; i < slot_count; i++) { |
136 // Look for the key in slot |i|. | 136 // Look for the key in slot |i|. |
137 ScopedSECKEYPrivateKey key( | 137 ScopedSECKEYPrivateKey key( |
138 PK11_FindKeyByKeyID(item->module->slots[i], cka_id.get(), nullptr)); | 138 PK11_FindKeyByKeyID(item->module->slots[i], cka_id.get(), nullptr)); |
139 if (key) | 139 if (key) |
140 return key.Pass(); | 140 return key; |
141 } | 141 } |
142 } | 142 } |
143 | 143 |
144 // The key wasn't found in any module. | 144 // The key wasn't found in any module. |
145 return nullptr; | 145 return nullptr; |
146 } | 146 } |
147 | 147 |
148 ScopedSECKEYPrivateKey FindNSSKeyFromPublicKeyInfoInSlot( | 148 ScopedSECKEYPrivateKey FindNSSKeyFromPublicKeyInfoInSlot( |
149 const std::vector<uint8_t>& input, | 149 const std::vector<uint8_t>& input, |
150 PK11SlotInfo* slot) { | 150 PK11SlotInfo* slot) { |
151 DCHECK(slot); | 151 DCHECK(slot); |
152 | 152 |
153 ScopedSECItem cka_id(MakeIDFromSPKI(input)); | 153 ScopedSECItem cka_id(MakeIDFromSPKI(input)); |
154 if (!cka_id) | 154 if (!cka_id) |
155 return nullptr; | 155 return nullptr; |
156 | 156 |
157 return ScopedSECKEYPrivateKey( | 157 return ScopedSECKEYPrivateKey( |
158 PK11_FindKeyByKeyID(slot, cka_id.get(), nullptr)); | 158 PK11_FindKeyByKeyID(slot, cka_id.get(), nullptr)); |
159 } | 159 } |
160 | 160 |
161 #endif // defined(USE_NSS_CERTS) | 161 #endif // defined(USE_NSS_CERTS) |
162 | 162 |
163 } // namespace crypto | 163 } // namespace crypto |
OLD | NEW |