refactor(server): removed miette out of server
This commit is contained in:
2
server/Cargo.lock
generated
2
server/Cargo.lock
generated
@@ -724,6 +724,7 @@ name = "arbiter-server"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"alloy",
|
"alloy",
|
||||||
|
"anyhow",
|
||||||
"arbiter-proto",
|
"arbiter-proto",
|
||||||
"arbiter-tokens-registry",
|
"arbiter-tokens-registry",
|
||||||
"argon2",
|
"argon2",
|
||||||
@@ -741,7 +742,6 @@ dependencies = [
|
|||||||
"k256",
|
"k256",
|
||||||
"kameo",
|
"kameo",
|
||||||
"memsafe",
|
"memsafe",
|
||||||
"miette",
|
|
||||||
"pem",
|
"pem",
|
||||||
"prost-types",
|
"prost-types",
|
||||||
"rand 0.10.0",
|
"rand 0.10.0",
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ chrono = { version = "0.4.44", features = ["serde"] }
|
|||||||
rand = "0.10.0"
|
rand = "0.10.0"
|
||||||
rustls = { version = "0.23.37", features = ["aws-lc-rs"] }
|
rustls = { version = "0.23.37", features = ["aws-lc-rs"] }
|
||||||
smlang = "0.8.0"
|
smlang = "0.8.0"
|
||||||
miette = { version = "7.6.0", features = ["fancy", "serde"] }
|
|
||||||
thiserror = "2.0.18"
|
thiserror = "2.0.18"
|
||||||
async-trait = "0.1.89"
|
async-trait = "0.1.89"
|
||||||
futures = "0.3.32"
|
futures = "0.3.32"
|
||||||
@@ -43,3 +42,4 @@ k256 = { version = "0.13.4", features = ["ecdsa", "pkcs8"] }
|
|||||||
rsa = { version = "0.9", features = ["sha2"] }
|
rsa = { version = "0.9", features = ["sha2"] }
|
||||||
sha2 = "0.10"
|
sha2 = "0.10"
|
||||||
spki = "0.7"
|
spki = "0.7"
|
||||||
|
miette = { version = "7.6.0", features = ["fancy", "serde"] }
|
||||||
@@ -122,9 +122,7 @@ async fn receive_auth_confirmation(
|
|||||||
.await
|
.await
|
||||||
.map_err(|_| AuthError::UnexpectedAuthResponse)?;
|
.map_err(|_| AuthError::UnexpectedAuthResponse)?;
|
||||||
|
|
||||||
let payload = response
|
let payload = response.payload.ok_or(AuthError::UnexpectedAuthResponse)?;
|
||||||
.payload
|
|
||||||
.ok_or(AuthError::UnexpectedAuthResponse)?;
|
|
||||||
match payload {
|
match payload {
|
||||||
ClientResponsePayload::Auth(response) => match response.payload {
|
ClientResponsePayload::Auth(response) => match response.payload {
|
||||||
Some(AuthResponsePayload::Result(result))
|
Some(AuthResponsePayload::Result(result))
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
|
|
||||||
use arbiter_client::ArbiterClient;
|
use arbiter_client::ArbiterClient;
|
||||||
@@ -22,8 +21,6 @@ async fn main() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let url = match ArbiterUrl::try_from(input) {
|
let url = match ArbiterUrl::try_from(input) {
|
||||||
Ok(url) => url,
|
Ok(url) => url,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
use arbiter_proto::{ClientMetadata, proto::arbiter_service_client::ArbiterServiceClient, url::ArbiterUrl};
|
use arbiter_proto::{
|
||||||
|
ClientMetadata, proto::arbiter_service_client::ArbiterServiceClient, url::ArbiterUrl,
|
||||||
|
};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::{Mutex, mpsc};
|
use tokio::sync::{Mutex, mpsc};
|
||||||
use tokio_stream::wrappers::ReceiverStream;
|
use tokio_stream::wrappers::ReceiverStream;
|
||||||
use tonic::transport::ClientTlsConfig;
|
use tonic::transport::ClientTlsConfig;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
StorageError, auth::{AuthError, authenticate}, storage::{FileSigningKeyStorage, SigningKeyStorage}, transport::{BUFFER_LENGTH, ClientTransport}
|
StorageError,
|
||||||
|
auth::{AuthError, authenticate},
|
||||||
|
storage::{FileSigningKeyStorage, SigningKeyStorage},
|
||||||
|
transport::{BUFFER_LENGTH, ClientTransport},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "evm")]
|
#[cfg(feature = "evm")]
|
||||||
@@ -30,7 +35,6 @@ pub enum Error {
|
|||||||
|
|
||||||
#[error("Storage error")]
|
#[error("Storage error")]
|
||||||
Storage(#[from] StorageError),
|
Storage(#[from] StorageError),
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ArbiterClient {
|
pub struct ArbiterClient {
|
||||||
@@ -61,7 +65,8 @@ impl ArbiterClient {
|
|||||||
let anchor = webpki::anchor_from_trusted_cert(&url.ca_cert)?.to_owned();
|
let anchor = webpki::anchor_from_trusted_cert(&url.ca_cert)?.to_owned();
|
||||||
let tls = ClientTlsConfig::new().trust_anchor(anchor);
|
let tls = ClientTlsConfig::new().trust_anchor(anchor);
|
||||||
|
|
||||||
let channel = tonic::transport::Channel::from_shared(format!("https://{}:{}", url.host, url.port))?
|
let channel =
|
||||||
|
tonic::transport::Channel::from_shared(format!("https://{}:{}", url.host, url.port))?
|
||||||
.tls_config(tls)?
|
.tls_config(tls)?
|
||||||
.connect()
|
.connect()
|
||||||
.await?;
|
.await?;
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ const ARBITER_URL_SCHEME: &str = "arbiter";
|
|||||||
const CERT_QUERY_KEY: &str = "cert";
|
const CERT_QUERY_KEY: &str = "cert";
|
||||||
const BOOTSTRAP_TOKEN_QUERY_KEY: &str = "bootstrap_token";
|
const BOOTSTRAP_TOKEN_QUERY_KEY: &str = "bootstrap_token";
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct ArbiterUrl {
|
pub struct ArbiterUrl {
|
||||||
pub host: String,
|
pub host: String,
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ tonic.features = ["tls-aws-lc"]
|
|||||||
tokio.workspace = true
|
tokio.workspace = true
|
||||||
rustls.workspace = true
|
rustls.workspace = true
|
||||||
smlang.workspace = true
|
smlang.workspace = true
|
||||||
miette.workspace = true
|
|
||||||
thiserror.workspace = true
|
thiserror.workspace = true
|
||||||
fatality = "0.1.1"
|
fatality = "0.1.1"
|
||||||
diesel_migrations = { version = "2.3.1", features = ["sqlite"] }
|
diesel_migrations = { version = "2.3.1", features = ["sqlite"] }
|
||||||
@@ -53,6 +52,7 @@ spki.workspace = true
|
|||||||
alloy.workspace = true
|
alloy.workspace = true
|
||||||
prost-types.workspace = true
|
prost-types.workspace = true
|
||||||
arbiter-tokens-registry.path = "../arbiter-tokens-registry"
|
arbiter-tokens-registry.path = "../arbiter-tokens-registry"
|
||||||
|
anyhow = "1.0.102"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
insta = "1.46.3"
|
insta = "1.46.3"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use arbiter_proto::{BOOTSTRAP_PATH, home_path};
|
|||||||
use diesel::QueryDsl;
|
use diesel::QueryDsl;
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
use kameo::{Actor, messages};
|
use kameo::{Actor, messages};
|
||||||
use miette::Diagnostic;
|
|
||||||
use rand::{RngExt, distr::Alphanumeric, make_rng, rngs::StdRng};
|
use rand::{RngExt, distr::Alphanumeric, make_rng, rngs::StdRng};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
@@ -25,18 +25,15 @@ pub async fn generate_token() -> Result<String, std::io::Error> {
|
|||||||
Ok(token)
|
Ok(token)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Error, Debug, Diagnostic)]
|
#[derive(Error, Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("Database error: {0}")]
|
#[error("Database error: {0}")]
|
||||||
#[diagnostic(code(arbiter_server::bootstrap::database))]
|
|
||||||
Database(#[from] db::PoolError),
|
Database(#[from] db::PoolError),
|
||||||
|
|
||||||
#[error("Database query error: {0}")]
|
#[error("Database query error: {0}")]
|
||||||
#[diagnostic(code(arbiter_server::bootstrap::database_query))]
|
|
||||||
Query(#[from] diesel::result::Error),
|
Query(#[from] diesel::result::Error),
|
||||||
|
|
||||||
#[error("I/O error: {0}")]
|
#[error("I/O error: {0}")]
|
||||||
#[diagnostic(code(arbiter_server::bootstrap::io))]
|
|
||||||
Io(#[from] std::io::Error),
|
Io(#[from] std::io::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -287,10 +287,7 @@ where
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn authenticate<T>(
|
pub async fn authenticate<T>(props: &mut ClientConnection, transport: &mut T) -> Result<i32, Error>
|
||||||
props: &mut ClientConnection,
|
|
||||||
transport: &mut T,
|
|
||||||
) -> Result<i32, Error>
|
|
||||||
where
|
where
|
||||||
T: Bi<Inbound, Result<Outbound, Error>> + Send + ?Sized,
|
T: Bi<Inbound, Result<Outbound, Error>> + Send + ?Sized,
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,10 +20,7 @@ pub struct ClientConnection {
|
|||||||
|
|
||||||
impl ClientConnection {
|
impl ClientConnection {
|
||||||
pub fn new(db: db::DatabasePool, actors: GlobalActors) -> Self {
|
pub fn new(db: db::DatabasePool, actors: GlobalActors) -> Self {
|
||||||
Self {
|
Self { db, actors }
|
||||||
db,
|
|
||||||
actors,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,11 +6,10 @@ use alloy::{consensus::TxEip1559, primitives::Address, signers::Signature};
|
|||||||
use crate::{
|
use crate::{
|
||||||
actors::{
|
actors::{
|
||||||
GlobalActors,
|
GlobalActors,
|
||||||
client::ClientConnection, flow_coordinator::RegisterClient,
|
client::ClientConnection,
|
||||||
|
|
||||||
evm::{ClientSignTransaction, SignTransactionError},
|
evm::{ClientSignTransaction, SignTransactionError},
|
||||||
|
flow_coordinator::RegisterClient,
|
||||||
keyholder::KeyHolderState,
|
keyholder::KeyHolderState,
|
||||||
|
|
||||||
},
|
},
|
||||||
db,
|
db,
|
||||||
evm::VetError,
|
evm::VetError,
|
||||||
@@ -95,7 +94,10 @@ impl Actor for ClientSession {
|
|||||||
impl ClientSession {
|
impl ClientSession {
|
||||||
pub fn new_test(db: db::DatabasePool, actors: GlobalActors) -> Self {
|
pub fn new_test(db: db::DatabasePool, actors: GlobalActors) -> Self {
|
||||||
let props = ClientConnection::new(db, actors);
|
let props = ClientConnection::new(db, actors);
|
||||||
Self { props, client_id: 0 }
|
Self {
|
||||||
|
props,
|
||||||
|
client_id: 0,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,45 +25,36 @@ use crate::{
|
|||||||
|
|
||||||
pub use crate::evm::safe_signer;
|
pub use crate::evm::safe_signer;
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error, miette::Diagnostic)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
pub enum SignTransactionError {
|
pub enum SignTransactionError {
|
||||||
#[error("Wallet not found")]
|
#[error("Wallet not found")]
|
||||||
#[diagnostic(code(arbiter::evm::sign::wallet_not_found))]
|
|
||||||
WalletNotFound,
|
WalletNotFound,
|
||||||
|
|
||||||
#[error("Database error: {0}")]
|
#[error("Database error: {0}")]
|
||||||
#[diagnostic(code(arbiter::evm::sign::database))]
|
|
||||||
Database(#[from] DatabaseError),
|
Database(#[from] DatabaseError),
|
||||||
|
|
||||||
#[error("Keyholder error: {0}")]
|
#[error("Keyholder error: {0}")]
|
||||||
#[diagnostic(code(arbiter::evm::sign::keyholder))]
|
|
||||||
Keyholder(#[from] crate::actors::keyholder::Error),
|
Keyholder(#[from] crate::actors::keyholder::Error),
|
||||||
|
|
||||||
#[error("Keyholder mailbox error")]
|
#[error("Keyholder mailbox error")]
|
||||||
#[diagnostic(code(arbiter::evm::sign::keyholder_send))]
|
|
||||||
KeyholderSend,
|
KeyholderSend,
|
||||||
|
|
||||||
#[error("Signing error: {0}")]
|
#[error("Signing error: {0}")]
|
||||||
#[diagnostic(code(arbiter::evm::sign::signing))]
|
|
||||||
Signing(#[from] alloy::signers::Error),
|
Signing(#[from] alloy::signers::Error),
|
||||||
|
|
||||||
#[error("Policy error: {0}")]
|
#[error("Policy error: {0}")]
|
||||||
#[diagnostic(code(arbiter::evm::sign::vet))]
|
|
||||||
Vet(#[from] evm::VetError),
|
Vet(#[from] evm::VetError),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error, miette::Diagnostic)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("Keyholder error: {0}")]
|
#[error("Keyholder error: {0}")]
|
||||||
#[diagnostic(code(arbiter::evm::keyholder))]
|
|
||||||
Keyholder(#[from] crate::actors::keyholder::Error),
|
Keyholder(#[from] crate::actors::keyholder::Error),
|
||||||
|
|
||||||
#[error("Keyholder mailbox error")]
|
#[error("Keyholder mailbox error")]
|
||||||
#[diagnostic(code(arbiter::evm::keyholder_send))]
|
|
||||||
KeyholderSend,
|
KeyholderSend,
|
||||||
|
|
||||||
#[error("Database error: {0}")]
|
#[error("Database error: {0}")]
|
||||||
#[diagnostic(code(arbiter::evm::database))]
|
|
||||||
Database(#[from] DatabaseError),
|
Database(#[from] DatabaseError),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ use crate::actors::{
|
|||||||
pub struct Args {
|
pub struct Args {
|
||||||
pub client: ClientProfile,
|
pub client: ClientProfile,
|
||||||
pub user_agents: Vec<ActorRef<UserAgentSession>>,
|
pub user_agents: Vec<ActorRef<UserAgentSession>>,
|
||||||
pub reply: ReplySender<Result<bool, ApprovalError>>
|
pub reply: ReplySender<Result<bool, ApprovalError>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ClientApprovalController {
|
pub struct ClientApprovalController {
|
||||||
@@ -39,7 +39,11 @@ impl Actor for ClientApprovalController {
|
|||||||
type Error = ();
|
type Error = ();
|
||||||
|
|
||||||
async fn on_start(
|
async fn on_start(
|
||||||
Args { client, mut user_agents, reply }: Self::Args,
|
Args {
|
||||||
|
client,
|
||||||
|
mut user_agents,
|
||||||
|
reply,
|
||||||
|
}: Self::Args,
|
||||||
actor_ref: ActorRef<Self>,
|
actor_ref: ActorRef<Self>,
|
||||||
) -> Result<Self, Self::Error> {
|
) -> Result<Self, Self::Error> {
|
||||||
let this = Self {
|
let this = Self {
|
||||||
|
|||||||
@@ -35,36 +35,28 @@ enum State {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error, miette::Diagnostic)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("Keyholder is already bootstrapped")]
|
#[error("Keyholder is already bootstrapped")]
|
||||||
#[diagnostic(code(arbiter::keyholder::already_bootstrapped))]
|
|
||||||
AlreadyBootstrapped,
|
AlreadyBootstrapped,
|
||||||
#[error("Keyholder is not bootstrapped")]
|
#[error("Keyholder is not bootstrapped")]
|
||||||
#[diagnostic(code(arbiter::keyholder::not_bootstrapped))]
|
|
||||||
NotBootstrapped,
|
NotBootstrapped,
|
||||||
#[error("Invalid key provided")]
|
#[error("Invalid key provided")]
|
||||||
#[diagnostic(code(arbiter::keyholder::invalid_key))]
|
|
||||||
InvalidKey,
|
InvalidKey,
|
||||||
|
|
||||||
#[error("Requested aead entry not found")]
|
#[error("Requested aead entry not found")]
|
||||||
#[diagnostic(code(arbiter::keyholder::aead_not_found))]
|
|
||||||
NotFound,
|
NotFound,
|
||||||
|
|
||||||
#[error("Encryption error: {0}")]
|
#[error("Encryption error: {0}")]
|
||||||
#[diagnostic(code(arbiter::keyholder::encryption_error))]
|
|
||||||
Encryption(#[from] chacha20poly1305::aead::Error),
|
Encryption(#[from] chacha20poly1305::aead::Error),
|
||||||
|
|
||||||
#[error("Database error: {0}")]
|
#[error("Database error: {0}")]
|
||||||
#[diagnostic(code(arbiter::keyholder::database_error))]
|
|
||||||
DatabaseConnection(#[from] db::PoolError),
|
DatabaseConnection(#[from] db::PoolError),
|
||||||
|
|
||||||
#[error("Database transaction error: {0}")]
|
#[error("Database transaction error: {0}")]
|
||||||
#[diagnostic(code(arbiter::keyholder::database_transaction_error))]
|
|
||||||
DatabaseTransaction(#[from] diesel::result::Error),
|
DatabaseTransaction(#[from] diesel::result::Error),
|
||||||
|
|
||||||
#[error("Broken database")]
|
#[error("Broken database")]
|
||||||
#[diagnostic(code(arbiter::keyholder::broken_database))]
|
|
||||||
BrokenDatabase,
|
BrokenDatabase,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
use kameo::actor::{ActorRef, Spawn};
|
use kameo::actor::{ActorRef, Spawn};
|
||||||
use miette::Diagnostic;
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -17,14 +16,12 @@ pub mod flow_coordinator;
|
|||||||
pub mod keyholder;
|
pub mod keyholder;
|
||||||
pub mod user_agent;
|
pub mod user_agent;
|
||||||
|
|
||||||
#[derive(Error, Debug, Diagnostic)]
|
#[derive(Error, Debug)]
|
||||||
pub enum SpawnError {
|
pub enum SpawnError {
|
||||||
#[error("Failed to spawn Bootstrapper actor")]
|
#[error("Failed to spawn Bootstrapper actor")]
|
||||||
#[diagnostic(code(SpawnError::Bootstrapper))]
|
|
||||||
Bootstrapper(#[from] bootstrap::Error),
|
Bootstrapper(#[from] bootstrap::Error),
|
||||||
|
|
||||||
#[error("Failed to spawn KeyHolder actor")]
|
#[error("Failed to spawn KeyHolder actor")]
|
||||||
#[diagnostic(code(SpawnError::KeyHolder))]
|
|
||||||
KeyHolder(#[from] keyholder::Error),
|
KeyHolder(#[from] keyholder::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ use chacha20poly1305::{AeadInPlace, XChaCha20Poly1305, XNonce, aead::KeyInit};
|
|||||||
use diesel::{ExpressionMethods as _, QueryDsl as _, SelectableHelper};
|
use diesel::{ExpressionMethods as _, QueryDsl as _, SelectableHelper};
|
||||||
use diesel_async::{AsyncConnection, RunQueryDsl};
|
use diesel_async::{AsyncConnection, RunQueryDsl};
|
||||||
use kameo::error::SendError;
|
use kameo::error::SendError;
|
||||||
use kameo::prelude::Context;
|
|
||||||
use kameo::messages;
|
use kameo::messages;
|
||||||
|
use kameo::prelude::Context;
|
||||||
use tracing::{error, info};
|
use tracing::{error, info};
|
||||||
use x25519_dalek::{EphemeralSecret, PublicKey};
|
use x25519_dalek::{EphemeralSecret, PublicKey};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use miette::Diagnostic;
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -11,30 +10,24 @@ use crate::{
|
|||||||
|
|
||||||
pub mod tls;
|
pub mod tls;
|
||||||
|
|
||||||
#[derive(Error, Debug, Diagnostic)]
|
#[derive(Error, Debug)]
|
||||||
pub enum InitError {
|
pub enum InitError {
|
||||||
#[error("Database setup failed: {0}")]
|
#[error("Database setup failed: {0}")]
|
||||||
#[diagnostic(code(arbiter_server::init::database_setup))]
|
|
||||||
DatabaseSetup(#[from] db::DatabaseSetupError),
|
DatabaseSetup(#[from] db::DatabaseSetupError),
|
||||||
|
|
||||||
#[error("Connection acquire failed: {0}")]
|
#[error("Connection acquire failed: {0}")]
|
||||||
#[diagnostic(code(arbiter_server::init::database_pool))]
|
|
||||||
DatabasePool(#[from] db::PoolError),
|
DatabasePool(#[from] db::PoolError),
|
||||||
|
|
||||||
#[error("Database query error: {0}")]
|
#[error("Database query error: {0}")]
|
||||||
#[diagnostic(code(arbiter_server::init::database_query))]
|
|
||||||
DatabaseQuery(#[from] diesel::result::Error),
|
DatabaseQuery(#[from] diesel::result::Error),
|
||||||
|
|
||||||
#[error("TLS initialization failed: {0}")]
|
#[error("TLS initialization failed: {0}")]
|
||||||
#[diagnostic(code(arbiter_server::init::tls_init))]
|
|
||||||
Tls(#[from] tls::InitError),
|
Tls(#[from] tls::InitError),
|
||||||
|
|
||||||
#[error("Actor spawn failed: {0}")]
|
#[error("Actor spawn failed: {0}")]
|
||||||
#[diagnostic(code(arbiter_server::init::actor_spawn))]
|
|
||||||
ActorSpawn(#[from] crate::actors::SpawnError),
|
ActorSpawn(#[from] crate::actors::SpawnError),
|
||||||
|
|
||||||
#[error("I/O Error: {0}")]
|
#[error("I/O Error: {0}")]
|
||||||
#[diagnostic(code(arbiter_server::init::io))]
|
|
||||||
Io(#[from] std::io::Error),
|
Io(#[from] std::io::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use std::{net::IpAddr, string::FromUtf8Error};
|
|||||||
|
|
||||||
use diesel::{ExpressionMethods as _, QueryDsl, SelectableHelper as _};
|
use diesel::{ExpressionMethods as _, QueryDsl, SelectableHelper as _};
|
||||||
use diesel_async::{AsyncConnection, RunQueryDsl};
|
use diesel_async::{AsyncConnection, RunQueryDsl};
|
||||||
use miette::Diagnostic;
|
|
||||||
use pem::Pem;
|
use pem::Pem;
|
||||||
use rcgen::{
|
use rcgen::{
|
||||||
BasicConstraints, Certificate, CertificateParams, CertifiedIssuer, DistinguishedName, DnType,
|
BasicConstraints, Certificate, CertificateParams, CertifiedIssuer, DistinguishedName, DnType,
|
||||||
@@ -29,30 +29,24 @@ const ENCODE_CONFIG: pem::EncodeConfig = {
|
|||||||
pem::EncodeConfig::new().set_line_ending(line_ending)
|
pem::EncodeConfig::new().set_line_ending(line_ending)
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Error, Debug, Diagnostic)]
|
#[derive(Error, Debug)]
|
||||||
pub enum InitError {
|
pub enum InitError {
|
||||||
#[error("Key generation error during TLS initialization: {0}")]
|
#[error("Key generation error during TLS initialization: {0}")]
|
||||||
#[diagnostic(code(arbiter_server::tls_init::key_generation))]
|
|
||||||
KeyGeneration(#[from] rcgen::Error),
|
KeyGeneration(#[from] rcgen::Error),
|
||||||
|
|
||||||
#[error("Key invalid format: {0}")]
|
#[error("Key invalid format: {0}")]
|
||||||
#[diagnostic(code(arbiter_server::tls_init::key_invalid_format))]
|
|
||||||
KeyInvalidFormat(#[from] FromUtf8Error),
|
KeyInvalidFormat(#[from] FromUtf8Error),
|
||||||
|
|
||||||
#[error("Key deserialization error: {0}")]
|
#[error("Key deserialization error: {0}")]
|
||||||
#[diagnostic(code(arbiter_server::tls_init::key_deserialization))]
|
|
||||||
KeyDeserializationError(rcgen::Error),
|
KeyDeserializationError(rcgen::Error),
|
||||||
|
|
||||||
#[error("Database error during TLS initialization: {0}")]
|
#[error("Database error during TLS initialization: {0}")]
|
||||||
#[diagnostic(code(arbiter_server::tls_init::database_error))]
|
|
||||||
DatabaseError(#[from] diesel::result::Error),
|
DatabaseError(#[from] diesel::result::Error),
|
||||||
|
|
||||||
#[error("Pem deserialization error during TLS initialization: {0}")]
|
#[error("Pem deserialization error during TLS initialization: {0}")]
|
||||||
#[diagnostic(code(arbiter_server::tls_init::pem_deserialization))]
|
|
||||||
PemDeserializationError(#[from] rustls::pki_types::pem::Error),
|
PemDeserializationError(#[from] rustls::pki_types::pem::Error),
|
||||||
|
|
||||||
#[error("Database pool acquire error during TLS initialization: {0}")]
|
#[error("Database pool acquire error during TLS initialization: {0}")]
|
||||||
#[diagnostic(code(arbiter_server::tls_init::database_pool_acquire))]
|
|
||||||
DatabasePoolAcquire(#[from] db::PoolError),
|
DatabasePoolAcquire(#[from] db::PoolError),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,9 +110,7 @@ impl TlsCa {
|
|||||||
];
|
];
|
||||||
params
|
params
|
||||||
.subject_alt_names
|
.subject_alt_names
|
||||||
.push(SanType::IpAddress(IpAddr::from([
|
.push(SanType::IpAddress(IpAddr::from([127, 0, 0, 1])));
|
||||||
127, 0, 0, 1,
|
|
||||||
])));
|
|
||||||
|
|
||||||
let mut dn = DistinguishedName::new();
|
let mut dn = DistinguishedName::new();
|
||||||
dn.push(DnType::CommonName, "Arbiter Instance Leaf");
|
dn.push(DnType::CommonName, "Arbiter Instance Leaf");
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use diesel_async::{
|
|||||||
sync_connection_wrapper::SyncConnectionWrapper,
|
sync_connection_wrapper::SyncConnectionWrapper,
|
||||||
};
|
};
|
||||||
use diesel_migrations::{EmbeddedMigrations, MigrationHarness, embed_migrations};
|
use diesel_migrations::{EmbeddedMigrations, MigrationHarness, embed_migrations};
|
||||||
use miette::Diagnostic;
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
|
|
||||||
@@ -21,26 +21,21 @@ static DB_FILE: &str = "arbiter.sqlite";
|
|||||||
|
|
||||||
const MIGRATIONS: EmbeddedMigrations = embed_migrations!("migrations");
|
const MIGRATIONS: EmbeddedMigrations = embed_migrations!("migrations");
|
||||||
|
|
||||||
#[derive(Error, Diagnostic, Debug)]
|
#[derive(Error, Debug)]
|
||||||
pub enum DatabaseSetupError {
|
pub enum DatabaseSetupError {
|
||||||
#[error("Failed to determine home directory")]
|
#[error("Failed to determine home directory")]
|
||||||
#[diagnostic(code(arbiter::db::home_dir))]
|
|
||||||
HomeDir(std::io::Error),
|
HomeDir(std::io::Error),
|
||||||
|
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
#[diagnostic(code(arbiter::db::connection))]
|
|
||||||
Connection(diesel::ConnectionError),
|
Connection(diesel::ConnectionError),
|
||||||
|
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
#[diagnostic(code(arbiter::db::concurrency))]
|
|
||||||
ConcurrencySetup(diesel::result::Error),
|
ConcurrencySetup(diesel::result::Error),
|
||||||
|
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
#[diagnostic(code(arbiter::db::migration))]
|
|
||||||
Migration(Box<dyn std::error::Error + Send + Sync>),
|
Migration(Box<dyn std::error::Error + Send + Sync>),
|
||||||
|
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
#[diagnostic(code(arbiter::db::pool))]
|
|
||||||
Pool(#[from] PoolInitError),
|
Pool(#[from] PoolInitError),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,39 +28,32 @@ pub mod policies;
|
|||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
/// Errors that can only occur once the transaction meaning is known (during policy evaluation)
|
/// Errors that can only occur once the transaction meaning is known (during policy evaluation)
|
||||||
#[derive(Debug, thiserror::Error, miette::Diagnostic)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
pub enum PolicyError {
|
pub enum PolicyError {
|
||||||
#[error("Database error")]
|
#[error("Database error")]
|
||||||
Database(#[from] crate::db::DatabaseError),
|
Database(#[from] crate::db::DatabaseError),
|
||||||
#[error("Transaction violates policy: {0:?}")]
|
#[error("Transaction violates policy: {0:?}")]
|
||||||
#[diagnostic(code(arbiter_server::evm::policy_error::violation))]
|
|
||||||
Violations(Vec<EvalViolation>),
|
Violations(Vec<EvalViolation>),
|
||||||
#[error("No matching grant found")]
|
#[error("No matching grant found")]
|
||||||
#[diagnostic(code(arbiter_server::evm::policy_error::no_matching_grant))]
|
|
||||||
NoMatchingGrant,
|
NoMatchingGrant,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error, miette::Diagnostic)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
pub enum VetError {
|
pub enum VetError {
|
||||||
#[error("Contract creation transactions are not supported")]
|
#[error("Contract creation transactions are not supported")]
|
||||||
#[diagnostic(code(arbiter_server::evm::vet_error::contract_creation_unsupported))]
|
|
||||||
ContractCreationNotSupported,
|
ContractCreationNotSupported,
|
||||||
#[error("Engine can't classify this transaction")]
|
#[error("Engine can't classify this transaction")]
|
||||||
#[diagnostic(code(arbiter_server::evm::vet_error::unsupported))]
|
|
||||||
UnsupportedTransactionType,
|
UnsupportedTransactionType,
|
||||||
#[error("Policy evaluation failed: {1}")]
|
#[error("Policy evaluation failed: {1}")]
|
||||||
#[diagnostic(code(arbiter_server::evm::vet_error::evaluated))]
|
|
||||||
Evaluated(SpecificMeaning, #[source] PolicyError),
|
Evaluated(SpecificMeaning, #[source] PolicyError),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error, miette::Diagnostic)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
pub enum AnalyzeError {
|
pub enum AnalyzeError {
|
||||||
#[error("Engine doesn't support granting permissions for contract creation")]
|
#[error("Engine doesn't support granting permissions for contract creation")]
|
||||||
#[diagnostic(code(arbiter_server::evm::analyze_error::contract_creation_not_supported))]
|
|
||||||
ContractCreationNotSupported,
|
ContractCreationNotSupported,
|
||||||
|
|
||||||
#[error("Unsupported transaction type")]
|
#[error("Unsupported transaction type")]
|
||||||
#[diagnostic(code(arbiter_server::evm::analyze_error::unsupported_transaction_type))]
|
|
||||||
UnsupportedTransactionType,
|
UnsupportedTransactionType,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use diesel::{
|
|||||||
ExpressionMethods as _, QueryDsl, SelectableHelper, result::QueryResult, sqlite::Sqlite,
|
ExpressionMethods as _, QueryDsl, SelectableHelper, result::QueryResult, sqlite::Sqlite,
|
||||||
};
|
};
|
||||||
use diesel_async::{AsyncConnection, RunQueryDsl};
|
use diesel_async::{AsyncConnection, RunQueryDsl};
|
||||||
use miette::Diagnostic;
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -33,33 +33,27 @@ pub struct EvalContext {
|
|||||||
pub max_priority_fee_per_gas: u128,
|
pub max_priority_fee_per_gas: u128,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Error, Diagnostic)]
|
#[derive(Debug, Error)]
|
||||||
pub enum EvalViolation {
|
pub enum EvalViolation {
|
||||||
#[error("This grant doesn't allow transactions to the target address {target}")]
|
#[error("This grant doesn't allow transactions to the target address {target}")]
|
||||||
#[diagnostic(code(arbiter_server::evm::eval_violation::invalid_target))]
|
|
||||||
InvalidTarget { target: Address },
|
InvalidTarget { target: Address },
|
||||||
|
|
||||||
#[error("Gas limit exceeded for this grant")]
|
#[error("Gas limit exceeded for this grant")]
|
||||||
#[diagnostic(code(arbiter_server::evm::eval_violation::gas_limit_exceeded))]
|
|
||||||
GasLimitExceeded {
|
GasLimitExceeded {
|
||||||
max_gas_fee_per_gas: Option<U256>,
|
max_gas_fee_per_gas: Option<U256>,
|
||||||
max_priority_fee_per_gas: Option<U256>,
|
max_priority_fee_per_gas: Option<U256>,
|
||||||
},
|
},
|
||||||
|
|
||||||
#[error("Rate limit exceeded for this grant")]
|
#[error("Rate limit exceeded for this grant")]
|
||||||
#[diagnostic(code(arbiter_server::evm::eval_violation::rate_limit_exceeded))]
|
|
||||||
RateLimitExceeded,
|
RateLimitExceeded,
|
||||||
|
|
||||||
#[error("Transaction exceeds volumetric limits of the grant")]
|
#[error("Transaction exceeds volumetric limits of the grant")]
|
||||||
#[diagnostic(code(arbiter_server::evm::eval_violation::volumetric_limit_exceeded))]
|
|
||||||
VolumetricLimitExceeded,
|
VolumetricLimitExceeded,
|
||||||
|
|
||||||
#[error("Transaction is outside of the grant's validity period")]
|
#[error("Transaction is outside of the grant's validity period")]
|
||||||
#[diagnostic(code(arbiter_server::evm::eval_violation::invalid_time))]
|
|
||||||
InvalidTime,
|
InvalidTime,
|
||||||
|
|
||||||
#[error("Transaction type is not allowed by this grant")]
|
#[error("Transaction type is not allowed by this grant")]
|
||||||
#[diagnostic(code(arbiter_server::evm::eval_violation::invalid_transaction_type))]
|
|
||||||
InvalidTransactionType,
|
InvalidTransactionType,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -140,7 +140,9 @@ impl Receiver<auth::Inbound> for AuthTransportAdapter<'_> {
|
|||||||
let Some(payload) = auth_request.payload else {
|
let Some(payload) = auth_request.payload else {
|
||||||
let _ = self
|
let _ = self
|
||||||
.bi
|
.bi
|
||||||
.send(Err(Status::invalid_argument("Missing client auth request payload")))
|
.send(Err(Status::invalid_argument(
|
||||||
|
"Missing client auth request payload",
|
||||||
|
)))
|
||||||
.await;
|
.await;
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
@@ -170,9 +172,7 @@ impl Receiver<auth::Inbound> for AuthTransportAdapter<'_> {
|
|||||||
metadata: client_metadata_from_proto(client_info),
|
metadata: client_metadata_from_proto(client_info),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
AuthRequestPayload::ChallengeSolution(ProtoAuthChallengeSolution {
|
AuthRequestPayload::ChallengeSolution(ProtoAuthChallengeSolution { signature }) => {
|
||||||
signature,
|
|
||||||
}) => {
|
|
||||||
let Ok(signature) = ed25519_dalek::Signature::try_from(signature.as_slice()) else {
|
let Ok(signature) = ed25519_dalek::Signature::try_from(signature.as_slice()) else {
|
||||||
let _ = self
|
let _ = self
|
||||||
.send_auth_result(ProtoAuthResult::InvalidSignature)
|
.send_auth_result(ProtoAuthResult::InvalidSignature)
|
||||||
|
|||||||
@@ -34,7 +34,9 @@ pub(super) async fn dispatch(
|
|||||||
req: proto_evm::Request,
|
req: proto_evm::Request,
|
||||||
) -> Result<ClientResponsePayload, Status> {
|
) -> Result<ClientResponsePayload, Status> {
|
||||||
let Some(payload) = req.payload else {
|
let Some(payload) = req.payload else {
|
||||||
return Err(Status::invalid_argument("Missing client EVM request payload"));
|
return Err(Status::invalid_argument(
|
||||||
|
"Missing client EVM request payload",
|
||||||
|
));
|
||||||
};
|
};
|
||||||
|
|
||||||
match payload {
|
match payload {
|
||||||
@@ -59,13 +61,13 @@ pub(super) async fn dispatch(
|
|||||||
))) => EvmSignTransactionResponse {
|
))) => EvmSignTransactionResponse {
|
||||||
result: Some(vet_error.convert()),
|
result: Some(vet_error.convert()),
|
||||||
},
|
},
|
||||||
Err(kameo::error::SendError::HandlerError(
|
Err(kameo::error::SendError::HandlerError(SignTransactionRpcError::Internal)) => {
|
||||||
SignTransactionRpcError::Internal,
|
EvmSignTransactionResponse {
|
||||||
)) => EvmSignTransactionResponse {
|
|
||||||
result: Some(EvmSignTransactionResult::Error(
|
result: Some(EvmSignTransactionResult::Error(
|
||||||
ProtoEvmError::Internal.into(),
|
ProtoEvmError::Internal.into(),
|
||||||
)),
|
)),
|
||||||
},
|
}
|
||||||
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
warn!(error = ?err, "Failed to sign EVM transaction");
|
warn!(error = ?err, "Failed to sign EVM transaction");
|
||||||
EvmSignTransactionResponse {
|
EvmSignTransactionResponse {
|
||||||
@@ -78,8 +80,8 @@ pub(super) async fn dispatch(
|
|||||||
|
|
||||||
Ok(wrap_response(EvmResponsePayload::SignTransaction(response)))
|
Ok(wrap_response(EvmResponsePayload::SignTransaction(response)))
|
||||||
}
|
}
|
||||||
EvmRequestPayload::AnalyzeTransaction(_) => {
|
EvmRequestPayload::AnalyzeTransaction(_) => Err(Status::unimplemented(
|
||||||
Err(Status::unimplemented("EVM transaction analysis is not yet implemented"))
|
"EVM transaction analysis is not yet implemented",
|
||||||
}
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
|
||||||
|
|||||||
@@ -12,11 +12,9 @@ use kameo::{actor::ActorRef, error::SendError};
|
|||||||
use tonic::Status;
|
use tonic::Status;
|
||||||
use tracing::warn;
|
use tracing::warn;
|
||||||
|
|
||||||
use crate::{
|
use crate::actors::{
|
||||||
actors::{
|
|
||||||
client::session::{ClientSession, Error, HandleQueryVaultState},
|
client::session::{ClientSession, Error, HandleQueryVaultState},
|
||||||
keyholder::KeyHolderState,
|
keyholder::KeyHolderState,
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(super) async fn dispatch(
|
pub(super) async fn dispatch(
|
||||||
@@ -24,7 +22,9 @@ pub(super) async fn dispatch(
|
|||||||
req: proto_vault::Request,
|
req: proto_vault::Request,
|
||||||
) -> Result<ClientResponsePayload, Status> {
|
) -> Result<ClientResponsePayload, Status> {
|
||||||
let Some(payload) = req.payload else {
|
let Some(payload) = req.payload else {
|
||||||
return Err(Status::invalid_argument("Missing client vault request payload"));
|
return Err(Status::invalid_argument(
|
||||||
|
"Missing client vault request payload",
|
||||||
|
));
|
||||||
};
|
};
|
||||||
|
|
||||||
match payload {
|
match payload {
|
||||||
|
|||||||
@@ -28,9 +28,8 @@ impl TryConvert for RawEvmTransaction {
|
|||||||
type Error = tonic::Status;
|
type Error = tonic::Status;
|
||||||
|
|
||||||
fn try_convert(self) -> Result<Self::Output, Self::Error> {
|
fn try_convert(self) -> Result<Self::Output, Self::Error> {
|
||||||
let tx = TxEip1559::decode(&mut self.0.as_slice()).map_err(|_| {
|
let tx = TxEip1559::decode(&mut self.0.as_slice())
|
||||||
tonic::Status::invalid_argument("Invalid EVM transaction format")
|
.map_err(|_| tonic::Status::invalid_argument("Invalid EVM transaction format"))?;
|
||||||
})?;
|
|
||||||
Ok(tx)
|
Ok(tx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
use alloy::primitives::U256;
|
use alloy::primitives::U256;
|
||||||
use arbiter_proto::proto::{
|
use arbiter_proto::proto::{
|
||||||
evm::{EvmError as ProtoEvmError, evm_sign_transaction_response::Result as EvmSignTransactionResult},
|
evm::{
|
||||||
|
EvmError as ProtoEvmError,
|
||||||
|
evm_sign_transaction_response::Result as EvmSignTransactionResult,
|
||||||
|
},
|
||||||
shared::evm::{
|
shared::evm::{
|
||||||
EvalViolation as ProtoEvalViolation, GasLimitExceededViolation,
|
EvalViolation as ProtoEvalViolation, GasLimitExceededViolation, NoMatchingGrantError,
|
||||||
NoMatchingGrantError, PolicyViolationsError, SpecificMeaning as ProtoSpecificMeaning,
|
PolicyViolationsError, SpecificMeaning as ProtoSpecificMeaning,
|
||||||
TokenInfo as ProtoTokenInfo, TransactionEvalError as ProtoTransactionEvalError,
|
TokenInfo as ProtoTokenInfo, TransactionEvalError as ProtoTransactionEvalError,
|
||||||
eval_violation::Kind as ProtoEvalViolationKind,
|
eval_violation::Kind as ProtoEvalViolationKind,
|
||||||
specific_meaning::Meaning as ProtoSpecificMeaningKind,
|
specific_meaning::Meaning as ProtoSpecificMeaningKind,
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
|
|
||||||
use arbiter_proto::{
|
use arbiter_proto::{
|
||||||
proto::{
|
proto::user_agent::{
|
||||||
user_agent::{
|
|
||||||
UserAgentRequest, UserAgentResponse,
|
UserAgentRequest, UserAgentResponse,
|
||||||
user_agent_request::Payload as UserAgentRequestPayload,
|
user_agent_request::Payload as UserAgentRequestPayload,
|
||||||
user_agent_response::Payload as UserAgentResponsePayload,
|
user_agent_response::Payload as UserAgentResponsePayload,
|
||||||
},
|
},
|
||||||
},
|
|
||||||
transport::{Error as TransportError, Receiver, Sender, grpc::GrpcBi},
|
transport::{Error as TransportError, Receiver, Sender, grpc::GrpcBi},
|
||||||
};
|
};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
use arbiter_proto::{
|
use arbiter_proto::{
|
||||||
proto::user_agent::{
|
proto::user_agent::{
|
||||||
UserAgentRequest, UserAgentResponse, auth::{
|
UserAgentRequest, UserAgentResponse,
|
||||||
|
auth::{
|
||||||
self as proto_auth, AuthChallenge as ProtoAuthChallenge,
|
self as proto_auth, AuthChallenge as ProtoAuthChallenge,
|
||||||
AuthChallengeRequest as ProtoAuthChallengeRequest,
|
AuthChallengeRequest as ProtoAuthChallengeRequest,
|
||||||
AuthChallengeSolution as ProtoAuthChallengeSolution, AuthResult as ProtoAuthResult,
|
AuthChallengeSolution as ProtoAuthChallengeSolution, AuthResult as ProtoAuthResult,
|
||||||
KeyType as ProtoKeyType, request::Payload as AuthRequestPayload,
|
KeyType as ProtoKeyType, request::Payload as AuthRequestPayload,
|
||||||
response::Payload as AuthResponsePayload,
|
response::Payload as AuthResponsePayload,
|
||||||
}, user_agent_request::Payload as UserAgentRequestPayload,
|
},
|
||||||
|
user_agent_request::Payload as UserAgentRequestPayload,
|
||||||
user_agent_response::Payload as UserAgentResponsePayload,
|
user_agent_response::Payload as UserAgentResponsePayload,
|
||||||
},
|
},
|
||||||
transport::{Bi, Error as TransportError, Receiver, Sender, grpc::GrpcBi},
|
transport::{Bi, Error as TransportError, Receiver, Sender, grpc::GrpcBi},
|
||||||
@@ -63,7 +65,9 @@ impl Sender<Result<auth::Outbound, auth::Error>> for AuthTransportAdapter<'_> {
|
|||||||
Ok(Outbound::AuthChallenge { nonce }) => {
|
Ok(Outbound::AuthChallenge { nonce }) => {
|
||||||
AuthResponsePayload::Challenge(ProtoAuthChallenge { nonce })
|
AuthResponsePayload::Challenge(ProtoAuthChallenge { nonce })
|
||||||
}
|
}
|
||||||
Ok(Outbound::AuthSuccess) => AuthResponsePayload::Result(ProtoAuthResult::Success.into()),
|
Ok(Outbound::AuthSuccess) => {
|
||||||
|
AuthResponsePayload::Result(ProtoAuthResult::Success.into())
|
||||||
|
}
|
||||||
Err(Error::UnregisteredPublicKey) => {
|
Err(Error::UnregisteredPublicKey) => {
|
||||||
AuthResponsePayload::Result(ProtoAuthResult::InvalidKey.into())
|
AuthResponsePayload::Result(ProtoAuthResult::InvalidKey.into())
|
||||||
}
|
}
|
||||||
@@ -171,9 +175,9 @@ impl Receiver<auth::Inbound> for AuthTransportAdapter<'_> {
|
|||||||
bootstrap_token,
|
bootstrap_token,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
AuthRequestPayload::ChallengeSolution(ProtoAuthChallengeSolution {
|
AuthRequestPayload::ChallengeSolution(ProtoAuthChallengeSolution { signature }) => {
|
||||||
signature,
|
Some(auth::Inbound::AuthChallengeSolution { signature })
|
||||||
}) => Some(auth::Inbound::AuthChallengeSolution { signature }),
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,7 @@ use arbiter_proto::proto::{
|
|||||||
EvmError as ProtoEvmError, EvmGrantCreateRequest, EvmGrantCreateResponse,
|
EvmError as ProtoEvmError, EvmGrantCreateRequest, EvmGrantCreateResponse,
|
||||||
EvmGrantDeleteRequest, EvmGrantDeleteResponse, EvmGrantList, EvmGrantListResponse,
|
EvmGrantDeleteRequest, EvmGrantDeleteResponse, EvmGrantList, EvmGrantListResponse,
|
||||||
EvmSignTransactionResponse, GrantEntry, WalletCreateResponse, WalletEntry, WalletList,
|
EvmSignTransactionResponse, GrantEntry, WalletCreateResponse, WalletEntry, WalletList,
|
||||||
WalletListResponse,
|
WalletListResponse, evm_grant_create_response::Result as EvmGrantCreateResult,
|
||||||
evm_grant_create_response::Result as EvmGrantCreateResult,
|
|
||||||
evm_grant_delete_response::Result as EvmGrantDeleteResult,
|
evm_grant_delete_response::Result as EvmGrantDeleteResult,
|
||||||
evm_grant_list_response::Result as EvmGrantListResult,
|
evm_grant_list_response::Result as EvmGrantListResult,
|
||||||
evm_sign_transaction_response::Result as EvmSignTransactionResult,
|
evm_sign_transaction_response::Result as EvmSignTransactionResult,
|
||||||
@@ -165,7 +164,12 @@ async fn handle_grant_delete(
|
|||||||
actor: &ActorRef<UserAgentSession>,
|
actor: &ActorRef<UserAgentSession>,
|
||||||
req: EvmGrantDeleteRequest,
|
req: EvmGrantDeleteRequest,
|
||||||
) -> Result<Option<UserAgentResponsePayload>, Status> {
|
) -> Result<Option<UserAgentResponsePayload>, Status> {
|
||||||
let result = match actor.ask(HandleGrantDelete { grant_id: req.grant_id }).await {
|
let result = match actor
|
||||||
|
.ask(HandleGrantDelete {
|
||||||
|
grant_id: req.grant_id,
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
{
|
||||||
Ok(()) => EvmGrantDeleteResult::Ok(()),
|
Ok(()) => EvmGrantDeleteResult::Ok(()),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
warn!(error = ?err, "Failed to delete EVM grant");
|
warn!(error = ?err, "Failed to delete EVM grant");
|
||||||
@@ -202,18 +206,18 @@ async fn handle_sign_transaction(
|
|||||||
signature.as_bytes().to_vec(),
|
signature.as_bytes().to_vec(),
|
||||||
)),
|
)),
|
||||||
},
|
},
|
||||||
Err(kameo::error::SendError::HandlerError(
|
Err(kameo::error::SendError::HandlerError(SessionSignTransactionError::Vet(vet_error))) => {
|
||||||
SessionSignTransactionError::Vet(vet_error),
|
EvmSignTransactionResponse {
|
||||||
)) => EvmSignTransactionResponse {
|
|
||||||
result: Some(vet_error.convert()),
|
result: Some(vet_error.convert()),
|
||||||
},
|
}
|
||||||
Err(kameo::error::SendError::HandlerError(
|
}
|
||||||
SessionSignTransactionError::Internal,
|
Err(kameo::error::SendError::HandlerError(SessionSignTransactionError::Internal)) => {
|
||||||
)) => EvmSignTransactionResponse {
|
EvmSignTransactionResponse {
|
||||||
result: Some(EvmSignTransactionResult::Error(
|
result: Some(EvmSignTransactionResult::Error(
|
||||||
ProtoEvmError::Internal.into(),
|
ProtoEvmError::Internal.into(),
|
||||||
)),
|
)),
|
||||||
},
|
}
|
||||||
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
warn!(error = ?err, "Failed to sign EVM transaction");
|
warn!(error = ?err, "Failed to sign EVM transaction");
|
||||||
EvmSignTransactionResponse {
|
EvmSignTransactionResponse {
|
||||||
@@ -224,7 +228,7 @@ async fn handle_sign_transaction(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Some(wrap_evm_response(EvmResponsePayload::SignTransaction(
|
Ok(Some(wrap_evm_response(
|
||||||
response,
|
EvmResponsePayload::SignTransaction(response),
|
||||||
))))
|
)))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,7 @@ use arbiter_proto::proto::{
|
|||||||
TransactionRateLimit as ProtoTransactionRateLimit, VolumeRateLimit as ProtoVolumeRateLimit,
|
TransactionRateLimit as ProtoTransactionRateLimit, VolumeRateLimit as ProtoVolumeRateLimit,
|
||||||
specific_grant::Grant as ProtoSpecificGrantType,
|
specific_grant::Grant as ProtoSpecificGrantType,
|
||||||
},
|
},
|
||||||
user_agent::sdk_client::{
|
user_agent::sdk_client::{WalletAccess, WalletAccessEntry as ProtoSdkClientWalletAccess},
|
||||||
WalletAccess, WalletAccessEntry as ProtoSdkClientWalletAccess,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use prost_types::Timestamp as ProtoTimestamp;
|
use prost_types::Timestamp as ProtoTimestamp;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use arbiter_proto::proto::{
|
use arbiter_proto::proto::{
|
||||||
|
shared::ClientInfo as ProtoClientMetadata,
|
||||||
user_agent::{
|
user_agent::{
|
||||||
sdk_client::{
|
sdk_client::{
|
||||||
self as proto_sdk_client, ConnectionCancel as ProtoSdkClientConnectionCancel,
|
self as proto_sdk_client, ConnectionCancel as ProtoSdkClientConnectionCancel,
|
||||||
@@ -13,7 +14,6 @@ use arbiter_proto::proto::{
|
|||||||
},
|
},
|
||||||
user_agent_response::Payload as UserAgentResponsePayload,
|
user_agent_response::Payload as UserAgentResponsePayload,
|
||||||
},
|
},
|
||||||
shared::ClientInfo as ProtoClientMetadata,
|
|
||||||
};
|
};
|
||||||
use kameo::actor::ActorRef;
|
use kameo::actor::ActorRef;
|
||||||
use tonic::Status;
|
use tonic::Status;
|
||||||
@@ -62,18 +62,22 @@ pub(super) async fn dispatch(
|
|||||||
req: proto_sdk_client::Request,
|
req: proto_sdk_client::Request,
|
||||||
) -> Result<Option<UserAgentResponsePayload>, Status> {
|
) -> Result<Option<UserAgentResponsePayload>, Status> {
|
||||||
let Some(payload) = req.payload else {
|
let Some(payload) = req.payload else {
|
||||||
return Err(Status::invalid_argument("Missing SDK client request payload"));
|
return Err(Status::invalid_argument(
|
||||||
|
"Missing SDK client request payload",
|
||||||
|
));
|
||||||
};
|
};
|
||||||
|
|
||||||
match payload {
|
match payload {
|
||||||
SdkClientRequestPayload::ConnectionResponse(resp) => {
|
SdkClientRequestPayload::ConnectionResponse(resp) => {
|
||||||
handle_connection_response(actor, resp).await
|
handle_connection_response(actor, resp).await
|
||||||
}
|
}
|
||||||
SdkClientRequestPayload::Revoke(_) => {
|
SdkClientRequestPayload::Revoke(_) => Err(Status::unimplemented(
|
||||||
Err(Status::unimplemented("SdkClientRevoke is not yet implemented"))
|
"SdkClientRevoke is not yet implemented",
|
||||||
}
|
)),
|
||||||
SdkClientRequestPayload::List(_) => handle_list(actor).await,
|
SdkClientRequestPayload::List(_) => handle_list(actor).await,
|
||||||
SdkClientRequestPayload::GrantWalletAccess(req) => handle_grant_wallet_access(actor, req).await,
|
SdkClientRequestPayload::GrantWalletAccess(req) => {
|
||||||
|
handle_grant_wallet_access(actor, req).await
|
||||||
|
}
|
||||||
SdkClientRequestPayload::RevokeWalletAccess(req) => {
|
SdkClientRequestPayload::RevokeWalletAccess(req) => {
|
||||||
handle_revoke_wallet_access(actor, req).await
|
handle_revoke_wallet_access(actor, req).await
|
||||||
}
|
}
|
||||||
@@ -128,11 +132,11 @@ async fn handle_list(
|
|||||||
ProtoSdkClientListResult::Error(ProtoSdkClientError::Internal.into())
|
ProtoSdkClientListResult::Error(ProtoSdkClientError::Internal.into())
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Ok(Some(wrap_sdk_client_response(SdkClientResponsePayload::List(
|
Ok(Some(wrap_sdk_client_response(
|
||||||
ProtoSdkClientListResponse {
|
SdkClientResponsePayload::List(ProtoSdkClientListResponse {
|
||||||
result: Some(result),
|
result: Some(result),
|
||||||
},
|
}),
|
||||||
))))
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_grant_wallet_access(
|
async fn handle_grant_wallet_access(
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use arbiter_proto::proto::shared::VaultState as ProtoVaultState;
|
||||||
use arbiter_proto::proto::user_agent::{
|
use arbiter_proto::proto::user_agent::{
|
||||||
user_agent_response::Payload as UserAgentResponsePayload,
|
user_agent_response::Payload as UserAgentResponsePayload,
|
||||||
vault::{
|
vault::{
|
||||||
@@ -11,18 +12,15 @@ use arbiter_proto::proto::user_agent::{
|
|||||||
unseal::{
|
unseal::{
|
||||||
self as proto_unseal, UnsealEncryptedKey as ProtoUnsealEncryptedKey,
|
self as proto_unseal, UnsealEncryptedKey as ProtoUnsealEncryptedKey,
|
||||||
UnsealResult as ProtoUnsealResult, UnsealStart,
|
UnsealResult as ProtoUnsealResult, UnsealStart,
|
||||||
request::Payload as UnsealRequestPayload,
|
request::Payload as UnsealRequestPayload, response::Payload as UnsealResponsePayload,
|
||||||
response::Payload as UnsealResponsePayload,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use arbiter_proto::proto::shared::VaultState as ProtoVaultState;
|
|
||||||
use kameo::{actor::ActorRef, error::SendError};
|
use kameo::{actor::ActorRef, error::SendError};
|
||||||
use tonic::Status;
|
use tonic::Status;
|
||||||
use tracing::warn;
|
use tracing::warn;
|
||||||
|
|
||||||
use crate::{
|
use crate::actors::{
|
||||||
actors::{
|
|
||||||
keyholder::KeyHolderState,
|
keyholder::KeyHolderState,
|
||||||
user_agent::{
|
user_agent::{
|
||||||
UserAgentSession,
|
UserAgentSession,
|
||||||
@@ -31,7 +29,6 @@ use crate::{
|
|||||||
HandleUnsealEncryptedKey, HandleUnsealRequest, UnsealError,
|
HandleUnsealEncryptedKey, HandleUnsealRequest, UnsealError,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
fn wrap_vault_response(payload: VaultResponsePayload) -> UserAgentResponsePayload {
|
fn wrap_vault_response(payload: VaultResponsePayload) -> UserAgentResponsePayload {
|
||||||
@@ -151,7 +148,9 @@ async fn handle_bootstrap_encrypted_key(
|
|||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(()) => ProtoBootstrapResult::Success,
|
Ok(()) => ProtoBootstrapResult::Success,
|
||||||
Err(SendError::HandlerError(BootstrapError::InvalidKey)) => ProtoBootstrapResult::InvalidKey,
|
Err(SendError::HandlerError(BootstrapError::InvalidKey)) => {
|
||||||
|
ProtoBootstrapResult::InvalidKey
|
||||||
|
}
|
||||||
Err(SendError::HandlerError(BootstrapError::AlreadyBootstrapped)) => {
|
Err(SendError::HandlerError(BootstrapError::AlreadyBootstrapped)) => {
|
||||||
ProtoBootstrapResult::AlreadyBootstrapped
|
ProtoBootstrapResult::AlreadyBootstrapped
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
|
|
||||||
|
use anyhow::anyhow;
|
||||||
use arbiter_proto::{proto::arbiter_service_server::ArbiterServiceServer, url::ArbiterUrl};
|
use arbiter_proto::{proto::arbiter_service_server::ArbiterServiceServer, url::ArbiterUrl};
|
||||||
use arbiter_server::{Server, actors::bootstrap::GetToken, context::ServerContext, db};
|
use arbiter_server::{Server, actors::bootstrap::GetToken, context::ServerContext, db};
|
||||||
use miette::miette;
|
|
||||||
use rustls::crypto::aws_lc_rs;
|
use rustls::crypto::aws_lc_rs;
|
||||||
use tonic::transport::{Identity, ServerTlsConfig};
|
use tonic::transport::{Identity, ServerTlsConfig};
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
@@ -10,7 +10,7 @@ use tracing::info;
|
|||||||
const PORT: u16 = 50051;
|
const PORT: u16 = 50051;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> miette::Result<()> {
|
async fn main() -> anyhow::Result<()> {
|
||||||
aws_lc_rs::default_provider().install_default().unwrap();
|
aws_lc_rs::default_provider().install_default().unwrap();
|
||||||
|
|
||||||
tracing_subscriber::fmt()
|
tracing_subscriber::fmt()
|
||||||
@@ -46,11 +46,11 @@ async fn main() -> miette::Result<()> {
|
|||||||
|
|
||||||
tonic::transport::Server::builder()
|
tonic::transport::Server::builder()
|
||||||
.tls_config(tls)
|
.tls_config(tls)
|
||||||
.map_err(|err| miette!("Faild to setup TLS: {err}"))?
|
.map_err(|err| anyhow!("Failed to setup TLS: {err}"))?
|
||||||
.add_service(ArbiterServiceServer::new(Server::new(context)))
|
.add_service(ArbiterServiceServer::new(Server::new(context)))
|
||||||
.serve(addr)
|
.serve(addr)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| miette::miette!("gRPC server error: {e}"))?;
|
.map_err(|e| anyhow!("gRPC server error: {e}"))?;
|
||||||
|
|
||||||
unreachable!("gRPC server should run indefinitely");
|
unreachable!("gRPC server should run indefinitely");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,10 @@ use arbiter_server::{
|
|||||||
actors::{
|
actors::{
|
||||||
GlobalActors,
|
GlobalActors,
|
||||||
keyholder::{Bootstrap, Seal},
|
keyholder::{Bootstrap, Seal},
|
||||||
user_agent::{UserAgentSession, session::connection::{
|
user_agent::{
|
||||||
HandleUnsealEncryptedKey, HandleUnsealRequest, UnsealError,
|
UserAgentSession,
|
||||||
}},
|
session::connection::{HandleUnsealEncryptedKey, HandleUnsealRequest, UnsealError},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
db,
|
db,
|
||||||
safe_cell::{SafeCell, SafeCellHandle as _},
|
safe_cell::{SafeCell, SafeCellHandle as _},
|
||||||
|
|||||||
Reference in New Issue
Block a user