Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Accept data from partners and devices that cannot read it back

A partner posts documents, a device reports readings, an upload client sends files. Each encrypts what it sends and has no way to decrypt it again, whatever its credentials leak. An asymmetric KEK is a KMS key pair: the public half encrypts the DEKs and is not a secret, the private half stays in the KMS and decrypts them for the readers. See Asymmetric KEKs.

The three sides

SideHoldsDoes
Producerthe public key and its fingerprint, in its configurationencrypts values; no KMS client, no KMS right
Readera KMS provider, with decrypt on the keydecrypts values, as for any KEK
Administrationthe public key’s source, read right on the keyhands the public key to the producers
  1. Create an RSA key for asymmetric decryption in the KMS, with the algorithm and the key size of Asymmetric KEKs;
  2. grant the readers the decrypt right and the administration the right to read the public key, see Under an asymmetric KEK;
  3. the administration fetches the public key on its provider, writes to_json() and the key’s fingerprint to the producers’ configuration;
  4. each producer builds a PublicKeyKekProvider from them and an envelope over it.

The producer

The fingerprint comes from a channel other than the one that delivered the key. pinned refuses a key with another fingerprint with ASYMMETRIC_KEK_MISMATCH, so a key taken from a wrong place does not become a key that encrypts for whoever supplied it:

use kms_aead::backends::AwsLc;
use kms_aead::formats::Envelope;
use kms_aead::providers::PublicKeyKekProvider;
use kms_aead::{AsymmetricKekPublicKey, Encrypted, KmsAeadEnvelope, AsymmetricKekFingerprint};
use secret_vault_value::SecretValue;
use kms_aead::providers::{LocalAsymmetricKmsProvider, LocalKekId};
use kms_aead::AsymmetricKekAlgorithm;

#[tokio::main(flavor = "current_thread")]
async fn main() -> kms_aead::KmsAeadResult<()> {
let reader_provider = LocalAsymmetricKmsProvider::<AwsLc>::ephemeral(
    LocalKekId::try_from("submissions".to_string())?,
    AsymmetricKekAlgorithm::RsaOaepSha256,
)?;
let public_key = reader_provider.public_key(None)?;
let public_key_json = public_key.to_json()?;
let fingerprint_from_config = public_key.fingerprint().to_string();
let public_key = AsymmetricKekPublicKey::try_from_json(&public_key_json)?;
let fingerprint = AsymmetricKekFingerprint::try_from(fingerprint_from_config)?;
let producer = KmsAeadEnvelope::<_, AwsLc>::new(PublicKeyKekProvider::<AwsLc>::pinned(
    public_key,
    fingerprint,
)?)?;

let encrypted: Encrypted<SecretValue, Envelope> = producer
    .encrypt(b"submissions/1042", &SecretValue::from("account 1234"))
    .await?;

// The reader's side: the provider it already uses
let reader =
    KmsAeadEnvelope::<LocalAsymmetricKmsProvider<AwsLc>, AwsLc>::new(reader_provider)?;
let decrypted: SecretValue = reader.decrypt(b"submissions/1042", &encrypted).await?;
assert_eq!(decrypted, SecretValue::from("account 1234"));
Ok(())
}

Encrypt one test value and decrypt it with a reader before a new producer writes anything that matters. The provider logs the fingerprint at INFO when it is built, which an operator compares with the administration’s.

What the compiler guarantees

PublicKeyKekProvider encrypts and does not decrypt. Every call that decrypts a value or a DEK, decrypt, beacon, the stream decryptors and the *_with_encrypted_dek calls, requires a decrypting provider, so over a producer none of them compiles. A producer streams as well: an envelope over it encrypts a large file with stream_encryptor and decrypts none, see Store customer uploads and serve byte ranges.

The guarantee covers the producer’s calls into the library. A producer process holds the plaintext DEKs of its cached writes, and its own code can read what it wrote in memory. A service that writes and reads holds a KMS provider and is a reader.

With a keyring

The administration opens its registry with an AsymmetricKekProvider, which encrypts each new version’s DEK with the public key, and the applications open theirs with the plain KMS provider. Whoever holds the public key can also encrypt a DEK of their own and file it in a record they can write, and every application then decrypts it. Run every keyring under an asymmetric KEK with signed records, and RecordSignaturePolicy::Required on every application, before the first DEK a public key encrypts, see Protect the keyring record.

What to watch for

  • The producer encrypts randomised values only. A beacon or a deterministic value needs a key’s plaintext, which only a reader holds;
  • Ring has no RSA encryption, so a producer needs AwsLc or RustCrypto, see Crypto backends;
  • the encryption is local, so the KMS audit log does not show who encrypted a DEK. The decrypt log stays;
  • anyone holding the public key makes a reader pay for an asymmetric KMS decryption by sending a made-up value. Rate-limit what readers decrypt;
  • a rotation of the KEK is a new public key for every producer;
  • RSA is not quantum-safe, so data that must stay confidential for decades stays under a symmetric KEK.

Full example available here.