Debian Codegraph @

crt/s2n/bindings/rust/aws-kms-tls-auth/README.md

raw symbols SCIP
1 # aws-kms-tls-auth
2
3 This crate provides a way to perform TLS authentication using the AWS Key Management Service (KMS) and Identity and Access Management (IAM). The only supported TLS implementation is currently [s2n-tls](https://github.com/aws/s2n-tls), but if you are interested in support for other TLS implementations please open a [github issue](https://github.com/aws/s2n-tls/issues/new/choose).
4
5 Clients use the [generateMAC](https://docs.aws.amazon.com/kms/latest/APIReference/API_GenerateMac.html) API to create a secret shared across the fleet. Clients then derive a unique secret for each connection, which the server is able to retrieve based on the PSKIdentity. The TLS connection then proceeds using the TLS 1.3 out-of-band PSK mechanism. Other TLS protocols are not supported.
6
7 The authenticated property is "the peer has kms:GenerateMac permissions on the KMS HMAC Key".
8
9 Note that this library is a data-plane dependency on KMS. If KMS is down for more than 24 hours, handshakes will fail.
10
11 # infrastructure setup
12 - KMS HMAC Key: Library users must provision a [KMS HMAC key](https://docs.aws.amazon.com/kms/latest/developerguide/hmac.html) using an [HMAC_384](https://docs.aws.amazon.com/kms/latest/developerguide/symm-asymm-choose-key-spec.html#hmac-key-specs) key spec.
13 - IAM Role: clients and servers must be configured with an IAM role that has `kms:GenerateMac` permissions on the created HMAC key.
14 - Rotation Failure Notification: Applications must supply a "failure notification" closure to the `PskProvider` and `PskReceiver`. This closure is invoked whenever there is a failure to rotate the epoch secret. Customers should alarm on this value. If a rotation fails, rotation will be reattempted in 1 hour. If rotation fails for 24 hours, handshakes will then fail.
15
16 # High Level Design
17
18 There are three components to this design
19
20 * epoch_secret: This is derived from the KMS HMAC key, and is shared across the fleet. Rotated daily
21 * PSK Secret: This is derived from the epoch_secret and a unique nonce. This is unique per-connection
22 * PSK Identity: This is a plaintext identifier that is sent from the client to the server. unique per-connection.
23
24 ### Daily Secret
25
26 The daily secret is generated using the KMS [GenerateMac](https://docs.aws.amazon.com/kms/latest/APIReference/API_GenerateMac.html) API. The message that the MAC is derived over will be an 8 bytes string of the days elapsed since the unix epoch. The HMAC algorithm will be selected to match the HMAC algorithm used in the underlying TLS protocol. This is not customer configurable, and will use `HMAC_SHA_384`.
27
28 ```rust
29 const KEY_PURPOSE: &[u8]: "aws-kms-tls-auth-daily-secret"
30
31 let key_epoch: u64 = seconds_since_unix_epoch() / (3_600 * 24)
32 let message = concat(key_epoch, KEY_PURPOSE)
33
34 let epoch_secret: Vec<u8> = kms.generate_mac(
35 key_id: KEY_ID,
36 mac_algorithm: HMAC_SHA_384
37 message: message,
38 )
39 ```
40
41 ### PSK Secret
42
43 First, the client will generate a random session_name to be used as a nonce. `session_name` will be 32 bytes long. This will be used along with `epoch_secret` in HKDF to derive the connection-specific secret. The digest used will match that used in the KMS HMAC and the underlying TLS protocol - SHA384.
44
45 ```rust
46 let session_name: [u8; 32] = random_bytes();
47 let psk_secret = HKDF(
48 secret: epoch_secret,
49 info: session_name,
50 salt: null,
51 )
52 ```
53
54 ### PSK Identity
55
56 The PSK identity is sent in plaintext in the client hello.
57
58 Note that we support a server trusting multiple KMS HMAC keys. This is necessary to allow for customers to manually rotate KMS keys in response to extraordinary circumstances without availability impact.
59
60 If a server trusts both `keyA` and `keyB`, then the client will need to communicate which key it used to derive its PSK. The naive solution would be to just include `keyA` or `keyB` in plaintext in the PSK Identity. However, this would leak information about “fleet membership”, because it is sent in the clear. Ideally, the PSK identity would not leak this information.
61
62 To do this we calculate a `kms_key_binder` which incorporates the
63
64 * kms key arn: the key that was used to generate the daily secret
65 * session_name: this makes the kms key binder unique per connection, preventing information from being correlated across multiple connections from a single client.
66 * epoch_secret: without secret information, then an attacker would be able to calculate whether the kms_key_binder is valid for some specific key, because the `session_name` is public information.
67
68 ```rust
69 KMS_KEY_ARN: Vec<u8> = "arn:123456789:iw78his7w3hg4if7g";
70
71 let kms_key_binder: Vec<u8> = HKDF(
72 secret: epoch_secret,
73 info: KMS_KEY_ARN,
74 salt: session_name
75 )
76
77 let psk_identity = concat(key_epoch, session_name, kms_key_binder)
78 ```
79
80 ### Server Flow
81
82 Upon a receiving a PSK identity, the server will parse out `key_epoch`, `session_name`, and the `kms_key_binder`.
83
84 Then for each KMS HMAC Key that it trusts, it would repeat the PSK secret and PSK identity derivation process. If one of the derived PSK identities matches the client’s PSK identity, then that will be the PSK used in the connection. If no PSK identities match, then the connection is rejected and the handshake will fail.
85
86 ### Material Disclosure Impact
87
88 If an attacker obtains an epoch secret, then they will be able to impersonate a server or a client. They can not decrypt any conversations between other peers, because TLS 1.3 PSK authentication performs an additional DHE key exchange.
89
90 If an attacker obtains a connection specific secret, then they will be able impersonate a client to any server. They will not be able to impersonate a server, or decrypt any client communications.