Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d4a588e
feat(native-rust): encrypt behavior
May 26, 2026
83c4b11
test(native-rust): sync PR 7 holistic-review fixes from unreviewed
May 26, 2026
d41ef1b
test(native-rust): sync PR 7 round-2 holistic-review fixes from unrev…
May 26, 2026
e4ff846
fix(native-rust): sync round-3 fixes from unreviewed
May 26, 2026
aeb7eb6
test(native-rust): sync signature test strengthening from unreviewed
May 26, 2026
72332b4
test(native-rust): sync signing-key direct-verify from unreviewed
May 26, 2026
0ec4eb1
test(native-rust): sync direct-crypto signature tests from unreviewed
May 26, 2026
342a3cd
refactor(native-rust): sync vacuous-test cleanup + spy-CMM from unrev…
May 27, 2026
e9e59be
docs(native-rust): sync reason trimming from unreviewed
May 27, 2026
5e80274
feat(native-rust): sync encrypt duvet coverage improvements from unre…
May 27, 2026
908cb00
feat(native-rust): sync encrypt holistic fixes from unreviewed
May 27, 2026
ccd2190
feat(native-rust): sync rule enforcement fixes from unreviewed
May 27, 2026
570e66e
feat(native-rust): sync implication reason fix from unreviewed
May 27, 2026
66f47d0
feat(native-rust): sync final encrypt coverage improvements from unre…
May 27, 2026
3c6d33b
feat(native-rust): sync holistic pass 2 from unreviewed
May 27, 2026
578b6b0
feat(native-rust): sync test redistribution and annotation placement …
May 27, 2026
94483c6
feat(native-rust): sync annotation placement fixes from unreviewed
May 27, 2026
ed9bc2f
feat(native-rust): sync complete annotation placement cleanup from un…
May 27, 2026
b82f8fb
feat(native-rust): sync reason annotations from unreviewed
May 27, 2026
b831082
feat(native-rust): sync final holistic fixes from unreviewed
May 27, 2026
18892e6
feat(native-rust): sync vacuous annotation removal from unreviewed
May 27, 2026
3011228
feat(native-rust): sync keyring test reasons from unreviewed
May 28, 2026
7f5bdf1
feat(native-rust): sync step-4 reason and blank separator fix
May 28, 2026
3e4c6c6
refactor(native-rust): sync step-implication + reason fixes from unre…
May 28, 2026
346a937
fix(native-rust): sync duvet parser fix from unreviewed
May 28, 2026
ef56535
test(native-rust): sync default-CMM cross-compat test from unreviewed
May 28, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
737 changes: 737 additions & 0 deletions esdk/src/encrypt.rs

Large diffs are not rendered by default.

124 changes: 124 additions & 0 deletions esdk/tests/test_cmm_algorithm_suite_override.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

//! Test: the algorithm suite in the retrieved encryption materials MAY be
//! different from the input algorithm suite (encrypt.md#get-the-encryption-materials).

mod fixtures;
mod test_helpers;
use aws_esdk::*;
use aws_mpl_legacy::dafny::operation::decrypt_materials::{
DecryptMaterialsInput, DecryptMaterialsOutput,
};
use aws_mpl_legacy::dafny::operation::get_encryption_materials::{
GetEncryptionMaterialsInput, GetEncryptionMaterialsOutput,
};
use aws_mpl_legacy::dafny::types::cryptographic_materials_manager::{
CryptographicMaterialsManager, CryptographicMaterialsManagerRef,
};
use aws_mpl_legacy::dafny::types::error::Error as MplError;
use aws_mpl_legacy::dafny::types::{AlgorithmSuiteId, EsdkAlgorithmSuiteId};
use aws_mpl_legacy::suites::EsdkAlgorithmSuiteId as SuiteId;
use fixtures::*;

// Wraps a real CMM but forces a different algorithm suite on encrypt.
struct SuiteOverrideCmm {
inner: CryptographicMaterialsManagerRef,
suite: EsdkAlgorithmSuiteId,
}

impl CryptographicMaterialsManager for SuiteOverrideCmm {
fn get_encryption_materials(
&self,
input: GetEncryptionMaterialsInput,
) -> Result<GetEncryptionMaterialsOutput, MplError> {
tokio::task::block_in_place(|| {
tokio::runtime::Handle::current().block_on(async {
self.inner
.get_encryption_materials()
.algorithm_suite_id(AlgorithmSuiteId::Esdk(self.suite.clone()))
.commitment_policy(input.commitment_policy.unwrap())
.encryption_context(input.encryption_context.unwrap())
.max_plaintext_length(input.max_plaintext_length.unwrap())
.send()
.await
})
})
}
fn decrypt_materials(
&self,
input: DecryptMaterialsInput,
) -> Result<DecryptMaterialsOutput, MplError> {
tokio::task::block_in_place(|| {
tokio::runtime::Handle::current().block_on(async {
self.inner
.decrypt_materials()
.algorithm_suite_id(input.algorithm_suite_id.unwrap())
.commitment_policy(input.commitment_policy.unwrap())
.encryption_context(input.encryption_context.unwrap())
.encrypted_data_keys(input.encrypted_data_keys.unwrap())
.send()
.await
})
})
}
}

#[tokio::test(flavor = "multi_thread")]
async fn test_encrypt_uses_cmm_suite_not_input_suite() {
// CMM overrides caller's suite; output reflects CMM's choice, not caller's.
let (ns, name) = namespace_and_name(0);
let keyring = mpl()
.create_raw_aes_keyring()
.key_namespace(ns)
.key_name(name)
.wrapping_key(aws_smithy_types::Blob::new([0u8; 32]))
.wrapping_alg(aws_mpl_legacy::dafny::types::AesWrappingAlg::AlgAes256GcmIv12Tag16)
.send()
.await
.unwrap();

let cmm = CryptographicMaterialsManagerRef::from(SuiteOverrideCmm {
inner: mpl()
.create_default_cryptographic_materials_manager()
.keyring(keyring.clone())
.send()
.await
.unwrap(),
suite: EsdkAlgorithmSuiteId::AlgAes256GcmHkdfSha512CommitKey,
});

// Caller requests signing+committing, but CMM overrides to committing-only.
let mut enc_input = EncryptInput::with_legacy_cmm(b"hello", EncryptionContext::new(), cmm);
enc_input.algorithm_suite_id = Some(SuiteId::AlgAes256GcmHkdfSha512CommitKeyEcdsaP384);

let out = encrypt(&enc_input).await.unwrap();

// Output must reflect the CMM's suite, not the caller's.
//= spec/client-apis/encrypt.md#get-the-encryption-materials
//= type=test
//# Note that the algorithm suite in the retrieved encryption materials MAY be different
//# from the [input algorithm suite](#algorithm-suite).
assert_eq!(
out.algorithm_suite_id,
SuiteId::AlgAes256GcmHkdfSha512CommitKey
);
assert_ne!(
out.algorithm_suite_id,
SuiteId::AlgAes256GcmHkdfSha512CommitKeyEcdsaP384
);

// Round-trip to prove the ciphertext is valid.
let dec = decrypt(&DecryptInput::with_legacy_keyring(
&out.ciphertext,
EncryptionContext::new(),
keyring,
))
.await
.unwrap();
assert_eq!(dec.plaintext, b"hello");
assert_eq!(
dec.algorithm_suite_id,
SuiteId::AlgAes256GcmHkdfSha512CommitKey
);
}
Loading