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

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

Powered by Google App Engine
This is Rietveld 408576698