authendicating daemon
This commit is contained in:
parent
3b3221099f
commit
784878d0a1
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -418,6 +418,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "detee-shared"
|
name = "detee-shared"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
source = "git+ssh://git@gitea.detee.cloud/noormohammedb/detee-shared?branch=stable_01#f2bc29149e32df09508519f3f88cdf880728e6dd"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64",
|
"base64",
|
||||||
"prost",
|
"prost",
|
||||||
|
49
src/grpc.rs
49
src/grpc.rs
@ -469,12 +469,23 @@ impl BrainAppDaemon for BrainAppDaemonMock {
|
|||||||
|
|
||||||
async fn brain_messages(
|
async fn brain_messages(
|
||||||
&self,
|
&self,
|
||||||
req: tonic::Request<detee_shared::pb::brain::Pubkey>,
|
req: tonic::Request<detee_shared::pb::brain::DaemonAuth>,
|
||||||
) -> Result<tonic::Response<Self::BrainMessagesStream>, Status> {
|
) -> Result<tonic::Response<Self::BrainMessagesStream>, Status> {
|
||||||
let req = req.into_inner();
|
let req_data = req.into_inner();
|
||||||
info!("Daemon {} connected to receive brain messages", req.pubkey);
|
let pubkey = req_data.pubkey.clone();
|
||||||
|
check_sig_from_parts(
|
||||||
|
&pubkey,
|
||||||
|
&req_data.timestamp,
|
||||||
|
&format!("{:?}", req_data.contracts),
|
||||||
|
&req_data.signature,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
info!(
|
||||||
|
"Daemon {} connected to receive brain messages",
|
||||||
|
req_data.pubkey
|
||||||
|
);
|
||||||
let (tx, rx) = mpsc::channel(6);
|
let (tx, rx) = mpsc::channel(6);
|
||||||
self.data.add_app_daemon_tx(&req.pubkey, tx);
|
self.data.add_app_daemon_tx(&req_data.pubkey, tx);
|
||||||
let output_stream = ReceiverStream::new(rx).map(Ok);
|
let output_stream = ReceiverStream::new(rx).map(Ok);
|
||||||
Ok(Response::new(
|
Ok(Response::new(
|
||||||
Box::pin(output_stream) as Self::BrainMessagesStream
|
Box::pin(output_stream) as Self::BrainMessagesStream
|
||||||
@ -488,11 +499,35 @@ impl BrainAppDaemon for BrainAppDaemonMock {
|
|||||||
let mut req_stream = req.into_inner();
|
let mut req_stream = req.into_inner();
|
||||||
let mut pubkey = String::new();
|
let mut pubkey = String::new();
|
||||||
|
|
||||||
|
if let Some(Ok(msg)) = req_stream.next().await {
|
||||||
|
log::debug!(
|
||||||
|
"demon_messages received the following auth message: {:?}",
|
||||||
|
msg.msg
|
||||||
|
);
|
||||||
|
if let Some(detee_shared::pb::brain::daemon_message_app::Msg::Auth(auth)) = msg.msg {
|
||||||
|
pubkey = auth.pubkey.clone();
|
||||||
|
check_sig_from_parts(
|
||||||
|
&pubkey,
|
||||||
|
&auth.timestamp,
|
||||||
|
&format!("{:?}", auth.contracts),
|
||||||
|
&auth.signature,
|
||||||
|
)?;
|
||||||
|
} else {
|
||||||
|
return Err(Status::unauthenticated(
|
||||||
|
"Could not authenticate the daemon: could not extract auth signature",
|
||||||
|
));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return Err(Status::unauthenticated("Could not authenticate the daemon"));
|
||||||
|
}
|
||||||
|
|
||||||
while let Some(daemon_message) = req_stream.next().await {
|
while let Some(daemon_message) = req_stream.next().await {
|
||||||
match daemon_message {
|
match daemon_message {
|
||||||
Ok(msg) => match msg.msg {
|
Ok(msg) => match msg.msg {
|
||||||
Some(detee_shared::pb::brain::daemon_message_app::Msg::Pubkey(node_pubkey)) => {
|
Some(detee_shared::pb::brain::daemon_message_app::Msg::Auth(daemon_auth)) => {
|
||||||
pubkey = node_pubkey;
|
dbg!(&daemon_auth);
|
||||||
|
// TODO: wip on authendication
|
||||||
|
pubkey = daemon_auth.pubkey;
|
||||||
}
|
}
|
||||||
Some(detee_shared::pb::brain::daemon_message_app::Msg::NewAppRes(new_cont)) => {
|
Some(detee_shared::pb::brain::daemon_message_app::Msg::NewAppRes(new_cont)) => {
|
||||||
self.data.send_new_container_resp(new_cont).await;
|
self.data.send_new_container_resp(new_cont).await;
|
||||||
@ -500,7 +535,7 @@ impl BrainAppDaemon for BrainAppDaemonMock {
|
|||||||
Some(detee_shared::pb::brain::daemon_message_app::Msg::AppNodeResources(_)) => {
|
Some(detee_shared::pb::brain::daemon_message_app::Msg::AppNodeResources(_)) => {
|
||||||
todo!("AppNodeResources not implemented yet");
|
todo!("AppNodeResources not implemented yet");
|
||||||
}
|
}
|
||||||
None => {
|
_ => {
|
||||||
dbg!("None");
|
dbg!("None");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user