This repository was archived by the owner on Feb 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFieldLevelEncryptionConfig.php
343 lines (298 loc) · 11 KB
/
FieldLevelEncryptionConfig.php
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
<?php
namespace Mastercard\Developer\Encryption;
use Mastercard\Developer\Keys\DecryptionKey;
use Mastercard\Developer\Keys\EncryptionKey;
/**
* A class for storing the encryption/decryption configuration.
* @package Mastercard\Developer\Encryption
*/
class FieldLevelEncryptionConfig {
/**
* A certificate object whose public key will be used for encryption.
* @var EncryptionKey
*/
private $encryptionCertificate;
/**
* The SHA-256 hex-encoded digest of the certificate used for encryption (optional, the digest will be
* automatically computed if this field is null or empty).
* Example: '4d9d7540be320429ffc8e6506f054525816e2d0e95a85247d5b58be713f28be0'
* @var string
*/
private $encryptionCertificateFingerprint;
/**
* The SHA-256 hex-encoded digest of the key used for encryption (optional, the digest will be
* automatically computed if this field is null or empty).
* Example: 'c3f8ef7053c4fb306f7476e7d1956f0aa992ff9dfdd5244b912a1d377ff3a84f'
* @var string
*/
private $encryptionKeyFingerprint;
/**
* A private key string to be used for decryption.
* @var DecryptionKey
*/
private $decryptionKey;
/**
* A list of JSON paths to encrypt in request payloads.
* Example:
* <pre>
* array(
* '$.path.to.element.to.be.encrypted' => '$.path.to.object.where.to.store.encryption.fields'
* )
* </pre>
*/
private $encryptionPaths = array();
/**
* A list of JSON paths to decrypt in response payloads.
* Example:
* <pre>
* array(
* '$.path.to.object.with.encryption.fields' => '$.path.where.to.write.decrypted.element'
* )
* </pre>
*/
private $decryptionPaths = array();
/**
* The digest algorithm to be used for the RSA OAEP padding. Example: 'SHA-512'.
* @var string
*/
private $oaepPaddingDigestAlgorithm;
/**
* The name of the payload field where to write/read the digest algorithm used for
* the RSA OAEP padding (optional, the field won't be set if the name is null or empty).
* @var string|null
*/
private $oaepPaddingDigestAlgorithmFieldName;
/**
* The name of the HTTP header where to write/read the digest algorithm used for
* the RSA OAEP padding (optional, the header won't be set if the name is null or empty).
* @var string|null
*/
private $oaepPaddingDigestAlgorithmHeaderName;
/**
* The name of the payload field where to write/read the initialization vector value.
* @var string|null
*/
private $ivFieldName;
/**
* The name of the header where to write/read the initialization vector value.
* @var string|null
*/
private $ivHeaderName;
/**
* The name of the payload field where to write/read the one-time usage encrypted symmetric key.
* @var string|null
*/
private $encryptedKeyFieldName;
/**
* The name of the header where to write/read the one-time usage encrypted symmetric key.
* @var string|null
*/
private $encryptedKeyHeaderName;
/**
* The name of the payload field where to write/read the encrypted data value.
* @var string|null
*/
private $encryptedValueFieldName;
/**
* The name of the payload field where to write/read the digest of the encryption
* certificate (optional, the field won't be set if the name is null or empty).
* @var string|null
*/
private $encryptionCertificateFingerprintFieldName;
/**
* The name of the header where to write/read the digest of the encryption
* certificate (optional, the header won't be set if the name is null or empty).
* @var string|null
*/
private $encryptionCertificateFingerprintHeaderName;
/**
* The name of the payload field where to write/read the digest of the encryption
* key (optional, the field won't be set if the name is null or empty).
* @var string|null
*/
private $encryptionKeyFingerprintFieldName;
/**
* The name of the header where to write/read the digest of the encryption
* key (optional, the header won't be set if the name is null or empty).
* @var string|null
*/
private $encryptionKeyFingerprintHeaderName;
/**
* How the field/header values have to be encoded.
* @see FieldValueEncoding
* @var int
*/
private $fieldValueEncoding;
/**
* If the encryption parameters must be written to/read from HTTP headers.
* @return bool
*/
public function useHttpHeaders() {
return !empty($this->encryptedKeyHeaderName) && !empty($this->ivHeaderName);
}
/**
* If the encryption parameters must be written to/read from HTTP payloads.
* @return bool
*/
public function useHttpPayloads() {
return !empty($this->encryptedKeyFieldName) && !empty($this->ivFieldName);
}
/**
* FieldLevelEncryptionConfig constructor.
*
* @param EncryptionKey $encryptionCertificate
* @param string $encryptionCertificateFingerprint
* @param string $encryptionKeyFingerprint
* @param DecryptionKey $decryptionKey
* @param array $encryptionPaths
* @param array $decryptionPaths
* @param string $oaepPaddingDigestAlgorithm
* @param string|null $oaepPaddingDigestAlgorithmFieldName
* @param string|null $oaepPaddingDigestAlgorithmHeaderName
* @param string|null $ivFieldName
* @param string|null $ivHeaderName
* @param string|null $encryptedKeyFieldName
* @param string|null $encryptedKeyHeaderName
* @param string|null $encryptedValueFieldName
* @param string|null $encryptionCertificateFingerprintFieldName
* @param string|null $encryptionCertificateFingerprintHeaderName
* @param string|null $encryptionKeyFingerprintFieldName
* @param string|null $encryptionKeyFingerprintHeaderName
* @param int $fieldValueEncoding
*/
public function __construct($encryptionCertificate, $encryptionCertificateFingerprint, $encryptionKeyFingerprint, $decryptionKey, $encryptionPaths, $decryptionPaths, $oaepPaddingDigestAlgorithm, $oaepPaddingDigestAlgorithmFieldName, $oaepPaddingDigestAlgorithmHeaderName, $ivFieldName, $ivHeaderName, $encryptedKeyFieldName, $encryptedKeyHeaderName, $encryptedValueFieldName, $encryptionCertificateFingerprintFieldName, $encryptionCertificateFingerprintHeaderName, $encryptionKeyFingerprintFieldName, $encryptionKeyFingerprintHeaderName, $fieldValueEncoding) {
$this->encryptionCertificate = $encryptionCertificate;
$this->encryptionCertificateFingerprint = $encryptionCertificateFingerprint;
$this->encryptionKeyFingerprint = $encryptionKeyFingerprint;
$this->decryptionKey = $decryptionKey;
$this->encryptionPaths = $encryptionPaths;
$this->decryptionPaths = $decryptionPaths;
$this->oaepPaddingDigestAlgorithm = $oaepPaddingDigestAlgorithm;
$this->oaepPaddingDigestAlgorithmFieldName = $oaepPaddingDigestAlgorithmFieldName;
$this->oaepPaddingDigestAlgorithmHeaderName = $oaepPaddingDigestAlgorithmHeaderName;
$this->ivFieldName = $ivFieldName;
$this->ivHeaderName = $ivHeaderName;
$this->encryptedKeyFieldName = $encryptedKeyFieldName;
$this->encryptedKeyHeaderName = $encryptedKeyHeaderName;
$this->encryptedValueFieldName = $encryptedValueFieldName;
$this->encryptionCertificateFingerprintFieldName = $encryptionCertificateFingerprintFieldName;
$this->encryptionCertificateFingerprintHeaderName = $encryptionCertificateFingerprintHeaderName;
$this->encryptionKeyFingerprintFieldName = $encryptionKeyFingerprintFieldName;
$this->encryptionKeyFingerprintHeaderName = $encryptionKeyFingerprintHeaderName;
$this->fieldValueEncoding = $fieldValueEncoding;
}
/**
* @return EncryptionKey
*/
public function getEncryptionCertificate() {
return $this->encryptionCertificate;
}
/**
* @return string
*/
public function getEncryptionCertificateFingerprint() {
return $this->encryptionCertificateFingerprint;
}
/**
* @return string
*/
public function getEncryptionKeyFingerprint() {
return $this->encryptionKeyFingerprint;
}
/**
* @return DecryptionKey
*/
public function getDecryptionKey() {
return $this->decryptionKey;
}
/**
* @return array
*/
public function getEncryptionPaths() {
return $this->encryptionPaths;
}
/**
* @return array
*/
public function getDecryptionPaths() {
return $this->decryptionPaths;
}
/**
* @return string
*/
public function getOaepPaddingDigestAlgorithm() {
return $this->oaepPaddingDigestAlgorithm;
}
/**
* @return string|null
*/
public function getOaepPaddingDigestAlgorithmFieldName() {
return $this->oaepPaddingDigestAlgorithmFieldName;
}
/**
* @return string|null
*/
public function getOaepPaddingDigestAlgorithmHeaderName() {
return $this->oaepPaddingDigestAlgorithmHeaderName;
}
/**
* @return string|null
*/
public function getIvFieldName() {
return $this->ivFieldName;
}
/**
* @return string|null
*/
public function getIvHeaderName() {
return $this->ivHeaderName;
}
/**
* @return string|null
*/
public function getEncryptedKeyFieldName() {
return $this->encryptedKeyFieldName;
}
/**
* @return string|null
*/
public function getEncryptedKeyHeaderName() {
return $this->encryptedKeyHeaderName;
}
/**
* @return string|null
*/
public function getEncryptedValueFieldName() {
return $this->encryptedValueFieldName;
}
/**
* @return string|null
*/
public function getEncryptionCertificateFingerprintFieldName() {
return $this->encryptionCertificateFingerprintFieldName;
}
/**
* @return string|null
*/
public function getEncryptionCertificateFingerprintHeaderName() {
return $this->encryptionCertificateFingerprintHeaderName;
}
/**
* @return string|null
*/
public function getEncryptionKeyFingerprintFieldName() {
return $this->encryptionKeyFingerprintFieldName;
}
/**
* @return string|null
*/
public function getEncryptionKeyFingerprintHeaderName() {
return $this->encryptionKeyFingerprintHeaderName;
}
/**
* @return int
*/
public function getFieldValueEncoding() {
return $this->fieldValueEncoding;
}
}