Manuel Pégourié-Gonnard | d9edd56 | 2021-09-30 15:05:01 +0200 | [diff] [blame^] | 1 | This document lists current limitations of the PSA Crypto API (as of version |
| 2 | 1.1) that may impact our ability to (1) use it for all crypto operations in |
| 3 | TLS and X.509 and (2) support isolation of all long-term secrets in TLS (that |
| 4 | is, goals G1 and G2 in [strategy.md][] in the same directory). |
| 5 | |
| 6 | This is supposed to be a complete list, based on a exhaustive review of crypto |
| 7 | operations done in TLS and X.509 code, but of course it's still possible that |
| 8 | subtle-but-important issues have been missed. The only way to be really sure |
| 9 | is, of course, to actually do the migration work. |
| 10 | |
| 11 | Limitations relevant for G1 (performing crypto operations) |
| 12 | ========================================================== |
| 13 | |
| 14 | Restartable ECC operations |
| 15 | -------------------------- |
| 16 | |
| 17 | There is currently no support for that in PSA at all. API design, as well as |
| 18 | implementation, would be non-trivial. |
| 19 | |
| 20 | Currently, `MBEDTLS_USE_PSA_CRYPTO` is simply incompatible with |
| 21 | `MBEDTLS_ECP_RESTARTABLE`. |
| 22 | |
| 23 | Arbitrary parameters for FFDH |
| 24 | ----------------------------- |
| 25 | |
| 26 | Currently, the PSA Crypto API can only perform FFDH with a limited set of |
| 27 | well-know parameters (some of them defined in the spec, but implementations |
| 28 | are free to extend that set). |
| 29 | |
| 30 | TLS 1.2 (and earlier) on the other hand have the server send explicit |
| 31 | parameters (P and G) in is ServerKeyExchange message. This has been found to |
| 32 | be suboptimal for security, as it is prohibitively hard for the client to |
| 33 | verify the strength of these parameters. This led to the development of RFC |
| 34 | 7919 which allows use of named groups in TLS 1.2 - however as this is only an |
| 35 | extension, servers can still send custom parameters if they don't support the |
| 36 | extension. |
| 37 | |
| 38 | In TLS 1.3 the situation will be simpler: named groups are the only |
| 39 | option, so the current PSA Crypto API is a good match for that. (Not |
| 40 | coincidentally, the groups used by RFC 7919 and TLS 1.3 are part those defined |
| 41 | in the specification.) |
| 42 | |
| 43 | There are several options here: |
| 44 | |
| 45 | 1. Implement support for custom FFDH parameters in PSA Crypto: this would pose |
| 46 | non-trivial API design problem, but most importantly seems backwards, as |
| 47 | the crypto community is moving away from custom FFDH parameters. |
| 48 | 2. Drop the DHE-RSA and DHE-PSK key exchanges in TLS 1.2 when moving to PSA. |
| 49 | 3. 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 |
| 52 | client-side the only option is to offer named groups and break the handshake |
| 53 | if the server didn't take on our offer. This is not fully satisfying, but is |
| 54 | perhaps the least unsatisfying option in terms of result; it's also probably |
| 55 | the one that requires the most work, but it would deliver value beyond PSA |
| 56 | migration by implementing RFC 7919. |
| 57 | |
| 58 | RSA-PSS parameters |
| 59 | ------------------ |
| 60 | |
| 61 | RSA-PSS signatures are defined by PKCS#1 v2, re-published as RFC 8017 |
| 62 | (previously RFC 3447). |
| 63 | |
| 64 | As standardized, the signature scheme takes several parameters, in addition to |
| 65 | the 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 | |
| 71 | Both the existing `mbedtls_` API and the PSA API support only MGF1 as the |
| 72 | generation function, but there are discrepancy in handling the salt length and |
| 73 | which 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 | |
| 109 | The RSA/PK API is in principle more flexible than the PSA Crypto API. The |
| 110 | following sub-sections study whether and how this matters in practice. |
| 111 | |
| 112 | ### Use in X.509 |
| 113 | |
| 114 | RFC 4055 Section 3.1 defines the encoding of RSA-PSS that's used in X.509. |
| 115 | It allows independently specifying the message hash (also used for encoding |
| 116 | hash), the MGF (and its hash if MGF1 is used), and the salt length (plus an |
| 117 | extra parameter "trailer field" that doesn't vary in practice"). These can be |
| 118 | encoded as part of the key, and of the signature. If both encoding are |
| 119 | presents, all values must match except possibly for the salt length, where the |
| 120 | value from the signature parameters is used. |
| 121 | |
| 122 | In Mbed TLS, RSA-PSS parameters can be parsed and displayed for various |
| 123 | objects (certificates, CRLs, CSRs). During parsing, the following properties |
| 124 | are 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 | |
| 129 | When 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 | |
| 133 | The verification is done using `mbedtls_pk_verify_ext()`. |
| 134 | |
| 135 | Note: 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 |
| 137 | three hash algorithms must be equal, which would be good news as it would |
| 138 | match a limitation of the PSA API. (TODO: double-check that.) |
| 139 | |
| 140 | Also, since we only use signature verification, the fact that PSA accepts any |
| 141 | valid salt length means that no valid certificate would be wrongly rejected; |
| 142 | however it means that signatures that don't match the announced salt length |
| 143 | would be incorrectly accepted. At first glance, it looks like this doesn't |
| 144 | allow an attacker to forge certificates, so this might be acceptable in |
| 145 | practice, while not fully implementing all the checks in the standard. (TODO: |
| 146 | triple-check that.) |
| 147 | |
| 148 | It is unclear what parameters people use in practice. |
| 149 | |
| 150 | ### Use in TLS |
| 151 | |
| 152 | In TLS 1.2 (or lower), RSA-PSS signatures are never used, except via X.509. |
| 153 | |
| 154 | In TLS 1.3, RSA-PSS signatures can be used directly in the protocol (in |
| 155 | addition to indirect use via X.509). It has two sets of three signature |
| 156 | algorithm identifiers (for SHA-256, SHA-384 and SHA-512), depending of what |
| 157 | the OID of the public key is (rsaEncryption or RSASSA-PSS). |
| 158 | |
| 159 | In 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 | |
| 164 | When signing, the salt length picked by PSA is the one required by TLS 1.3 |
| 165 | (unless the key is unreasonably small). |
| 166 | |
| 167 | When verifying signatures, again is doesn't look like accepting any salt |
| 168 | length would give an attacker any advantage, but this must be triple-checked |
| 169 | (TODO). |
| 170 | |
| 171 | ### Current testing - X509 |
| 172 | |
| 173 | TODO: 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 | |
| 186 | TODO - once the previous section has been completed |
| 187 | |
| 188 | Limitations relevant for G2 (isolation of long-term secrets) |
| 189 | ============================================================ |
| 190 | |
| 191 | Custom key derivations for mixed-PSK handshake |
| 192 | ---------------------------------------------- |
| 193 | |
| 194 | Currently, `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 |
| 197 | Master Secret (MS) be done on the PSA side. To support this, an algorithm |
| 198 | family `PSA_ALG_TLS12_PSK_TO_MS(hash_alg)` was added to PSA Crypto. |
| 199 | |
| 200 | If we want to support key isolation for the "mixed PSK" key exchanges: |
| 201 | DHE-PSK, RSA-PSK, ECDHE-PSK, where the PSK is concatenated with the result of |
| 202 | a DH key agreement (resp. RSA decryption) to form the pre-master secret (PMS) |
| 203 | from which the MS is derived. If the value of the PSK is to remain hidden, we |
| 204 | need the derivation PSK + secondary secret -> MS to be implemented as an |
| 205 | ad-hoc PSA key derivation algorithm. |
| 206 | |
| 207 | Adding this new, TLS-specific, key derivation algorithm to PSA Crypto should |
| 208 | be no harder than it was to add `PSA_ALG_TLS12_PSK_TO_MS()` but still requires |
| 209 | an extension to PSA Crypto. |
| 210 | |
| 211 | Note: looking at RFCs 4279 and 5489, it appears that the structure of the PMS |
| 212 | is always the same: 2-byte length of the secondary secret, secondary secret, |
| 213 | 2-byte length of the PSK, PSK. So, a single key derivation algorithm should be |
| 214 | able to cover the 3 key exchanges DHE-PSK, RSA-PSK and ECDHE-PSK. (That's a |
| 215 | minor gain: adding 3 algorithms would not be a blocker anyway.) |
| 216 | |
| 217 | Note: if later we want to also isolate short-term secret (G3), the "secondary |
| 218 | secret" (output of DHE/ECDHE key agreement or RSA decryption) could be a |
| 219 | candidate. This wouldn't be a problem as the PSA key derivation API always |
| 220 | allows inputs from key slots. (Tangent: the hard part in isolating the result |
| 221 | of RSA decryption would be still checking that is has the correct format: |
| 222 | 48 bytes, the first two matching the TLS version - note that this is timing |
| 223 | sensitive.) |
| 224 | |