Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a signmessage rpc command to the PrivaAPI #221

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions teos/proto/teos/v2/tower_services.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "user.proto";
import "common/teos/v2/appointment.proto";
import "common/teos/v2/user.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/wrappers.proto";

message NetworkAddress {
// Tower public API endpoint.
Expand Down Expand Up @@ -46,5 +47,6 @@ service PrivateTowerServices {
rpc get_tower_info(google.protobuf.Empty) returns (GetTowerInfoResponse) {}
rpc get_users(google.protobuf.Empty) returns (GetUsersResponse) {}
rpc get_user(GetUserRequest) returns (GetUserResponse) {}
rpc sign_message(google.protobuf.StringValue) returns (google.protobuf.StringValue) {}
rpc stop(google.protobuf.Empty) returns (google.protobuf.Empty) {}
}
7 changes: 7 additions & 0 deletions teos/src/api/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,13 @@ impl PrivateTowerServices for Arc<InternalAPI> {
}
}

/// Signs a message using the tower's signing key
async fn sign_message(&self, request: Request<String>) -> Result<Response<String>, Status> {
Ok(Response::new(
self.watcher.sign_message(&request.into_inner()),
))
}

/// Stop endpoint. Stops the tower daemon. Part of the private API.
async fn stop(&self, request: Request<()>) -> Result<Response<()>, Status> {
self.shutdown_trigger.trigger();
Expand Down
4 changes: 4 additions & 0 deletions teos/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ async fn main() {
Err(e) => println!("{e}"),
};
}
Command::SignMessage(m) => {
let sig = client.sign_message(Request::new(m.message)).await;
println!("{}", sig.unwrap().into_inner());
}
Command::Stop => {
println!("Shutting down tower");
client.stop(Request::new(())).await.unwrap();
Expand Down
8 changes: 8 additions & 0 deletions teos/src/cli_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub enum Command {
GetUsers,
/// Gets information about a specific user
GetUser(GetUserData),
/// Signs a message using the tower's secret key
SignMessage(MessageToSign),
/// Requests a graceful shutdown of the tower
Stop,
}
Expand All @@ -33,6 +35,12 @@ pub struct GetAppointmentsData {
pub locator: String,
}

#[derive(Debug, StructOpt, Clone)]
pub struct MessageToSign {
/// The locator of the appointments (16-byte hexadecimal string).
pub message: String,
}

/// Holds all the command line options and commands.
#[derive(StructOpt, Debug)]
#[structopt(rename_all = "lowercase")]
Expand Down
5 changes: 5 additions & 0 deletions teos/src/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,11 @@ impl Watcher {

Ok((subscription_info, locators))
}

/// Signs a message using the tower's signing key
pub(crate) fn sign_message(&self, message: &str) -> String {
cryptography::sign(message.as_bytes(), &self.signing_key).unwrap()
}
}

/// Listen implementation by the [Watcher]. Handles monitoring and reorgs.
Expand Down