Demystifying AWS KMS in Plain Language Jan 2024
Demystifying AWS KMS in Plain Language Jan 2024
Management Service)
This material is entirely my own
and has not been reviewed by
AWS. It should not be
considered canonical and might
contain errors. It is provided “as
is.” Think of it as my scribbles
on the board in the classroom.
www.linkedin.com/in/carel-grove
Data encryption
Agenda
• Data encryption
• AWS KMS
• AWS KMS Keys
• KMS:GenerateDataKey
• KMS:Decrypt
Why isn’t everything encrypted everywhere?
• Because it is hard?
• The encryption part is easy.
• The hard part is the keys
• Generating keys
• in software (PRNG)
• in hardware (HRNG)
• Storing keys
• On the server’s disk drive
• In secure hardware
Key generation and storage in hardware
• Smart Card
• SIM chip (a type of smart card)
• Trusted Platform Module (TPM)
• Apple Secure Enclave & T2 chip
• Hardware Security Module
Some Countermeasures
It is a digital safe
Server HSM
1. Generate keypair
3. Done
Security Officer(s)
Challenges with HSMs
Also, deploying this at scale, running for years is a very challenging task
Proprietary
Server HSM
Command
Proprietary
Response
Very limited
Proprietary storage
Security Officer(s)
AWS KMS
Four of the main actors
Symmetric envelope encryption used by over 120 AWS services
Over 120 AWS services AWS KMS Service AWS KMS HSM
AWS Storage
Comms between the main actors
API calls to
120+ AWS services KMS AWS KMS Service AWS KMS HSM
AWS Storage
Here is how is DOESN’T Work 1/3
Amazon S3
Amazon S3
Encrypting
50MB file
Here is how is DOESN’T Work 3/3
Amazon S3
• The HBK is an actual symmetric cryptographic key and is associated with the KMS “Key”
• It is generated inside the AWS KMS HSM (as part of the same operation when you create
a KMS Key)
• After being generated, the HBK is in turn encrypted by the AWS KMS HSM and exported
to AWS Storage.
• In its encrypted form in AWS Storage it is called the EKT (Exported Key Token)
• This prevents the AWS KMS HSMs from filling up almost immediately with a gazillion
keys.
• When the HBK is needed for an operation, the EKT is imported into the AWS KMS HSM,
and decrypted for use.
• It never leaves the AWS KMS HSM in unencrypted form
• Details about the HBK and EKT are stored with the KMS key as metadata attributes of the
KMS key
There are more sources of “key material”
But this (AWS KMS HSM) is the recommended use case
When creating a
KMS key you can
select where you
want the
corresponding key
material for that
KMS key to come
from
Where the keys “live”
KMS “Key”
AWS KMS Service AWS KMS HSM • The AWS KMS “Key” has
metadata that reference
the corresponding EKT /
HBK
• The HBK is only in the
KMS when initially
HBK (HSM Backing Key) generated or when it
AWS Storage needs to be used.
• When the HBK is
required for an
operation, the AWS KMS
EKT (Exported Key Token)
Service imports the EKT
into the AWS KMS HSM.
This might surprise you, but
• None of these keys (KMS “Key”, HBK or EKT) encrypt / decrypt any of
your data.
• That is right, these keys do not encrypt or decrypt your data
• Your data gets encrypted / decrypted by yet another key: the CDK
(Customer Data Key) – more in a moment.
• The job of the HBK is NOT to encrypt your data, but to derive a 5th (!)
key - the DEK (Derived Encryption Key).
• The DEK does not encrypt your data either, it encrypts the CDK
Thus… Envelope encryption – the full story
The only key that every
POINTS TO actually encrypt or ENCRYPTS
decrypt your data. A new DECRYPTS
one is generated inside @ the calling
KMS “Key” the HSM every time a CDK Plaintext CDK service Your data
is requested
S
(Data Key) (SSE-KMS) +
YPT
R
D EC Ciphertext CDK
+ Nonce /
TS
(Data Key)
YP
The same key - DERIVE CR
EN The same key -
HBK is the HBK DEK
Plaintext CDK is the
unencrypted (HSM Backing Key) (Derived Encryption Key)
version inside unencrypted version sent (over
TLS) to the AWS service (e.g. S3)
HSM
that is used it to do the actual
encryption
EKT is the
encrypted
version Ciphertext CDK is the
encrypted version sent (over
outside the
TLS) to the AWS service (e.g. S3)
HSM in AWS
Storage EKT Ciphertext CDK where the service stores it along
(Exported Key Token) (Data Key) with the encrypted data
The CDK (Customer Data Key)
Amazon S3
Amazon S3
Amazon S3
AWS Storage
Return Plaintext CDK &
Ciphertext CDK
Here is how is encryption ACTUALLY Works 5
AWS Storage
(1) Return
(3) S3 Flush the Plaintext CDK &
plaintext 50MB data Ciphertext CDK
file and stores the
ciphertext 50MB
data file WITH the
ciphertext CDK
Here is how is encryption ACTUALLY Works 6
Amazon S3
AWS Storage
All done!
KMS:Decrypt
Here is how is decryption ACTUALLY Works 1
Amazon S3
Amazon S3
Amazon S3
Amazon S3