Update RSA, other deps
This commit is contained in:
@@ -84,6 +84,9 @@ pub(crate) enum ErrorKind {
|
||||
#[error("Couldn't build signing string, {0}")]
|
||||
PrepareSign(#[from] PrepareSignError),
|
||||
|
||||
#[error("Couldn't sign digest")]
|
||||
Signature(#[from] signature::Error),
|
||||
|
||||
#[error("Couldn't parse the signature header")]
|
||||
HeaderValidation(#[from] actix_web::http::header::InvalidHeaderValue),
|
||||
|
||||
|
||||
@@ -7,8 +7,9 @@ use crate::{
|
||||
use activitystreams::{base::BaseExt, iri, iri_string::types::IriString};
|
||||
use actix_web::web;
|
||||
use http_signature_normalization_actix::{prelude::*, verify::DeprecatedAlgorithm};
|
||||
use rsa::{hash::Hash, padding::PaddingScheme, pkcs8::DecodePublicKey, PublicKey, RsaPublicKey};
|
||||
use rsa::{pkcs1v15::VerifyingKey, pkcs8::DecodePublicKey, RsaPublicKey};
|
||||
use sha2::{Digest, Sha256};
|
||||
use signature::{DigestVerifier, Signature};
|
||||
use std::{future::Future, pin::Pin};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -111,15 +112,11 @@ async fn do_verify(
|
||||
|
||||
web::block(move || {
|
||||
let decoded = base64::decode(signature)?;
|
||||
let hashed = Sha256::digest(signing_string.as_bytes());
|
||||
let signature = Signature::from_bytes(&decoded)?;
|
||||
let hashed = Sha256::new_with_prefix(signing_string.as_bytes());
|
||||
|
||||
public_key.verify(
|
||||
PaddingScheme::PKCS1v15Sign {
|
||||
hash: Some(Hash::SHA2_256),
|
||||
},
|
||||
&hashed,
|
||||
&decoded,
|
||||
)?;
|
||||
let verifying_key = VerifyingKey::new_with_prefix(public_key);
|
||||
verifying_key.verify_digest(hashed, &signature)?;
|
||||
|
||||
Ok(()) as Result<(), Error>
|
||||
})
|
||||
|
||||
+6
-8
@@ -4,8 +4,10 @@ use actix_web::{http::header::Date, web::Bytes};
|
||||
use awc::Client;
|
||||
use dashmap::DashMap;
|
||||
use http_signature_normalization_actix::prelude::*;
|
||||
use rsa::{hash::Hash, padding::PaddingScheme, RsaPrivateKey};
|
||||
use rand::thread_rng;
|
||||
use rsa::{pkcs1v15::SigningKey, RsaPrivateKey};
|
||||
use sha2::{Digest, Sha256};
|
||||
use signature::RandomizedSigner;
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
rc::Rc,
|
||||
@@ -420,12 +422,8 @@ struct Signer {
|
||||
impl Signer {
|
||||
fn sign(&self, signing_string: &str) -> Result<String, Error> {
|
||||
let hashed = Sha256::digest(signing_string.as_bytes());
|
||||
let bytes = self.private_key.sign(
|
||||
PaddingScheme::PKCS1v15Sign {
|
||||
hash: Some(Hash::SHA2_256),
|
||||
},
|
||||
&hashed,
|
||||
)?;
|
||||
Ok(base64::encode(bytes))
|
||||
let signing_key = SigningKey::<Sha256>::new_with_prefix(self.private_key.clone());
|
||||
let signature = signing_key.try_sign_with_rng(thread_rng(), &hashed)?;
|
||||
Ok(base64::encode(signature.as_ref()))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user