Page MenuHomePhabricator

D5945.id20230.diff
No OneTemporary

D5945.id20230.diff

diff --git a/services/tunnelbroker/src/server/tools.rs b/services/tunnelbroker/src/server/tools.rs
--- a/services/tunnelbroker/src/server/tools.rs
+++ b/services/tunnelbroker/src/server/tools.rs
@@ -1,4 +1,7 @@
use crate::server::GRPCStatusCodes;
+use openssl::pkey::PKey;
+use openssl::sign::Verifier;
+use openssl::{error::ErrorStack, hash::MessageDigest};
use tonic::{Code, Status};
pub fn create_tonic_status(code: GRPCStatusCodes, text: &str) -> Status {
@@ -24,3 +27,17 @@
};
Status::new(status, text)
}
+
+pub fn verify_signed_string(
+ public_key_pem: &str,
+ string_to_be_signed: &str,
+ base64_signature: &str,
+) -> Result<bool, ErrorStack> {
+ let public_key = PKey::public_key_from_pem(public_key_pem.as_bytes())?;
+ let mut verifier = Verifier::new(MessageDigest::sha256(), &public_key)?;
+ verifier.update(string_to_be_signed.as_bytes()).unwrap();
+ verifier.verify(
+ &base64::decode(base64_signature)
+ .expect("Error on decoding the signature from base64"),
+ )
+}

File Metadata

Mime Type
text/plain
Expires
Thu, Dec 19, 6:17 PM (14 h, 18 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2676851
Default Alt Text
D5945.id20230.diff (1012 B)

Event Timeline