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

Side by Side Diff: chrome/browser/chromeos/settings/owner_key_util.cc

Issue 10828032: Add DeviceSettingsService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 8 years, 3 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 (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/stl_util.h"
12 #include "crypto/rsa_private_key.h"
13
14 namespace chromeos {
15
16 ///////////////////////////////////////////////////////////////////////////
17 // OwnerKeyUtil
18
19 OwnerKeyUtil* OwnerKeyUtil::Create() {
20 return new OwnerKeyUtilImpl(FilePath(OwnerKeyUtilImpl::kOwnerKeyFile));
21 }
22
23 OwnerKeyUtil::OwnerKeyUtil() {}
24
25 OwnerKeyUtil::~OwnerKeyUtil() {}
26
27 ///////////////////////////////////////////////////////////////////////////
28 // OwnerKeyUtilImpl
29
30 // static
31 const char OwnerKeyUtilImpl::kOwnerKeyFile[] = "/var/lib/whitelist/owner.key";
32
33 OwnerKeyUtilImpl::OwnerKeyUtilImpl(const FilePath& key_file)
34 : key_file_(key_file) {}
35
36 OwnerKeyUtilImpl::~OwnerKeyUtilImpl() {}
37
38 bool OwnerKeyUtilImpl::ImportPublicKey(std::vector<uint8>* output) {
39 // Get the file size (must fit in a 32 bit int for NSS).
40 int64 file_size;
41 if (!file_util::GetFileSize(key_file_, &file_size)) {
42 LOG(ERROR) << "Could not get size of " << key_file_.value();
43 return false;
44 }
45 if (file_size > static_cast<int64>(std::numeric_limits<int>::max())) {
46 LOG(ERROR) << key_file_.value() << "is "
47 << file_size << "bytes!!! Too big!";
48 return false;
49 }
50 int32 safe_file_size = static_cast<int32>(file_size);
51
52 output->resize(safe_file_size);
53
54 if (safe_file_size == 0) {
55 LOG(WARNING) << "Public key file is empty. This seems wrong.";
56 return false;
57 }
58
59 // Get the key data off of disk
60 int data_read = file_util::ReadFile(
61 key_file_,
62 reinterpret_cast<char*>(vector_as_array(output)),
63 safe_file_size);
64 return data_read == safe_file_size;
65 }
66
67 crypto::RSAPrivateKey* OwnerKeyUtilImpl::FindPrivateKey(
68 const std::vector<uint8>& key) {
69 return crypto::RSAPrivateKey::FindFromPublicKeyInfo(key);
70 }
71
72 bool OwnerKeyUtilImpl::IsPublicKeyPresent() {
73 return file_util::PathExists(key_file_);
74 }
75
76 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/settings/owner_key_util.h ('k') | chrome/browser/chromeos/settings/owner_key_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698