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

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: Restored pure base OwnerKeyUtil. 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_
erikwright (departed) 2014/08/28 18:39:57 Please add class comments for each of the classes
ygorshenin1 2014/08/28 18:59:05 Done.
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/macros.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"
20 17
21 namespace base { 18 #if defined(USE_NSS)
22 class FilePath; 19 struct PK11SlotInfoStr;
23 } 20 typedef struct PK11SlotInfoStr PK11SlotInfo;
21 #endif // defined(USE_NSS)
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 // Attempts to read the public key from the file system. Upon success,
75 static OwnerKeyUtil* Create(); 76 // returns true and populates |output|. False on failure.
76
77 // Attempts to read the public key from the file system.
78 // Upon success, returns true and populates |output|. False on failure.
79 virtual bool ImportPublicKey(std::vector<uint8>* output) = 0; 77 virtual bool ImportPublicKey(std::vector<uint8>* output) = 0;
80 78
79 #if defined(USE_NSS)
81 // Looks for the private key associated with |key| in the |slot| 80 // Looks for the private key associated with |key| in the |slot|
82 // and returns it if it can be found. Returns NULL otherwise. 81 // and returns it if it can be found. Returns NULL otherwise.
83 // Caller takes ownership. 82 // Caller takes ownership.
84 virtual crypto::RSAPrivateKey* FindPrivateKeyInSlot( 83 virtual crypto::RSAPrivateKey* FindPrivateKeyInSlot(
85 const std::vector<uint8>& key, 84 const std::vector<uint8>& key,
86 PK11SlotInfo* slot) = 0; 85 PK11SlotInfo* slot) = 0;
86 #endif // defined(USE_NSS)
87 87
88 // Checks whether the public key is present in the file system. 88 // Checks whether the public key is present in the file system.
89 virtual bool IsPublicKeyPresent() = 0; 89 virtual bool IsPublicKeyPresent() = 0;
90 90
91 protected: 91 protected:
92 OwnerKeyUtil(); 92 OwnerKeyUtil();
erikwright (departed) 2014/08/28 18:39:57 This is not required, since you will remove DISALL
ygorshenin1 2014/08/28 18:59:05 Done.
93
93 virtual ~OwnerKeyUtil(); 94 virtual ~OwnerKeyUtil();
erikwright (departed) 2014/08/28 18:39:57 This can be inline defined. Although, in this case
ygorshenin1 2014/08/28 18:59:05 Done.
94 95
95 private: 96 private:
96 friend class base::RefCountedThreadSafe<OwnerKeyUtil>; 97 friend class base::RefCountedThreadSafe<OwnerKeyUtil>;
97 98
98 FRIEND_TEST_ALL_PREFIXES(OwnerKeyUtilTest, ExportImportPublicKey); 99 DISALLOW_COPY_AND_ASSIGN(OwnerKeyUtil);
erikwright (departed) 2014/08/28 18:39:57 This is not required, because this class is pure-v
ygorshenin1 2014/08/28 18:59:05 Done.
99 }; 100 };
100 101
101 // Implementation of OwnerKeyUtil that is used in production code. 102 } // namespace ownership
102 class OwnerKeyUtilImpl : public OwnerKeyUtil {
103 public:
104 explicit OwnerKeyUtilImpl(const base::FilePath& public_key_file);
105 103
106 // OwnerKeyUtil: 104 #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