keyforkd: allow performing multiple requests on the same socket

This commit is contained in:
Ryan Heywood 2024-02-12 02:36:54 -05:00
parent a24a0166cc
commit f1c24fb33e
Signed by: ryan
GPG Key ID: 8E401478A3FBEF72
2 changed files with 45 additions and 47 deletions

View File

@ -81,9 +81,6 @@ fn ed25519_test_suite() {
continue;
}
for i in 2..chain_len {
// FIXME: Keyfork will only allow one request per session
let socket = UnixStream::connect(&socket_path).unwrap();
let mut client = Client::new(socket);
// Consistency check: ensure the server and the client can each derive the same
// key using an XPrv, for all but the last XPrv, which is verified after this
let path = DerivationPath::from_str(test.chain).unwrap();
@ -95,8 +92,6 @@ fn ed25519_test_suite() {
.fold(DerivationPath::default(), |p, i| p.chain_push(i.clone()));
let xprv = dbg!(client.request_xprv::<SigningKey>(&left_path)).unwrap();
let derived_xprv = xprv.derive_path(&right_path).unwrap();
let socket = UnixStream::connect(&socket_path).unwrap();
let mut client = Client::new(socket);
let keyforkd_xprv = client.request_xprv::<SigningKey>(&path).unwrap();
assert_eq!(
derived_xprv, keyforkd_xprv,

View File

@ -68,6 +68,8 @@ impl UnixServer {
#[cfg(feature = "tracing")]
debug!("new socket connected");
tokio::spawn(async move {
// Process requests until an error occurs or a client disconnects
loop {
let bytes = match try_decode_from(&mut socket).await {
Ok(bytes) => bytes,
Err(e) => {
@ -118,6 +120,7 @@ impl UnixServer {
#[cfg(feature = "tracing")]
debug!(%e, "Error sending response to client");
}
}
});
}
}