mirror of
https://git.asonix.dog/asonix/relay.git
synced 2024-12-21 02:36:30 +00:00
Improve error in signature verification
This commit is contained in:
parent
b53ec4d980
commit
5cd0b21ae3
2 changed files with 12 additions and 6 deletions
|
@ -100,6 +100,9 @@ pub(crate) enum ErrorKind {
|
||||||
#[error("Couldn't sign digest")]
|
#[error("Couldn't sign digest")]
|
||||||
Signature(#[from] signature::Error),
|
Signature(#[from] signature::Error),
|
||||||
|
|
||||||
|
#[error("Couldn't read signature")]
|
||||||
|
ReadSignature(signature::Error),
|
||||||
|
|
||||||
#[error("Couldn't parse the signature header")]
|
#[error("Couldn't parse the signature header")]
|
||||||
HeaderValidation(#[from] actix_web::http::header::InvalidHeaderValue),
|
HeaderValidation(#[from] actix_web::http::header::InvalidHeaderValue),
|
||||||
|
|
||||||
|
|
|
@ -113,9 +113,11 @@ async fn do_verify(
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let public_key = RsaPublicKey::from_public_key_pem(public_key.trim())?;
|
let public_key = RsaPublicKey::from_public_key_pem(public_key.trim())?;
|
||||||
|
|
||||||
|
let span = tracing::Span::current();
|
||||||
web::block(move || {
|
web::block(move || {
|
||||||
|
span.in_scope(|| {
|
||||||
let decoded = base64::decode(signature)?;
|
let decoded = base64::decode(signature)?;
|
||||||
let signature = Signature::from_bytes(&decoded)?;
|
let signature = Signature::from_bytes(&decoded).map_err(ErrorKind::ReadSignature)?;
|
||||||
let hashed = Sha256::new_with_prefix(signing_string.as_bytes());
|
let hashed = Sha256::new_with_prefix(signing_string.as_bytes());
|
||||||
|
|
||||||
let verifying_key = VerifyingKey::new_with_prefix(public_key);
|
let verifying_key = VerifyingKey::new_with_prefix(public_key);
|
||||||
|
@ -123,6 +125,7 @@ async fn do_verify(
|
||||||
|
|
||||||
Ok(()) as Result<(), Error>
|
Ok(()) as Result<(), Error>
|
||||||
})
|
})
|
||||||
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue