Page MenuHomePhabricator

D5487.id17921.diff
No OneTemporary

D5487.id17921.diff

diff --git a/services/tunnelbroker/src/cxx_bridge.rs b/services/tunnelbroker/src/cxx_bridge.rs
--- a/services/tunnelbroker/src/cxx_bridge.rs
+++ b/services/tunnelbroker/src/cxx_bridge.rs
@@ -1,7 +1,18 @@
#[cxx::bridge]
pub mod ffi {
+ struct grpcResult {
+ statusCode: u8,
+ errorText: String,
+ }
+
+ struct SessionSignatureResult {
+ toSign: String,
+ grpcStatus: grpcResult,
+ }
+
unsafe extern "C++" {
include!("tunnelbroker/src/libcpp/Tunnelbroker.h");
pub fn initialization();
+ pub fn sessionSignatureHandler(deviceID: &str) -> SessionSignatureResult;
}
}
diff --git a/services/tunnelbroker/src/libcpp/Tunnelbroker.h b/services/tunnelbroker/src/libcpp/Tunnelbroker.h
--- a/services/tunnelbroker/src/libcpp/Tunnelbroker.h
+++ b/services/tunnelbroker/src/libcpp/Tunnelbroker.h
@@ -1,5 +1,7 @@
#pragma once
#include "rust/cxx.h"
+#include "tunnelbroker/src/cxx_bridge.rs.h"
void initialization();
+SessionSignatureResult sessionSignatureHandler(rust::Str deviceID);
diff --git a/services/tunnelbroker/src/libcpp/Tunnelbroker.cpp b/services/tunnelbroker/src/libcpp/Tunnelbroker.cpp
--- a/services/tunnelbroker/src/libcpp/Tunnelbroker.cpp
+++ b/services/tunnelbroker/src/libcpp/Tunnelbroker.cpp
@@ -7,6 +7,7 @@
#include "Tools.h"
#include "rust/cxx.h"
+#include "tunnelbroker/src/cxx_bridge.rs.h"
void initialization() {
comm::network::tools::InitLogging("tunnelbroker");
@@ -35,3 +36,23 @@
};
comm::network::AmqpManager::getInstance().init();
}
+
+SessionSignatureResult sessionSignatureHandler(rust::Str deviceID) {
+ const std::string requestedDeviceID(deviceID);
+ if (!comm::network::tools::validateDeviceID(requestedDeviceID)) {
+ return SessionSignatureResult{
+ .grpcStatus = {
+ .statusCode = 3,
+ .errorText =
+ "Format validation failed for deviceID: " + requestedDeviceID}};
+ }
+ const std::string toSign = comm::network::tools::generateRandomString(
+ comm::network::SIGNATURE_REQUEST_LENGTH);
+ std::shared_ptr<comm::network::database::SessionSignItem> SessionSignItem =
+ std::make_shared<comm::network::database::SessionSignItem>(
+ toSign, requestedDeviceID);
+ comm::network::database::DatabaseManager::getInstance().putSessionSignItem(
+ *SessionSignItem);
+
+ return SessionSignatureResult{.toSign = toSign};
+}
diff --git a/services/tunnelbroker/src/server/mod.rs b/services/tunnelbroker/src/server/mod.rs
--- a/services/tunnelbroker/src/server/mod.rs
+++ b/services/tunnelbroker/src/server/mod.rs
@@ -1,3 +1,4 @@
+use super::cxx_bridge;
use futures::Stream;
use std::pin::Pin;
use tonic::transport::Server;
@@ -5,7 +6,7 @@
use tunnelbroker::tunnelbroker_service_server::{
TunnelbrokerService, TunnelbrokerServiceServer,
};
-
+mod tools;
mod tunnelbroker {
tonic::include_proto!("tunnelbroker");
}
@@ -17,9 +18,19 @@
impl TunnelbrokerService for TunnelbrokerServiceHandlers {
async fn session_signature(
&self,
- _request: Request<tunnelbroker::SessionSignatureRequest>,
+ request: Request<tunnelbroker::SessionSignatureRequest>,
) -> Result<Response<tunnelbroker::SessionSignatureResponse>, Status> {
- Err(Status::unimplemented("Not implemented yet"))
+ let result =
+ cxx_bridge::ffi::sessionSignatureHandler(&request.into_inner().device_id);
+ if result.grpcStatus.statusCode > 0 {
+ return Err(tools::create_tonic_status(
+ result.grpcStatus.statusCode,
+ &result.grpcStatus.errorText,
+ ));
+ }
+ Ok(Response::new(tunnelbroker::SessionSignatureResponse {
+ to_sign: result.toSign,
+ }))
}
async fn new_session(
diff --git a/services/tunnelbroker/src/server/tools.rs b/services/tunnelbroker/src/server/tools.rs
new file mode 100644
--- /dev/null
+++ b/services/tunnelbroker/src/server/tools.rs
@@ -0,0 +1,25 @@
+use tonic::{Code, Status};
+
+pub fn create_tonic_status(code: u8, text: &str) -> Status {
+ let status = match code {
+ 0 => Code::Ok,
+ 1 => Code::Cancelled,
+ 2 => Code::Unknown,
+ 3 => Code::InvalidArgument,
+ 4 => Code::DeadlineExceeded,
+ 5 => Code::NotFound,
+ 6 => Code::AlreadyExists,
+ 7 => Code::PermissionDenied,
+ 8 => Code::ResourceExhausted,
+ 9 => Code::FailedPrecondition,
+ 10 => Code::Aborted,
+ 11 => Code::OutOfRange,
+ 12 => Code::Unimplemented,
+ 13 => Code::Internal,
+ 14 => Code::Unavailable,
+ 15 => Code::DataLoss,
+ 16 => Code::Unauthenticated,
+ _ => Code::Internal,
+ };
+ Status::new(status, text)
+}

File Metadata

Mime Type
text/plain
Expires
Tue, Nov 26, 3:47 AM (13 h, 3 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2582604
Default Alt Text
D5487.id17921.diff (4 KB)

Event Timeline