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

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

Issue 10828032: Add DeviceSettingsService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_OWNER_KEY_UTIL_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_OWNER_KEY_UTIL_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/basictypes.h"
12 #include "base/file_path.h"
13 #include "base/gtest_prod_util.h"
14 #include "base/memory/ref_counted.h"
15
16 class FilePath;
17
18 namespace crypto {
19 class RSAPrivateKey;
20 }
21
22 namespace chromeos {
23
24 class OwnerKeyUtilTest;
25
26 class OwnerKeyUtil : public base::RefCounted<OwnerKeyUtil> {
27 public:
28 // Creates an OwnerKeyUtil instance.
29 static OwnerKeyUtil* Create();
30
31 // Attempts to read the public key from the file system.
32 // Upon success, returns true and populates |output|. False on failure.
33 virtual bool ImportPublicKey(std::vector<uint8>* output) = 0;
34
35 // Verfiy that |signature| is a SHA1-with-RSA signature over |data| with
36 // |public_key|. Returns true if so, false on bad signature or other error.
37 virtual bool Verify(const std::string& data,
38 const std::vector<uint8> signature,
39 const std::vector<uint8> public_key);
40
41 // Sign |data| with |key| using Sha1 with RSA. If successful, return true
42 // and populate |OUT_signature|.
43 virtual bool Sign(const std::string& data,
44 std::vector<uint8>* OUT_signature,
45 crypto::RSAPrivateKey* key);
46
47 // Looks for the private key associated with |key| in the default slot,
48 // and returns it if it can be found. Returns NULL otherwise.
49 // Caller takes ownership.
50 virtual crypto::RSAPrivateKey* FindPrivateKey(
51 const std::vector<uint8>& key) = 0;
52
53 // Checks whether the public key is present in the file system.
54 virtual bool IsPublicKeyPresent() = 0;
55
56 protected:
57 OwnerKeyUtil();
58 virtual ~OwnerKeyUtil();
59
60 // DER encodes public half of |pair| and writes it to the file system.
61 // The blob on disk is a DER-encoded X509 SubjectPublicKeyInfo object.
62 // Returns false on error.
63 virtual bool ExportPublicKey(crypto::RSAPrivateKey* pair) = 0;
64
65 private:
66 friend class base::RefCounted<OwnerKeyUtil>;
67
68 FRIEND_TEST_ALL_PREFIXES(OwnerKeyUtilTest, ExportImportPublicKey);
69 };
70
71 // Implementation of OwnerKeyUtil that is used in production code.
72 class OwnerKeyUtilImpl : public OwnerKeyUtil {
73 public:
74 // The file outside the owner's encrypted home directory where her
75 // key will live.
76 static const char kOwnerKeyFile[];
77
78 explicit OwnerKeyUtilImpl(const FilePath& public_key_file);
79
80 // OwnerKeyUtil:
81 bool ImportPublicKey(std::vector<uint8>* output) OVERRIDE;
82 crypto::RSAPrivateKey* FindPrivateKey(
83 const std::vector<uint8>& key) OVERRIDE;
84 bool IsPublicKeyPresent() OVERRIDE;
85
86 protected:
87 virtual ~OwnerKeyUtilImpl();
88
89 bool ExportPublicKey(crypto::RSAPrivateKey* pair) OVERRIDE;
90
91 private:
92 // The file that holds the public key.
93 FilePath key_file_;
94
95 DISALLOW_COPY_AND_ASSIGN(OwnerKeyUtilImpl);
96 };
97
98 } // namespace chromeos
99
100 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_OWNER_KEY_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698