feat(vault)!: add multi-operator Shamir custody
This commit is contained in:
@@ -1,13 +1,10 @@
|
||||
use super::common::ChannelTransport;
|
||||
use arbiter_crypto::{
|
||||
authn::{self, AuthChallenge, OPERATOR_CONTEXT},
|
||||
safecell::{SafeCell, SafeCellHandle as _},
|
||||
};
|
||||
use arbiter_crypto::authn::{self, AuthChallenge, OPERATOR_CONTEXT};
|
||||
use arbiter_proto::transport::{Error as TransportError, Receiver, Sender};
|
||||
use arbiter_server::{
|
||||
actors::{GlobalActors, bootstrap::GetToken, vault::Bootstrap},
|
||||
crypto::integrity,
|
||||
db::{self, schema},
|
||||
crypto::{KeyCell, integrity},
|
||||
db::{self, models::OperatorId, schema},
|
||||
peers::operator::{self, Credentials, OperatorConnection, auth, vault_gate},
|
||||
};
|
||||
|
||||
@@ -154,13 +151,6 @@ impl Sender<auth::Inbound> for StartTestTransport {
|
||||
pub async fn bootstrap_token_auth() {
|
||||
let db = db::create_test_pool().await;
|
||||
let actors = GlobalActors::spawn(db.clone()).await.unwrap();
|
||||
actors
|
||||
.vault
|
||||
.ask(Bootstrap {
|
||||
seal_key_raw: SafeCell::new(b"test-seal-key".to_vec()),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
let token = actors.bootstrapper.ask(GetToken).await.unwrap().unwrap();
|
||||
|
||||
let (mut server_transport, mut test_transport) = ChannelTransport::new();
|
||||
@@ -275,7 +265,8 @@ pub async fn challenge_auth() {
|
||||
actors
|
||||
.vault
|
||||
.ask(Bootstrap {
|
||||
seal_key_raw: SafeCell::new(b"test-seal-key".to_vec()),
|
||||
seal_key: KeyCell::from([0u8; 32]),
|
||||
custody: None,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -285,10 +276,10 @@ pub async fn challenge_auth() {
|
||||
|
||||
{
|
||||
let mut conn = db.get().await.unwrap();
|
||||
let id: i32 = insert_into(schema::operator_identity::table)
|
||||
let id: OperatorId = insert_into(schema::operator_identity::table)
|
||||
.values((schema::operator_identity::public_key.eq(pubkey_bytes.clone()),))
|
||||
.returning(schema::operator_identity::id)
|
||||
.get_result(&mut conn)
|
||||
.get_result::<OperatorId>(&mut conn)
|
||||
.await
|
||||
.unwrap();
|
||||
integrity::sign_entity(
|
||||
@@ -361,7 +352,8 @@ pub async fn challenge_auth_rejects_integrity_tag_mismatch_when_unsealed() {
|
||||
actors
|
||||
.vault
|
||||
.ask(Bootstrap {
|
||||
seal_key_raw: SafeCell::new(b"test-seal-key".to_vec()),
|
||||
seal_key: KeyCell::from([0u8; 32]),
|
||||
custody: None,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -434,7 +426,8 @@ pub async fn challenge_auth_rejects_invalid_signature() {
|
||||
actors
|
||||
.vault
|
||||
.ask(Bootstrap {
|
||||
seal_key_raw: SafeCell::new(b"test-seal-key".to_vec()),
|
||||
seal_key: KeyCell::from([0u8; 32]),
|
||||
custody: None,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -444,10 +437,10 @@ pub async fn challenge_auth_rejects_invalid_signature() {
|
||||
|
||||
{
|
||||
let mut conn = db.get().await.unwrap();
|
||||
let id: i32 = insert_into(schema::operator_identity::table)
|
||||
let id: OperatorId = insert_into(schema::operator_identity::table)
|
||||
.values((schema::operator_identity::public_key.eq(pubkey_bytes.clone()),))
|
||||
.returning(schema::operator_identity::id)
|
||||
.get_result(&mut conn)
|
||||
.get_result::<OperatorId>(&mut conn)
|
||||
.await
|
||||
.unwrap();
|
||||
integrity::sign_entity(
|
||||
@@ -506,3 +499,92 @@ pub async fn challenge_auth_rejects_invalid_signature() {
|
||||
Err(auth::Error::InvalidChallengeSolution)
|
||||
));
|
||||
}
|
||||
|
||||
/// The bootstrap token authorises registering committee members *before* the
|
||||
/// vault exists. Once any bootstrap path succeeds it must stop working, or its
|
||||
/// holder could keep minting operator identities until the next restart.
|
||||
#[tokio::test]
|
||||
#[test_log::test]
|
||||
pub async fn bootstrap_token_rejected_after_bootstrap() {
|
||||
let db = db::create_test_pool().await;
|
||||
let actors = GlobalActors::spawn(db.clone()).await.unwrap();
|
||||
let token = actors.bootstrapper.ask(GetToken).await.unwrap().unwrap();
|
||||
|
||||
actors
|
||||
.vault
|
||||
.ask(Bootstrap {
|
||||
seal_key: KeyCell::from([0u8; 32]),
|
||||
custody: None,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// `Bootstrapped` travels through the message bus, so the token disappears
|
||||
// a couple of actor turns after the bootstrap call returns.
|
||||
let mut retired = false;
|
||||
for _ in 0..100 {
|
||||
if actors.bootstrapper.ask(GetToken).await.unwrap().is_none() {
|
||||
retired = true;
|
||||
break;
|
||||
}
|
||||
tokio::task::yield_now().await;
|
||||
}
|
||||
assert!(
|
||||
retired,
|
||||
"the bootstrap token must be retired once the vault is bootstrapped"
|
||||
);
|
||||
|
||||
let (mut server_transport, mut test_transport) = ChannelTransport::new();
|
||||
let db_for_task = db.clone();
|
||||
let task = tokio::spawn(async move {
|
||||
let mut props = OperatorConnection::new(db_for_task, actors);
|
||||
auth::authenticate(&mut props, &mut server_transport).await
|
||||
});
|
||||
|
||||
let new_key = MlDsa87::key_gen(&mut rand::rng());
|
||||
test_transport
|
||||
.send(auth::Inbound::AuthChallengeRequest {
|
||||
pubkey: verifying_key(&new_key).into(),
|
||||
bootstrap_token: Some(token.into_bytes()),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let response = test_transport
|
||||
.recv()
|
||||
.await
|
||||
.expect("should receive challenge");
|
||||
let challenge = match response {
|
||||
Ok(auth::Outbound::AuthChallenge { challenge }) => challenge,
|
||||
other => panic!("Expected AuthChallenge, got {other:?}"),
|
||||
};
|
||||
|
||||
let signature = sign_operator_challenge(&new_key, &challenge);
|
||||
test_transport
|
||||
.send(auth::Inbound::AuthChallengeSolution {
|
||||
signature: signature.to_bytes(),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let response = test_transport
|
||||
.recv()
|
||||
.await
|
||||
.expect("should receive auth result");
|
||||
assert!(
|
||||
matches!(response, Err(auth::Error::InvalidBootstrapToken)),
|
||||
"a spent bootstrap token must not authorise a new identity, got {response:?}"
|
||||
);
|
||||
assert!(task.await.unwrap().is_err(), "authentication must fail");
|
||||
|
||||
let mut conn = db.get().await.unwrap();
|
||||
let registered: i64 = schema::operator_identity::table
|
||||
.count()
|
||||
.get_result(&mut conn)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
registered, 0,
|
||||
"no identity may be registered after the bootstrap"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
use arbiter_crypto::{
|
||||
authn,
|
||||
safecell::{SafeCell, SafeCellHandle as _},
|
||||
};
|
||||
use arbiter_crypto::authn;
|
||||
use arbiter_server::{
|
||||
actors::{
|
||||
GlobalActors,
|
||||
vault::{Bootstrap, Seal},
|
||||
},
|
||||
db,
|
||||
crypto::KeyCell,
|
||||
db::{self, models::OperatorId},
|
||||
peers::operator::{
|
||||
Credentials,
|
||||
vault_gate::{
|
||||
@@ -22,7 +20,7 @@ use tokio::sync::oneshot;
|
||||
use x25519_dalek::{EphemeralSecret, PublicKey};
|
||||
|
||||
async fn setup_sealed_gate(
|
||||
seal_key: &[u8],
|
||||
seal_key: [u8; 32],
|
||||
) -> (
|
||||
db::DatabasePool,
|
||||
kameo::actor::ActorRef<VaultGate>,
|
||||
@@ -34,7 +32,8 @@ async fn setup_sealed_gate(
|
||||
actors
|
||||
.vault
|
||||
.ask(Bootstrap {
|
||||
seal_key_raw: SafeCell::new(seal_key.to_vec()),
|
||||
seal_key: KeyCell::from(seal_key),
|
||||
custody: None,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -42,7 +41,10 @@ async fn setup_sealed_gate(
|
||||
|
||||
let (promotion_tx, promotion_rx) = oneshot::channel();
|
||||
let pubkey = authn::SigningKey::generate().public_key();
|
||||
let auth_creds = Credentials { id: 1, pubkey };
|
||||
let auth_creds = Credentials {
|
||||
id: OperatorId::from_raw(1),
|
||||
pubkey,
|
||||
};
|
||||
let gate = VaultGate::spawn(VaultGate::new(auth_creds, actors, db.clone(), promotion_tx));
|
||||
|
||||
(db, gate, promotion_rx)
|
||||
@@ -83,10 +85,10 @@ async fn client_dh_encrypt(
|
||||
#[tokio::test]
|
||||
#[test_log::test]
|
||||
pub async fn unseal_success() {
|
||||
let seal_key = b"test-seal-key";
|
||||
let seal_key = [7u8; 32];
|
||||
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;
|
||||
|
||||
let response = gate.ask(encrypted_key).await;
|
||||
assert!(matches!(response, Ok(())));
|
||||
@@ -95,10 +97,10 @@ pub async fn unseal_success() {
|
||||
#[tokio::test]
|
||||
#[test_log::test]
|
||||
pub async fn unseal_wrong_seal_key() {
|
||||
let seal_key = b"test-seal-key";
|
||||
let seal_key = [7u8; 32];
|
||||
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, &[8u8; 32]).await;
|
||||
|
||||
let response = gate.ask(encrypted_key).await;
|
||||
assert!(matches!(
|
||||
@@ -112,7 +114,7 @@ pub async fn unseal_wrong_seal_key() {
|
||||
#[tokio::test]
|
||||
#[test_log::test]
|
||||
pub async fn unseal_corrupted_ciphertext() {
|
||||
let seal_key = b"test-seal-key";
|
||||
let seal_key = [7u8; 32];
|
||||
let (_db, gate, _promotion_rx) = setup_sealed_gate(seal_key).await;
|
||||
|
||||
let client_secret = EphemeralSecret::random();
|
||||
@@ -143,11 +145,11 @@ pub async fn unseal_corrupted_ciphertext() {
|
||||
#[tokio::test]
|
||||
#[test_log::test]
|
||||
pub async fn unseal_retry_after_invalid_key() {
|
||||
let seal_key = b"real-seal-key";
|
||||
let seal_key = [9u8; 32];
|
||||
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, &[8u8; 32]).await;
|
||||
|
||||
let response = gate.ask(encrypted_key).await;
|
||||
assert!(matches!(
|
||||
@@ -159,7 +161,7 @@ pub async fn unseal_retry_after_invalid_key() {
|
||||
}
|
||||
|
||||
{
|
||||
let encrypted_key = client_dh_encrypt(&gate, seal_key).await;
|
||||
let encrypted_key = client_dh_encrypt(&gate, &seal_key).await;
|
||||
|
||||
let response = gate.ask(encrypted_key).await;
|
||||
assert!(matches!(response, Ok(())));
|
||||
|
||||
Reference in New Issue
Block a user