diff --git a/.cargo/mutants.toml b/.cargo/mutants.toml index eb07653982..e0b85a8b93 100644 --- a/.cargo/mutants.toml +++ b/.cargo/mutants.toml @@ -57,7 +57,7 @@ exclude_globs = ["packages/stack-encrypt-derive/**"] # mutant does not compile, because `AutoStrategy` has no `Default`. So the # entry excludes no mutant that a test could catch. # -# The two wasm32 `into_future` entries in `pending.rs` match any line for the +# The four wasm32 `into_future` entries in `pending.rs` match any line for the # same reason. The future that a native `into_future` returns has no # `Default`, so the native mutant does not compile. exclude_re = [ @@ -80,6 +80,8 @@ exclude_re = [ 'stack-encrypt/src/cipher\.rs:\d+:\d+: replace client_key_provider -> EnvKeyProvider with Default::default\(\)$', 'stack-encrypt/src/target/pending\.rs:\d+:\d+: replace >::into_future -> Self::IntoFuture with Default::default\(\)$', 'stack-encrypt/src/target/pending\.rs:\d+:\d+: replace >>::into_future -> Self::IntoFuture with Default::default\(\)$', + 'stack-encrypt/src/target/pending\.rs:\d+:\d+: replace >>::into_future -> Self::IntoFuture with Default::default\(\)$', + 'stack-encrypt/src/target/pending\.rs:\d+:\d+: replace >>>::into_future -> Self::IntoFuture with Default::default\(\)$', # stack-encrypt — equivalent. # An operator and an index are unit structs, whose `Default` is the value # `clone` and `case_sensitive` already return. diff --git a/.changeset/auth-credential-per-call.md b/.changeset/auth-credential-per-call.md new file mode 100644 index 0000000000..55eb529ca7 --- /dev/null +++ b/.changeset/auth-credential-per-call.md @@ -0,0 +1,5 @@ +--- +'@cipherstash/auth': patch +--- + +Rebuild on a `stack-auth` whose Rust API can issue the token for a credential passed with the call. The JavaScript API is unchanged: `getToken` and `getTokenForJwt` behave as before, and share one token cache. In Rust, `CredentialAuthStrategy` is the trait for a credential passed with the call, and an `OidcFederationStrategy` can be built with no provider callback (`OidcFederationStrategy::credential_per_call`). Such a strategy has no `get_token`, so a call that brings no credential does not compile. A Rust strategy built with a provider callback takes no JWT from its caller. The Node and wasm bindings therefore build the Rust strategy with `credential_per_call`, keep the `getJwt` callback themselves, and pass a JWT with each call. diff --git a/languages/golang/encrypt/guest/src/abi.rs b/languages/golang/encrypt/guest/src/abi.rs index 09fa1f37ca..22deb2d323 100644 --- a/languages/golang/encrypt/guest/src/abi.rs +++ b/languages/golang/encrypt/guest/src/abi.rs @@ -100,7 +100,7 @@ use stack_guest_abi::step::{self, Operation, Step}; use crate::io; use crate::ops::{self, Bytes}; -use crate::options::{parse_options, parse_selector, scope_for, KeysetSelector, Side}; +use crate::options::{cipher_ref_for, parse_options, parse_selector, KeysetSelector, Side}; #[cfg(not(feature = "deterministic-kms"))] use crate::status::STATUS_INTERNAL; #[cfg(not(feature = "deterministic-kms"))] @@ -256,12 +256,12 @@ fn cipher_init(config: InitConfig) -> Result, u32> { let initialising = Initialising::begin(); run(Box::pin(async move { let _initialising = initialising; - install( - builder - .init() - .await - .map_err(|e| crate::status::fail_error(&e))?, - ) + let cipher = builder + .init() + .await + .map_err(|e| crate::status::fail_error(&e))?; + let default = default_keyset_id(&cipher).await?; + install(cipher, default) })) } @@ -278,12 +278,12 @@ fn cipher_init(seed: InitConfig) -> Result, u32> { let initialising = Initialising::begin(); run(Box::pin(async move { let _initialising = initialising; - install( - builder - .init() - .await - .map_err(|e| crate::status::fail_error(&e))?, - ) + let cipher = builder + .init() + .await + .map_err(|e| crate::status::fail_error(&e))?; + let default = default_keyset_id(&cipher).await?; + install(cipher, default) })) } @@ -318,14 +318,24 @@ fn init_out_of_order() -> u32 { out_of_order("the cipher is already initialised or initialising, or the instance is shut down") } -/// Install the built cipher as the instance's and return its default -/// keyset's id. -fn install(cipher: GuestCipher) -> Result, u32> { +/// The id of the cipher's default keyset. `init` loaded that keyset, so +/// this makes no request. +async fn default_keyset_id(cipher: &GuestCipher) -> Result, u32> { + let id = cipher + .default_keyset() + .keyset_id() + .await + .map_err(|e| crate::status::fail_error(&e))?; + Ok(id.as_bytes().to_vec()) +} + +/// Install the built cipher as the instance's and return `default`, its +/// default keyset's id. +fn install(cipher: GuestCipher, default: Vec) -> Result, u32> { // A shutdown that overtook a paused init installs nothing. if SHUT_DOWN.with(Cell::get) { return Err(init_out_of_order()); } - let default = cipher.default_keyset().keyset_id().as_bytes().to_vec(); CIPHER.with(|c| *c.borrow_mut() = Some(Rc::new(cipher))); Ok(default) } @@ -377,7 +387,11 @@ pub unsafe extern "C" fn se_keyset(sel_ptr: *const u8, sel_len: u32) -> u64 { let cipher = cipher()?; run(Box::pin(async move { let keyset = selector.resolve(&cipher).await?; - Ok(keyset.keyset_id().as_bytes().to_vec()) + let id = keyset + .keyset_id() + .await + .map_err(|e| crate::status::fail_error(&e))?; + Ok(id.as_bytes().to_vec()) })) }) } @@ -500,8 +514,8 @@ pub unsafe extern "C" fn se_decrypt_record( ops::validate::record_tree(&record, &plan, options.context.as_ref())?; let cipher = cipher()?; run(Box::pin(async move { - let scope = scope_for(&cipher, &options.keyset).await?; - ops::decrypt_record(scope, &record, &plan, options.context).await + let cipher_ref = cipher_ref_for(&cipher, &options.keyset).await?; + ops::decrypt_record(cipher_ref, &record, &plan, options.context).await })) }) } diff --git a/languages/golang/encrypt/guest/src/ops.rs b/languages/golang/encrypt/guest/src/ops.rs index 14ffe2e751..0ce52f6b28 100644 --- a/languages/golang/encrypt/guest/src/ops.rs +++ b/languages/golang/encrypt/guest/src/ops.rs @@ -216,7 +216,7 @@ where /// were sealed under. The output buffer contains plaintext — the ABI layer's /// ownership rules govern its wiping. pub async fn decrypt_record<'a, K>( - scope: impl Into>, + cipher_ref: impl Into>, record: &[u8], plan: &Bytes, expected: Option