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

Side by Side Diff: components/ownership/owner_key_util.h

Issue 494093002: OwnerKeyUtil is moved to components/ownership. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added public static OwnerSettingsService::MakeOwnerKeyUtil() method. Created 6 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_SETTINGS_OWNER_KEY_UTIL_H_ 5 #ifndef COMPONENTS_OWNERSHIP_OWNER_KEY_UTIL_H_
6 #define CHROME_BROWSER_CHROMEOS_SETTINGS_OWNER_KEY_UTIL_H_ 6 #define COMPONENTS_OWNERSHIP_OWNER_KEY_UTIL_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/files/file_path.h"
14 #include "base/gtest_prod_util.h"
15 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
17 #include "base/stl_util.h" 15 #include "base/stl_util.h"
18 #include "crypto/rsa_private_key.h" 16 #include "components/ownership/ownership_export.h"
19 #include "net/cert/x509_util_nss.h" 17 #include "net/cert/x509_util_nss.h"
wtc 2014/08/26 18:00:30 It seems wrong to include a header just for a forw
ygorshenin1 2014/08/27 20:39:12 Done.
20 18
21 namespace base { 19 namespace base {
22 class FilePath; 20 class FilePath;
23 } 21 }
24 22
25 namespace crypto { 23 namespace crypto {
26 class RSAPrivateKey; 24 class RSAPrivateKey;
27 } 25 }
28 26
29 namespace chromeos { 27 namespace ownership {
30 28
31 class OwnerKeyUtilTest; 29 class OwnerKeyUtilTest;
32 30
33 class PublicKey : public base::RefCountedThreadSafe<PublicKey> { 31 class OWNERSHIP_EXPORT PublicKey
32 : public base::RefCountedThreadSafe<PublicKey> {
34 public: 33 public:
35 PublicKey(); 34 PublicKey();
36 35
37 std::vector<uint8>& data() { return data_; } 36 std::vector<uint8>& data() { return data_; }
38 37
39 bool is_loaded() const { return !data_.empty(); } 38 bool is_loaded() const { return !data_.empty(); }
40 39
41 std::string as_string() { 40 std::string as_string() {
42 return std::string(reinterpret_cast<const char*>(vector_as_array(&data_)), 41 return std::string(reinterpret_cast<const char*>(vector_as_array(&data_)),
43 data_.size()); 42 data_.size());
44 } 43 }
45 44
46 private: 45 private:
47 friend class base::RefCountedThreadSafe<PublicKey>; 46 friend class base::RefCountedThreadSafe<PublicKey>;
48 47
49 virtual ~PublicKey(); 48 virtual ~PublicKey();
50 49
51 std::vector<uint8> data_; 50 std::vector<uint8> data_;
52 51
53 DISALLOW_COPY_AND_ASSIGN(PublicKey); 52 DISALLOW_COPY_AND_ASSIGN(PublicKey);
54 }; 53 };
55 54
56 class PrivateKey : public base::RefCountedThreadSafe<PrivateKey> { 55 class OWNERSHIP_EXPORT PrivateKey
56 : public base::RefCountedThreadSafe<PrivateKey> {
57 public: 57 public:
58 explicit PrivateKey(crypto::RSAPrivateKey* key); 58 explicit PrivateKey(crypto::RSAPrivateKey* key);
59 59
60 crypto::RSAPrivateKey* key() { return key_.get(); } 60 crypto::RSAPrivateKey* key() { return key_.get(); }
61 61
62 private: 62 private:
63 friend class base::RefCountedThreadSafe<PrivateKey>; 63 friend class base::RefCountedThreadSafe<PrivateKey>;
64 64
65 virtual ~PrivateKey(); 65 virtual ~PrivateKey();
66 66
67 scoped_ptr<crypto::RSAPrivateKey> key_; 67 scoped_ptr<crypto::RSAPrivateKey> key_;
68 68
69 DISALLOW_COPY_AND_ASSIGN(PrivateKey); 69 DISALLOW_COPY_AND_ASSIGN(PrivateKey);
70 }; 70 };
71 71
72 class OwnerKeyUtil : public base::RefCountedThreadSafe<OwnerKeyUtil> { 72 class OWNERSHIP_EXPORT OwnerKeyUtil
73 : public base::RefCountedThreadSafe<OwnerKeyUtil> {
73 public: 74 public:
74 // Creates an OwnerKeyUtil instance. 75 // Creates an OwnerKeyUtil instance.
75 static OwnerKeyUtil* Create(); 76 static scoped_refptr<OwnerKeyUtil> Create(
77 const base::FilePath& public_key_path);
76 78
77 // Attempts to read the public key from the file system. 79 // Attempts to read the public key from the file system.
78 // Upon success, returns true and populates |output|. False on failure. 80 // Upon success, returns true and populates |output|. False on failure.
79 virtual bool ImportPublicKey(std::vector<uint8>* output) = 0; 81 virtual bool ImportPublicKey(std::vector<uint8>* output) = 0;
80 82
81 // Looks for the private key associated with |key| in the |slot| 83 // Looks for the private key associated with |key| in the |slot|
82 // and returns it if it can be found. Returns NULL otherwise. 84 // and returns it if it can be found. Returns NULL otherwise.
83 // Caller takes ownership. 85 // Caller takes ownership.
84 virtual crypto::RSAPrivateKey* FindPrivateKeyInSlot( 86 virtual crypto::RSAPrivateKey* FindPrivateKeyInSlot(
85 const std::vector<uint8>& key, 87 const std::vector<uint8>& key,
86 PK11SlotInfo* slot) = 0; 88 PK11SlotInfo* slot) = 0;
87 89
88 // Checks whether the public key is present in the file system. 90 // Checks whether the public key is present in the file system.
89 virtual bool IsPublicKeyPresent() = 0; 91 virtual bool IsPublicKeyPresent() = 0;
90 92
91 protected: 93 protected:
92 OwnerKeyUtil(); 94 OwnerKeyUtil();
93 virtual ~OwnerKeyUtil(); 95 virtual ~OwnerKeyUtil();
94 96
95 private: 97 private:
96 friend class base::RefCountedThreadSafe<OwnerKeyUtil>; 98 friend class base::RefCountedThreadSafe<OwnerKeyUtil>;
97
98 FRIEND_TEST_ALL_PREFIXES(OwnerKeyUtilTest, ExportImportPublicKey);
99 }; 99 };
100 100
101 // Implementation of OwnerKeyUtil that is used in production code. 101 } // namespace ownership
102 class OwnerKeyUtilImpl : public OwnerKeyUtil {
103 public:
104 explicit OwnerKeyUtilImpl(const base::FilePath& public_key_file);
105 102
106 // OwnerKeyUtil: 103 #endif // COMPONENTS_OWNERSHIP_OWNER_KEY_UTIL_H_
107 virtual bool ImportPublicKey(std::vector<uint8>* output) OVERRIDE;
108 virtual crypto::RSAPrivateKey* FindPrivateKeyInSlot(
109 const std::vector<uint8>& key,
110 PK11SlotInfo* slot) OVERRIDE;
111 virtual bool IsPublicKeyPresent() OVERRIDE;
112
113 protected:
114 virtual ~OwnerKeyUtilImpl();
115
116 private:
117 // The file that holds the public key.
118 base::FilePath key_file_;
119
120 DISALLOW_COPY_AND_ASSIGN(OwnerKeyUtilImpl);
121 };
122
123 } // namespace chromeos
124
125 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_OWNER_KEY_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698