| 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" | |
| 15 #include "crypto/rsa_private_key.h" | 11 #include "crypto/rsa_private_key.h" |
| 16 #endif | |
| 17 | 12 |
| 18 namespace ownership { | 13 namespace ownership { |
| 19 | 14 |
| 20 OwnerKeyUtilImpl::OwnerKeyUtilImpl(const base::FilePath& public_key_file) | 15 OwnerKeyUtilImpl::OwnerKeyUtilImpl(const base::FilePath& public_key_file) |
| 21 : public_key_file_(public_key_file) { | 16 : public_key_file_(public_key_file) { |
| 22 } | 17 } |
| 23 | 18 |
| 24 OwnerKeyUtilImpl::~OwnerKeyUtilImpl() { | 19 OwnerKeyUtilImpl::~OwnerKeyUtilImpl() { |
| 25 } | 20 } |
| 26 | 21 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 52 base::ReadFile(public_key_file_, | 47 base::ReadFile(public_key_file_, |
| 53 reinterpret_cast<char*>(vector_as_array(output)), | 48 reinterpret_cast<char*>(vector_as_array(output)), |
| 54 safe_file_size); | 49 safe_file_size); |
| 55 return data_read == safe_file_size; | 50 return data_read == safe_file_size; |
| 56 } | 51 } |
| 57 | 52 |
| 58 #if defined(USE_NSS_CERTS) | 53 #if defined(USE_NSS_CERTS) |
| 59 crypto::RSAPrivateKey* OwnerKeyUtilImpl::FindPrivateKeyInSlot( | 54 crypto::RSAPrivateKey* OwnerKeyUtilImpl::FindPrivateKeyInSlot( |
| 60 const std::vector<uint8>& key, | 55 const std::vector<uint8>& key, |
| 61 PK11SlotInfo* slot) { | 56 PK11SlotInfo* slot) { |
| 62 crypto::ScopedSECKEYPrivateKey private_key( | 57 return crypto::RSAPrivateKey::FindFromPublicKeyInfoInSlot(key, slot); |
| 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 | |
| 74 } | 58 } |
| 75 #endif // defined(USE_NSS_CERTS) | 59 #endif // defined(USE_NSS_CERTS) |
| 76 | 60 |
| 77 bool OwnerKeyUtilImpl::IsPublicKeyPresent() { | 61 bool OwnerKeyUtilImpl::IsPublicKeyPresent() { |
| 78 return base::PathExists(public_key_file_); | 62 return base::PathExists(public_key_file_); |
| 79 } | 63 } |
| 80 | 64 |
| 81 } // namespace ownership | 65 } // namespace ownership |
| OLD | NEW |