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

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

Issue 6805019: Move crypto files out of base, to a top level directory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fixes comments by eroman Created 9 years, 8 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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"
10 #include "base/crypto/signature_creator.h"
11 #include "base/crypto/signature_verifier.h"
12 #include "base/file_path.h" 9 #include "base/file_path.h"
13 #include "base/file_util.h" 10 #include "base/file_util.h"
14 #include "base/logging.h" 11 #include "base/logging.h"
15 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
16 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "crypto/rsa_private_key.h"
15 #include "crypto/signature_creator.h"
16 #include "crypto/signature_verifier.h"
17 #include "chrome/browser/chromeos/cros/cros_library.h" 17 #include "chrome/browser/chromeos/cros/cros_library.h"
18 #include "chrome/browser/chromeos/cros/login_library.h" 18 #include "chrome/browser/chromeos/cros/login_library.h"
19 #include "chrome/common/extensions/extension_constants.h" 19 #include "chrome/common/extensions/extension_constants.h"
20 20
21 using base::RSAPrivateKey;
22 using extension_misc::kSignatureAlgorithm; 21 using extension_misc::kSignatureAlgorithm;
23 22
24 namespace chromeos { 23 namespace chromeos {
25 24
26 /////////////////////////////////////////////////////////////////////////// 25 ///////////////////////////////////////////////////////////////////////////
27 // OwnerKeyUtils 26 // OwnerKeyUtils
28 27
29 // static 28 // static
30 OwnerKeyUtils::Factory* OwnerKeyUtils::factory_ = NULL; 29 OwnerKeyUtils::Factory* OwnerKeyUtils::factory_ = NULL;
31 30
(...skipping 10 matching lines...) Expand all
42 41
43 bool ImportPublicKey(const FilePath& key_file, 42 bool ImportPublicKey(const FilePath& key_file,
44 std::vector<uint8>* output); 43 std::vector<uint8>* output);
45 44
46 bool Verify(const std::string& data, 45 bool Verify(const std::string& data,
47 const std::vector<uint8> signature, 46 const std::vector<uint8> signature,
48 const std::vector<uint8> public_key); 47 const std::vector<uint8> public_key);
49 48
50 bool Sign(const std::string& data, 49 bool Sign(const std::string& data,
51 std::vector<uint8>* OUT_signature, 50 std::vector<uint8>* OUT_signature,
52 base::RSAPrivateKey* key); 51 crypto::RSAPrivateKey* key);
53 52
54 RSAPrivateKey* FindPrivateKey(const std::vector<uint8>& key); 53 crypto::RSAPrivateKey* FindPrivateKey(const std::vector<uint8>& key);
55 54
56 FilePath GetOwnerKeyFilePath(); 55 FilePath GetOwnerKeyFilePath();
57 56
58 protected: 57 protected:
59 virtual ~OwnerKeyUtilsImpl(); 58 virtual ~OwnerKeyUtilsImpl();
60 59
61 bool ExportPublicKeyToFile(RSAPrivateKey* pair, const FilePath& key_file); 60 bool ExportPublicKeyToFile(crypto::RSAPrivateKey* pair,
61 const FilePath& key_file);
62 62
63 private: 63 private:
64 // The file outside the owner's encrypted home directory where her 64 // The file outside the owner's encrypted home directory where her
65 // key will live. 65 // key will live.
66 static const char kOwnerKeyFile[]; 66 static const char kOwnerKeyFile[];
67 67
68 DISALLOW_COPY_AND_ASSIGN(OwnerKeyUtilsImpl); 68 DISALLOW_COPY_AND_ASSIGN(OwnerKeyUtilsImpl);
69 }; 69 };
70 70
71 // Defined here, instead of up above, because we need OwnerKeyUtilsImpl. 71 // Defined here, instead of up above, because we need OwnerKeyUtilsImpl.
72 OwnerKeyUtils* OwnerKeyUtils::Create() { 72 OwnerKeyUtils* OwnerKeyUtils::Create() {
73 if (!factory_) 73 if (!factory_)
74 return new OwnerKeyUtilsImpl(); 74 return new OwnerKeyUtilsImpl();
75 else 75 else
76 return factory_->CreateOwnerKeyUtils(); 76 return factory_->CreateOwnerKeyUtils();
77 } 77 }
78 78
79 // static 79 // static
80 const char OwnerKeyUtilsImpl::kOwnerKeyFile[] = "/var/lib/whitelist/owner.key"; 80 const char OwnerKeyUtilsImpl::kOwnerKeyFile[] = "/var/lib/whitelist/owner.key";
81 81
82 OwnerKeyUtilsImpl::OwnerKeyUtilsImpl() {} 82 OwnerKeyUtilsImpl::OwnerKeyUtilsImpl() {}
83 83
84 OwnerKeyUtilsImpl::~OwnerKeyUtilsImpl() {} 84 OwnerKeyUtilsImpl::~OwnerKeyUtilsImpl() {}
85 85
86 bool OwnerKeyUtilsImpl::ExportPublicKeyToFile(RSAPrivateKey* pair, 86 bool OwnerKeyUtilsImpl::ExportPublicKeyToFile(crypto::RSAPrivateKey* pair,
87 const FilePath& key_file) { 87 const FilePath& key_file) {
88 DCHECK(pair); 88 DCHECK(pair);
89 bool ok = false; 89 bool ok = false;
90 int safe_file_size = 0; 90 int safe_file_size = 0;
91 91
92 std::vector<uint8> to_export; 92 std::vector<uint8> to_export;
93 if (!pair->ExportPublicKey(&to_export)) { 93 if (!pair->ExportPublicKey(&to_export)) {
94 LOG(ERROR) << "Formatting key for export failed!"; 94 LOG(ERROR) << "Formatting key for export failed!";
95 return false; 95 return false;
96 } 96 }
(...skipping 30 matching lines...) Expand all
127 // Get the key data off of disk 127 // Get the key data off of disk
128 int data_read = file_util::ReadFile(key_file, 128 int data_read = file_util::ReadFile(key_file,
129 reinterpret_cast<char*>(&(output->at(0))), 129 reinterpret_cast<char*>(&(output->at(0))),
130 safe_file_size); 130 safe_file_size);
131 return data_read == safe_file_size; 131 return data_read == safe_file_size;
132 } 132 }
133 133
134 bool OwnerKeyUtilsImpl::Verify(const std::string& data, 134 bool OwnerKeyUtilsImpl::Verify(const std::string& data,
135 const std::vector<uint8> signature, 135 const std::vector<uint8> signature,
136 const std::vector<uint8> public_key) { 136 const std::vector<uint8> public_key) {
137 base::SignatureVerifier verifier; 137 crypto::SignatureVerifier verifier;
138 if (!verifier.VerifyInit(kSignatureAlgorithm, sizeof(kSignatureAlgorithm), 138 if (!verifier.VerifyInit(kSignatureAlgorithm, sizeof(kSignatureAlgorithm),
139 &signature[0], signature.size(), 139 &signature[0], signature.size(),
140 &public_key[0], public_key.size())) { 140 &public_key[0], public_key.size())) {
141 return false; 141 return false;
142 } 142 }
143 143
144 verifier.VerifyUpdate(reinterpret_cast<const uint8*>(data.c_str()), 144 verifier.VerifyUpdate(reinterpret_cast<const uint8*>(data.c_str()),
145 data.length()); 145 data.length());
146 return (verifier.VerifyFinal()); 146 return (verifier.VerifyFinal());
147 } 147 }
148 148
149 bool OwnerKeyUtilsImpl::Sign(const std::string& data, 149 bool OwnerKeyUtilsImpl::Sign(const std::string& data,
150 std::vector<uint8>* OUT_signature, 150 std::vector<uint8>* OUT_signature,
151 base::RSAPrivateKey* key) { 151 crypto::RSAPrivateKey* key) {
152 scoped_ptr<base::SignatureCreator> signer( 152 scoped_ptr<crypto::SignatureCreator> signer(
153 base::SignatureCreator::Create(key)); 153 crypto::SignatureCreator::Create(key));
154 if (!signer->Update(reinterpret_cast<const uint8*>(data.c_str()), 154 if (!signer->Update(reinterpret_cast<const uint8*>(data.c_str()),
155 data.length())) { 155 data.length())) {
156 return false; 156 return false;
157 } 157 }
158 return signer->Final(OUT_signature); 158 return signer->Final(OUT_signature);
159 } 159 }
160 160
161 RSAPrivateKey* OwnerKeyUtilsImpl::FindPrivateKey( 161 crypto::RSAPrivateKey* OwnerKeyUtilsImpl::FindPrivateKey(
162 const std::vector<uint8>& key) { 162 const std::vector<uint8>& key) {
163 return RSAPrivateKey::FindFromPublicKeyInfo(key); 163 return crypto::RSAPrivateKey::FindFromPublicKeyInfo(key);
164 } 164 }
165 165
166 FilePath OwnerKeyUtilsImpl::GetOwnerKeyFilePath() { 166 FilePath OwnerKeyUtilsImpl::GetOwnerKeyFilePath() {
167 return FilePath(OwnerKeyUtilsImpl::kOwnerKeyFile); 167 return FilePath(OwnerKeyUtilsImpl::kOwnerKeyFile);
168 } 168 }
169 169
170 } // 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