-
Notifications
You must be signed in to change notification settings - Fork 0
/
encrypt.install
238 lines (215 loc) · 7.92 KB
/
encrypt.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<?php
/**
* @file
* Install, update and uninstall functions for the encrypt module.
*/
/**
* Implements hook_schema().
*
* Create table to store encryption configurations.
*/
function encrypt_schema() {
$schema['encrypt_config'] = array(
'description' => 'Stores encryption configurations.',
'fields' => array(
'name' => array(
'description' => 'The machine name of the configuration.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
),
'label' => array(
'description' => 'The human-readable label of the configuration.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'description' => array(
'description' => 'A brief description of the configuration.',
'type' => 'text',
'not null' => TRUE,
'size' => 'medium',
),
'method' => array(
'description' => 'The encryption method to use.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'method_settings' => array(
'description' => 'Additional settings for the encryption method.',
'type' => 'blob',
'not null' => TRUE,
'size' => 'big',
),
'provider' => array(
'description' => 'The key provider to use.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'provider_settings' => array(
'description' => 'Additional settings for the key provider.',
'type' => 'blob',
'not null' => TRUE,
'size' => 'big',
),
'enabled' => array(
'description' => 'A boolean indicating whether this configuration is enabled.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'created' => array(
'description' => 'The Unix timestamp when the configuration was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'changed' => array(
'description' => 'The Unix timestamp when the configuration was last saved.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'indexes' => array(
'enabled' => array('enabled'),
),
'primary key' => array('name'),
);
return $schema;
}
/**
* Implements hook_install().
*/
function encrypt_install() {
$t = get_t();
// Check if encrypt_backdrop_variable_key already exists. If so, use it.
// Otherwise, set it.
if (!($key = config_get('encrypt.settings', 'encrypt_backdrop_variable_key'))) {
$key = base64_encode(backdrop_random_bytes(24));
config_set('encrypt.settings', 'encrypt_backdrop_variable_key', $key);
}
// Add a default configuration.
db_insert('encrypt_config')
->fields(array(
'name' => 'default',
'label' => $t('Default'),
'description' => $t('The default configuration.'),
'method' => 'none',
'method_settings' => '',
'provider' => 'backdrop_variable',
'provider_settings' => serialize(array('method' => 'base64_decode')),
'enabled' => 1,
'created' => REQUEST_TIME,
'changed' => REQUEST_TIME,
))
->execute();
config_set('encrypt.settings', 'encrypt_default_config', 'default');
// Dynamically generated variable data was detected on the following lines.
// /encrypt/encrypt.install line 310
}
/**
* Implements hook_uninstall().
*
* Delete all of our variables from the variables table.
*/
function encrypt_uninstall() {
config_clear('encrypt.settings', 'encrypt_default_config');
// Delete any variables left over from older versions of Encrypt.
config_clear('encrypt.settings', 'encrypt_encryption_method');
$provider = config_get('encrypt.settings', 'encrypt_key_provider');
if ($provider) {
config_clear('encrypt.settings', 'encrypt_key_providers_' . $provider . '_settings');
}
config_clear('encrypt.settings', 'encrypt_key_provider');
}
/**
* Implements hook_requirements().
*/
function encrypt_requirements($phase) {
$t = get_t();
$requirements = array();
switch ($phase) {
case 'runtime':
$method = encrypt_get_encryption_method();
$key_provider = encrypt_get_key_provider();
// Check the plugins for dependency errors.
if (isset($method['dependency errors']) && !empty($method['dependency errors'])) {
$dependency_errors .= theme('item_list', array('items' => $method['dependency errors']));
}
if (isset($key_provider['dependency errors']) && !empty($key_provider['dependency errors'])) {
$dependency_errors .= theme('item_list', array('items' => $key_provider['dependency errors']));
}
if (isset($dependency_errors) && !empty($dependency_errors)) {
$requirements['encrypt_dependencies'] = array(
'title' => $t('Encrypt Dependencies'),
'value' => $t('Unmet dependencies'),
'description' => $t('There are unmet dependencies in your active encryption plugins. Either !change_link or resolve the following dependencies: !deps', array(
'!change_link' => l($t('change your encryption settings'), 'admin/config/system/encrypt'),
'!deps' => $dependency_errors,
)),
'severity' => REQUIREMENT_ERROR,
);
}
// Set a warning about the Backdrop Private Key method.
if (isset($key_provider['name']) && $key_provider['name'] == 'backdrop_private_key') {
$requirements['encrypt_secure'] = array(
'title' => $t('Encryption Security'),
'description' => $t(
'The site is using the private key stored in the database to encrypt
data. While this provides some level of obfuscation, it is highly
recommended to store the encryption key outside of the database.
See the !link for more information.', array(
'!link' => l($t('Encrypt module page'), 'http://drupal.org/project/encrypt'),
)
),
'severity' => REQUIREMENT_WARNING,
'value' => $t('Security concerns'),
);
}
break;
}
return $requirements;
}
// TODO The old hook_update_N functions cannot be applied to Backdrop.
function encrypt_update_7200() { }
// TODO The old hook_update_N functions cannot be applied to Backdrop.
function encrypt_update_7201() { }
// TODO The old hook_update_N functions cannot be applied to Backdrop.
function encrypt_update_7202() { }
// TODO The old hook_update_N functions cannot be applied to Backdrop.
function encrypt_update_7203() { }
/**
* Implements hook_update_last_removed().
*/
function encrypt_update_last_removed() {
return 7203;
}
/**
* Migrate encrypt variables to config.
*/
/*
function encrypt_update_1000() {
$config = config('encrypt.settings');
$config->set('encrypt_backdrop_variable_key', update_variable_get('encrypt_backdrop_variable_key', 'NULL'));
$config->set('encrypt_key_provider', update_variable_get('encrypt_key_provider', 'backdrop_private_key'));
$config->set('encrypt_default_method', update_variable_get('encrypt_default_method', 'NULL'));
$config->set('encrypt_secure_key_path', update_variable_get('encrypt_secure_key_path', 'NULL'));
$config->set('encrypt_encryption_method', update_variable_get('encrypt_encryption_method', 'default'));
$config->set('encrypt_key_providers_provider_settings', update_variable_get('encrypt_key_providers_provider_settings', 'dynamic variable in file /encrypt/encrypt.install line 310'));
$config->set('encrypt_default_config', update_variable_get('encrypt_default_config', 'NULL'));
$config->save();
update_variable_del('encrypt_backdrop_variable_key');
update_variable_del('encrypt_key_provider');
update_variable_del('encrypt_default_method');
update_variable_del('encrypt_secure_key_path');
update_variable_del('encrypt_encryption_method');
update_variable_del('encrypt_key_providers_provider_settings');
update_variable_del('encrypt_default_config');
}
*/