blob: d5d7d07818ee0152bf0a24cfc685f23f738d8c16 [file] [log] [blame] [view]
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +02001This document lists current limitations of the PSA Crypto API (as of version
21.1) that may impact our ability to (1) use it for all crypto operations in
3TLS and X.509 and (2) support isolation of all long-term secrets in TLS (that
4is, goals G1 and G2 in [strategy.md][] in the same directory).
5
6This is supposed to be a complete list, based on a exhaustive review of crypto
7operations done in TLS and X.509 code, but of course it's still possible that
8subtle-but-important issues have been missed. The only way to be really sure
9is, of course, to actually do the migration work.
10
11Limitations relevant for G1 (performing crypto operations)
12==========================================================
13
14Restartable ECC operations
15--------------------------
16
17There is currently no support for that in PSA at all. API design, as well as
18implementation, would be non-trivial.
19
20Currently, `MBEDTLS_USE_PSA_CRYPTO` is simply incompatible with
21`MBEDTLS_ECP_RESTARTABLE`.
22
23Arbitrary parameters for FFDH
24-----------------------------
25
26Currently, the PSA Crypto API can only perform FFDH with a limited set of
27well-know parameters (some of them defined in the spec, but implementations
28are free to extend that set).
29
30TLS 1.2 (and earlier) on the other hand have the server send explicit
31parameters (P and G) in is ServerKeyExchange message. This has been found to
32be suboptimal for security, as it is prohibitively hard for the client to
33verify the strength of these parameters. This led to the development of RFC
347919 which allows use of named groups in TLS 1.2 - however as this is only an
35extension, servers can still send custom parameters if they don't support the
36extension.
37
38In TLS 1.3 the situation will be simpler: named groups are the only
39option, so the current PSA Crypto API is a good match for that. (Not
40coincidentally, the groups used by RFC 7919 and TLS 1.3 are part those defined
41in the specification.)
42
43There are several options here:
44
451. Implement support for custom FFDH parameters in PSA Crypto: this would pose
46 non-trivial API design problem, but most importantly seems backwards, as
47the crypto community is moving away from custom FFDH parameters.
482. Drop the DHE-RSA and DHE-PSK key exchanges in TLS 1.2 when moving to PSA.
493. Implement RFC 7919, support DHE-RSA and DHE-PSK only in conjunction with it
50 when moving to PSA. We can modify our server so that it only selects a DHE
51 ciphersuite if the client offered name FFDH groups; unfortunately
52client-side the only option is to offer named groups and break the handshake
53if the server didn't take on our offer. This is not fully satisfying, but is
54perhaps the least unsatisfying option in terms of result; it's also probably
55the one that requires the most work, but it would deliver value beyond PSA
56migration by implementing RFC 7919.
57
58RSA-PSS parameters
59------------------
60
61RSA-PSS signatures are defined by PKCS#1 v2, re-published as RFC 8017
62(previously RFC 3447).
63
64As standardized, the signature scheme takes several parameters, in addition to
65the hash algorithm potentially used to hash the message being signed:
66- a hash algorithm use for the encoding function
67- a mask generation function
68 - most commonly MGF1, which in turn is parametrized by a hash algorithm
69- a salt length
70
71Both the existing `mbedtls_` API and the PSA API support only MGF1 as the
72generation function, but there are discrepancy in handling the salt length and
73which of the various hash algorithms can differ from each other.
74
75### API comparison
76
77- RSA:
78 - signature: `mbedtls_rsa_rsassa_pss_sign()`
79 - message hashed externally
80 - encoding hash = MGF1 hash (from context, or argument = message hash)
81 - salt length: always using the maximum legal value
82 - signature: `mbedtls_rsa_rsassa_pss_sign_ext()`
83 - message hashed externally
84 - encoding hash = MGF1 hash (from context, or argument = message hash)
85 - salt length: specified explicitly
86 - verification: `mbedtls_rsassa_pss_verify()`
87 - message hashed externally
88 - encoding hash = MGF1 hash (from context, or argument = message hash)
89 - salt length: any valid length accepted
90 - verification: `mbedtls_rsassa_pss_verify_ext()`
91 - message hashed externally
92 - encoding hash = MGF1 hash from dedicated argument
93 - expected salt length: specified explicitly, can specify "ANY"
94- PK:
95 - signature: not supported
96 - verification: `mbedtls_pk_verify_ext()`
97 - message hashed externally
98 - encoding hash = MGF1 hash, specified explicitly
99 - expected salt length: specified explicitly, can specify "ANY"
100- PSA:
101 - algorithm specification:
102 - hash alg used for message hashing, encoding and MGF1
103 - salt length cannot be specified
104 - signature generation:
105 - salt length: always using the maximum legal value
106 - verification:
107 - salt length: any valid length accepted
108
109The RSA/PK API is in principle more flexible than the PSA Crypto API. The
110following sub-sections study whether and how this matters in practice.
111
112### Use in X.509
113
114RFC 4055 Section 3.1 defines the encoding of RSA-PSS that's used in X.509.
115It allows independently specifying the message hash (also used for encoding
116hash), the MGF (and its hash if MGF1 is used), and the salt length (plus an
117extra parameter "trailer field" that doesn't vary in practice"). These can be
118encoded as part of the key, and of the signature. If both encoding are
119presents, all values must match except possibly for the salt length, where the
120value from the signature parameters is used.
121
122In Mbed TLS, RSA-PSS parameters can be parsed and displayed for various
123objects (certificates, CRLs, CSRs). During parsing, the following properties
124are enforced:
Manuel Pégourié-Gonnardf5ee4b32021-10-21 13:04:01 +0200125- (the extra "trailer field" parameter must have its default value)
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +0200126- the mask generation function is MGF1
127- encoding hash = message hashing algorithm (may differ from MGF1 hash)
128
129When it comes to cryptographic operations, only two things are supported:
130- verifying the signature on a certificate from its parent;
131- verifying the signature on a CRL from the issuing CA.
132
133The verification is done using `mbedtls_pk_verify_ext()`.
134
135Note: since X.509 parsing ensures that message hash = encoding hash, and
136`mbedtls_pk_verify_ext()` use encoding hash = mgf1 hash, it looks like all
137three hash algorithms must be equal, which would be good news as it would
138match a limitation of the PSA API. (TODO: double-check that.)
139
140Also, since we only use signature verification, the fact that PSA accepts any
141valid salt length means that no valid certificate would be wrongly rejected;
142however it means that signatures that don't match the announced salt length
143would be incorrectly accepted. At first glance, it looks like this doesn't
144allow an attacker to forge certificates, so this might be acceptable in
145practice, while not fully implementing all the checks in the standard. (TODO:
146triple-check that.)
147
148It is unclear what parameters people use in practice.
149
Manuel Pégourié-Gonnardf5ee4b32021-10-21 13:04:01 +0200150TODO: look at what OpenSSL and GnuTLS do by default?
151
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +0200152### Use in TLS
153
154In TLS 1.2 (or lower), RSA-PSS signatures are never used, except via X.509.
155
156In TLS 1.3, RSA-PSS signatures can be used directly in the protocol (in
157addition to indirect use via X.509). It has two sets of three signature
158algorithm identifiers (for SHA-256, SHA-384 and SHA-512), depending of what
159the OID of the public key is (rsaEncryption or RSASSA-PSS).
160
161In both cases, it specifies that:
162- the mask generation function is MGF1
163- all three hashes are equal
164- the length of the salt MUST be equal to the length of the digest algorithm
165
166When signing, the salt length picked by PSA is the one required by TLS 1.3
167(unless the key is unreasonably small).
168
169When verifying signatures, again is doesn't look like accepting any salt
170length would give an attacker any advantage, but this must be triple-checked
171(TODO).
172
173### Current testing - X509
174
Manuel Pégourié-Gonnardf5ee4b32021-10-21 13:04:01 +0200175TODO: look at hex testing (do we have negative testing of bad trailer field?)
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +0200176
Manuel Pégourié-Gonnardf5ee4b32021-10-21 13:04:01 +0200177All test files use the default trailer field of 0xBC. Files with "bad" in the
178name are expected to be invalid and rejected in tests.
179
180**Test certificates:**
181
182server9-bad-mgfhash.crt (announcing mgf1(sha224), signed with another mgf)
183 Hash Algorithm: sha256
184 Mask Algorithm: mgf1 with sha224
185 Salt Length: 0xDE
186server9-bad-saltlen.crt (announcing saltlen = 0xDE, signed with another len)
187 Hash Algorithm: sha256
188 Mask Algorithm: mgf1 with sha256
189 Salt Length: 0xDE
190server9-badsign.crt (one bit flipped in the signature)
191 Hash Algorithm: sha1 (default)
192 Mask Algorithm: mgf1 with sha1 (default)
193 Salt Length: 0xEA
194server9-defaults.crt
195 Hash Algorithm: sha1 (default)
196 Mask Algorithm: mgf1 with sha1 (default)
197 Salt Length: 0x14 (default)
198server9-sha224.crt
199 Hash Algorithm: sha224
200 Mask Algorithm: mgf1 with sha224
201 Salt Length: 0xE2
202server9-sha256.crt
203 Hash Algorithm: sha256
204 Mask Algorithm: mgf1 with sha256
205 Salt Length: 0xDE
206server9-sha384.crt
207 Hash Algorithm: sha384
208 Mask Algorithm: mgf1 with sha384
209 Salt Length: 0xCE
210server9-sha512.crt
211 Hash Algorithm: sha512
212 Mask Algorithm: mgf1 with sha512
213 Salt Length: 0xBE
214server9-with-ca.crt
215 Hash Algorithm: sha1 (default)
216 Mask Algorithm: mgf1 with sha1 (default)
217 Salt Length: 0xEA
218server9.crt
219 Hash Algorithm: sha1 (default)
220 Mask Algorithm: mgf1 with sha1 (default)
221 Salt Length: 0xEA
222
223These certificates are signed with a 2048-bit key. It appears that they are
224all using saltlen = keylen - hashlen - 2, except for server9-defaults which is
225using saltlen = hashlen.
226
227**Test CRLs:**
228
229crl-rsa-pss-sha1-badsign.pem
230 Hash Algorithm: sha1 (default)
231 Mask Algorithm: mgf1 with sha1 (default)
232 Salt Length: 0xEA
233crl-rsa-pss-sha1.pem
234 Hash Algorithm: sha1 (default)
235 Mask Algorithm: mgf1 with sha1 (default)
236 Salt Length: 0xEA
237crl-rsa-pss-sha224.pem
238 Hash Algorithm: sha224
239 Mask Algorithm: mgf1 with sha224
240 Salt Length: 0xE2
241crl-rsa-pss-sha256.pem
242 Hash Algorithm: sha256
243 Mask Algorithm: mgf1 with sha256
244 Salt Length: 0xDE
245crl-rsa-pss-sha384.pem
246 Hash Algorithm: sha384
247 Mask Algorithm: mgf1 with sha384
248 Salt Length: 0xCE
249crl-rsa-pss-sha512.pem
250 Hash Algorithm: sha512
251 Mask Algorithm: mgf1 with sha512
252 Salt Length: 0xBE
253
254These CRLs are signed with a 2048-bit key. It appears that they are
255all using saltlen = keylen - hashlen - 2.
256
257**Test CSRs:**
258
259server9.req.sha1
260 Hash Algorithm: sha1 (default)
261 Mask Algorithm: mgf1 with sha1 (default)
262 Salt Length: 0x6A
263server9.req.sha224
264 Hash Algorithm: sha224
265 Mask Algorithm: mgf1 with sha224
266 Salt Length: 0x62
267server9.req.sha256
268 Hash Algorithm: sha256
269 Mask Algorithm: mgf1 with sha256
270 Salt Length: 0x5E
271server9.req.sha384
272 Hash Algorithm: sha384
273 Mask Algorithm: mgf1 with sha384
274 Salt Length: 0x4E
275server9.req.sha512
276 Hash Algorithm: sha512
277 Mask Algorithm: mgf1 with sha512
278 Salt Length: 0x3E
279
280These CSRss are signed with a 2048-bit key. It appears that they are
281all using saltlen = keylen - hashlen - 2.
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +0200282
283### Possible course of actions
284
285TODO - once the previous section has been completed
286
287Limitations relevant for G2 (isolation of long-term secrets)
288============================================================
289
290Custom key derivations for mixed-PSK handshake
291----------------------------------------------
292
293Currently, `MBEDTLS_USE_PSA_CRYPTO` enables the new configuration function
294`mbedtls_ssl_conf_psk_opaque()` which allows a PSA-held key to be used for the
295(pure) `PSK` key exchange in TLS 1.2. This requires that the derivation of the
296Master Secret (MS) be done on the PSA side. To support this, an algorithm
297family `PSA_ALG_TLS12_PSK_TO_MS(hash_alg)` was added to PSA Crypto.
298
299If we want to support key isolation for the "mixed PSK" key exchanges:
300DHE-PSK, RSA-PSK, ECDHE-PSK, where the PSK is concatenated with the result of
301a DH key agreement (resp. RSA decryption) to form the pre-master secret (PMS)
302from which the MS is derived. If the value of the PSK is to remain hidden, we
303need the derivation PSK + secondary secret -> MS to be implemented as an
304ad-hoc PSA key derivation algorithm.
305
306Adding this new, TLS-specific, key derivation algorithm to PSA Crypto should
307be no harder than it was to add `PSA_ALG_TLS12_PSK_TO_MS()` but still requires
308an extension to PSA Crypto.
309
310Note: looking at RFCs 4279 and 5489, it appears that the structure of the PMS
311is always the same: 2-byte length of the secondary secret, secondary secret,
3122-byte length of the PSK, PSK. So, a single key derivation algorithm should be
313able to cover the 3 key exchanges DHE-PSK, RSA-PSK and ECDHE-PSK. (That's a
314minor gain: adding 3 algorithms would not be a blocker anyway.)
315
316Note: if later we want to also isolate short-term secret (G3), the "secondary
317secret" (output of DHE/ECDHE key agreement or RSA decryption) could be a
318candidate. This wouldn't be a problem as the PSA key derivation API always
319allows inputs from key slots. (Tangent: the hard part in isolating the result
320of RSA decryption would be still checking that is has the correct format:
32148 bytes, the first two matching the TLS version - note that this is timing
322sensitive.)
323