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

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

Issue 10824112: Move Chrome OS device settings stuff to chrome/browser/chromeos/settings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. 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_MANAGER_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_OWNER_MANAGER_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "chrome/browser/chromeos/login/owner_key_utils.h"
15 #include "content/public/browser/browser_thread.h"
16 #include "crypto/rsa_private_key.h"
17
18 namespace content {
19 class NotificationDetails;
20 }
21
22 namespace chromeos {
23
24 // This class allows the registration of an Owner of a Chromium OS device.
25 // It handles generating the appropriate keys and storing them in the
26 // appropriate locations.
27 class OwnerManager : public base::RefCountedThreadSafe<OwnerManager> {
28 public:
29 // Return codes for public/private key operations.
30 enum KeyOpCode {
31 SUCCESS,
32 KEY_UNAVAILABLE, // The necessary key isn't available yet.
33 OPERATION_FAILED // The crypto operation failed.
34 };
35
36 class Delegate {
37 public:
38 // Upon completion of a key operation, this method will be called.
39 // |return_code| indicates what happened, |payload| will be used to pass
40 // back any artifacts of the operation. For example, if the operation
41 // was a signature attempt, the signature blob would come back in |payload|.
42 virtual void OnKeyOpComplete(const KeyOpCode return_code,
43 const std::vector<uint8>& payload) = 0;
44 };
45
46 class KeyUpdateDelegate {
47 public:
48 // Called upon completion of a key update operation.
49 virtual void OnKeyUpdated() = 0;
50 };
51
52 OwnerManager();
53
54 // Sets a new owner key from a provided memory buffer.
55 void UpdateOwnerKey(const content::BrowserThread::ID thread_id,
56 const std::vector<uint8>& key,
57 KeyUpdateDelegate* d);
58
59 // Pulls the owner's public key off disk and into memory.
60 //
61 // Call this on the FILE thread.
62 void LoadOwnerKey();
63
64 bool EnsurePublicKey();
65 bool EnsurePrivateKey();
66
67 // Do the actual work of signing |data| with |private_key_|. First,
68 // ensures that we have the keys we need. Then, computes the signature.
69 //
70 // On success, calls d->OnKeyOpComplete() on |thread_id| with a
71 // successful return code, passing the signaure blob in |payload|.
72 // On failure, calls d->OnKeyOpComplete() on |thread_id| with an appropriate
73 // error and passes an empty string for |payload|.
74 void Sign(const content::BrowserThread::ID thread_id,
75 const std::string& data,
76 Delegate* d);
77
78 // Do the actual work of verifying that |signature| is valid over
79 // |data| with |public_key_|. First, ensures we have the key we
80 // need, then does the verify.
81 //
82 // On success, calls d->OnKeyOpComplete() on |thread_id| with a
83 // successful return code, passing an empty string for |payload|.
84 // On failure, calls d->OnKeyOpComplete() on |thread_id| with an appropriate
85 // error code, passing an empty string for |payload|.
86 void Verify(const content::BrowserThread::ID thread_id,
87 const std::string& data,
88 const std::vector<uint8>& signature,
89 Delegate* d);
90
91 protected:
92 virtual ~OwnerManager();
93
94 private:
95 friend class base::RefCountedThreadSafe<OwnerManager>;
96
97 // A helper method to send a notification on another thread.
98 void SendNotification(int type,
99 const content::NotificationDetails& details);
100
101 // Calls back a key update delegate on a given thread.
102 void CallKeyUpdateDelegate(KeyUpdateDelegate* d) {
103 d->OnKeyUpdated();
104 }
105
106 // A helper method to call back a delegte on another thread.
107 void CallDelegate(Delegate* d,
108 const KeyOpCode return_code,
109 const std::vector<uint8>& payload) {
110 d->OnKeyOpComplete(return_code, payload);
111 }
112
113 scoped_ptr<crypto::RSAPrivateKey> private_key_;
114 std::vector<uint8> public_key_;
115
116 scoped_refptr<OwnerKeyUtils> utils_;
117
118 friend class OwnerManagerTest;
119
120 DISALLOW_COPY_AND_ASSIGN(OwnerManager);
121 };
122
123 } // namespace chromeos
124
125 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_OWNER_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/owner_key_utils_unittest.cc ('k') | chrome/browser/chromeos/login/owner_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698