| 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 "components/ownership/owner_key_util_impl.h" | 5 #include "components/ownership/owner_key_util_impl.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 |
| 12 #if defined(USE_NSS_CERTS) |
| 13 #include <keythi.h> |
| 14 #include "crypto/nss_key_util.h" |
| 11 #include "crypto/rsa_private_key.h" | 15 #include "crypto/rsa_private_key.h" |
| 16 #endif |
| 12 | 17 |
| 13 namespace ownership { | 18 namespace ownership { |
| 14 | 19 |
| 15 OwnerKeyUtilImpl::OwnerKeyUtilImpl(const base::FilePath& public_key_file) | 20 OwnerKeyUtilImpl::OwnerKeyUtilImpl(const base::FilePath& public_key_file) |
| 16 : public_key_file_(public_key_file) { | 21 : public_key_file_(public_key_file) { |
| 17 } | 22 } |
| 18 | 23 |
| 19 OwnerKeyUtilImpl::~OwnerKeyUtilImpl() { | 24 OwnerKeyUtilImpl::~OwnerKeyUtilImpl() { |
| 20 } | 25 } |
| 21 | 26 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 47 base::ReadFile(public_key_file_, | 52 base::ReadFile(public_key_file_, |
| 48 reinterpret_cast<char*>(vector_as_array(output)), | 53 reinterpret_cast<char*>(vector_as_array(output)), |
| 49 safe_file_size); | 54 safe_file_size); |
| 50 return data_read == safe_file_size; | 55 return data_read == safe_file_size; |
| 51 } | 56 } |
| 52 | 57 |
| 53 #if defined(USE_NSS_CERTS) | 58 #if defined(USE_NSS_CERTS) |
| 54 crypto::RSAPrivateKey* OwnerKeyUtilImpl::FindPrivateKeyInSlot( | 59 crypto::RSAPrivateKey* OwnerKeyUtilImpl::FindPrivateKeyInSlot( |
| 55 const std::vector<uint8>& key, | 60 const std::vector<uint8>& key, |
| 56 PK11SlotInfo* slot) { | 61 PK11SlotInfo* slot) { |
| 57 return crypto::RSAPrivateKey::FindFromPublicKeyInfoInSlot(key, slot); | 62 crypto::ScopedSECKEYPrivateKey private_key( |
| 63 crypto::FindNSSKeyFromPublicKeyInfoInSlot(key, slot)); |
| 64 if (!private_key || SECKEY_GetPrivateKeyType(private_key.get()) != rsaKey) |
| 65 return nullptr; |
| 66 #if defined(USE_OPENSSL) |
| 67 // TODO(davidben): This assumes that crypto::RSAPrivateKey also uses NSS. |
| 68 // https://crbug.com/478777 |
| 69 NOTIMPLEMENTED(); |
| 70 return nullptr; |
| 71 #else |
| 72 return crypto::RSAPrivateKey::CreateFromKey(private_key.get()); |
| 73 #endif |
| 58 } | 74 } |
| 59 #endif // defined(USE_NSS_CERTS) | 75 #endif // defined(USE_NSS_CERTS) |
| 60 | 76 |
| 61 bool OwnerKeyUtilImpl::IsPublicKeyPresent() { | 77 bool OwnerKeyUtilImpl::IsPublicKeyPresent() { |
| 62 return base::PathExists(public_key_file_); | 78 return base::PathExists(public_key_file_); |
| 63 } | 79 } |
| 64 | 80 |
| 65 } // namespace ownership | 81 } // namespace ownership |
| OLD | NEW |