oak 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -3
- data/CHANGELOG.md +10 -1
- data/DESIDERATA.md +9 -4
- data/DESIGN.md +410 -0
- data/ENCRYPTION.md +893 -0
- data/README.md +2 -6
- data/bin/oak +1 -0
- data/bin/oak.rb +122 -124
- data/lib/oak.rb +13 -0
- data/lib/oak/version.rb +1 -1
- metadata +5 -3
- data/bin/oak +0 -245
data/ENCRYPTION.md
ADDED
@@ -0,0 +1,893 @@
|
|
1
|
+
# OAK: Encryption-in-OAK
|
2
|
+
|
3
|
+
OAK is a serialization and envelope format which encodes simple Ruby
|
4
|
+
objects as strings. It bundles together a variety of well-understood
|
5
|
+
encoding libraries into a succinct self-describing package.
|
6
|
+
|
7
|
+
OAK v3 was first described in [OAK: The Object ArKive](DESIGN.md).
|
8
|
+
|
9
|
+
Since 2017-09-13, OAK has been used by ALI for volatile caches in
|
10
|
+
Redis, and for durable Correspondence bodies in S3.
|
11
|
+
|
12
|
+
In Q4 2017 I evaluated, then set aside, the possibility of adding
|
13
|
+
encryption features to OAK. The motive then was to encrypt our
|
14
|
+
volatile caches in Redis, for which our hosting provider offers no
|
15
|
+
encryption-at-rest. This plan was eventually scrapped because we
|
16
|
+
decided we didn't need it and because I learned enough about modern
|
17
|
+
encryption to see that my plan was off track.
|
18
|
+
|
19
|
+
In Q3 2018 I am updating and simplifying that plan to to support
|
20
|
+
encryption of secrets.
|
21
|
+
|
22
|
+
Author: [JHW](https://github.com/jhwillett)
|
23
|
+
Advisors: Isaac, Rishav, Chris L.
|
24
|
+
|
25
|
+
Things get tricky with symmetric encryption. The _identity_ of our
|
26
|
+
encryption keys must be communicated from `OAK.encode` to
|
27
|
+
`OAK.decode`, but they cannot be explicitly present in the OAK
|
28
|
+
string itself.
|
29
|
+
|
30
|
+
Absent encryption, `OAK.decode` is nice unary pure function on OAK
|
31
|
+
strings. But to support decryption, `OAK.decode` cannot _only_ look
|
32
|
+
at the OAK string to effect a decode. It must also have a
|
33
|
+
side-channel for secrets. It degenerates to a binary function which
|
34
|
+
also must be passed a table of available encryption keys.
|
35
|
+
|
36
|
+
In anticipation of key migration, OAK works with a dictionary of
|
37
|
+
multiple named keys. `OAK.encode` records the encryption key (if
|
38
|
+
any) in the OAK string, and `OAK.decode` uses the key to select the
|
39
|
+
proper secrets from the keychain table.
|
40
|
+
|
41
|
+
Furthermore, sound encryption practice with streaming modes demands we
|
42
|
+
include random noise at the start of each encrypted stream. Hence,
|
43
|
+
`OAK.encode` degrades from a pure function to be nondeterministic.
|
44
|
+
|
45
|
+
Here's a sneak preview of some OAK encryption:
|
46
|
+
|
47
|
+
```
|
48
|
+
$ export TOE_KEYS=foo,bar # set up a key chain with 1 keys
|
49
|
+
|
50
|
+
$ export TOE_KEY_foo=oak_3CNB_3725491808_52_RjFTQTMyX0qAlJNbIK4fwYY0kh5vNKF5mMpHK-ZBZkfFarRjVPxS_ok
|
51
|
+
|
52
|
+
$ export TOE_KEY_bar=oak_3CNB_201101230_52_RjFTQTMyXxbYlRcFH8JgiFNZMbnlFTAfUyvJCnXgCESpBmav_Etp_ok
|
53
|
+
|
54
|
+
$ echo 'Hello!' | bin/oak.rb --format none # OAK_3 with naked interior
|
55
|
+
oak_3CNN_2640238464_12_F1SU6_Hello!_ok
|
56
|
+
|
57
|
+
$ echo 'Hello!' | bin/oak.rb --format none --force-oak-4 # OAK_4 with naked interior sneak preview
|
58
|
+
oak_4_N25_CN2640238464_F1SU6_Hello!_ok
|
59
|
+
|
60
|
+
$ echo 'Hello!' | bin/oak.rb # OAK_3 defaults to base64
|
61
|
+
oak_3CNB_2640238464_16_RjFTVTZfSGVsbG8h_ok
|
62
|
+
|
63
|
+
$ echo 'Hello!' | bin/oak.rb --force-oak-4 # OAK_4 defaults to base64
|
64
|
+
oak_4_B34_Q04yNjQwMjM4NDY0X0YxU1U2X0hlbGxvIQ_ok
|
65
|
+
|
66
|
+
$ echo 'Hello!' | bin/oak.rb --key-chain TOE --key foo # OAK_4 encrypted
|
67
|
+
oak_4foo_B71_HlcPvmphFuA2gj1GsMBFzZuaHT1YMvq7EOcsBIO7DNtxwszsD4M4p-ZuYc5Z7oq2tl12SA0_ok
|
68
|
+
|
69
|
+
$ echo 'Hello!' | bin/oak.rb --key-chain TOE --key foo # OAK_4 encryption is nondeterministic
|
70
|
+
oak_4foo_B71_TcLpBTydPhfImx7Uorg_EQPPn2q01AHjHZaXCiGimEoJA2nJZB9nhJP9Bt8_Itv7Kvn0kKs_ok
|
71
|
+
|
72
|
+
$ echo 'Hello!' | bin/oak.rb --key-chain TOE --key foo | bin/oak.rb --key-chain TOE --mode decode-lines
|
73
|
+
Hello!
|
74
|
+
```
|
75
|
+
Here is a quick parse of some OAK strings:
|
76
|
+
```
|
77
|
+
$ echo 'Hello!' | bin/oak.rb --format none # OAK_3 with naked interior
|
78
|
+
oak_3CNN_2640238464_12_F1SU6_Hello!_ok
|
79
|
+
oak_3 # OAK ver 3
|
80
|
+
C # checksum Crc32
|
81
|
+
N # compression None
|
82
|
+
N # format None
|
83
|
+
2640238464 # checksum value (F1SU6_Hello!)
|
84
|
+
12 # 12 data bytes (F1SU6_Hello!)
|
85
|
+
F1SU6_Hello! # data FRIZZY, 1 UTF-8 str, 6 chars, "Hello!"
|
86
|
+
ok # end of sequence
|
87
|
+
|
88
|
+
$ echo 'Hello!' | bin/oak.rb --format none --force-oak-4 # OAK_4 with naked interior
|
89
|
+
oak_4_N25_CN2640238464_F1SU6_Hello!_ok
|
90
|
+
oak_4 # OAK ver 4 w/ no encryption key
|
91
|
+
N # format None
|
92
|
+
25 # 25 data bytes (CN2640238464_F1SU6_Hello!)
|
93
|
+
C # checksum Crc32
|
94
|
+
N # compression None
|
95
|
+
2640238464 # checksum value
|
96
|
+
F1SU6_Hello! # data FRIZZY, 1 UTF-8 str, 6 chars, "Hello!"
|
97
|
+
ok # end of sequence
|
98
|
+
|
99
|
+
$ echo 'Hello!' | bin/oak.rb # OAK_3 defaults to base64
|
100
|
+
oak_3CNB_2640238464_16_RjFTVTZfSGVsbG8h_ok
|
101
|
+
oak_3 # OAK ver 3
|
102
|
+
C # checksum Crc32
|
103
|
+
N # compression None
|
104
|
+
B # format Base64
|
105
|
+
2640238464 # checksum value (F1SU6_Hello!)
|
106
|
+
16 # 16 data bytes
|
107
|
+
RjFTVTZfSGVsbG8h # data: base64("F1SU6_Hello!")
|
108
|
+
ok # end of sequence
|
109
|
+
|
110
|
+
$ echo 'Hello!' | bin/oak.rb --force-oak-4 # OAK_4 defaults to base64
|
111
|
+
oak_4_B34_Q04yNjQwMjM4NDY0X0YxU1U2X0hlbGxvIQ_ok
|
112
|
+
oak_4 # OAK ver 4 w/ no encryption key
|
113
|
+
B # format Base64
|
114
|
+
34 # 34 data bytes Q04u...vxIQ
|
115
|
+
Q04yNjQwMjM4NDY0X0YxU1U2X0hlbGxvIQ # data: base64("CN2640238464_F1SU6_Hello!")
|
116
|
+
ok # end of sequence
|
117
|
+
|
118
|
+
$ echo 'Hello!' | bin/oak.rb --key-chain TOE --key foo # OAK_4 encrypted
|
119
|
+
oak_4foo_B71_HlcPvmphFuA2gj1GsMBFzZuaHT1YMvq7EOcsBIO7DNtxwszsD4M4p-ZuYc5Z7oq2tl12SA0_ok
|
120
|
+
oak_4foo # OAK ver 4 encrypted with key "foo"
|
121
|
+
B # format Base64
|
122
|
+
71 # 71 data bytes HlcP...2SA0
|
123
|
+
HlcPvmphFuA2g... # base64 of encrypted data
|
124
|
+
```
|
125
|
+
The header fields are authenticated, even the ones which are presented
|
126
|
+
in plaintext:
|
127
|
+
```
|
128
|
+
oak_4foo_B # authenticated-but-plaintext part
|
129
|
+
71 # in-between part
|
130
|
+
HlcPvmphFuA2g... # authenticated-and-encrypted part
|
131
|
+
```
|
132
|
+
|
133
|
+
## OAK Encryption History
|
134
|
+
|
135
|
+
* Proposed Q4 2017: [oak-openssl-ciphers](https://github.com/ProsperWorks/ALI/pull/5434 )
|
136
|
+
* Initial support for symmetric key encryption. Not integrated or active.
|
137
|
+
* Introduced OAK_4 for encryption but preserves read+write for OAK_3.
|
138
|
+
* Sought to expose all algorithms supported by OpenSSL::Cipher.
|
139
|
+
* By failing to curate algorithms, less-educated users are put
|
140
|
+
in a position of making expert decisions.
|
141
|
+
* Neglected differences between modes of operation.
|
142
|
+
* Sought to be deterministic.
|
143
|
+
* Neglected risks reusing initialization vectors.
|
144
|
+
* Did not merge.
|
145
|
+
|
146
|
+
* Proposed Q3 2018: [oak-openssl-ciphers-redux](https://github.com/ProsperWorks/ALI/pull/9335/files)
|
147
|
+
* Still introduces OAK_4 for encryption but preserves read+write for OAK_3.
|
148
|
+
* Narrows choices to just AES-256-GCM with random IV.
|
149
|
+
* Authenticates all headers.
|
150
|
+
* Encrypts all headers not required for decryption.
|
151
|
+
* Split out into smaller PRs:
|
152
|
+
* [oak-openssl-ciphers-redux-part-i](https://github.com/ProsperWorks/ALI/pull/9560) plan docs
|
153
|
+
* [oak-openssl-ciphers-redux-part-ii](https://github.com/ProsperWorks/ALI/pull/9561) api syntax
|
154
|
+
* [oak-openssl-ciphers-redux-part-iii](https://github.com/ProsperWorks/ALI/pull/9562) corruption tests
|
155
|
+
* [oak-openssl-ciphers-redux-part-iv](https://github.com/ProsperWorks/ALI/pull/9563) main implementation
|
156
|
+
* [oak-openssl-ciphers-redux-part-v](https://github.com/ProsperWorks/ALI/pull/9572) bin/oak.rb cli
|
157
|
+
|
158
|
+
## JHW Revisits Encryption-in-OAK 2018-07-15
|
159
|
+
|
160
|
+
[oak-openssl-ciphers](https://github.com/ProsperWorks/ALI/pull/5434)
|
161
|
+
was originally prepared against
|
162
|
+
[minor_2017_10_mystic](https://github.com/ProsperWorks/ALI/pull/5930)
|
163
|
+
and presented in Arch Review 2017-09-18. It never merged because
|
164
|
+
feedback and further research raised many questions. In particular,
|
165
|
+
the IV is much more delicate than I originally understood.
|
166
|
+
|
167
|
+
Per expert recommendations, GCM and CBC are the two more viable stream
|
168
|
+
modes. Of them, GCM is much more sensitive to accidental IV reuse.
|
169
|
+
So much so, that GCM is not recommended in the absence of a fully
|
170
|
+
automated IV management.
|
171
|
+
|
172
|
+
_**At ProsperWorks' current level of organization I believe the only
|
173
|
+
credible option is CBC or GCM with a random IV selected for every
|
174
|
+
message.**_
|
175
|
+
|
176
|
+
Therefore _**encrypted OAK will be nondeterministic in the plaintext**_.
|
177
|
+
This is a bummer but I see no way to avoid it without compromising
|
178
|
+
security.
|
179
|
+
|
180
|
+
Also, today I see no point in supporting anything other than AES. All
|
181
|
+
of AES-128, AES-192, and AES-256 are probably adequate for our needs,
|
182
|
+
but if we support just AES-256 then we don't have to answer any thorny
|
183
|
+
questions. There too much security downside in letting the caller
|
184
|
+
pick any old block cipher or mode of operation which is supported by
|
185
|
+
OpenSSL. This outweighs any ambition to future-proof OAK by offering
|
186
|
+
open-ended support.
|
187
|
+
|
188
|
+
GCM not only encrypts, but authenticates. It is an
|
189
|
+
[AEAD](https://en.wikipedia.org/wiki/Authenticated_encryption) and we
|
190
|
+
can authenticate all the headers, including those which are
|
191
|
+
transmitted in plaintext.
|
192
|
+
|
193
|
+
Therefore, _**OAK_4 will support only AES-256-GCM with a random IV
|
194
|
+
selected each time a message is encrypted**_. OAK_4 keys will be 32
|
195
|
+
byte random binary strings. OAK_4 IVs will be 12 byte binary strings
|
196
|
+
which are encoded into each OAK string. OAK_4 will use no salt other
|
197
|
+
than the random IV for each encryption
|
198
|
+
|
199
|
+
_**OAK_4 will allow compression within encryption.**_
|
200
|
+
|
201
|
+
_**OAK_4 will encrypt all OAK header fields except those which are
|
202
|
+
necessary to support decryption.**_ Yes, [Kerckhoffs's
|
203
|
+
Principle](https://en.wikipedia.org/wiki/Kerckhoffs%27s_principle),
|
204
|
+
but also [Precautionary
|
205
|
+
Principle](https://en.wikipedia.org/wiki/Precautionary_principle). To
|
206
|
+
be transmitted plain: the format and version identifiers "oak_4", the
|
207
|
+
format code (base64 or none), the name of the key used, and the
|
208
|
+
redundancy check for the _encrypted_ message.
|
209
|
+
|
210
|
+
OAK_4 will also support authentication via GCM. "oak_4", the
|
211
|
+
encryption key name, and the format flag will be authenticated but
|
212
|
+
transmitted plain. All the encrypted fields are also authenticated.
|
213
|
+
We can save space by skipping redundancy flags in encrypted OAK_4
|
214
|
+
sequences.
|
215
|
+
|
216
|
+
## Appendix: Excerpts from Best Practices Research
|
217
|
+
|
218
|
+
[https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation) (sentences rearranged some here to group subtopics better)
|
219
|
+
|
220
|
+
An initialization vector (IV) or starting variable
|
221
|
+
(SV)[[5]](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#cite_note-ISO-10116-5)
|
222
|
+
is a block of bits that is used by several modes to randomize the
|
223
|
+
encryption and hence to produce distinct ciphertexts even if the same
|
224
|
+
plaintext is encrypted multiple times, without the need for a slower
|
225
|
+
re-keying
|
226
|
+
process.[[6]](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#cite_note-HUANG-6)
|
227
|
+
|
228
|
+
An initialization vector has different security requirements than a
|
229
|
+
key, so the IV usually does not need to be secret. However, in most
|
230
|
+
cases, it is important that an initialization vector is never reused
|
231
|
+
under the same key.
|
232
|
+
|
233
|
+
For CBC and CFB, reusing an IV leaks some information about the first
|
234
|
+
block of plaintext, and about any common prefix shared by the two
|
235
|
+
messages. ...
|
236
|
+
|
237
|
+
In CBC mode, the IV must, in addition, be unpredictable at encryption
|
238
|
+
time; in particular, the (previously) common practice of re-using the
|
239
|
+
last ciphertext block of a message as the IV for the next message is
|
240
|
+
insecure (for example, this method was used by SSL 2.0). If an
|
241
|
+
attacker knows the IV (or the previous block of ciphertext) before he
|
242
|
+
specifies the next plaintext, he can check his guess about plaintext
|
243
|
+
of some block that was encrypted with the same key before (this is
|
244
|
+
known as the TLS CBC IV attack).
|
245
|
+
|
246
|
+
For OFB and CTR, reusing an IV completely destroys security. This can
|
247
|
+
be seen because both modes effectively create a bitstream that is
|
248
|
+
XORed with the plaintext, and this bitstream is dependent on the
|
249
|
+
password and IV only. Reusing a bitstream destroys security
|
250
|
+
|
251
|
+
[https://esj.com/Articles/2008/07/01/8-Best-Practices-for-Encryption-Key-Management-and-Data-Security.aspx?Page=2](https://esj.com/Articles/2008/07/01/8-Best-Practices-for-Encryption-Key-Management-and-Data-Security.aspx?Page=2)
|
252
|
+
|
253
|
+
* Step 1: Eliminate as much collection and storage of sensitive data
|
254
|
+
as possible - if you don't really need it, get rid of it (or never
|
255
|
+
collect it in the first place);
|
256
|
+
* Step 2: Encrypt, hash, or mask the remaining sensitive data at rest
|
257
|
+
and in transit.
|
258
|
+
|
259
|
+
* Best Practice #1: Decentralize encryption and decryption
|
260
|
+
* Best Practice #2: Centralize key management with distributed execution
|
261
|
+
* Best Practice #3: Support multiple encryption standards
|
262
|
+
* Best Practice #4: Centralize user profiles for authentication and access to keys
|
263
|
+
* Best Practice #5: Do not require decryption/re-encryption for key rotation or expiration
|
264
|
+
* Best Practice #6: Keep comprehensive logs and audit trails
|
265
|
+
* Best Practice #7: Use one solution to support fields, files, and databases
|
266
|
+
* Best Practice #8: Support third-party integration
|
267
|
+
|
268
|
+
[https://cloud.google.com/security/encryption-at-rest/default-encryption/](https://cloud.google.com/security/encryption-at-rest/default-encryption/)
|
269
|
+
|
270
|
+
April 2017
|
271
|
+
|
272
|
+
* Google uses several layers of encryption to protect customer data at
|
273
|
+
rest in Google Cloud Platform products.
|
274
|
+
* Google Cloud Platform encrypts customer content stored at rest,
|
275
|
+
without any action required from the customer, using one or more
|
276
|
+
encryption mechanisms. There are some minor exceptions.
|
277
|
+
* Data for storage is split into chunks, and each chunk is encrypted
|
278
|
+
with a unique data encryption key. These data encryption keys are
|
279
|
+
stored with the data, encrypted with ("wrapped" by) key encryption
|
280
|
+
keys that are exclusively stored and used inside Google's central
|
281
|
+
Key Management Service. Google's Key Management Service is redundant
|
282
|
+
and globally distributed.
|
283
|
+
* Data stored in Google Cloud Platform is encrypted at the storage
|
284
|
+
level using either AES256 or AES128.
|
285
|
+
* Google uses a common cryptographic library, Keyczar, to implement
|
286
|
+
encryption consistently across almost all Google Cloud Platform
|
287
|
+
products. (The open-sourced version of Keyczar has known security
|
288
|
+
issues, and is NOT the version used internally at Google.) Because
|
289
|
+
this common library is widely accessible, only a small team of
|
290
|
+
cryptographers needs to properly implement and maintain this tightly
|
291
|
+
controlled and reviewed code.
|
292
|
+
* Google uses the Advanced Encryption Standard (AES) algorithm to
|
293
|
+
encrypt data at rest. AES is widely used because (1) [both AES256
|
294
|
+
and AES128 are recommended by the National Institute of Standards
|
295
|
+
and Technology (NIST) for long-term storage
|
296
|
+
use](http://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-131Ar1.pdf)
|
297
|
+
(as of November 2015), and (2) AES is often included as part of
|
298
|
+
customer compliance requirements.
|
299
|
+
* Data stored across Google Cloud Storage is encrypted at the storage
|
300
|
+
level using AES, in [Galois/Counter Mode
|
301
|
+
(GCM)](http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/gcm/gcm-spec.pdf)
|
302
|
+
in almost all cases. This is implemented in the [BoringSSL
|
303
|
+
library](https://boringssl.googlesource.com/boringssl/) that Google
|
304
|
+
maintains. This library was forked from OpenSSL for internal use,
|
305
|
+
after [many flaws were exposed in
|
306
|
+
OpenSSL](https://www.openssl.org/news/vulnerabilities.html). In
|
307
|
+
select cases, AES is used in Cipher Block Chaining (CBC) mode with a
|
308
|
+
hashed message authentication code (HMAC) for authentication; and
|
309
|
+
for some replicated files, AES is used in Counter (CTR) mode with
|
310
|
+
HMAC. (Further details on algorithms are provided [later in this
|
311
|
+
document](https://cloud.google.com/security/encryption-at-rest/default-encryption/#googles_common_cryptographic_library).)
|
312
|
+
In other Google Cloud Platform products, AES is used in a variety of
|
313
|
+
modes.
|
314
|
+
* In addition to the storage system level encryption described above,
|
315
|
+
in most cases data is also encrypted at the storage device level,
|
316
|
+
with at least AES128 for hard disks (HDD) and AES256 for new solid
|
317
|
+
state drives (SSD), using a separate device-level key (which is
|
318
|
+
different than the key used to encrypt the data at the storage
|
319
|
+
level). As older devices are replaced, solely AES256 will be used
|
320
|
+
for device-level encryption.
|
321
|
+
* At the time of this document's publication, Google uses the
|
322
|
+
following encryption algorithms for encryption at rest for DEKs and
|
323
|
+
KEKs. These are subject to change as we continue to improve our
|
324
|
+
capabilities and security.
|
325
|
+
* Symmetric Encryption
|
326
|
+
* **AES-GCM (256 bits) (preferred)**
|
327
|
+
* AES-CBC
|
328
|
+
* AES-CTR (128 and 256 bits)
|
329
|
+
* AES-EAX (128 and 256 bits)
|
330
|
+
* Symmetric Signatures
|
331
|
+
* HMAC-SHA256 (preferred)
|
332
|
+
* HMAC-SHA512
|
333
|
+
* HMAC-SHA1
|
334
|
+
|
335
|
+
[http://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-131Ar1.pdf](http://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-131Ar1.pdf)
|
336
|
+
|
337
|
+
NIST Special Publication 800-131A Revision 1
|
338
|
+
|
339
|
+
Transitions: Recommendation for Transitioning the Use of Cryptographic Algorithms and Key Lengths
|
340
|
+
|
341
|
+
November 2015
|
342
|
+
|
343
|
+
* **The use of AES-128, AES-192, AES-256 and three-key TDEA is acceptable.**
|
344
|
+
|
345
|
+
[http://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf](http://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf)
|
346
|
+
|
347
|
+
NIST Special Publication 800-38D
|
348
|
+
|
349
|
+
Recommendation for Block Cipher Modes of Operation: Galois/Counter
|
350
|
+
Mode (GCM) and GMAC
|
351
|
+
|
352
|
+
November, 2007
|
353
|
+
|
354
|
+
* This Recommendation specifies the Galois/Counter Mode (GCM), an
|
355
|
+
algorithm for authenticated encryption with associated data, and its
|
356
|
+
specialization, GMAC, for generating a message authentication code
|
357
|
+
(MAC) on data that is not encrypted. **GCM and GMAC are modes of
|
358
|
+
operation for an underlying approved symmetric key block cipher.**
|
359
|
+
* GCM is constructed from an approved symmetric key block cipher with
|
360
|
+
a block size of 128 bits, such as the Advanced Encryption Standard
|
361
|
+
(AES) algorithm that is specified in Federal Information Processing
|
362
|
+
Standard (FIPS) Pub. 197 [2]. **Thus, GCM is a mode of operation of
|
363
|
+
the AES algorithm.**
|
364
|
+
* ..If the GCM input is restricted to data that is not to be
|
365
|
+
encrypted, the resulting specialization of GCM, called GMAC, is
|
366
|
+
simply an authentication mode on the input data. In the rest of this
|
367
|
+
document, statements about GCM also apply to GMAC.
|
368
|
+
* **GCM provides stronger authentication assurance than a
|
369
|
+
(non-cryptographic) checksum or error detecting code;** in
|
370
|
+
particular, GCM can detect both 1) accidental modifications of the
|
371
|
+
data and 2) intentional, unauthorized modifications.
|
372
|
+
* ...The underlying block cipher shall be approved, the block size
|
373
|
+
shall be 128 bits, and **the key size shall be at least 128 bits**.
|
374
|
+
* ...For IVs, it is recommended that implementations restrict support
|
375
|
+
to the length of **96 bits, to promote interoperability, efficiency,
|
376
|
+
and simplicity of design**.
|
377
|
+
* JHW checked 96 == OpenSSL::Cipher.new('aes-256-gcm').random_iv.size * 8
|
378
|
+
* JHW checked 96 == OpenSSL::Cipher.new('aes-128-gcm').random_iv.size * 8
|
379
|
+
* ... **The IVs in GCM must fulfill the following "uniqueness"
|
380
|
+
requirement**: The probability that the authenticated encryption
|
381
|
+
function ever will be invoked with the same IV and the same key on
|
382
|
+
two (or more) distinct sets of input data shall be no greater than
|
383
|
+
2^32.
|
384
|
+
* Compliance with this requirement is crucial to the security of
|
385
|
+
GCM. Across all instances of the authenticated encryption function
|
386
|
+
with a given key, if even one IV is ever repeated, then the
|
387
|
+
implementation may be vulnerable to the forgery attacks that are
|
388
|
+
described in Ref [5] and summarized in Appendix A. **In practice,
|
389
|
+
this requirement is almost as important as the secrecy of the key. **
|
390
|
+
|
391
|
+
[http://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38c.pdf](http://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38c.pdf)
|
392
|
+
|
393
|
+
NIST Special Publication 800-38C
|
394
|
+
|
395
|
+
Recommendation for Block Cipher Modes of Operation: The CCM Mode for
|
396
|
+
Authentication and Confidentiality
|
397
|
+
|
398
|
+
May 2004
|
399
|
+
|
400
|
+
[http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSEncryption.html](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSEncryption.html)
|
401
|
+
|
402
|
+
Amazon EBS encryption handles key management for you. Each newly
|
403
|
+
created volume is encrypted with a unique 256-bit key. Any snapshots
|
404
|
+
of this volume and any subsequent volumes created from those snapshots
|
405
|
+
also share that key. These keys are protected by AWS key management
|
406
|
+
infrastructure, which implements strong logical and physical security
|
407
|
+
controls to prevent unauthorized access. Your data and associated keys
|
408
|
+
are encrypted using the industry standard AES-256 algorithm.
|
409
|
+
|
410
|
+
You cannot change the CMK that is associated with an existing snapshot
|
411
|
+
or encrypted volume. However, you can associate a different CMK during
|
412
|
+
a snapshot copy operation (including encrypting a copy of an
|
413
|
+
unencrypted snapshot) and the resulting copied snapshot use the new
|
414
|
+
CMK.
|
415
|
+
|
416
|
+
The AWS overall key management infrastructure is consistent with
|
417
|
+
National Institute of Standards and Technology (NIST) 800-57
|
418
|
+
recommendations and uses cryptographic algorithms approved by Federal
|
419
|
+
Information Processing Standards (FIPS) 140-2.
|
420
|
+
|
421
|
+
Each AWS account has a unique master key that is stored separately
|
422
|
+
from your data, on a system that is surrounded with strong physical
|
423
|
+
and logical security controls. Each encrypted volume (and its
|
424
|
+
subsequent snapshots) is encrypted with a unique volume encryption key
|
425
|
+
that is then encrypted with a region-specific secure master key. The
|
426
|
+
volume encryption keys are used in memory on the server that hosts
|
427
|
+
your EC2 instance; they are never stored on disk in plaintext.
|
428
|
+
|
429
|
+
[http://docs.aws.amazon.com/AmazonS3/latest/dev/serv-side-encryption.html](http://docs.aws.amazon.com/AmazonS3/latest/dev/serv-side-encryption.html)
|
430
|
+
|
431
|
+
You have three mutually exclusive options depending on how you choose
|
432
|
+
to manage the encryption keys:
|
433
|
+
|
434
|
+
* Use Server-Side Encryption with Amazon S3-Managed Keys (SSE-S3) -
|
435
|
+
Each object is encrypted with a unique key employing strong
|
436
|
+
multi-factor encryption. As an additional safeguard, it encrypts the
|
437
|
+
key itself with a master key that it regularly rotates. Amazon S3
|
438
|
+
server-side encryption uses one of the strongest block ciphers
|
439
|
+
available, 256-bit Advanced Encryption Standard (AES-256), to
|
440
|
+
encrypt your data. For more information, see [Protecting Data Using
|
441
|
+
Server-Side Encryption with Amazon S3-Managed Encryption Keys
|
442
|
+
(SSE-S3)](http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingServerSideEncryption.html).
|
443
|
+
* Use Server-Side Encryption with AWS KMS-Managed Keys (SSE-KMS) -
|
444
|
+
Similar to SSE-S3, but with some additional benefits along with some
|
445
|
+
additional charges for using this service. There are separate
|
446
|
+
permissions for the use of an envelope key (that is, a key that
|
447
|
+
protects your data's encryption key) that provides added protection
|
448
|
+
against unauthorized access of your objects in S3. SSE-KMS also
|
449
|
+
provides you with an audit trail of when your key was used and by
|
450
|
+
whom. Additionally, you have the option to create and manage
|
451
|
+
encryption keys yourself, or use a default key that is unique to
|
452
|
+
you, the service you're using, and the region you're working in. For
|
453
|
+
more information, see [Protecting Data Using Server-Side Encryption
|
454
|
+
with AWS KMS-Managed Keys
|
455
|
+
(SSE-KMS)](http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingKMSEncryption.html).
|
456
|
+
* Use Server-Side Encryption with Customer-Provided Keys (SSE-C) - You
|
457
|
+
manage the encryption keys and Amazon S3 manages the encryption, as
|
458
|
+
it writes to disks, and decryption, when you access your
|
459
|
+
objects. For more information, see [Protecting Data Using
|
460
|
+
Server-Side Encryption with Customer-Provided Encryption Keys
|
461
|
+
(SSE-C)](http://docs.aws.amazon.com/AmazonS3/latest/dev/ServerSideEncryptionCustomerKeys.html).
|
462
|
+
|
463
|
+
[https://tools.ietf.org/html/rfc5084#section-2](https://tools.ietf.org/html/rfc5084#section-2)
|
464
|
+
|
465
|
+
Using AES-CCM and AES-GCM Authenticated Encryption in the Cryptographic Message Syntax (CMS)
|
466
|
+
|
467
|
+
November 2007
|
468
|
+
|
469
|
+
Status: Proposed Standard
|
470
|
+
|
471
|
+
The reuse of an **AES-CCM** or **AES-GCM** nonce/key combination destroys
|
472
|
+
the security guarantees. As a result, it can be extremely difficult
|
473
|
+
to use AES-CCM or AES-GCM securely when using statically configured
|
474
|
+
keys. **For safety's sake, implementations MUST use an automated key
|
475
|
+
management system**.
|
476
|
+
|
477
|
+
JHW Note: If we want to avoid building or buying or renting a KMS, we
|
478
|
+
should hold back from AES-CCM or AES- GCM for now. AES-CBC is still a
|
479
|
+
credible choice and even recommended by some.
|
480
|
+
|
481
|
+
[https://tools.ietf.org/html/rfc4107](https://tools.ietf.org/html/rfc4107)
|
482
|
+
|
483
|
+
Guidelines for Cryptographic Key Management
|
484
|
+
|
485
|
+
June 2005
|
486
|
+
|
487
|
+
Status: BEST CURRENT PRACTICE
|
488
|
+
|
489
|
+
* When symmetric cryptographic mechanisms are used in a protocol, the
|
490
|
+
presumption is that automated key management is generally but not
|
491
|
+
always needed. If manual keying is proposed, the burden of proving
|
492
|
+
that automated key management is not required falls to the proposer.
|
493
|
+
* There is not one answer to that question; circumstances differ. **In
|
494
|
+
general, automated key management SHOULD be used.** Occasionally,
|
495
|
+
relying on manual key management is reasonable; we propose some
|
496
|
+
guidelines for making that judgment.
|
497
|
+
* Automated key management and manual key management provide very
|
498
|
+
different features.
|
499
|
+
* In particular, the protocol associated with an automated key
|
500
|
+
management technique will confirm the liveness of the peer,
|
501
|
+
protect against replay, authenticate the source of the
|
502
|
+
short-term session key, associate protocol state information
|
503
|
+
with the short-term session key, and ensure that a fresh
|
504
|
+
short-term session key is generated.
|
505
|
+
* For some symmetric cryptographic algorithms, implementations
|
506
|
+
must prevent overuse of a given key. An implementation of such
|
507
|
+
algorithms can make use of automated key management when the
|
508
|
+
usage limits are nearly exhausted, in order to establish
|
509
|
+
replacement keys before the limits are reached, thereby
|
510
|
+
maintaining secure communications.
|
511
|
+
* Examples of automated key management systems include IPsec IKE
|
512
|
+
and Kerberos. S/MIME and TLS also include automated key
|
513
|
+
management functions.
|
514
|
+
* Key management schemes should not be designed by amateurs; it is
|
515
|
+
almost certainly inappropriate for working groups to design their
|
516
|
+
own.
|
517
|
+
* In general, automated key management SHOULD be used to establish
|
518
|
+
session keys.
|
519
|
+
* Automated key management MUST be used if any of these conditions hold:
|
520
|
+
* A party will have to manage n^2 static keys, where n may become large.
|
521
|
+
* Any stream cipher (such as RC4
|
522
|
+
[[TK](https://tools.ietf.org/html/rfc4107#ref-TK)], AES-CTR
|
523
|
+
[[NIST](https://tools.ietf.org/html/rfc4107#ref-NIST)], or
|
524
|
+
AES-CCM [[WHF](https://tools.ietf.org/html/rfc4107#ref-WHF)]) is
|
525
|
+
used.
|
526
|
+
* An initialization vector (IV) might be reused, especially an
|
527
|
+
implicit IV. Note that random or pseudo-random explicit IVs are
|
528
|
+
not a problem unless the probability of repetition is high.
|
529
|
+
* Large amounts of data might need to be encrypted in a short
|
530
|
+
time, causing frequent change of the short-term session key.
|
531
|
+
* Long-term session keys are used by more than two
|
532
|
+
parties. Multicast is a necessary exception, but multicast key
|
533
|
+
management standards are emerging in order to avoid this in the
|
534
|
+
future. Sharing long-term session keys should generally be
|
535
|
+
discouraged.
|
536
|
+
* The likely operational environment is one where personnel (or
|
537
|
+
device) turnover is frequent, causing frequent change of the
|
538
|
+
short-term session key.
|
539
|
+
* Manual key management may be a reasonable approach in any of these
|
540
|
+
situations:
|
541
|
+
* The environment has very limited available bandwidth or very
|
542
|
+
high round-trip times. Public key systems tend to require long
|
543
|
+
messages and lots of computation; symmetric key alternatives,
|
544
|
+
such as Kerberos, often require several round trips and
|
545
|
+
interaction with third parties.
|
546
|
+
* The information being protected has low value.
|
547
|
+
* The total volume of traffic over the entire lifetime of the
|
548
|
+
long-term session key will be very low.
|
549
|
+
* The scale of each deployment is very limited.
|
550
|
+
* Note that assertions about such things should often be viewed with
|
551
|
+
skepticism. The burden of demonstrating that manual key management
|
552
|
+
is appropriate falls to the proponents -- and it is a fairly high
|
553
|
+
hurdle.
|
554
|
+
* Systems that employ manual key management need provisions for key
|
555
|
+
changes. There MUST be some way to indicate which key is in use to
|
556
|
+
avoid problems during transition. Designs SHOULD sketch plausible
|
557
|
+
mechanisms for deploying new keys and replacing old ones that might
|
558
|
+
have been compromised. If done well, such mechanisms can later be
|
559
|
+
used by an add-on key management scheme.
|
560
|
+
* Lack of clarity about the parties involved in authentication is not
|
561
|
+
a valid reason for avoiding key management. Rather, it tends to
|
562
|
+
indicate a deeper problem with the underlying security model.
|
563
|
+
* When manual key management is used, long-term shared secrets MUST be
|
564
|
+
unpredictable "random" values, ensuring that an adversary will have
|
565
|
+
no greater expectation than 50% of finding the value after searching
|
566
|
+
half the key search space.
|
567
|
+
|
568
|
+
JHW Note: RFC-4107 talks a lot about session keys. I don't know how
|
569
|
+
the session concept applies to our encryption at rest use cases, so I
|
570
|
+
am not sure how to interpret some of this.
|
571
|
+
|
572
|
+
[https://tools.ietf.org/html/bcp106](https://tools.ietf.org/html/bcp106)
|
573
|
+
|
574
|
+
Randomness Requirements for Security
|
575
|
+
|
576
|
+
June 2005
|
577
|
+
|
578
|
+
* /dev/random returns bytes from the pool but blocks when the
|
579
|
+
estimated entropy drops to zero. As entropy is added to the pool
|
580
|
+
from events, more data becomes available via /dev/random. Random
|
581
|
+
data obtained from such a /dev/random device is suitable for key
|
582
|
+
generation for long term keys, if enough random bits are in the pool
|
583
|
+
or are added in a reasonable amount of time.
|
584
|
+
* **Random data obtained from ... /dev/random ... is suitable for
|
585
|
+
key generation for long term keys**
|
586
|
+
* /dev/urandom works like /dev/random; however, it provides data even
|
587
|
+
when the entropy estimate for the random pool drops to zero. This
|
588
|
+
may be adequate for session keys or for other key generation tasks
|
589
|
+
for which blocking to await more random bits is not acceptable. The
|
590
|
+
risk of continuing to take data even when the pool's entropy
|
591
|
+
estimate is small in that past output may be computable from current
|
592
|
+
output, provided that an attacker can reverse SHA-1. Given that
|
593
|
+
SHA-1 is designed to be non-invertible, this is a reasonable risk.
|
594
|
+
* **/dev/urandom ... may be adequate for session keys or for other
|
595
|
+
key generation tasks for which blocking to await more random
|
596
|
+
bits is not acceptable.**
|
597
|
+
* To obtain random numbers under Linux, Solaris, or other UNIX systems
|
598
|
+
equipped with code as described above, all an application has to do
|
599
|
+
is open either /dev/random or /dev/urandom and read the desired
|
600
|
+
number of bytes.
|
601
|
+
|
602
|
+
[https://www.feistyduck.com/library/openssl-cookbook/online/ch-openssl.html#openssl-recommended-configuration](https://www.feistyduck.com/library/openssl-cookbook/online/ch-openssl.html#openssl-recommended-configuration)
|
603
|
+
|
604
|
+
The design principles for all configurations here are essentially the
|
605
|
+
same as those from the previous section, but I am going to make two
|
606
|
+
changes to achieve better performance. First, I am going to put
|
607
|
+
128-bit suites on top of the list. Although 256-bit suites provide
|
608
|
+
some increase in security, for most sites the increase is not
|
609
|
+
meaningful and yet still comes with the performance penalty. Second, I
|
610
|
+
am going to prefer HMAC-SHA over HMAC-SHA256 and HMAC-SHA384
|
611
|
+
suites. The latter two are much slower but also don't provide a
|
612
|
+
meaningful increase in security.
|
613
|
+
|
614
|
+
...
|
615
|
+
|
616
|
+
The following is my default starting configuration, designed to offer
|
617
|
+
strong security as well as good performance:
|
618
|
+
|
619
|
+
- ECDHE-ECDSA-AES128-GCM-SHA256
|
620
|
+
- ECDHE-ECDSA-AES256-GCM-SHA384
|
621
|
+
- ECDHE-ECDSA-AES128-SHA
|
622
|
+
- ECDHE-ECDSA-AES256-SHA
|
623
|
+
- ECDHE-ECDSA-AES128-SHA256
|
624
|
+
- ECDHE-ECDSA-AES256-SHA384
|
625
|
+
- ECDHE-RSA-AES128-GCM-SHA256
|
626
|
+
- ECDHE-RSA-AES256-GCM-SHA384
|
627
|
+
- ECDHE-RSA-AES128-SHA
|
628
|
+
- ECDHE-RSA-AES256-SHA
|
629
|
+
- ECDHE-RSA-AES128-SHA256
|
630
|
+
- ECDHE-RSA-AES256-SHA384
|
631
|
+
- DHE-RSA-AES128-GCM-SHA256
|
632
|
+
- DHE-RSA-AES256-GCM-SHA384
|
633
|
+
- DHE-RSA-AES128-SHA
|
634
|
+
- DHE-RSA-AES256-SHA
|
635
|
+
- DHE-RSA-AES128-SHA256
|
636
|
+
- DHE-RSA-AES256-SHA256
|
637
|
+
|
638
|
+
JHW Note: ^^^ Of course that recommendation is for a web site, not for
|
639
|
+
cold storage.
|
640
|
+
|
641
|
+
[http://ruby-doc.org/stdlib-2.0.0/libdoc/openssl/rdoc/OpenSSL/Cipher.html](http://ruby-doc.org/stdlib-2.0.0/libdoc/openssl/rdoc/OpenSSL/Cipher.html)
|
642
|
+
|
643
|
+
Ruby docs for OpenSSL::Cipher
|
644
|
+
|
645
|
+
* You should never use ECB mode unless you are absolutely sure that
|
646
|
+
you absolutely need it
|
647
|
+
* Always create a secure random IV for every encryption of your
|
648
|
+
[Cipher](http://ruby-doc.org/stdlib-2.0.0/libdoc/openssl/rdoc/OpenSSL/Cipher/Cipher.html)
|
649
|
+
* If the
|
650
|
+
[OpenSSL](http://ruby-doc.org/stdlib-2.0.0/libdoc/openssl/rdoc/OpenSSL.html)
|
651
|
+
version used supports it, an Authenticated Encryption mode (such as
|
652
|
+
GCM or CCM) should always be preferred over any unauthenticated
|
653
|
+
mode.
|
654
|
+
* Currently,
|
655
|
+
[OpenSSL](http://ruby-doc.org/stdlib-2.0.0/libdoc/openssl/rdoc/OpenSSL.html)
|
656
|
+
supports AE only in combination with Associated Data (AEAD) where
|
657
|
+
additional associated data is included in the encryption process to
|
658
|
+
compute a tag at the end of the encryption. This tag will also be
|
659
|
+
used in the decryption process and by verifying its validity, the
|
660
|
+
authenticity of a given ciphertext is established.
|
661
|
+
* This is superior to unauthenticated modes in that it allows to
|
662
|
+
detect if somebody effectively changed the ciphertext after it had
|
663
|
+
been encrypted. This prevents malicious modifications of the
|
664
|
+
ciphertext that could otherwise be exploited to modify ciphertexts
|
665
|
+
in ways beneficial to potential attackers.
|
666
|
+
* If no associated data is needed for encryption and later decryption,
|
667
|
+
the
|
668
|
+
[OpenSSL](http://ruby-doc.org/stdlib-2.0.0/libdoc/openssl/rdoc/OpenSSL.html)
|
669
|
+
library still requires a value to be set - "" may be used in case
|
670
|
+
none is available. An example using the GCM (Galois Counter Mode)...
|
671
|
+
|
672
|
+
[https://tools.ietf.org/html/rfc4880#page-6](https://tools.ietf.org/html/rfc4880#page-6)
|
673
|
+
|
674
|
+
OpenPGP Message Format
|
675
|
+
|
676
|
+
November 2007
|
677
|
+
|
678
|
+
Status PROPOSED STANDARD
|
679
|
+
|
680
|
+
* OpenPGP wraps it all in Radix-64 aka ASCII Armor.
|
681
|
+
* header (e.g. "-----BEGIN PGP MESSAGE-----")
|
682
|
+
* armor headers
|
683
|
+
* armored data
|
684
|
+
* checksum
|
685
|
+
* footer
|
686
|
+
* To encrypt, OpenPGP generates a new "session key" for each message,
|
687
|
+
which is encrypted with the recipient's public key.
|
688
|
+
* The encrypted session key is sent with the message.
|
689
|
+
|
690
|
+
The (unencrypted) session key is used to symmetrically encrypt the
|
691
|
+
(usually compressed) message.
|
692
|
+
|
693
|
+
* To authenticate, OpenPGP generates a hash of the message, encrypts
|
694
|
+
it with the sender's private key.
|
695
|
+
* The encrypted message hash is sent with the message.
|
696
|
+
* OpenPGP implements, and recommends, compress-then-encrypt!
|
697
|
+
* "OpenPGP implementations SHOULD compress the message after
|
698
|
+
applying the signature but before encryption."
|
699
|
+
* "... Furthermore, compression has the added side effect that
|
700
|
+
some types of attacks can be thwarted by the fact that slightly
|
701
|
+
altered, compressed data rarely uncompresses without severe
|
702
|
+
errors. This is hardly rigorous, but it is operationally
|
703
|
+
useful. ..."
|
704
|
+
* Asymmetric include RSA, Elgamal, DSA.
|
705
|
+
* Symmetric include plain, IDEA, TripleDES, CAST5, Blowfish, AES-128,
|
706
|
+
-192, -256, Twofish
|
707
|
+
* No IV but super-salty.
|
708
|
+
* "OpenPGP CFB mode uses an initialization vector (IV) of all
|
709
|
+
zeros, and prefixes the plaintext with BS+2 octets of random
|
710
|
+
data, such that octets BS+1 and BS+2 match octets BS-1 and BS.
|
711
|
+
It does a CFB resynchronization after encrypting those BS+2
|
712
|
+
octets."
|
713
|
+
* Compression include none, ZIP, ZLIB, BZIP2
|
714
|
+
* Hashes include MD5, SHA-1, SHA256, SHA512, others
|
715
|
+
* GnuPG is a compliant implementation.
|
716
|
+
* OpenPGP is slammed in
|
717
|
+
[https://blog.cryptographyengineering.com/2014/08/13/whats-matter-with-pgp/](https://blog.cryptographyengineering.com/2014/08/13/whats-matter-with-pgp/)
|
718
|
+
on:
|
719
|
+
* Key management
|
720
|
+
* Format
|
721
|
+
* Defaults
|
722
|
+
|
723
|
+
[https://www.apple.com/business/docs/iOS_Security_Guide.pdf](https://www.apple.com/business/docs/iOS_Security_Guide.pdf)
|
724
|
+
|
725
|
+
iOS Security
|
726
|
+
|
727
|
+
10 March 2017
|
728
|
+
|
729
|
+
* When an iOS device is turned on, its application processor
|
730
|
+
immediately executes code from read-only memory known as the Boot
|
731
|
+
ROM. This immutable code, known as the hardware root of trust, is
|
732
|
+
laid down during chip fabrication, and is implicitly trusted. The
|
733
|
+
Boot ROM code contains the Apple Root CA public key, which is used
|
734
|
+
to verify that the iBoot bootloader is signed by Apple before
|
735
|
+
allowing it to load.
|
736
|
+
* Every iOS device has a dedicated AES 256 crypto engine built into
|
737
|
+
the DMA path between the flash storage and main system memory,
|
738
|
+
making file encryption highly efficient.
|
739
|
+
* The device's unique ID (UID) and a device group ID (GID) are AES
|
740
|
+
256-bit keys fused (UID) or compiled (GID) into the application
|
741
|
+
processor and Secure Enclave during manufacturing. No software or
|
742
|
+
firmware can read them directly;
|
743
|
+
* Additionally, the Secure Enclave's UID and GID can only be used by
|
744
|
+
the AES engine dedicated to the Secure Enclave. The UIDs are unique
|
745
|
+
to each device and aren't recorded by Apple or any of its suppliers.
|
746
|
+
* The UID allows data to be cryptographically tied to a particular device.
|
747
|
+
* Apart from the UID and GID, all other cryptographic keys are created
|
748
|
+
by the system's random number generator (RNG) using an algorithm
|
749
|
+
based on CTR_DRBG. System entropy is generated from timing
|
750
|
+
variations during boot, and additionally from interrupt timing once
|
751
|
+
the device has booted. Keys generated inside the Secure Enclave use
|
752
|
+
its true hardware random number.
|
753
|
+
* **Every time a file on the data partition is created,** Data
|
754
|
+
Protection creates **a new 256-bit key** (the "per-file" key) and
|
755
|
+
gives it to the hardware AES engine, which uses the key to encrypt
|
756
|
+
the file as it **is written to flash memory using AES CBC
|
757
|
+
mode**. ... **The initialization vector (IV) is calculated with the
|
758
|
+
block offset into the file, encrypted with the SHA-1 hash of the
|
759
|
+
per-file key.** The **per-file key is wrapped** with one of several
|
760
|
+
class keys, depending on the circumstances under which the file
|
761
|
+
should be accessible. Like all other wrappings, this is performed
|
762
|
+
**using NIST AES key wrapping, per RFC 3394**. The wrapped per-file
|
763
|
+
key is stored in the file's metadata.
|
764
|
+
* The metadata of all files in the file system is encrypted with a
|
765
|
+
random key, which is created when iOS is first installed or when the
|
766
|
+
device is wiped by a user.
|
767
|
+
* ...this key isn't used to maintain the confidentiality of data;
|
768
|
+
instead, it's designed to be quickly erased on demand
|
769
|
+
|
770
|
+
[https://tools.ietf.org/html/rfc3394](https://tools.ietf.org/html/rfc3394)
|
771
|
+
|
772
|
+
Advanced Encryption Standard (AES) Key Wrap Algorithm
|
773
|
+
|
774
|
+
September 2002
|
775
|
+
|
776
|
+
* The AES Key Wrap algorithm will probably be adopted by the USA for
|
777
|
+
encryption of AES keys.
|
778
|
+
* NIST has assigned the following object identifiers to identify the
|
779
|
+
key wrap algorithm...
|
780
|
+
* id-aes128-wrap
|
781
|
+
* id-aes192-wrap
|
782
|
+
* id-aes256-wrap
|
783
|
+
|
784
|
+
[https://tools.ietf.org/html/rfc529](https://tools.ietf.org/html/rfc5297)[7](https://tools.ietf.org/html/rfc5297)
|
785
|
+
|
786
|
+
Synthetic Initialization Vector (SIV) Authenticated Encryption
|
787
|
+
|
788
|
+
Using the Advanced Encryption Standard (AES)
|
789
|
+
|
790
|
+
October 2008
|
791
|
+
|
792
|
+
* The nonce-based authenticated encryption schemes described above are
|
793
|
+
susceptible to reuse and/or misuse of the nonce. Depending on the
|
794
|
+
specific scheme there are subtle and critical requirements placed on
|
795
|
+
the nonce.
|
796
|
+
* ... many applications obtain access to cryptographic functions via
|
797
|
+
an application program interface to a cryptographic library.
|
798
|
+
* These libraries are typically not stateful and any nonce,
|
799
|
+
initialization vector, or counter required by the cipher mode is
|
800
|
+
passed to the cryptographic library by the application.
|
801
|
+
* Putting the construction of a security-critical datum outside the
|
802
|
+
control of the encryption engine places an onerous burden on the
|
803
|
+
application writer who may not provide the necessary cryptographic
|
804
|
+
hygiene.
|
805
|
+
* Perhaps his random number generator is not very good or maybe an
|
806
|
+
application fault causes a counter to be reset. The fragility of
|
807
|
+
the cipher mode may result in its inadvertent misuse. Also, if
|
808
|
+
one's environment is (knowingly or unknowingly) a virtual machine,
|
809
|
+
it may be possible to roll back a virtual state machine and cause
|
810
|
+
nonce reuse thereby gutting the security of the authenticated
|
811
|
+
encryption scheme.
|
812
|
+
|
813
|
+
[https://www.schneier.com/books/cryptography_engineering/](https://www.schneier.com/books/cryptography_engineering/)
|
814
|
+
|
815
|
+
Cryptography Engineering: Design Principles and Practical Applications
|
816
|
+
|
817
|
+
© 2010 Ferguson, Schneier, Kohno
|
818
|
+
|
819
|
+
I cite here the book, not the website.
|
820
|
+
|
821
|
+
* Chapter 3, Section 3.5.6, p59
|
822
|
+
* "Despite these cryptographic advances, **AES is still what we
|
823
|
+
recommend**. It is fast. All known attacks are theoretical, not
|
824
|
+
practical... It is also the official standard, sanctioned by the
|
825
|
+
U.S. government."
|
826
|
+
* Chapter 3, Section 3.5.7, p60
|
827
|
+
* "Note that **we advocate the use of 256-bit keys for systems with
|
828
|
+
a design strength of 128 bits**."
|
829
|
+
* "To emphasize our desire for 128 bits of security, and thus our
|
830
|
+
quest for a secure block cipher, **we will use AES with 256-bit
|
831
|
+
keys throughout the rest of this book**." But once there is a
|
832
|
+
clear consensus of how to respond to the new cryptanalytic
|
833
|
+
results against AES, we will likely replace AWS with another
|
834
|
+
block cipher with 256-bit keys."
|
835
|
+
* Chapter 4, Section 4.5, p70
|
836
|
+
* "As with OFB mode, **you must make absolutely sure never to reuse
|
837
|
+
a single key/nonce combination**. This is a disadvantage that is
|
838
|
+
often mentioned for CTR, but CBC has exactly the same problem.
|
839
|
+
If you use the same IV twice, you start leaking data about the
|
840
|
+
plaintexts. **CBC is a bit more robust, as it is more likely to
|
841
|
+
* "The real question is whether you can ensure that the nonce is
|
842
|
+
unique. If there's any doubt, **you should use a mode like
|
843
|
+
random IV CBC mode, where the IV is generated randomly and
|
844
|
+
outside of the application developer's control**.
|
845
|
+
* Chapter 4, Section 4.7, p71
|
846
|
+
* "Nonce generation turns out to be a really hard problem in many
|
847
|
+
systems, so we do not recommend exposing to application
|
848
|
+
developers any mode that uses nonces. ... so **if you're
|
849
|
+
developing an application and need to use an encryption mode,
|
850
|
+
play it safe and use random IV CBC mode**.
|
851
|
+
* Chapter 5, Section 5.5, p87
|
852
|
+
* "In the short term, **we recommend using one of the newer SHA
|
853
|
+
hash function family members - SHA-224, SHA-256, SHA-385, or
|
854
|
+
SHA-512**. Moreover we suggest you choose a hash function from
|
855
|
+
the SHA(sub d) family, or **use SHA-512 and truncate the output
|
856
|
+
to 256 bits**. In the long run, **we will very likely recommend
|
857
|
+
the winner of the SHA-3 competition**."
|
858
|
+
* JHW Note: [https://en.wikipedia.org/wiki/SHA-3](https://en.wikipedia.org/wiki/SHA-3) SHA-3 released August 5, 2015
|
859
|
+
* Chapter 6, Introduction, p89
|
860
|
+
* "**Encryption** prevents Eve from reading the messages but **does
|
861
|
+
not prevent her from manipulating the messages**. This is where
|
862
|
+
the MAC comes in."
|
863
|
+
* Chapter 6, Section 6.6, p95
|
864
|
+
* "As you may have gathered from the previous discussion, **we
|
865
|
+
would choose HMAC-SHA-256**: the HMAC construction using SHA-256
|
866
|
+
as a hash function. Most systems use 64- or 96-bit MAC values,
|
867
|
+
and even that might seem like a lot of overhead. As far as we
|
868
|
+
know, there is no collision attack on the MAC value if it is
|
869
|
+
used in the traditional manner, so **truncating the results from
|
870
|
+
HMAC-SHA-256 to 128 bits should be safe**, given current
|
871
|
+
knowledge in the field"
|
872
|
+
* "GMAC is fast, but provides only at most 64 bits of security and
|
873
|
+
isn't suitable when used to produce short tags. It also
|
874
|
+
requires a nonce, which is a common source of security problem
|
875
|
+
[sic -jhw]."
|
876
|
+
* Chapter 6, Section 6.7, p97
|
877
|
+
* "This is where the Horton Principle comes in. **You should
|
878
|
+
authenticate the meaning, not the message.** This means that **the
|
879
|
+
MAC should authenticate not only _m_, but also all the
|
880
|
+
information that Bob uses in parsing _m_ into its meaning**.
|
881
|
+
This would typically include data like protocol identifier,
|
882
|
+
protocol version number, protocol message identifier, sizes for
|
883
|
+
various fields, etc."
|
884
|
+
* "The Horton Principle is one of the reasons why **authentication
|
885
|
+
at lower protocol levels does not provide adequate
|
886
|
+
authentication for higher-level protocols**. An authentication
|
887
|
+
system at the IP packet level cannot know how the e-mail program
|
888
|
+
is going to interpret the data. This precludes it from checking
|
889
|
+
that the context in which the message is interpreted is the same
|
890
|
+
as the context in which the message was sent. The only solution
|
891
|
+
is to have the e-mail program provide its own authentication of
|
892
|
+
the data exchanged - in addition to the authentication on the
|
893
|
+
lower levels of course."
|