blob: ca3b44029bfea560cbe3122b5aa8a5adbaffa8f3 [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
Manuel Pégourié-Gonnard8e559da2022-02-01 10:26:07 +01004is, goals G1 and G2 in [strategy.md](strategy.md) in the same directory).
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +02005
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
Manuel Pégourié-Gonnard42a14532024-05-21 11:43:06 +020014Executive summary
15-----------------
16
17- Restartable/interruptible ECC operations: in progress (mid-2024).
18- Arbitrary parameters for FFDH: will be dropped in 4.0.
19- RSA-PSS parameters: already implemented safe though arguably non-compliant
20 solution in Mbed TLS 3.4, no complaints so far.
21
Manuel Pégourié-Gonnard03cb87e2023-03-22 16:06:47 +010022Restartable (aka interruptible) ECC operations
23----------------------------------------------
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +020024
Manuel Pégourié-Gonnard03cb87e2023-03-22 16:06:47 +010025Support for interruptible ECDSA sign/verify was added to PSA in Mbed TLS 3.4.
Manuel Pégourié-Gonnard5c8c9e02023-03-29 10:33:03 +020026However, support for interruptible ECDH is not present yet. Also, PK, X.509 and
Manuel Pégourié-Gonnard03cb87e2023-03-22 16:06:47 +010027TLS have not yet been adapted to take advantage of the new PSA APIs. See:
28- <https://github.com/Mbed-TLS/mbedtls/issues/7292>;
29- <https://github.com/Mbed-TLS/mbedtls/issues/7293>;
30- <https://github.com/Mbed-TLS/mbedtls/issues/7294>.
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +020031
Manuel Pégourié-Gonnard55a188b2022-12-06 12:00:33 +010032Currently, when `MBEDTLS_USE_PSA_CRYPTO` and `MBEDTLS_ECP_RESTARTABLE` are
33both enabled, some operations that should be restartable are not (ECDH in TLS
341.2 clients using ECDHE-ECDSA), as they are using PSA instead, and some
35operations that should use PSA do not (signature generation & verification) as
36they use the legacy API instead, in order to get restartable behaviour.
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +020037
38Arbitrary parameters for FFDH
39-----------------------------
40
41Currently, the PSA Crypto API can only perform FFDH with a limited set of
Manuel Pégourié-Gonnard58d101b2022-02-10 12:58:09 +010042well-known parameters (some of them defined in the spec, but implementations
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +020043are free to extend that set).
44
45TLS 1.2 (and earlier) on the other hand have the server send explicit
Manuel Pégourié-Gonnard58d101b2022-02-10 12:58:09 +010046parameters (P and G) in its ServerKeyExchange message. This has been found to
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +020047be suboptimal for security, as it is prohibitively hard for the client to
48verify the strength of these parameters. This led to the development of RFC
497919 which allows use of named groups in TLS 1.2 - however as this is only an
50extension, servers can still send custom parameters if they don't support the
51extension.
52
53In TLS 1.3 the situation will be simpler: named groups are the only
54option, so the current PSA Crypto API is a good match for that. (Not
Manuel Pégourié-Gonnardc7f32542022-02-10 13:00:33 +010055coincidentally, all the groups used by RFC 7919 and TLS 1.3 are included
56in the PSA specification.)
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +020057
58There are several options here:
59
601. Implement support for custom FFDH parameters in PSA Crypto: this would pose
61 non-trivial API design problem, but most importantly seems backwards, as
Manuel Pégourié-Gonnard83c53882022-04-20 14:27:48 +020062the crypto community is moving away from custom FFDH parameters. (Could be
63done any time.)
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +0200642. Drop the DHE-RSA and DHE-PSK key exchanges in TLS 1.2 when moving to PSA.
Manuel Pégourié-Gonnard83c53882022-04-20 14:27:48 +020065 (For people who want some algorithmic variety in case ECC collapses, FFDH
66would still be available in TLS 1.3, just not in 1.2.) (Can only be done in
674.0 or another major version.)
683. Variant of the precedent: only drop client-side support. Server-side is
69 easy to support in terms of API/protocol, as the server picks the
70parameters: we just need remove the existing `mbedtls_ssl_conf_dh_param_xxx()`
71APIs and tell people to use `mbedtls_ssl_conf_groups()` instead. (Can only be
72done in 4.0 or another major version.)
734. Implement RFC 7919, support DHE-RSA and DHE-PSK only in conjunction with it
74 when moving to PSA. Server-side would work as above; unfortunately
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +020075client-side the only option is to offer named groups and break the handshake
76if the server didn't take on our offer. This is not fully satisfying, but is
77perhaps the least unsatisfying option in terms of result; it's also probably
78the one that requires the most work, but it would deliver value beyond PSA
Manuel Pégourié-Gonnard83c53882022-04-20 14:27:48 +020079migration by implementing RFC 7919. (Implementing RFC 7919 could be done any
80time; making it mandatory can only be done in 4.0 or another major version.)
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +020081
Manuel Pégourié-Gonnard03cb87e2023-03-22 16:06:47 +010082As of early 2023, the plan is to go with option 2 in Mbed TLS 4.0, which has
83been announced on the mailing-list and got no push-back, see
84<https://github.com/Mbed-TLS/mbedtls/issues/5278>.
85
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +020086RSA-PSS parameters
87------------------
88
89RSA-PSS signatures are defined by PKCS#1 v2, re-published as RFC 8017
90(previously RFC 3447).
91
92As standardized, the signature scheme takes several parameters, in addition to
93the hash algorithm potentially used to hash the message being signed:
Manuel Pégourié-Gonnarde459be22021-10-27 13:25:49 +020094- a hash algorithm used for the encoding function
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +020095- a mask generation function
96 - most commonly MGF1, which in turn is parametrized by a hash algorithm
97- a salt length
Manuel Pégourié-Gonnardc70013e2022-02-10 13:07:22 +010098- a trailer field - the value is fixed to 0xBC by PKCS#1 v2.1, but was left
Andrzej Kurek5c65c572022-04-13 14:28:52 -040099 configurable in the original scheme; 0xBC is used everywhere in practice.
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +0200100
101Both the existing `mbedtls_` API and the PSA API support only MGF1 as the
Manuel Pégourié-Gonnarde459be22021-10-27 13:25:49 +0200102generation function (and only 0xBC as the trailer field), but there are
103discrepancies in handling the salt length and which of the various hash
104algorithms can differ from each other.
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +0200105
106### API comparison
107
108- RSA:
109 - signature: `mbedtls_rsa_rsassa_pss_sign()`
110 - message hashed externally
111 - encoding hash = MGF1 hash (from context, or argument = message hash)
112 - salt length: always using the maximum legal value
113 - signature: `mbedtls_rsa_rsassa_pss_sign_ext()`
114 - message hashed externally
115 - encoding hash = MGF1 hash (from context, or argument = message hash)
116 - salt length: specified explicitly
117 - verification: `mbedtls_rsassa_pss_verify()`
118 - message hashed externally
119 - encoding hash = MGF1 hash (from context, or argument = message hash)
120 - salt length: any valid length accepted
121 - verification: `mbedtls_rsassa_pss_verify_ext()`
122 - message hashed externally
123 - encoding hash = MGF1 hash from dedicated argument
124 - expected salt length: specified explicitly, can specify "ANY"
125- PK:
126 - signature: not supported
127 - verification: `mbedtls_pk_verify_ext()`
128 - message hashed externally
129 - encoding hash = MGF1 hash, specified explicitly
130 - expected salt length: specified explicitly, can specify "ANY"
131- PSA:
132 - algorithm specification:
133 - hash alg used for message hashing, encoding and MGF1
Manuel Pégourié-Gonnard539b9a52022-02-07 10:19:08 +0100134 - salt length can be either "standard" (<= hashlen, see note) or "any"
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +0200135 - signature generation:
Manuel Pégourié-Gonnard539b9a52022-02-07 10:19:08 +0100136 - salt length: always <= hashlen (see note) and random salt
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +0200137 - verification:
Manuel Pégourié-Gonnard539b9a52022-02-07 10:19:08 +0100138 - salt length: either <= hashlen (see note), or any depending on algorithm
139
140Note: above, "<= hashlen" means that hashlen is used if possible, but if it
Manuel Pégourié-Gonnard80759c42022-02-08 10:33:11 +0100141doesn't fit because the key is too short, then the maximum length that fits is
Manuel Pégourié-Gonnard539b9a52022-02-07 10:19:08 +0100142used.
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +0200143
144The RSA/PK API is in principle more flexible than the PSA Crypto API. The
145following sub-sections study whether and how this matters in practice.
146
147### Use in X.509
148
149RFC 4055 Section 3.1 defines the encoding of RSA-PSS that's used in X.509.
150It allows independently specifying the message hash (also used for encoding
151hash), the MGF (and its hash if MGF1 is used), and the salt length (plus an
152extra parameter "trailer field" that doesn't vary in practice"). These can be
153encoded as part of the key, and of the signature. If both encoding are
154presents, all values must match except possibly for the salt length, where the
155value from the signature parameters is used.
156
157In Mbed TLS, RSA-PSS parameters can be parsed and displayed for various
158objects (certificates, CRLs, CSRs). During parsing, the following properties
159are enforced:
Manuel Pégourié-Gonnarde459be22021-10-27 13:25:49 +0200160- the extra "trailer field" parameter must have its default value
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +0200161- the mask generation function is MGF1
162- encoding hash = message hashing algorithm (may differ from MGF1 hash)
163
164When it comes to cryptographic operations, only two things are supported:
165- verifying the signature on a certificate from its parent;
166- verifying the signature on a CRL from the issuing CA.
167
168The verification is done using `mbedtls_pk_verify_ext()`.
169
170Note: since X.509 parsing ensures that message hash = encoding hash, and
Manuel Pégourié-Gonnard58d101b2022-02-10 12:58:09 +0100171`mbedtls_pk_verify_ext()` uses encoding hash = mgf1 hash, it looks like all
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +0200172three hash algorithms must be equal, which would be good news as it would
Manuel Pégourié-Gonnarde459be22021-10-27 13:25:49 +0200173match a limitation of the PSA API.
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +0200174
Manuel Pégourié-Gonnarde459be22021-10-27 13:25:49 +0200175It is unclear what parameters people use in practice. It looks like by default
176OpenSSL picks saltlen = keylen - hashlen - 2 (tested with openssl 1.1.1f).
Tom Cosgrove0b86ac12022-07-29 13:44:01 +0100177The `certtool` command provided by GnuTLS seems to be picking saltlen = hashlen
Manuel Pégourié-Gonnard839bb8a2022-02-08 10:33:41 +0100178by default (tested with GnuTLS 3.6.13). FIPS 186-4 requires 0 <= saltlen <=
Manuel Pégourié-Gonnard8e559da2022-02-01 10:26:07 +0100179hashlen.
Manuel Pégourié-Gonnardf5ee4b32021-10-21 13:04:01 +0200180
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +0200181### Use in TLS
182
183In TLS 1.2 (or lower), RSA-PSS signatures are never used, except via X.509.
184
185In TLS 1.3, RSA-PSS signatures can be used directly in the protocol (in
186addition to indirect use via X.509). It has two sets of three signature
187algorithm identifiers (for SHA-256, SHA-384 and SHA-512), depending of what
188the OID of the public key is (rsaEncryption or RSASSA-PSS).
189
190In both cases, it specifies that:
191- the mask generation function is MGF1
192- all three hashes are equal
193- the length of the salt MUST be equal to the length of the digest algorithm
194
195When signing, the salt length picked by PSA is the one required by TLS 1.3
196(unless the key is unreasonably small).
197
Manuel Pégourié-Gonnarde459be22021-10-27 13:25:49 +0200198When verifying signatures, PSA will by default enforce the salt len is the one
199required by TLS 1.3.
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +0200200
201### Current testing - X509
202
Manuel Pégourié-Gonnarde459be22021-10-27 13:25:49 +0200203All test files use the default trailer field of 0xBC, as enforced by our
204parser. (There's a negative test for that using the
205`x509_parse_rsassa_pss_params` test function and hex data.)
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +0200206
Manuel Pégourié-Gonnarde459be22021-10-27 13:25:49 +0200207Files with "bad" in the name are expected to be invalid and rejected in tests.
Manuel Pégourié-Gonnardf5ee4b32021-10-21 13:04:01 +0200208
209**Test certificates:**
210
211server9-bad-mgfhash.crt (announcing mgf1(sha224), signed with another mgf)
212 Hash Algorithm: sha256
213 Mask Algorithm: mgf1 with sha224
214 Salt Length: 0xDE
215server9-bad-saltlen.crt (announcing saltlen = 0xDE, signed with another len)
216 Hash Algorithm: sha256
217 Mask Algorithm: mgf1 with sha256
218 Salt Length: 0xDE
219server9-badsign.crt (one bit flipped in the signature)
220 Hash Algorithm: sha1 (default)
221 Mask Algorithm: mgf1 with sha1 (default)
222 Salt Length: 0xEA
223server9-defaults.crt
224 Hash Algorithm: sha1 (default)
225 Mask Algorithm: mgf1 with sha1 (default)
226 Salt Length: 0x14 (default)
227server9-sha224.crt
228 Hash Algorithm: sha224
229 Mask Algorithm: mgf1 with sha224
230 Salt Length: 0xE2
231server9-sha256.crt
232 Hash Algorithm: sha256
233 Mask Algorithm: mgf1 with sha256
234 Salt Length: 0xDE
235server9-sha384.crt
236 Hash Algorithm: sha384
237 Mask Algorithm: mgf1 with sha384
238 Salt Length: 0xCE
239server9-sha512.crt
240 Hash Algorithm: sha512
241 Mask Algorithm: mgf1 with sha512
242 Salt Length: 0xBE
243server9-with-ca.crt
244 Hash Algorithm: sha1 (default)
245 Mask Algorithm: mgf1 with sha1 (default)
246 Salt Length: 0xEA
247server9.crt
248 Hash Algorithm: sha1 (default)
249 Mask Algorithm: mgf1 with sha1 (default)
250 Salt Length: 0xEA
251
252These certificates are signed with a 2048-bit key. It appears that they are
253all using saltlen = keylen - hashlen - 2, except for server9-defaults which is
254using saltlen = hashlen.
255
256**Test CRLs:**
257
258crl-rsa-pss-sha1-badsign.pem
259 Hash Algorithm: sha1 (default)
260 Mask Algorithm: mgf1 with sha1 (default)
261 Salt Length: 0xEA
262crl-rsa-pss-sha1.pem
263 Hash Algorithm: sha1 (default)
264 Mask Algorithm: mgf1 with sha1 (default)
265 Salt Length: 0xEA
266crl-rsa-pss-sha224.pem
267 Hash Algorithm: sha224
268 Mask Algorithm: mgf1 with sha224
269 Salt Length: 0xE2
270crl-rsa-pss-sha256.pem
271 Hash Algorithm: sha256
272 Mask Algorithm: mgf1 with sha256
273 Salt Length: 0xDE
274crl-rsa-pss-sha384.pem
275 Hash Algorithm: sha384
276 Mask Algorithm: mgf1 with sha384
277 Salt Length: 0xCE
278crl-rsa-pss-sha512.pem
279 Hash Algorithm: sha512
280 Mask Algorithm: mgf1 with sha512
281 Salt Length: 0xBE
282
283These CRLs are signed with a 2048-bit key. It appears that they are
284all using saltlen = keylen - hashlen - 2.
285
286**Test CSRs:**
287
288server9.req.sha1
289 Hash Algorithm: sha1 (default)
290 Mask Algorithm: mgf1 with sha1 (default)
291 Salt Length: 0x6A
292server9.req.sha224
293 Hash Algorithm: sha224
294 Mask Algorithm: mgf1 with sha224
295 Salt Length: 0x62
296server9.req.sha256
297 Hash Algorithm: sha256
298 Mask Algorithm: mgf1 with sha256
299 Salt Length: 0x5E
300server9.req.sha384
301 Hash Algorithm: sha384
302 Mask Algorithm: mgf1 with sha384
303 Salt Length: 0x4E
304server9.req.sha512
305 Hash Algorithm: sha512
306 Mask Algorithm: mgf1 with sha512
307 Salt Length: 0x3E
308
Manuel Pégourié-Gonnard83c53882022-04-20 14:27:48 +0200309These CSRs are signed with a 2048-bit key. It appears that they are
Manuel Pégourié-Gonnardf5ee4b32021-10-21 13:04:01 +0200310all using saltlen = keylen - hashlen - 2.
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +0200311
Manuel Pégourié-Gonnarde459be22021-10-27 13:25:49 +0200312### Possible courses of action
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +0200313
Manuel Pégourié-Gonnarde459be22021-10-27 13:25:49 +0200314There's no question about what to do with TLS (any version); the only question
315is about X.509 signature verification. Options include:
316
3171. Doing all verifications with `PSA_ALG_RSA_PSS_ANY_SALT` - while this
318 wouldn't cause a concrete security issue, this would be non-compliant.
3192. Doing verifications with `PSA_ALG_RSA_PSS` when we're lucky and the encoded
320 saltlen happens to match hashlen, and falling back to `ANY_SALT` otherwise.
321Same issue as with the previous point, except more contained.
3223. Reject all certificates with saltlen != hashlen. This includes all
Manuel Pégourié-Gonnard83c53882022-04-20 14:27:48 +0200323 certificates generated with OpenSSL using the default parameters, so it's
Manuel Pégourié-Gonnarde459be22021-10-27 13:25:49 +0200324probably not acceptable.
3254. Request an extension to the PSA Crypto API and use one of the above options
326 in the meantime. Such an extension seems inconvenient and not motivated by
327strong security arguments, so it's unclear whether it would be accepted.
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +0200328
Manuel Pégourié-Gonnard03cb87e2023-03-22 16:06:47 +0100329Since Mbed TLS 3.4, option 1 is implemented.
330
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +0200331Limitations relevant for G2 (isolation of long-term secrets)
332============================================================
333
Manuel Pégourié-Gonnard103b9922022-05-11 13:21:39 +0200334Currently none.