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

Populates the algorithm Signature Parameter based on which Signer is used. #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions src/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ pub trait HttpSignatureSign: Debug + Send + Sync + 'static {
/// header. For all currently supported signature schemes, the encoding is
/// specified to be base64.
fn http_sign(&self, bytes_to_sign: &[u8]) -> String;

/// Returns the name of this signing algorithm, as expected by the algorithm
/// parameter in the HTTP Authorization header.
fn name(&self) -> &str;
}

/// Implements the verification half of an HTTP signature algorithm. For symmetric
Expand Down Expand Up @@ -57,6 +61,10 @@ macro_rules! hmac_signature {
let tag = hmac.finalize().into_bytes();
base64::encode(tag)
}

fn name(&self) -> &str {
$name
}
}
impl HttpSignatureVerify for $typename {
fn http_verify(&self, bytes_to_verify: &[u8], signature: &str) -> bool {
Expand Down
6 changes: 6 additions & 0 deletions src/algorithm/openssl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ macro_rules! rsa_signature {
.expect("Signing to be infallible");
base64::encode(&tag)
}


fn name(&self) -> &str {
$name
}

}
impl HttpSignatureVerify for $verify_name {
fn http_verify(&self, bytes_to_verify: &[u8], signature: &str) -> bool {
Expand Down
4 changes: 4 additions & 0 deletions src/algorithm/ring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ macro_rules! rsa_signature {
.expect("Signing should be infallible");
base64::encode(&tag)
}

fn name(&self) -> &str {
$name
}
}
impl HttpSignatureVerify for $verify_name {
fn http_verify(&self, bytes_to_verify: &[u8], signature: &str) -> bool {
Expand Down
7 changes: 5 additions & 2 deletions src/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,13 @@ impl<R: ClientRequestLike> SigningExt for R {
// Sign the content
let signature = config.signature.http_sign(content.as_bytes());

// Get the algorithm name
let sig_algo = config.signature.name();

// Construct the authorization header
let auth_header = format!(
r#"Signature keyId="{}",algorithm="{}",signature="{}",headers="{}"#,
config.key_id, "hs2019", signature, joined_headers
r#"Signature keyId="{}",algorithm="{}",signature="{}",headers="{}""#,
config.key_id, sig_algo, signature, joined_headers
);

// Attach the authorization header to the request
Expand Down