Skip to content

Commit

Permalink
feat: add cli command for requesting file decryption
Browse files Browse the repository at this point in the history
  • Loading branch information
dufkan committed Oct 29, 2023
1 parent 3772464 commit c1319a0
Show file tree
Hide file tree
Showing 3 changed files with 212 additions and 5 deletions.
152 changes: 152 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ tempfile = "3.3.0"
lazy_static = "1.4.0"
openssl = "0.10.57"
sha2 = "0.10.6"
meesign-crypto = { git = "https://github.com/crocs-muni/meesign-crypto", rev = "6a6fbf7", default-features = false }
meesign-crypto = { git = "https://github.com/crocs-muni/meesign-crypto", rev = "6a6fbf7", default-features = false, features = ["elgamal"] }

[build-dependencies]
tonic-build = "0.10"
Expand Down
63 changes: 59 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ mod cli {
group_id: String,
data: String,
},
RequestDecryptFile {
name: String,
group_id: String,
data_file: String,
data_type: String,
},
}

pub(super) async fn handle_command(args: Args) -> Result<(), String> {
Expand Down Expand Up @@ -213,7 +219,9 @@ mod cli {
for task in response.tasks {
let task_type = match task.r#type {
0 => "Group",
1 => "Sign",
1 => "Sign pdf",
2 => "Sign challenge",
3 => "Decrypt",
_ => "Unknown",
};
println!(
Expand Down Expand Up @@ -258,7 +266,9 @@ mod cli {
let task = response;
let task_type = match task.r#type {
0 => "Group",
1 => "Sign",
1 => "Sign pdf",
2 => "Sign challenge",
3 => "Decrypt",
_ => "Unknown",
};
println!(
Expand Down Expand Up @@ -291,7 +301,9 @@ mod cli {
let task = response;
let task_type = match task.r#type {
0 => "Group",
1 => "Sign",
1 => "Sign pdf",
2 => "Sign challenge",
3 => "Decrypt",
_ => "Unknown",
};
println!(
Expand Down Expand Up @@ -325,7 +337,50 @@ mod cli {
let task = response;
let task_type = match task.r#type {
0 => "Group",
1 => "Sign",
1 => "Sign pdf",
2 => "Sign challenge",
3 => "Decrypt",
_ => "Unknown",
};
println!(
"Task {} [{}] (state {}:{})",
task_type,
hex::encode(task.id),
task.state,
task.round
);
}
Commands::RequestDecryptFile {
name,
group_id,
data_file,
data_type,
} => {
use meesign_crypto::protocol::elgamal::encrypt as elgamal_encrypt;
let group_id = hex::decode(group_id).unwrap();
let data = tokio::fs::read(data_file).await.unwrap();
let data = elgamal_encrypt(&data, &group_id).unwrap();
println!("{:?}", data);

let request = tonic::Request::new(crate::proto::DecryptRequest {
name,
group_id,
data,
data_type,
});

let response = client
.decrypt(request)
.await
.map_err(|_| String::from("Request failed"))?
.into_inner();

let task = response;
let task_type = match task.r#type {
0 => "Group",
1 => "Sign pdf",
2 => "Sign challenge",
3 => "Decrypt",
_ => "Unknown",
};
println!(
Expand Down

0 comments on commit c1319a0

Please sign in to comment.