fix(server::tests): tighten unseal test seal_key params to &[u8; 32]
This commit is contained in:
@@ -235,7 +235,7 @@ mod tests {
|
|||||||
);
|
);
|
||||||
actor
|
actor
|
||||||
.ask(Bootstrap {
|
.ask(Bootstrap {
|
||||||
seal_key_raw: SafeCell::new(b"integrity-test-seal-key".to_vec()),
|
seal_key_raw: SafeCell::new([0u8; 32].to_vec()),
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ async fn spawn_test_actors(db: &db::DatabasePool) -> GlobalActors {
|
|||||||
actors
|
actors
|
||||||
.vault
|
.vault
|
||||||
.ask(Bootstrap {
|
.ask(Bootstrap {
|
||||||
seal_key_raw: SafeCell::new(b"test-seal-key".to_vec()),
|
seal_key_raw: SafeCell::new([0u8; 32].to_vec()),
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ pub(crate) async fn bootstrapped_vault(db: &db::DatabasePool) -> Vault {
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
actor
|
actor
|
||||||
.bootstrap(SafeCell::new(b"test-seal-key".to_vec()))
|
.bootstrap(SafeCell::new([0u8; 32].to_vec()))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
actor
|
actor
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ pub async fn bootstrap_token_auth() {
|
|||||||
actors
|
actors
|
||||||
.vault
|
.vault
|
||||||
.ask(Bootstrap {
|
.ask(Bootstrap {
|
||||||
seal_key_raw: SafeCell::new(b"test-seal-key".to_vec()),
|
seal_key_raw: SafeCell::new([0u8; 32].to_vec()),
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@@ -275,7 +275,7 @@ pub async fn challenge_auth() {
|
|||||||
actors
|
actors
|
||||||
.vault
|
.vault
|
||||||
.ask(Bootstrap {
|
.ask(Bootstrap {
|
||||||
seal_key_raw: SafeCell::new(b"test-seal-key".to_vec()),
|
seal_key_raw: SafeCell::new([0u8; 32].to_vec()),
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@@ -361,7 +361,7 @@ pub async fn challenge_auth_rejects_integrity_tag_mismatch_when_unsealed() {
|
|||||||
actors
|
actors
|
||||||
.vault
|
.vault
|
||||||
.ask(Bootstrap {
|
.ask(Bootstrap {
|
||||||
seal_key_raw: SafeCell::new(b"test-seal-key".to_vec()),
|
seal_key_raw: SafeCell::new([0u8; 32].to_vec()),
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@@ -434,7 +434,7 @@ pub async fn challenge_auth_rejects_invalid_signature() {
|
|||||||
actors
|
actors
|
||||||
.vault
|
.vault
|
||||||
.ask(Bootstrap {
|
.ask(Bootstrap {
|
||||||
seal_key_raw: SafeCell::new(b"test-seal-key".to_vec()),
|
seal_key_raw: SafeCell::new([0u8; 32].to_vec()),
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ use tokio::sync::oneshot;
|
|||||||
use x25519_dalek::{EphemeralSecret, PublicKey};
|
use x25519_dalek::{EphemeralSecret, PublicKey};
|
||||||
|
|
||||||
async fn setup_sealed_gate(
|
async fn setup_sealed_gate(
|
||||||
seal_key: &[u8],
|
seal_key: &[u8; 32],
|
||||||
) -> (
|
) -> (
|
||||||
db::DatabasePool,
|
db::DatabasePool,
|
||||||
kameo::actor::ActorRef<VaultGate>,
|
kameo::actor::ActorRef<VaultGate>,
|
||||||
@@ -50,7 +50,7 @@ async fn setup_sealed_gate(
|
|||||||
|
|
||||||
async fn client_dh_encrypt(
|
async fn client_dh_encrypt(
|
||||||
gate: &kameo::actor::ActorRef<VaultGate>,
|
gate: &kameo::actor::ActorRef<VaultGate>,
|
||||||
key_to_send: &[u8],
|
key_to_send: &[u8; 32],
|
||||||
) -> HandleUnsealEncryptedKey {
|
) -> HandleUnsealEncryptedKey {
|
||||||
let client_secret = EphemeralSecret::random();
|
let client_secret = EphemeralSecret::random();
|
||||||
let client_public = PublicKey::from(&client_secret);
|
let client_public = PublicKey::from(&client_secret);
|
||||||
@@ -83,7 +83,7 @@ async fn client_dh_encrypt(
|
|||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[test_log::test]
|
#[test_log::test]
|
||||||
pub async fn unseal_success() {
|
pub async fn unseal_success() {
|
||||||
let seal_key = b"test-seal-key";
|
let seal_key = b"test-seal-key-padded-to-32bytes!";
|
||||||
let (_db, gate, _promotion_rx) = setup_sealed_gate(seal_key).await;
|
let (_db, gate, _promotion_rx) = setup_sealed_gate(seal_key).await;
|
||||||
|
|
||||||
let encrypted_key = client_dh_encrypt(&gate, seal_key).await;
|
let encrypted_key = client_dh_encrypt(&gate, seal_key).await;
|
||||||
@@ -95,10 +95,10 @@ pub async fn unseal_success() {
|
|||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[test_log::test]
|
#[test_log::test]
|
||||||
pub async fn unseal_wrong_seal_key() {
|
pub async fn unseal_wrong_seal_key() {
|
||||||
let seal_key = b"test-seal-key";
|
let seal_key = b"test-seal-key-padded-to-32bytes!";
|
||||||
let (_db, gate, _promotion_rx) = setup_sealed_gate(seal_key).await;
|
let (_db, gate, _promotion_rx) = setup_sealed_gate(seal_key).await;
|
||||||
|
|
||||||
let encrypted_key = client_dh_encrypt(&gate, b"wrong-key").await;
|
let encrypted_key = client_dh_encrypt(&gate, b"wrong-key-padded-to-32-bytes!!!!").await;
|
||||||
|
|
||||||
let response = gate.ask(encrypted_key).await;
|
let response = gate.ask(encrypted_key).await;
|
||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
@@ -112,7 +112,7 @@ pub async fn unseal_wrong_seal_key() {
|
|||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[test_log::test]
|
#[test_log::test]
|
||||||
pub async fn unseal_corrupted_ciphertext() {
|
pub async fn unseal_corrupted_ciphertext() {
|
||||||
let seal_key = b"test-seal-key";
|
let seal_key = b"test-seal-key-padded-to-32bytes!";
|
||||||
let (_db, gate, _promotion_rx) = setup_sealed_gate(seal_key).await;
|
let (_db, gate, _promotion_rx) = setup_sealed_gate(seal_key).await;
|
||||||
|
|
||||||
let client_secret = EphemeralSecret::random();
|
let client_secret = EphemeralSecret::random();
|
||||||
@@ -143,11 +143,11 @@ pub async fn unseal_corrupted_ciphertext() {
|
|||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[test_log::test]
|
#[test_log::test]
|
||||||
pub async fn unseal_retry_after_invalid_key() {
|
pub async fn unseal_retry_after_invalid_key() {
|
||||||
let seal_key = b"real-seal-key";
|
let seal_key = b"real-seal-key-padded-to-32bytes!";
|
||||||
let (_db, gate, _promotion_rx) = setup_sealed_gate(seal_key).await;
|
let (_db, gate, _promotion_rx) = setup_sealed_gate(seal_key).await;
|
||||||
|
|
||||||
{
|
{
|
||||||
let encrypted_key = client_dh_encrypt(&gate, b"wrong-key").await;
|
let encrypted_key = client_dh_encrypt(&gate, b"wrong-key-padded-to-32-bytes!!!!").await;
|
||||||
|
|
||||||
let response = gate.ask(encrypted_key).await;
|
let response = gate.ask(encrypted_key).await;
|
||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ async fn decrypt_roundtrip_after_high_concurrency() {
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
decryptor
|
decryptor
|
||||||
.try_unseal(SafeCell::new(b"test-seal-key".to_vec()))
|
.try_unseal(SafeCell::new([0u8; 32].to_vec()))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ async fn test_bootstrap() {
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let seal_key = SafeCell::new(b"test-seal-key".to_vec());
|
let seal_key = SafeCell::new([0u8; 32].to_vec());
|
||||||
actor.bootstrap(seal_key).await.unwrap();
|
actor.bootstrap(seal_key).await.unwrap();
|
||||||
|
|
||||||
let mut conn = db.get().await.unwrap();
|
let mut conn = db.get().await.unwrap();
|
||||||
@@ -43,7 +43,7 @@ async fn test_bootstrap_rejects_double() {
|
|||||||
let db = db::create_test_pool().await;
|
let db = db::create_test_pool().await;
|
||||||
let mut actor = common::bootstrapped_vault(&db).await;
|
let mut actor = common::bootstrapped_vault(&db).await;
|
||||||
|
|
||||||
let seal_key2 = SafeCell::new(b"test-seal-key".to_vec());
|
let seal_key2 = SafeCell::new([0u8; 32].to_vec());
|
||||||
let err = actor.bootstrap(seal_key2).await.unwrap_err();
|
let err = actor.bootstrap(seal_key2).await.unwrap_err();
|
||||||
assert!(matches!(err, Error::AlreadyBootstrapped));
|
assert!(matches!(err, Error::AlreadyBootstrapped));
|
||||||
}
|
}
|
||||||
@@ -105,7 +105,7 @@ async fn test_unseal_correct_password() {
|
|||||||
let mut actor = Vault::new(db.clone(), GlobalActors::spawn_message_bus())
|
let mut actor = Vault::new(db.clone(), GlobalActors::spawn_message_bus())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let seal_key = SafeCell::new(b"test-seal-key".to_vec());
|
let seal_key = SafeCell::new([0u8; 32].to_vec());
|
||||||
actor.try_unseal(seal_key).await.unwrap();
|
actor.try_unseal(seal_key).await.unwrap();
|
||||||
|
|
||||||
let mut decrypted = actor.decrypt(aead_id).await.unwrap();
|
let mut decrypted = actor.decrypt(aead_id).await.unwrap();
|
||||||
@@ -129,11 +129,11 @@ async fn test_unseal_wrong_then_correct_password() {
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let bad_key = SafeCell::new(b"wrong-password".to_vec());
|
let bad_key = SafeCell::new([1u8; 32].to_vec());
|
||||||
let err = actor.try_unseal(bad_key).await.unwrap_err();
|
let err = actor.try_unseal(bad_key).await.unwrap_err();
|
||||||
assert!(matches!(err, Error::InvalidKey));
|
assert!(matches!(err, Error::InvalidKey));
|
||||||
|
|
||||||
let good_key = SafeCell::new(b"test-seal-key".to_vec());
|
let good_key = SafeCell::new([0u8; 32].to_vec());
|
||||||
actor.try_unseal(good_key).await.unwrap();
|
actor.try_unseal(good_key).await.unwrap();
|
||||||
|
|
||||||
let mut decrypted = actor.decrypt(aead_id).await.unwrap();
|
let mut decrypted = actor.decrypt(aead_id).await.unwrap();
|
||||||
|
|||||||
Reference in New Issue
Block a user