blob: 05a4d54a2728869946aed6c612086d6a48e604dc [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:
125- (the extra "trailer field" parameter must has its default value)
126- 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
150### Use in TLS
151
152In TLS 1.2 (or lower), RSA-PSS signatures are never used, except via X.509.
153
154In TLS 1.3, RSA-PSS signatures can be used directly in the protocol (in
155addition to indirect use via X.509). It has two sets of three signature
156algorithm identifiers (for SHA-256, SHA-384 and SHA-512), depending of what
157the OID of the public key is (rsaEncryption or RSASSA-PSS).
158
159In both cases, it specifies that:
160- the mask generation function is MGF1
161- all three hashes are equal
162- the length of the salt MUST be equal to the length of the digest algorithm
163
164When signing, the salt length picked by PSA is the one required by TLS 1.3
165(unless the key is unreasonably small).
166
167When verifying signatures, again is doesn't look like accepting any salt
168length would give an attacker any advantage, but this must be triple-checked
169(TODO).
170
171### Current testing - X509
172
173TODO: look at the parameters used by the various test files
174
175- server9.crt
176 -HASH
177 -badsign
178 -defaults
179 -bad-saltlen
180 -bad-mgfhash
181- crl-rsa-pss-HASH.pem
182- server9.req.HASH
183
184### Possible course of actions
185
186TODO - once the previous section has been completed
187
188Limitations relevant for G2 (isolation of long-term secrets)
189============================================================
190
191Custom key derivations for mixed-PSK handshake
192----------------------------------------------
193
194Currently, `MBEDTLS_USE_PSA_CRYPTO` enables the new configuration function
195`mbedtls_ssl_conf_psk_opaque()` which allows a PSA-held key to be used for the
196(pure) `PSK` key exchange in TLS 1.2. This requires that the derivation of the
197Master Secret (MS) be done on the PSA side. To support this, an algorithm
198family `PSA_ALG_TLS12_PSK_TO_MS(hash_alg)` was added to PSA Crypto.
199
200If we want to support key isolation for the "mixed PSK" key exchanges:
201DHE-PSK, RSA-PSK, ECDHE-PSK, where the PSK is concatenated with the result of
202a DH key agreement (resp. RSA decryption) to form the pre-master secret (PMS)
203from which the MS is derived. If the value of the PSK is to remain hidden, we
204need the derivation PSK + secondary secret -> MS to be implemented as an
205ad-hoc PSA key derivation algorithm.
206
207Adding this new, TLS-specific, key derivation algorithm to PSA Crypto should
208be no harder than it was to add `PSA_ALG_TLS12_PSK_TO_MS()` but still requires
209an extension to PSA Crypto.
210
211Note: looking at RFCs 4279 and 5489, it appears that the structure of the PMS
212is always the same: 2-byte length of the secondary secret, secondary secret,
2132-byte length of the PSK, PSK. So, a single key derivation algorithm should be
214able to cover the 3 key exchanges DHE-PSK, RSA-PSK and ECDHE-PSK. (That's a
215minor gain: adding 3 algorithms would not be a blocker anyway.)
216
217Note: if later we want to also isolate short-term secret (G3), the "secondary
218secret" (output of DHE/ECDHE key agreement or RSA decryption) could be a
219candidate. This wouldn't be a problem as the PSA key derivation API always
220allows inputs from key slots. (Tangent: the hard part in isolating the result
221of RSA decryption would be still checking that is has the correct format:
22248 bytes, the first two matching the TLS version - note that this is timing
223sensitive.)
224