Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(239)

Side by Side Diff: components/ownership/owner_key_util_chromeos.cc

Issue 494093002: OwnerKeyUtil is moved to components/ownership. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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_chromeos.h"
6
7 #include <limits>
8
9 #include "base/basictypes.h"
10 #include "base/files/file_util.h"
11 #include "base/logging.h"
12 #include "base/sys_info.h"
13 #include "crypto/rsa_private_key.h"
14
15 namespace ownership {
16
17 OwnerKeyUtilChromeOS::OwnerKeyUtilChromeOS(const base::FilePath& key_file)
18 : key_file_(key_file) {
19 }
20
21 OwnerKeyUtilChromeOS::~OwnerKeyUtilChromeOS() {
22 }
23
24 bool OwnerKeyUtilChromeOS::ImportPublicKey(std::vector<uint8>* output) {
25 // Get the file size (must fit in a 32 bit int for NSS).
26 int64 file_size;
27 if (!base::GetFileSize(key_file_, &file_size)) {
28 LOG_IF(ERROR, base::SysInfo::IsRunningOnChromeOS())
29 << "Could not get size of " << key_file_.value();
30 return false;
31 }
32 if (file_size > static_cast<int64>(std::numeric_limits<int>::max())) {
33 LOG(ERROR) << key_file_.value() << "is " << file_size
34 << "bytes!!! Too big!";
35 return false;
36 }
37 int32 safe_file_size = static_cast<int32>(file_size);
38
39 output->resize(safe_file_size);
40
41 if (safe_file_size == 0) {
42 LOG(WARNING) << "Public key file is empty. This seems wrong.";
43 return false;
44 }
45
46 // Get the key data off of disk
47 int data_read =
48 base::ReadFile(key_file_,
49 reinterpret_cast<char*>(vector_as_array(output)),
50 safe_file_size);
51 return data_read == safe_file_size;
52 }
53
54 crypto::RSAPrivateKey* OwnerKeyUtilChromeOS::FindPrivateKeyInSlot(
55 const std::vector<uint8>& key,
56 PK11SlotInfo* slot) {
57 return crypto::RSAPrivateKey::FindFromPublicKeyInfoInSlot(key, slot);
58 }
59
60 bool OwnerKeyUtilChromeOS::IsPublicKeyPresent() {
61 return base::PathExists(key_file_);
62 }
63
64 } // namespace ownership
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698