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

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

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 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_OWNER_KEY_UTILS_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_OWNER_KEY_UTILS_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_OWNER_KEY_UTILS_H_ 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_OWNER_KEY_UTILS_H_
7 #pragma once 7 #pragma once
8 8
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/gtest_prod_util.h"
12 #include "base/ref_counted.h" 13 #include "base/ref_counted.h"
13 #include "chrome/browser/chromeos/cros/login_library.h" 14 #include "chrome/browser/chromeos/cros/login_library.h"
14 15
15 class FilePath; 16 class FilePath;
16 17
17 namespace base { 18 namespace base {
18 class RSAPrivateKey; 19 class RSAPrivateKey;
19 } 20 }
20 21
21 namespace chromeos { 22 namespace chromeos {
22 23
24 class OwnerKeyUtilsTest;
25
23 class OwnerKeyUtils : public base::RefCounted<OwnerKeyUtils> { 26 class OwnerKeyUtils : public base::RefCounted<OwnerKeyUtils> {
24 public: 27 public:
25 class Factory { 28 class Factory {
26 public: 29 public:
27 virtual OwnerKeyUtils* CreateOwnerKeyUtils() = 0; 30 virtual OwnerKeyUtils* CreateOwnerKeyUtils() = 0;
28 }; 31 };
29 32
30 OwnerKeyUtils(); 33 OwnerKeyUtils();
31 34
32 // Sets the factory used by the static method Create to create an 35 // Sets the factory used by the static method Create to create an
33 // OwnerKeyUtils. OwnerKeyUtils does not take ownership of 36 // OwnerKeyUtils. OwnerKeyUtils does not take ownership of
34 // |factory|. A value of NULL results in an OwnerKeyUtils being 37 // |factory|. A value of NULL results in an OwnerKeyUtils being
35 // created directly. 38 // created directly.
36 #if defined(UNIT_TEST) 39 #if defined(UNIT_TEST)
37 static void set_factory(Factory* factory) { factory_ = factory; } 40 static void set_factory(Factory* factory) { factory_ = factory; }
38 #endif 41 #endif
39 42
40 // Creates an OwnerKeyUtils, ownership returns to the caller. If there is no 43 // Creates an OwnerKeyUtils, ownership returns to the caller. If there is no
41 // Factory (the default) this creates and returns a new OwnerKeyUtils. 44 // Factory (the default) this creates and returns a new OwnerKeyUtils.
42 static OwnerKeyUtils* Create(); 45 static OwnerKeyUtils* Create();
43 46
44 // Generate a public/private RSA keypair and store them in the NSS database.
45 // The keys will be kKeySizeInBits in length (Recommend >= 2048 bits).
46 // The caller takes ownership.
47 //
48 // Returns NULL on error.
49 virtual base::RSAPrivateKey* GenerateKeyPair() = 0;
50
51 // DER encodes public half of |pair| and asynchronously exports it via DBus.
52 // The data sent is a DER-encoded X509 SubjectPublicKeyInfo object.
53 // Returns false on error, true if the attempt is successfully begun.
54 // d->Run() will be called with a boolean indicating success or failure when
55 // the attempt is complete.
56 virtual bool ExportPublicKeyViaDbus(base::RSAPrivateKey* pair,
57 LoginLibrary::Delegate* d) = 0;
58
59 // DER encodes public half of |pair| and writes it out to |key_file|.
60 // The blob on disk is a DER-encoded X509 SubjectPublicKeyInfo object.
61 // Returns false on error.
62 virtual bool ExportPublicKeyToFile(base::RSAPrivateKey* pair,
63 const FilePath& key_file) = 0;
64
65 // Assumes that the file at |key_file| exists. 47 // Assumes that the file at |key_file| exists.
66 // Upon success, returns true and populates |output|. False on failure. 48 // Upon success, returns true and populates |output|. False on failure.
67 virtual bool ImportPublicKey(const FilePath& key_file, 49 virtual bool ImportPublicKey(const FilePath& key_file,
68 std::vector<uint8>* output) = 0; 50 std::vector<uint8>* output) = 0;
69 51
70 // Verfiy that |signature| is a Sha1-with-RSA signature over |data| with 52 // Verfiy that |signature| is a Sha1-with-RSA signature over |data| with
71 // |public_key| 53 // |public_key|
72 // Returns true if so, false on bad signature or other error. 54 // Returns true if so, false on bad signature or other error.
73 virtual bool Verify(const std::string& data, 55 virtual bool Verify(const std::string& data,
74 const std::vector<uint8> signature, 56 const std::vector<uint8> signature,
75 const std::vector<uint8> public_key) = 0; 57 const std::vector<uint8> public_key) = 0;
76 58
77 // Sign |data| with |key| using Sha1 with RSA. If successful, return true 59 // Sign |data| with |key| using Sha1 with RSA. If successful, return true
78 // and populate |OUT_signature|. 60 // and populate |OUT_signature|.
79 virtual bool Sign(const std::string& data, 61 virtual bool Sign(const std::string& data,
80 std::vector<uint8>* OUT_signature, 62 std::vector<uint8>* OUT_signature,
81 base::RSAPrivateKey* key) = 0; 63 base::RSAPrivateKey* key) = 0;
82 64
83 // Looks for the private key associated with |key| in the default slot, 65 // Looks for the private key associated with |key| in the default slot,
84 // and returns it if it can be found. Returns NULL otherwise. 66 // and returns it if it can be found. Returns NULL otherwise.
85 // Caller takes ownership. 67 // Caller takes ownership.
86 virtual base::RSAPrivateKey* FindPrivateKey( 68 virtual base::RSAPrivateKey* FindPrivateKey(
87 const std::vector<uint8>& key) = 0; 69 const std::vector<uint8>& key) = 0;
88 70
89 virtual FilePath GetOwnerKeyFilePath() = 0; 71 virtual FilePath GetOwnerKeyFilePath() = 0;
90 72
91 protected: 73 protected:
92 virtual ~OwnerKeyUtils(); 74 virtual ~OwnerKeyUtils();
93 75
76 // DER encodes public half of |pair| and writes it out to |key_file|.
77 // The blob on disk is a DER-encoded X509 SubjectPublicKeyInfo object.
78 // Returns false on error.
79 virtual bool ExportPublicKeyToFile(base::RSAPrivateKey* pair,
80 const FilePath& key_file) = 0;
81
94 private: 82 private:
95 friend class base::RefCounted<OwnerKeyUtils>; 83 friend class base::RefCounted<OwnerKeyUtils>;
96 static Factory* factory_; 84 static Factory* factory_;
85
86 FRIEND_TEST_ALL_PREFIXES(OwnerKeyUtilsTest, ExportImportPublicKey);
97 }; 87 };
98 88
99 } // namespace chromeos 89 } // namespace chromeos
100 90
101 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_OWNER_KEY_UTILS_H_ 91 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_OWNER_KEY_UTILS_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/mock_ownership_service.h ('k') | chrome/browser/chromeos/login/owner_key_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698