Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/settings/owner_key_util.h" | |
| 6 | |
| 7 #include <limits> | |
| 8 | |
| 9 #include "base/file_util.h" | |
| 10 #include "base/logging.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/string_util.h" | |
| 13 #include "chrome/browser/chromeos/cros/cros_library.h" | |
|
Chris Masone
2012/08/03 16:28:25
I probably just missed it, but what's this used fo
Mattias Nissler (ping if slow)
2012/08/06 21:28:14
It's not. A few others as well, I removed them all
| |
| 14 #include "chrome/common/extensions/extension_constants.h" | |
| 15 #include "crypto/rsa_private_key.h" | |
| 16 #include "crypto/signature_creator.h" | |
| 17 #include "crypto/signature_verifier.h" | |
| 18 | |
| 19 using extension_misc::kSignatureAlgorithm; | |
| 20 | |
| 21 namespace chromeos { | |
| 22 | |
| 23 /////////////////////////////////////////////////////////////////////////// | |
| 24 // OwnerKeyUtil | |
| 25 | |
| 26 OwnerKeyUtil* OwnerKeyUtil::Create() { | |
| 27 return new OwnerKeyUtilImpl(FilePath(OwnerKeyUtilImpl::kOwnerKeyFile)); | |
| 28 } | |
| 29 | |
| 30 OwnerKeyUtil::OwnerKeyUtil() {} | |
| 31 | |
| 32 OwnerKeyUtil::~OwnerKeyUtil() {} | |
| 33 | |
| 34 /////////////////////////////////////////////////////////////////////////// | |
| 35 // OwnerKeyUtilImpl | |
| 36 | |
| 37 // static | |
| 38 const char OwnerKeyUtilImpl::kOwnerKeyFile[] = "/var/lib/whitelist/owner.key"; | |
| 39 | |
| 40 OwnerKeyUtilImpl::OwnerKeyUtilImpl(const FilePath& key_file) | |
| 41 : key_file_(key_file) {} | |
| 42 | |
| 43 OwnerKeyUtilImpl::~OwnerKeyUtilImpl() {} | |
| 44 | |
| 45 bool OwnerKeyUtilImpl::ImportPublicKey(std::vector<uint8>* output) { | |
| 46 // Get the file size (must fit in a 32 bit int for NSS). | |
| 47 int64 file_size; | |
| 48 if (!file_util::GetFileSize(key_file_, &file_size)) { | |
| 49 LOG(ERROR) << "Could not get size of " << key_file_.value(); | |
| 50 return false; | |
| 51 } | |
| 52 if (file_size > static_cast<int64>(std::numeric_limits<int>::max())) { | |
| 53 LOG(ERROR) << key_file_.value() << "is " | |
| 54 << file_size << "bytes!!! Too big!"; | |
| 55 return false; | |
| 56 } | |
| 57 int32 safe_file_size = static_cast<int32>(file_size); | |
| 58 | |
| 59 output->resize(safe_file_size); | |
| 60 | |
| 61 if (safe_file_size == 0) { | |
| 62 LOG(WARNING) << "Public key file is empty. This seems wrong."; | |
| 63 return false; | |
| 64 } | |
| 65 | |
| 66 // Get the key data off of disk | |
| 67 int data_read = file_util::ReadFile(key_file_, | |
| 68 reinterpret_cast<char*>(&(output->at(0))), | |
| 69 safe_file_size); | |
| 70 return data_read == safe_file_size; | |
| 71 } | |
| 72 | |
| 73 crypto::RSAPrivateKey* OwnerKeyUtilImpl::FindPrivateKey( | |
| 74 const std::vector<uint8>& key) { | |
| 75 return crypto::RSAPrivateKey::FindFromPublicKeyInfo(key); | |
| 76 } | |
| 77 | |
| 78 bool OwnerKeyUtilImpl::IsPublicKeyPresent() { | |
| 79 return file_util::PathExists(key_file_); | |
| 80 } | |
| 81 | |
| 82 } // namespace chromeos | |
| OLD | NEW |