| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium 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_CRYPTOHOME_CRYPTOHOME_PARAMETERS_H_ | 5 #ifndef CHROMEOS_CRYPTOHOME_CRYPTOHOME_PARAMETERS_H_ |
| 6 #define CHROMEOS_CRYPTOHOME_CRYPTOHOME_PARAMETERS_H_ | 6 #define CHROMEOS_CRYPTOHOME_CRYPTOHOME_PARAMETERS_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 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/scoped_vector.h" | |
| 14 #include "chromeos/chromeos_export.h" | 13 #include "chromeos/chromeos_export.h" |
| 15 | 14 |
| 16 namespace cryptohome { | 15 namespace cryptohome { |
| 17 | 16 |
| 18 enum AuthKeyPrivileges { | 17 enum AuthKeyPrivileges { |
| 19 PRIV_MOUNT = 1 << 0, // Can mount with this key. | 18 PRIV_MOUNT = 1 << 0, // Can mount with this key. |
| 20 PRIV_ADD = 1 << 1, // Can add new keys. | 19 PRIV_ADD = 1 << 1, // Can add new keys. |
| 21 PRIV_REMOVE = 1 << 2, // Can remove other keys. | 20 PRIV_REMOVE = 1 << 2, // Can remove other keys. |
| 22 PRIV_MIGRATE = 1 << 3, // Destroy all keys and replace with new. | 21 PRIV_MIGRATE = 1 << 3, // Destroy all keys and replace with new. |
| 23 PRIV_AUTHORIZED_UPDATE = 1 << 4, // Key can be updated in place. | 22 PRIV_AUTHORIZED_UPDATE = 1 << 4, // Key can be updated in place. |
| 24 PRIV_DEFAULT = PRIV_MOUNT | PRIV_ADD | PRIV_REMOVE | PRIV_MIGRATE | 23 PRIV_DEFAULT = PRIV_MOUNT | PRIV_ADD | PRIV_REMOVE | PRIV_MIGRATE |
| 25 }; | 24 }; |
| 26 | 25 |
| 27 // Identification of the user calling cryptohome method. | 26 // Identification of the user calling cryptohome method. |
| 28 struct CHROMEOS_EXPORT Identification { | 27 struct CHROMEOS_EXPORT Identification { |
| 29 explicit Identification(const std::string& user_id); | 28 explicit Identification(const std::string& user_id); |
| 30 | 29 |
| 31 bool operator==(const Identification& other) const; | 30 bool operator==(const Identification& other) const; |
| 32 | 31 |
| 33 std::string user_id; | 32 std::string user_id; |
| 34 }; | 33 }; |
| 35 | 34 |
| 36 // Definition of the key (e.g. password) for the cryptohome. | 35 // Definition of the key (e.g. password) for the cryptohome. |
| 37 // It contains authorization data along with extra parameters like perimissions | 36 // It contains authorization data along with extra parameters like permissions |
| 38 // associated with this key. | 37 // associated with this key. |
| 39 struct CHROMEOS_EXPORT KeyDefinition { | 38 struct CHROMEOS_EXPORT KeyDefinition { |
| 40 KeyDefinition(const std::string& key, | 39 enum Type { |
| 40 TYPE_PASSWORD = 0 |
| 41 }; |
| 42 |
| 43 struct AuthorizationData { |
| 44 enum Type { |
| 45 TYPE_HMACSHA256 = 0, |
| 46 TYPE_AES256CBC_HMACSHA256 |
| 47 }; |
| 48 |
| 49 struct Secret { |
| 50 Secret(); |
| 51 Secret(bool encrypt, |
| 52 bool sign, |
| 53 const std::string& symmetric_key, |
| 54 const std::string& public_key, |
| 55 bool wrapped); |
| 56 |
| 57 bool operator==(const Secret& other) const; |
| 58 |
| 59 bool encrypt; |
| 60 bool sign; |
| 61 std::string symmetric_key; |
| 62 std::string public_key; |
| 63 bool wrapped; |
| 64 }; |
| 65 |
| 66 AuthorizationData(); |
| 67 AuthorizationData(bool encrypt, |
| 68 bool sign, |
| 69 const std::string& symmetric_key); |
| 70 ~AuthorizationData(); |
| 71 |
| 72 bool operator==(const AuthorizationData& other) const; |
| 73 |
| 74 Type type; |
| 75 std::vector<Secret> secrets; |
| 76 }; |
| 77 |
| 78 // This struct holds metadata that will be stored alongside the key. Each |
| 79 // |ProviderData| entry must have a |name| and may hold either a |number| or a |
| 80 // sequence of |bytes|. The metadata is entirely opaque to cryptohome. It is |
| 81 // stored with the key and returned when requested but is never interpreted by |
| 82 // cryptohome in any way. The metadata can be used to store information such |
| 83 // as the hashing algorithm and the salt used to create the key. |
| 84 struct ProviderData { |
| 85 ProviderData(); |
| 86 explicit ProviderData(const std::string& name); |
| 87 explicit ProviderData(const ProviderData& other); |
| 88 void operator=(const ProviderData& other); |
| 89 ~ProviderData(); |
| 90 |
| 91 bool operator==(const ProviderData& other) const; |
| 92 |
| 93 std::string name; |
| 94 scoped_ptr<int64> number; |
| 95 scoped_ptr<std::string> bytes; |
| 96 }; |
| 97 |
| 98 KeyDefinition(); |
| 99 KeyDefinition(const std::string& secret, |
| 41 const std::string& label, | 100 const std::string& label, |
| 42 int /*AuthKeyPrivileges*/ privileges); | 101 int privileges); |
| 43 ~KeyDefinition(); | 102 ~KeyDefinition(); |
| 44 | 103 |
| 45 bool operator==(const KeyDefinition& other) const; | 104 bool operator==(const KeyDefinition& other) const; |
| 46 | 105 |
| 106 Type type; |
| 47 std::string label; | 107 std::string label; |
| 48 | |
| 49 int revision; | |
| 50 std::string key; | |
| 51 | |
| 52 std::string encryption_key; | |
| 53 std::string signature_key; | |
| 54 // Privileges associated with key. Combination of |AuthKeyPrivileges| values. | 108 // Privileges associated with key. Combination of |AuthKeyPrivileges| values. |
| 55 int privileges; | 109 int privileges; |
| 110 int revision; |
| 111 std::string secret; |
| 112 |
| 113 std::vector<AuthorizationData> authorization_data; |
| 114 std::vector<ProviderData> provider_data; |
| 56 }; | 115 }; |
| 57 | 116 |
| 58 // Authorization attempt data for user. | 117 // Authorization attempt data for user. |
| 59 struct CHROMEOS_EXPORT Authorization { | 118 struct CHROMEOS_EXPORT Authorization { |
| 60 Authorization(const std::string& key, const std::string& label); | 119 Authorization(const std::string& key, const std::string& label); |
| 61 explicit Authorization(const KeyDefinition& key); | 120 explicit Authorization(const KeyDefinition& key); |
| 62 | 121 |
| 63 bool operator==(const Authorization& other) const; | 122 bool operator==(const Authorization& other) const; |
| 64 | 123 |
| 65 std::string key; | 124 std::string key; |
| 66 std::string label; | 125 std::string label; |
| 67 }; | 126 }; |
| 68 | 127 |
| 69 // Information about keys returned by GetKeyDataEx(). | |
| 70 struct CHROMEOS_EXPORT RetrievedKeyData { | |
| 71 enum Type { | |
| 72 TYPE_PASSWORD = 0 | |
| 73 }; | |
| 74 | |
| 75 enum AuthorizationType { | |
| 76 AUTHORIZATION_TYPE_HMACSHA256 = 0, | |
| 77 AUTHORIZATION_TYPE_AES256CBC_HMACSHA256 | |
| 78 }; | |
| 79 | |
| 80 struct ProviderData { | |
| 81 explicit ProviderData(const std::string& name); | |
| 82 ~ProviderData(); | |
| 83 | |
| 84 std::string name; | |
| 85 scoped_ptr<int64> number; | |
| 86 scoped_ptr<std::string> bytes; | |
| 87 }; | |
| 88 | |
| 89 RetrievedKeyData(Type type, const std::string& label, int64 revision); | |
| 90 ~RetrievedKeyData(); | |
| 91 | |
| 92 Type type; | |
| 93 std::string label; | |
| 94 // Privileges associated with key. Combination of |AuthKeyPrivileges| values. | |
| 95 int privileges; | |
| 96 int64 revision; | |
| 97 std::vector<AuthorizationType> authorization_types; | |
| 98 ScopedVector<ProviderData> provider_data; | |
| 99 }; | |
| 100 | |
| 101 // Parameters for Mount call. | 128 // Parameters for Mount call. |
| 102 class CHROMEOS_EXPORT MountParameters { | 129 class CHROMEOS_EXPORT MountParameters { |
| 103 public: | 130 public: |
| 104 explicit MountParameters(bool ephemeral); | 131 explicit MountParameters(bool ephemeral); |
| 105 ~MountParameters(); | 132 ~MountParameters(); |
| 106 | 133 |
| 107 bool operator==(const MountParameters& other) const; | 134 bool operator==(const MountParameters& other) const; |
| 108 | 135 |
| 109 // If |true|, the mounted home dir will be backed by tmpfs. If |false|, the | 136 // If |true|, the mounted home dir will be backed by tmpfs. If |false|, the |
| 110 // ephemeral users policy decides whether tmpfs or an encrypted directory is | 137 // ephemeral users policy decides whether tmpfs or an encrypted directory is |
| 111 // used as the backend. | 138 // used as the backend. |
| 112 bool ephemeral; | 139 bool ephemeral; |
| 113 | 140 |
| 114 // If not empty, home dir will be created with these keys if it exist. | 141 // If not empty, home dir will be created with these keys if it exist. |
| 115 std::vector<KeyDefinition> create_keys; | 142 std::vector<KeyDefinition> create_keys; |
| 116 }; | 143 }; |
| 117 | 144 |
| 118 } // namespace cryptohome | 145 } // namespace cryptohome |
| 119 | 146 |
| 120 #endif // CHROMEOS_CRYPTOHOME_CRYPTOHOME_PARAMETERS_H_ | 147 #endif // CHROMEOS_CRYPTOHOME_CRYPTOHOME_PARAMETERS_H_ |
| OLD | NEW |