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

Side by Side Diff: chrome/browser/chromeos/login/owner_key_utils.cc

Issue 6538098: [Chrome OS] Owner keys are generated outside Chrome now; handle appropriately (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 10 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
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/chromeos/login/owner_key_utils.h" 5 #include "chrome/browser/chromeos/login/owner_key_utils.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/crypto/rsa_private_key.h" 9 #include "base/crypto/rsa_private_key.h"
10 #include "base/crypto/signature_creator.h" 10 #include "base/crypto/signature_creator.h"
(...skipping 22 matching lines...) Expand all
33 33
34 OwnerKeyUtils::~OwnerKeyUtils() {} 34 OwnerKeyUtils::~OwnerKeyUtils() {}
35 35
36 /////////////////////////////////////////////////////////////////////////// 36 ///////////////////////////////////////////////////////////////////////////
37 // OwnerKeyUtilsImpl 37 // OwnerKeyUtilsImpl
38 38
39 class OwnerKeyUtilsImpl : public OwnerKeyUtils { 39 class OwnerKeyUtilsImpl : public OwnerKeyUtils {
40 public: 40 public:
41 OwnerKeyUtilsImpl(); 41 OwnerKeyUtilsImpl();
42 42
43 RSAPrivateKey* GenerateKeyPair();
44
45 bool ExportPublicKeyViaDbus(RSAPrivateKey* pair,
46 LoginLibrary::Delegate* d);
47
48 bool ExportPublicKeyToFile(RSAPrivateKey* pair, const FilePath& key_file);
49
50 bool ImportPublicKey(const FilePath& key_file, 43 bool ImportPublicKey(const FilePath& key_file,
51 std::vector<uint8>* output); 44 std::vector<uint8>* output);
52 45
53 bool Verify(const std::string& data, 46 bool Verify(const std::string& data,
54 const std::vector<uint8> signature, 47 const std::vector<uint8> signature,
55 const std::vector<uint8> public_key); 48 const std::vector<uint8> public_key);
56 49
57 bool Sign(const std::string& data, 50 bool Sign(const std::string& data,
58 std::vector<uint8>* OUT_signature, 51 std::vector<uint8>* OUT_signature,
59 base::RSAPrivateKey* key); 52 base::RSAPrivateKey* key);
60 53
61 RSAPrivateKey* FindPrivateKey(const std::vector<uint8>& key); 54 RSAPrivateKey* FindPrivateKey(const std::vector<uint8>& key);
62 55
63 FilePath GetOwnerKeyFilePath(); 56 FilePath GetOwnerKeyFilePath();
64 57
65 protected: 58 protected:
66 virtual ~OwnerKeyUtilsImpl(); 59 virtual ~OwnerKeyUtilsImpl();
67 60
61 bool ExportPublicKeyToFile(RSAPrivateKey* pair, const FilePath& key_file);
62
68 private: 63 private:
69 // The file outside the owner's encrypted home directory where her 64 // The file outside the owner's encrypted home directory where her
70 // key will live. 65 // key will live.
71 static const char kOwnerKeyFile[]; 66 static const char kOwnerKeyFile[];
72 67
73 // Key generation parameters.
74 static const uint16 kKeySizeInBits;
75
76 DISALLOW_COPY_AND_ASSIGN(OwnerKeyUtilsImpl); 68 DISALLOW_COPY_AND_ASSIGN(OwnerKeyUtilsImpl);
77 }; 69 };
78 70
79 // Defined here, instead of up above, because we need OwnerKeyUtilsImpl. 71 // Defined here, instead of up above, because we need OwnerKeyUtilsImpl.
80 OwnerKeyUtils* OwnerKeyUtils::Create() { 72 OwnerKeyUtils* OwnerKeyUtils::Create() {
81 if (!factory_) 73 if (!factory_)
82 return new OwnerKeyUtilsImpl(); 74 return new OwnerKeyUtilsImpl();
83 else 75 else
84 return factory_->CreateOwnerKeyUtils(); 76 return factory_->CreateOwnerKeyUtils();
85 } 77 }
86 78
87 // static 79 // static
88 const char OwnerKeyUtilsImpl::kOwnerKeyFile[] = "/var/lib/whitelist/owner.key"; 80 const char OwnerKeyUtilsImpl::kOwnerKeyFile[] = "/var/lib/whitelist/owner.key";
89 81
90 // We're generating and using 2048-bit RSA keys.
91 // static
92 const uint16 OwnerKeyUtilsImpl::kKeySizeInBits = 2048;
93
94 OwnerKeyUtilsImpl::OwnerKeyUtilsImpl() {} 82 OwnerKeyUtilsImpl::OwnerKeyUtilsImpl() {}
95 83
96 OwnerKeyUtilsImpl::~OwnerKeyUtilsImpl() {} 84 OwnerKeyUtilsImpl::~OwnerKeyUtilsImpl() {}
97 85
98 RSAPrivateKey* OwnerKeyUtilsImpl::GenerateKeyPair() {
99 return RSAPrivateKey::CreateSensitive(kKeySizeInBits);
100 }
101
102 bool OwnerKeyUtilsImpl::ExportPublicKeyViaDbus(RSAPrivateKey* pair,
103 LoginLibrary::Delegate* d) {
104 DCHECK(pair);
105 bool ok = false;
106
107 std::vector<uint8> to_export;
108 if (!pair->ExportPublicKey(&to_export)) {
109 LOG(ERROR) << "Formatting key for export via dbus failed!";
110 return false;
111 }
112
113 if (CrosLibrary::Get()->EnsureLoaded())
114 ok = CrosLibrary::Get()->GetLoginLibrary()->SetOwnerKeyAsync(to_export, d);
115
116 return ok;
117 }
118
119 bool OwnerKeyUtilsImpl::ExportPublicKeyToFile(RSAPrivateKey* pair, 86 bool OwnerKeyUtilsImpl::ExportPublicKeyToFile(RSAPrivateKey* pair,
120 const FilePath& key_file) { 87 const FilePath& key_file) {
121 DCHECK(pair); 88 DCHECK(pair);
122 bool ok = false; 89 bool ok = false;
123 int safe_file_size = 0; 90 int safe_file_size = 0;
124 91
125 std::vector<uint8> to_export; 92 std::vector<uint8> to_export;
126 if (!pair->ExportPublicKey(&to_export)) { 93 if (!pair->ExportPublicKey(&to_export)) {
127 LOG(ERROR) << "Formatting key for export failed!"; 94 LOG(ERROR) << "Formatting key for export failed!";
128 return false; 95 return false;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 RSAPrivateKey* OwnerKeyUtilsImpl::FindPrivateKey( 161 RSAPrivateKey* OwnerKeyUtilsImpl::FindPrivateKey(
195 const std::vector<uint8>& key) { 162 const std::vector<uint8>& key) {
196 return RSAPrivateKey::FindFromPublicKeyInfo(key); 163 return RSAPrivateKey::FindFromPublicKeyInfo(key);
197 } 164 }
198 165
199 FilePath OwnerKeyUtilsImpl::GetOwnerKeyFilePath() { 166 FilePath OwnerKeyUtilsImpl::GetOwnerKeyFilePath() {
200 return FilePath(OwnerKeyUtilsImpl::kOwnerKeyFile); 167 return FilePath(OwnerKeyUtilsImpl::kOwnerKeyFile);
201 } 168 }
202 169
203 } // namespace chromeos 170 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/owner_key_utils.h ('k') | chrome/browser/chromeos/login/owner_key_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698