Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/ownership/owner_key_util_impl.h" | |
| 6 | |
| 7 #include <limits> | |
| 8 | |
| 9 #include "base/file_util.h" | |
| 10 #include "base/logging.h" | |
| 11 #include "base/sys_info.h" | |
| 12 #include "crypto/rsa_private_key.h" | |
| 13 | |
| 14 namespace ownership { | |
| 15 | |
| 16 OwnerKeyUtilImpl::OwnerKeyUtilImpl(const base::FilePath& public_key_file) | |
| 17 : public_key_file_(public_key_file) { | |
| 18 } | |
| 19 | |
| 20 OwnerKeyUtilImpl::~OwnerKeyUtilImpl() { | |
| 21 } | |
| 22 | |
| 23 bool OwnerKeyUtilImpl::ImportPublicKey(std::vector<uint8>* output) { | |
| 24 // Get the file size (must fit in a 32 bit int for NSS). | |
| 25 int64 file_size; | |
| 26 if (!base::GetFileSize(public_key_file_, &file_size)) { | |
| 27 #if defined(OS_CHROMEOS) | |
| 28 LOG_IF(ERROR, base::SysInfo::IsRunningOnChromeOS()) | |
|
erikwright (departed)
2014/08/28 18:39:58
Is this LOG_IF actually required, given the "#if d
ygorshenin1
2014/08/28 18:59:05
Done.
| |
| 29 << "Could not get size of " << public_key_file_.value(); | |
| 30 #endif // defined(OS_CHROMEOS) | |
| 31 return false; | |
| 32 } | |
| 33 if (file_size > static_cast<int64>(std::numeric_limits<int>::max())) { | |
| 34 LOG(ERROR) << public_key_file_.value() << "is " << file_size | |
| 35 << "bytes!!! Too big!"; | |
| 36 return false; | |
| 37 } | |
| 38 int32 safe_file_size = static_cast<int32>(file_size); | |
| 39 | |
| 40 output->resize(safe_file_size); | |
| 41 | |
| 42 if (safe_file_size == 0) { | |
| 43 LOG(WARNING) << "Public key file is empty. This seems wrong."; | |
| 44 return false; | |
| 45 } | |
| 46 | |
| 47 // Get the key data off of disk | |
| 48 int data_read = | |
| 49 base::ReadFile(public_key_file_, | |
| 50 reinterpret_cast<char*>(vector_as_array(output)), | |
| 51 safe_file_size); | |
| 52 return data_read == safe_file_size; | |
| 53 } | |
| 54 | |
| 55 #if defined(USE_NSS) | |
| 56 crypto::RSAPrivateKey* OwnerKeyUtilImpl::FindPrivateKeyInSlot( | |
| 57 const std::vector<uint8>& key, | |
| 58 PK11SlotInfo* slot) { | |
| 59 return crypto::RSAPrivateKey::FindFromPublicKeyInfoInSlot(key, slot); | |
| 60 } | |
| 61 #endif // defined(USE_NSS) | |
| 62 | |
| 63 bool OwnerKeyUtilImpl::IsPublicKeyPresent() { | |
| 64 return base::PathExists(public_key_file_); | |
| 65 } | |
| 66 | |
| 67 } // namespace ownership | |
| OLD | NEW |