-
Notifications
You must be signed in to change notification settings - Fork 1
/
client_side_file_crypto.install
154 lines (150 loc) · 3.9 KB
/
client_side_file_crypto.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
<?php
/**
* @file
* Install and uninstall functions for the client_side_file_crypto module.
*/
/**
* Implements hook_install().
*
* This hook will run upon installation of this module and will generate
* multiple key requests, one per user per role that they are in.
*
* written to the database table created in hook_schema().
*
* @see hook_install()
*
* @ingroup client_side_file_crypto
*/
function client_side_file_crypto_install() {
$users = \Drupal::entityManager()->getStorage('user')->loadMultiple();
$values = [];
foreach ($users as $user) {
$roles = $user->getRoles();
foreach ($roles as $role) {
$values[] = [
'accessKey' => '100',
'roleName' => $role,
'userID' => $user->id(),
'needsKey' => 1,
];
}
}
$query = db_insert('client_side_file_crypto_Keys')->fields([
'accessKey',
'roleName',
'userID',
]
);
foreach ($values as $record) {
$query->values($record);
}
$query->execute();
}
/**
* Implements hook_schema().
*
* Defines the database tables used by this module.
*
* @see hook_schema()
*
* @ingroup client_side_file_crypto
*/
function client_side_file_crypto_schema() {
$schema['client_side_file_crypto_Keys'] = [
'description' => 'Stores all the access keys for the users',
'fields' => [
'keyIndex' => [
'type' => 'serial',
'not null' => TRUE,
'description' => "Index ident for the keys",
],
'accessKey' => [
'type' => 'varchar',
'length' => 300,
'not null' => TRUE,
'default' => '',
'description' => "The access key that must be decrypted for data access",
],
'userID' => [
'type' => 'int',
'not null' => TRUE,
'description' => "The user ID of the key's owner",
],
'roleName' => [
'type' => 'varchar',
'length' => 20,
'not null' => TRUE,
'description' => "The Group name that this key is for",
],
'salt' => [
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'default' => '',
'description' => 'Salt used if any',
],
'needsKey' => [
'type' => 'int',
'default' => 1,
'not null' => TRUE,
'description' => 'Boolean determines if an access key is required.',
],
],
'primary key' => ['keyIndex'],
'indexes' => [
'key_pub' => ['accessKey'],
'group_key' => ['roleName'],
],
];
$schema['client_side_file_crypto_files'] = [
'description' => 'Stores all metadata for encrypted files',
'fields' => [
'fileIndex' => [
'type' => 'int',
'not null' => TRUE,
'description' => "fileID identifier for the file metadata",
],
'fileName' => [
'type' => 'varchar',
'length' => 100,
'not null' => TRUE,
'description' => "file name before encryption",
],
'nodeID' => [
'type' => 'int',
'not null' => TRUE,
'description' => "node ID of the node where the file is attached",
],
'isImage' => [
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => "Boolean value for if the file is an image or not.",
],
'MIMEtype' => [
'type' => 'varchar',
'length' => 20,
'not null' => FALSE,
'description' => "MIME type for the file",
],
'roleName' => [
'type' => 'varchar',
'length' => 20,
'not null' => TRUE,
'description' => "role name for which the file is encrypted",
],
'pathToFile' => [
'type' => 'varchar',
'length' => 1000,
'not null' => TRUE,
'description' => "Path at which the file is stored",
],
],
'primary key' => ['fileIndex'],
'indexes' => [
'file_name' => ['fileName'],
'group_key' => ['roleName'],
],
];
return $schema;
}