OLD | NEW |
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/ref_counted.h" |
| 13 #include "chrome/browser/chromeos/cros/login_library.h" |
12 | 14 |
13 class FilePath; | 15 class FilePath; |
14 | 16 |
15 namespace base { | 17 namespace base { |
16 class RSAPrivateKey; | 18 class RSAPrivateKey; |
17 } | 19 } |
18 | 20 |
19 namespace chromeos { | 21 namespace chromeos { |
20 | 22 |
21 class OwnerKeyUtils { | 23 class OwnerKeyUtils : public base::RefCounted<OwnerKeyUtils> { |
22 public: | 24 public: |
23 class Factory { | 25 class Factory { |
24 public: | 26 public: |
25 virtual OwnerKeyUtils* CreateOwnerKeyUtils() = 0; | 27 virtual OwnerKeyUtils* CreateOwnerKeyUtils() = 0; |
26 }; | 28 }; |
27 | 29 |
28 OwnerKeyUtils(); | 30 OwnerKeyUtils(); |
29 virtual ~OwnerKeyUtils(); | |
30 | 31 |
31 // Sets the factory used by the static method Create to create an | 32 // Sets the factory used by the static method Create to create an |
32 // OwnerKeyUtils. OwnerKeyUtils does not take ownership of | 33 // OwnerKeyUtils. OwnerKeyUtils does not take ownership of |
33 // |factory|. A value of NULL results in an OwnerKeyUtils being | 34 // |factory|. A value of NULL results in an OwnerKeyUtils being |
34 // created directly. | 35 // created directly. |
35 #if defined(UNIT_TEST) | 36 #if defined(UNIT_TEST) |
36 static void set_factory(Factory* factory) { factory_ = factory; } | 37 static void set_factory(Factory* factory) { factory_ = factory; } |
37 #endif | 38 #endif |
38 | 39 |
39 // Creates an OwnerKeyUtils, ownership returns to the caller. If there is no | 40 // Creates an OwnerKeyUtils, ownership returns to the caller. If there is no |
40 // Factory (the default) this creates and returns a new OwnerKeyUtils. | 41 // Factory (the default) this creates and returns a new OwnerKeyUtils. |
41 static OwnerKeyUtils* Create(); | 42 static OwnerKeyUtils* Create(); |
42 | 43 |
43 // Generate a public/private RSA keypair and store them in the NSS database. | 44 // Generate a public/private RSA keypair and store them in the NSS database. |
44 // The keys will be kKeySizeInBits in length (Recommend >= 2048 bits). | 45 // The keys will be kKeySizeInBits in length (Recommend >= 2048 bits). |
45 // The caller takes ownership. | 46 // The caller takes ownership. |
46 // | 47 // |
47 // Returns NULL on error. | 48 // Returns NULL on error. |
48 virtual base::RSAPrivateKey* GenerateKeyPair() = 0; | 49 virtual base::RSAPrivateKey* GenerateKeyPair() = 0; |
49 | 50 |
50 // DER encodes public half of |pair| and exports it via DBus. | 51 // DER encodes public half of |pair| and asynchronously exports it via DBus. |
51 // The data sent is a DER-encoded X509 SubjectPublicKeyInfo object. | 52 // The data sent is a DER-encoded X509 SubjectPublicKeyInfo object. |
52 // Returns false on error. | 53 // Returns false on error, true if the attempt is successfully begun. |
53 virtual bool ExportPublicKeyViaDbus(base::RSAPrivateKey* pair) = 0; | 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<bool>* d) = 0; |
54 | 58 |
55 // DER encodes public half of |pair| and writes it out to |key_file|. | 59 // DER encodes public half of |pair| and writes it out to |key_file|. |
56 // The blob on disk is a DER-encoded X509 SubjectPublicKeyInfo object. | 60 // The blob on disk is a DER-encoded X509 SubjectPublicKeyInfo object. |
57 // Returns false on error. | 61 // Returns false on error. |
58 virtual bool ExportPublicKeyToFile(base::RSAPrivateKey* pair, | 62 virtual bool ExportPublicKeyToFile(base::RSAPrivateKey* pair, |
59 const FilePath& key_file) = 0; | 63 const FilePath& key_file) = 0; |
60 | 64 |
61 // Assumes that the file at |key_file| exists. | 65 // Assumes that the file at |key_file| exists. |
62 // Upon success, returns true and populates |output|. False on failure. | 66 // Upon success, returns true and populates |output|. False on failure. |
63 virtual bool ImportPublicKey(const FilePath& key_file, | 67 virtual bool ImportPublicKey(const FilePath& key_file, |
64 std::vector<uint8>* output) = 0; | 68 std::vector<uint8>* output) = 0; |
65 | 69 |
66 // Looks for the private key associated with |key| in the default slot, | 70 // Looks for the private key associated with |key| in the default slot, |
67 // and returns it if it can be found. Returns NULL otherwise. | 71 // and returns it if it can be found. Returns NULL otherwise. |
68 // Caller takes ownership. | 72 // Caller takes ownership. |
69 virtual base::RSAPrivateKey* FindPrivateKey( | 73 virtual base::RSAPrivateKey* FindPrivateKey( |
70 const std::vector<uint8>& key) = 0; | 74 const std::vector<uint8>& key) = 0; |
71 | 75 |
72 virtual FilePath GetOwnerKeyFilePath() = 0; | 76 virtual FilePath GetOwnerKeyFilePath() = 0; |
73 | 77 |
| 78 protected: |
| 79 virtual ~OwnerKeyUtils(); |
| 80 |
74 private: | 81 private: |
| 82 friend class base::RefCounted<OwnerKeyUtils>; |
75 static Factory* factory_; | 83 static Factory* factory_; |
76 }; | 84 }; |
77 | 85 |
78 } // namespace chromeos | 86 } // namespace chromeos |
79 | 87 |
80 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_OWNER_KEY_UTILS_H_ | 88 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_OWNER_KEY_UTILS_H_ |
OLD | NEW |