OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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 #pragma once |
| 8 |
| 9 #include "base/basictypes.h" |
| 10 #include "base/ref_counted.h" |
| 11 #include "base/scoped_ptr.h" |
| 12 #include "chrome/browser/chromeos/login/owner_key_utils.h" |
| 13 #include "chrome/browser/chrome_thread.h" |
| 14 |
| 15 class FilePath; |
| 16 class NotificationDetails; |
| 17 class NotificationType; |
| 18 |
| 19 namespace chromeos { |
| 20 |
| 21 // This class allows the registration of an Owner of a Chromium OS device. |
| 22 // It handles generating the appropriate keys and storing them in the |
| 23 // appropriate locations. |
| 24 class OwnerManager : public base::RefCountedThreadSafe<OwnerManager> { |
| 25 public: |
| 26 // Return codes for public/private key operations. |
| 27 enum KeyOpCode { |
| 28 SUCCESS, |
| 29 KEY_UNAVAILABLE, // The necessary key isn't available yet. |
| 30 OPERATION_FAILED // The crypto operation failed. |
| 31 }; |
| 32 |
| 33 class Delegate { |
| 34 public: |
| 35 // Upon completion of a key operation, this method will be called. |
| 36 // |return_code| indicates what happened, |payload| will be used to pass |
| 37 // back any artifacts of the operation. For example, if the operation |
| 38 // was a signature attempt, the signature blob would come back in |payload|. |
| 39 virtual void OnKeyOpComplete(const KeyOpCode return_code, |
| 40 const std::string& payload) = 0; |
| 41 }; |
| 42 |
| 43 OwnerManager(); |
| 44 virtual ~OwnerManager(); |
| 45 |
| 46 bool IsAlreadyOwned(); |
| 47 |
| 48 // If the device has been owned already, posts a task to the FILE thread to |
| 49 // fetch the public key off disk. |
| 50 // Returns true if the attempt was initiated, false otherwise. |
| 51 // |
| 52 // Sends out a OWNER_KEY_FETCH_ATTEMPT_COMPLETE notification on completion. |
| 53 // Notification comes with a Details<SECKEYPublicKey*> that contains a pointer |
| 54 // to the public key, or NULL if the fetch attempt failed. |
| 55 bool StartLoadOwnerKeyAttempt(); |
| 56 |
| 57 // If the device has not yet been owned, posts a task to the FILE |
| 58 // thread to generate the owner's keys and put them in the right |
| 59 // places. Keeps them in memory as well, for later use. |
| 60 // Returns true if the attempt was initiated, false otherwise. |
| 61 // |
| 62 // Sends out a OWNER_KEY_FETCH_ATTEMPT_COMPLETE notification on completion. |
| 63 // Notification comes with a Details<SECKEYPublicKey*> that contains a pointer |
| 64 // to the public key, or NULL if the fetch attempt failed. |
| 65 bool StartTakeOwnershipAttempt(); |
| 66 |
| 67 // Initiate an attempt to sign |data| with |private_key_|. Will call |
| 68 // d->OnKeyOpComplete() when done. Upon success, the signature will be passed |
| 69 // as the |payload| argument to d->OnKeyOpComplete(). |
| 70 // Returns true if the attempt was initiated, false otherwise. |
| 71 // |
| 72 // If you call this on a well-known thread, you'll be called back on that |
| 73 // thread. Otherwise, you'll get called back on the UI thread. |
| 74 bool StartSigningAttempt(const std::string& data, Delegate* d); |
| 75 |
| 76 // Initiate an attempt to verify that |signature| is valid over |data| with |
| 77 // |public_key_|. When the attempt is completed, an appropriate KeyOpCode |
| 78 // will be passed to d->OnKeyOpComplete(). |
| 79 // Returns true if the attempt was initiated, false otherwise. |
| 80 // |
| 81 // If you call this on a well-known thread, you'll be called back on that |
| 82 // thread. Otherwise, you'll get called back on the UI thread. |
| 83 bool StartVerifyAttempt(const std::string& data, |
| 84 const std::string& signature, |
| 85 Delegate* d); |
| 86 |
| 87 private: |
| 88 // Pulls the owner's public key off disk and into memory. |
| 89 // |
| 90 // Call this on the FILE thread. |
| 91 void LoadOwnerKey(); |
| 92 |
| 93 // Generates the owner's keys in the default NSS token. Also stores |
| 94 // them in |public_key_| and |private_key_|. When done, causes the |
| 95 // public key to get exported via DBus. |
| 96 // |
| 97 // Call this on the FILE thread. |
| 98 void GenerateKeysAndExportPublic(); |
| 99 |
| 100 // Exports |public_key_| via DBus. |
| 101 // |
| 102 // Call this on the UI thread (because of DBus usage). |
| 103 void ExportKey(); |
| 104 |
| 105 bool EnsurePublicKey(); |
| 106 bool EnsurePrivateKey(); |
| 107 |
| 108 // Do the actual work of signing |data| with |private_key_|. First, |
| 109 // ensures that we have the keys we need. Then, computes the signature. |
| 110 // |
| 111 // On success, calls d->OnKeyOpComplete() on |thread_id| with a |
| 112 // successful return code, passing the signaure blob in |payload|. |
| 113 // On failure, calls d->OnKeyOpComplete() on |thread_id| with an appropriate |
| 114 // error and passes an empty string for |payload|. |
| 115 void Sign(const ChromeThread::ID thread_id, |
| 116 const std::string& data, |
| 117 Delegate* d); |
| 118 |
| 119 // Do the actual work of verifying that |signature| is valid over |
| 120 // |data| with |public_key_|. First, ensures we have the key we |
| 121 // need, then does the verify. |
| 122 // |
| 123 // On success, calls d->OnKeyOpComplete() on |thread_id| with a |
| 124 // successful return code, passing an empty string for |payload|. |
| 125 // On failure, calls d->OnKeyOpComplete() on |thread_id| with an appropriate |
| 126 // error code, passing an empty string for |payload|. |
| 127 void Verify(const ChromeThread::ID thread_id, |
| 128 const std::string& data, |
| 129 const std::string& signature, |
| 130 Delegate* d); |
| 131 |
| 132 // A helper method to send a notification on another thread. |
| 133 void SendNotification(NotificationType type, |
| 134 const NotificationDetails& details); |
| 135 |
| 136 // A helper method to call back a delegte on another thread. |
| 137 void CallDelegate(Delegate* d, |
| 138 const KeyOpCode return_code, |
| 139 const std::string& payload) { |
| 140 d->OnKeyOpComplete(return_code, payload); |
| 141 } |
| 142 |
| 143 SECKEYPrivateKey* private_key_; |
| 144 SECKEYPublicKey* public_key_; |
| 145 |
| 146 scoped_ptr<OwnerKeyUtils> utils_; |
| 147 |
| 148 friend class OwnerManagerTest; |
| 149 |
| 150 DISALLOW_COPY_AND_ASSIGN(OwnerManager); |
| 151 }; |
| 152 |
| 153 } // namespace chromeos |
| 154 |
| 155 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_OWNER_MANAGER_H_ |
OLD | NEW |