OLD | NEW |
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS 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 CHROMEOS_LOGIN_H_ | 5 #ifndef CHROMEOS_LOGIN_H_ |
6 #define CHROMEOS_LOGIN_H_ | 6 #define CHROMEOS_LOGIN_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 | 12 |
13 namespace chromeos { // NOLINT | 13 namespace chromeos { // NOLINT |
14 | 14 |
15 // TODO(cmasone): change references to "login" (LoginLibrary, etc) to "session" | 15 // TODO(cmasone): change references to "login" (LoginLibrary, etc) to "session" |
16 // or similar. The API implemented here doesn't really deal with logging in | 16 // or similar. The API implemented here doesn't really deal with logging in |
17 // so much as state relating to user and the user sessions. | 17 // so much as state relating to user and the user sessions. |
18 | 18 |
19 enum OwnershipEvent { | 19 enum OwnershipEvent { |
20 SetKeySuccess = 0, | 20 SetKeySuccess = 0, |
21 SetKeyFailure = 1, | 21 SetKeyFailure = 1, |
22 WhitelistOpSuccess = 2, | 22 WhitelistOpSuccess = 2, |
23 WhitelistOpFailure = 3, | 23 WhitelistOpFailure = 3, |
24 PropertyOpSuccess = 4, | 24 PropertyOpSuccess = 4, |
25 PropertyOpFailure = 5, | 25 PropertyOpFailure = 5, |
26 }; | 26 }; |
27 | 27 |
| 28 struct CryptoBlob { |
| 29 const uint8* data; |
| 30 int length; |
| 31 }; |
| 32 |
| 33 struct Property { |
| 34 const char* name; |
| 35 const char* value; |
| 36 CryptoBlob* signature; |
| 37 }; |
| 38 |
| 39 struct UserList { |
| 40 const char** users; // array of NULL-terminated C-strings |
| 41 int num_users; |
| 42 }; |
| 43 |
28 static const char kOwnerKeyFile[] = "/var/lib/whitelist/owner.key"; | 44 static const char kOwnerKeyFile[] = "/var/lib/whitelist/owner.key"; |
29 | 45 |
30 class OpaqueSessionConnection; | 46 class OpaqueSessionConnection; |
31 typedef OpaqueSessionConnection* SessionConnection; | 47 typedef OpaqueSessionConnection* SessionConnection; |
32 typedef void(*SessionMonitor)(void*, const OwnershipEvent&); | 48 typedef void(*SessionMonitor)(void*, const OwnershipEvent&); |
33 | 49 |
34 extern SessionConnection (*MonitorSession)(SessionMonitor monitor, void*); | 50 extern SessionConnection (*MonitorSession)(SessionMonitor monitor, void*); |
35 extern void (*DisconnectSession)(SessionConnection connection); | 51 extern void (*DisconnectSession)(SessionConnection connection); |
36 | 52 |
| 53 // DEPRECATED due to memory unsafety. |
37 extern bool (*CheckWhitelist)(const char* email, | 54 extern bool (*CheckWhitelist)(const char* email, |
38 std::vector<uint8>* OUT_signature); | 55 std::vector<uint8>* OUT_signature); |
| 56 |
| 57 // Checks if |email| is on the whitelist. |
| 58 // Returns true if so, and allocates a CryptoBlob to pass back in the out param. |
| 59 // If not, returns false and |OUT_signature| is untouched. |
| 60 // Free |OUT_signature| using FreeCryptoBlob(). |
| 61 extern bool (*CheckWhitelistSafe)(const char* email, |
| 62 CryptoBlob** OUT_signature); |
| 63 |
| 64 // Kicks off an attempt to emit the "login-prompt-ready" upstart signal. |
39 extern bool (*EmitLoginPromptReady)(); | 65 extern bool (*EmitLoginPromptReady)(); |
40 | 66 |
| 67 // DEPRECATED due to memory unsafety. |
| 68 extern bool (*EnumerateWhitelisted)(std::vector<std::string>* OUT_whitelisted); |
| 69 |
41 // EnumerateWhitelisted() is for informational purposes only. The data | 70 // EnumerateWhitelisted() is for informational purposes only. The data |
42 // is returned without signatures. To determine if a user is allowed to log in | 71 // is returned without signatures. To determine if a user is allowed to log in |
43 // to the device, YOU MUST use CheckWhitelist and verify the signature that is | 72 // to the device, YOU MUST use CheckWhitelist and verify the signature that is |
44 // returned. | 73 // returned. |
45 extern bool (*EnumerateWhitelisted)(std::vector<std::string>* OUT_whitelisted); | 74 // Free |OUT_whitelisted| using FreeUserList(). |
| 75 extern bool (*EnumerateWhitelistedSafe)(UserList** OUT_whitelisted); |
| 76 |
| 77 // These methods are used to create structures to pass to |
| 78 // the "*Safe" functions defined in this file. We need to do this |
| 79 // to safely pass data over the dll boundary between our .so and Chrome. |
| 80 extern CryptoBlob* (*CreateCryptoBlob)(const uint8* in, const int in_len); |
| 81 extern Property* (*CreateProperty)(const char* name, const char* value, |
| 82 const uint8* sig, const int sig_len); |
| 83 extern UserList* (*CreateUserList)(char** users); |
| 84 |
| 85 // These methods are used to free structures that were returned in |
| 86 // out-params from "*Safe" functions defined in this file. We need to do this |
| 87 // to safely pass data over the dll boundary between our .so and Chrome. |
| 88 extern void (*FreeCryptoBlob)(CryptoBlob* blob); |
| 89 extern void (*FreeProperty)(Property* property); |
| 90 extern void (*FreeUserList)(UserList* userlist); |
| 91 |
46 extern bool (*RestartJob)(int pid, const char* command_line); | 92 extern bool (*RestartJob)(int pid, const char* command_line); |
| 93 |
| 94 // DEPRECATED due to memory unsafety. |
47 extern bool (*RetrieveProperty)(const char* name, | 95 extern bool (*RetrieveProperty)(const char* name, |
48 std::string* OUT_value, | 96 std::string* OUT_value, |
49 std::vector<uint8>* OUT_signature); | 97 std::vector<uint8>* OUT_signature); |
| 98 |
| 99 // Fetches the property called |name|. |
| 100 // Returns true if it can be fetched, allocates a Property to pass back. |
| 101 // If not, returns false and |OUT_property| is untouched |
| 102 // Free |OUT_property| using FreeProperty. |
| 103 extern bool (*RetrievePropertySafe)(const char* name, Property** OUT_property); |
| 104 |
| 105 // DEPRECATED due to memory unsafety. |
50 extern bool (*SetOwnerKey)(const std::vector<uint8>& public_key_der); | 106 extern bool (*SetOwnerKey)(const std::vector<uint8>& public_key_der); |
| 107 |
| 108 // Attempts to set the Owner key to |public_key_der|. |
| 109 // Returns true if the attempt starts successfully. |
| 110 extern bool (*SetOwnerKeySafe)(const CryptoBlob* public_key_der); |
| 111 |
51 extern bool (*StartSession)(const char* user_email, | 112 extern bool (*StartSession)(const char* user_email, |
52 const char* unique_id /* unused */); | 113 const char* unique_id /* unused */); |
| 114 |
53 extern bool (*StopSession)(const char* unique_id /* unused */); | 115 extern bool (*StopSession)(const char* unique_id /* unused */); |
| 116 |
| 117 // DEPRECATED due to memory unsafety. |
54 extern bool (*StoreProperty)(const char* name, | 118 extern bool (*StoreProperty)(const char* name, |
55 const char* value, | 119 const char* value, |
56 const std::vector<uint8>& signature); | 120 const std::vector<uint8>& signature); |
| 121 |
| 122 // Attempts to store |prop|. |
| 123 // Returns true if the attempt starts successfully. |
| 124 extern bool (*StorePropertySafe)(const Property* prop); |
| 125 |
| 126 // DEPRECATED due to memory unsafety. |
57 extern bool (*Unwhitelist)(const char* email, | 127 extern bool (*Unwhitelist)(const char* email, |
58 const std::vector<uint8>& signature); | 128 const std::vector<uint8>& signature); |
| 129 |
| 130 // Attempts to remove |email| from the whitelist. |
| 131 // Returns true if the attempt is started successfully. |
| 132 extern bool (*UnwhitelistSafe)(const char* email, |
| 133 const CryptoBlob* signature); |
| 134 |
| 135 // DEPRECATED due to memory unsafety. |
59 extern bool (*Whitelist)(const char* email, | 136 extern bool (*Whitelist)(const char* email, |
60 const std::vector<uint8>& signature); | 137 const std::vector<uint8>& signature); |
61 | 138 |
| 139 // Attempts to whitelist |email|. |
| 140 // Returns true if the attempt is successfully started. |
| 141 extern bool (*WhitelistSafe)(const char* email, |
| 142 const CryptoBlob* signature); |
| 143 |
62 } // namespace chromeos | 144 } // namespace chromeos |
63 | 145 |
64 #endif // CHROMEOS_LOGIN_H_ | 146 #endif // CHROMEOS_LOGIN_H_ |
OLD | NEW |