Decouple client contracts and close private role registries
This commit is contained in:
parent
786049534d
commit
22325aa76a
1 changed files with 1041 additions and 321 deletions
|
|
@ -5,6 +5,7 @@ use std::path::PathBuf;
|
|||
use std::sync::Mutex;
|
||||
|
||||
use ed25519_dalek::SigningKey;
|
||||
use lazaret_control_client::{ControlClient, ControlClientError, PendingClientEnrollment};
|
||||
use lazaret_core::identity::{ClientId, SessionAnchorId, SessionId};
|
||||
use lazaret_core::records::{
|
||||
ClientEnrollmentResponse, ControlRequest, ControlResponse, DeveloperDecision,
|
||||
|
|
@ -13,9 +14,6 @@ use lazaret_core::records::{
|
|||
ProtocolPublicationIdentity, ProtocolVersion, SessionBinding, SessionExitOutcome,
|
||||
SessionRegistrationRequest, TlsSubjectId,
|
||||
};
|
||||
use lazaret_host_coordinator::control::{
|
||||
ControlError, PendingClientEnrollment, PublishedControlFace,
|
||||
};
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
use crate::terminal::{HostTerminal, InteractiveSessionTransport, run_interactive_session};
|
||||
|
|
@ -23,6 +21,7 @@ use crate::terminal::{HostTerminal, InteractiveSessionTransport, run_interactive
|
|||
pub mod cli;
|
||||
pub mod coordinator_backend;
|
||||
mod domain_observation;
|
||||
pub mod private_roles;
|
||||
pub mod state;
|
||||
pub mod terminal;
|
||||
|
||||
|
|
@ -59,7 +58,7 @@ pub enum ClientError<E> {
|
|||
EmptyCommand,
|
||||
Backend(E),
|
||||
Io(io::Error),
|
||||
Control(ControlError),
|
||||
Control(ControlClientError),
|
||||
Protocol(&'static str),
|
||||
}
|
||||
|
||||
|
|
@ -302,15 +301,15 @@ pub fn execute_over_control_face_as<E>(
|
|||
let cli_id = identity.cli_id;
|
||||
let session_id = identity.session_id;
|
||||
let pending = PendingClientEnrollment::create(generation.clone(), cli_id)?;
|
||||
let anonymous = PublishedControlFace::client_config(&endpoint.publication, None)?;
|
||||
let anonymous = ControlClient::config(&endpoint.publication, None)?;
|
||||
let mut enrollment =
|
||||
PublishedControlFace::connect(&endpoint.socket_path, anonymous, &endpoint.publication)?;
|
||||
PublishedControlFace::send(
|
||||
ControlClient::connect(&endpoint.socket_path, anonymous, &endpoint.publication)?;
|
||||
ControlClient::send(
|
||||
&mut enrollment,
|
||||
&ControlRequest::Enroll(pending.request().clone()),
|
||||
)?;
|
||||
let ControlResponse::Enrolled(ClientEnrollmentResponse { credential, .. }) =
|
||||
PublishedControlFace::receive(&mut enrollment)?
|
||||
ControlClient::receive(&mut enrollment)?
|
||||
else {
|
||||
return Err(ClientError::Protocol(
|
||||
"enrollment response was not Enrolled",
|
||||
|
|
@ -331,21 +330,20 @@ pub fn execute_over_control_face_as<E>(
|
|||
session_id,
|
||||
session_anchor_public_key: identity.anchor.verifying_key().to_bytes().to_vec(),
|
||||
};
|
||||
let authenticated = PublishedControlFace::client_config(
|
||||
let authenticated = ControlClient::config(
|
||||
&endpoint.publication,
|
||||
Some((&credential, pending.private_key())),
|
||||
)?;
|
||||
let mut stream =
|
||||
PublishedControlFace::connect(&endpoint.socket_path, authenticated, &endpoint.publication)?;
|
||||
PublishedControlFace::send(
|
||||
ControlClient::connect(&endpoint.socket_path, authenticated, &endpoint.publication)?;
|
||||
ControlClient::send(
|
||||
&mut stream,
|
||||
&ControlRequest::Register(SessionRegistrationRequest {
|
||||
protocol_version: ProtocolVersion::V1,
|
||||
session_binding: binding.clone(),
|
||||
}),
|
||||
)?;
|
||||
let ControlResponse::Registered(registered) = PublishedControlFace::receive(&mut stream)?
|
||||
else {
|
||||
let ControlResponse::Registered(registered) = ControlClient::receive(&mut stream)? else {
|
||||
return Err(ClientError::Protocol(
|
||||
"registration response was not Registered",
|
||||
));
|
||||
|
|
@ -356,7 +354,7 @@ pub fn execute_over_control_face_as<E>(
|
|||
));
|
||||
}
|
||||
endpoint.acknowledge_waiter_transfer()?;
|
||||
PublishedControlFace::send(
|
||||
ControlClient::send(
|
||||
&mut stream,
|
||||
&ControlRequest::Execute(NonInteractiveSessionRequest {
|
||||
protocol_version: ProtocolVersion::V1,
|
||||
|
|
@ -365,8 +363,8 @@ pub fn execute_over_control_face_as<E>(
|
|||
}),
|
||||
)?;
|
||||
loop {
|
||||
let message = PublishedControlFace::receive(&mut stream).map_err(|error| match error {
|
||||
ControlError::Io(_) => ClientError::LostConnection,
|
||||
let message = ControlClient::receive(&mut stream).map_err(|error| match error {
|
||||
ControlClientError::Io(_) => ClientError::LostConnection,
|
||||
other => ClientError::Control(other),
|
||||
})?;
|
||||
match message {
|
||||
|
|
@ -412,15 +410,15 @@ pub fn execute_interactive_over_control_face_as<E, H: HostTerminal>(
|
|||
let cli_id = identity.cli_id;
|
||||
let session_id = identity.session_id;
|
||||
let pending = PendingClientEnrollment::create(generation.clone(), cli_id)?;
|
||||
let anonymous = PublishedControlFace::client_config(&endpoint.publication, None)?;
|
||||
let anonymous = ControlClient::config(&endpoint.publication, None)?;
|
||||
let mut enrollment =
|
||||
PublishedControlFace::connect(&endpoint.socket_path, anonymous, &endpoint.publication)?;
|
||||
PublishedControlFace::send(
|
||||
ControlClient::connect(&endpoint.socket_path, anonymous, &endpoint.publication)?;
|
||||
ControlClient::send(
|
||||
&mut enrollment,
|
||||
&ControlRequest::Enroll(pending.request().clone()),
|
||||
)?;
|
||||
let ControlResponse::Enrolled(ClientEnrollmentResponse { credential, .. }) =
|
||||
PublishedControlFace::receive(&mut enrollment)?
|
||||
ControlClient::receive(&mut enrollment)?
|
||||
else {
|
||||
return Err(ClientError::Protocol(
|
||||
"enrollment response was not Enrolled",
|
||||
|
|
@ -440,21 +438,20 @@ pub fn execute_interactive_over_control_face_as<E, H: HostTerminal>(
|
|||
session_id,
|
||||
session_anchor_public_key: identity.anchor.verifying_key().to_bytes().to_vec(),
|
||||
};
|
||||
let authenticated = PublishedControlFace::client_config(
|
||||
let authenticated = ControlClient::config(
|
||||
&endpoint.publication,
|
||||
Some((&credential, pending.private_key())),
|
||||
)?;
|
||||
let mut stream =
|
||||
PublishedControlFace::connect(&endpoint.socket_path, authenticated, &endpoint.publication)?;
|
||||
PublishedControlFace::send(
|
||||
ControlClient::connect(&endpoint.socket_path, authenticated, &endpoint.publication)?;
|
||||
ControlClient::send(
|
||||
&mut stream,
|
||||
&ControlRequest::Register(SessionRegistrationRequest {
|
||||
protocol_version: ProtocolVersion::V1,
|
||||
session_binding: binding.clone(),
|
||||
}),
|
||||
)?;
|
||||
let ControlResponse::Registered(registered) = PublishedControlFace::receive(&mut stream)?
|
||||
else {
|
||||
let ControlResponse::Registered(registered) = ControlClient::receive(&mut stream)? else {
|
||||
return Err(ClientError::Protocol(
|
||||
"registration response was not Registered",
|
||||
));
|
||||
|
|
@ -481,7 +478,7 @@ impl InteractiveSessionTransport for ControlFaceInteractiveTransport {
|
|||
&mut self,
|
||||
request: InteractiveSessionRequest,
|
||||
) -> Result<InteractiveSessionBatch, ClientError<Self::Error>> {
|
||||
PublishedControlFace::send(
|
||||
ControlClient::send(
|
||||
&mut self.stream,
|
||||
&ControlRequest::ExecuteInteractive(request),
|
||||
)?;
|
||||
|
|
@ -492,7 +489,7 @@ impl InteractiveSessionTransport for ControlFaceInteractiveTransport {
|
|||
&mut self,
|
||||
event: InteractiveSessionEvent,
|
||||
) -> Result<InteractiveSessionBatch, ClientError<Self::Error>> {
|
||||
PublishedControlFace::send(&mut self.stream, &event).map_err(map_control_connection)?;
|
||||
ControlClient::send(&mut self.stream, &event).map_err(map_control_connection)?;
|
||||
receive_interactive_batch(&mut self.stream)
|
||||
}
|
||||
}
|
||||
|
|
@ -500,12 +497,12 @@ impl InteractiveSessionTransport for ControlFaceInteractiveTransport {
|
|||
fn receive_interactive_batch(
|
||||
stream: &mut impl std::io::Read,
|
||||
) -> Result<InteractiveSessionBatch, ClientError<std::convert::Infallible>> {
|
||||
PublishedControlFace::receive(stream).map_err(map_control_connection)
|
||||
ControlClient::receive(stream).map_err(map_control_connection)
|
||||
}
|
||||
|
||||
fn map_control_connection(error: ControlError) -> ClientError<std::convert::Infallible> {
|
||||
fn map_control_connection(error: ControlClientError) -> ClientError<std::convert::Infallible> {
|
||||
match error {
|
||||
ControlError::Io(_) => ClientError::LostConnection,
|
||||
ControlClientError::Io(_) => ClientError::LostConnection,
|
||||
other => ClientError::Control(other),
|
||||
}
|
||||
}
|
||||
|
|
@ -547,8 +544,8 @@ impl<E> From<io::Error> for ClientError<E> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<E> From<ControlError> for ClientError<E> {
|
||||
fn from(error: ControlError) -> Self {
|
||||
impl<E> From<ControlClientError> for ClientError<E> {
|
||||
fn from(error: ControlClientError) -> Self {
|
||||
Self::Control(error)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue