-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
873d1ff
commit df28163
Showing
11 changed files
with
293 additions
and
149 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use crate::cryptography::Secp256k1; | ||
use aws_sdk_kms::types::{KeySpec, KeyUsageType, SigningAlgorithmSpec}; | ||
|
||
/// Defines the needed methods for providing a definition of cryptography used with AWS KMS | ||
pub trait AwsKmsCryptography { | ||
/// Returns the [KeySpec] for the desired cryptography | ||
fn key_spec() -> KeySpec; | ||
|
||
/// Returns the [KeyUsageType] for the desired cryptography | ||
fn key_usage_type() -> KeyUsageType; | ||
|
||
/// Returns the [SigningAlgorithmSpec] for the desired cryptography | ||
fn signing_algorithm_spec() -> SigningAlgorithmSpec; | ||
} | ||
|
||
impl AwsKmsCryptography for Secp256k1 { | ||
fn key_spec() -> KeySpec { | ||
KeySpec::EccSecgP256K1 | ||
} | ||
|
||
fn key_usage_type() -> KeyUsageType { | ||
KeyUsageType::SignVerify | ||
} | ||
|
||
fn signing_algorithm_spec() -> SigningAlgorithmSpec { | ||
SigningAlgorithmSpec::EcdsaSha256 | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use crate::cryptography::Ed25519; | ||
use vaultrs::api::transit::KeyType; | ||
|
||
/// Defines the needed methods for providing a definition of cryptography used with HashiCorp Vault | ||
pub trait HashiCorpVaultCryptography { | ||
/// Returns the [KeyType] for the desired cryptography | ||
fn key_type() -> KeyType; | ||
} | ||
|
||
impl HashiCorpVaultCryptography for Ed25519 { | ||
fn key_type() -> KeyType { | ||
KeyType::Ed25519 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
pub mod aws_kms; | ||
pub mod google_kms; | ||
pub mod hashicorp_vault; | ||
pub mod verifier; | ||
|
||
/// The Secp256k1 curve. | ||
#[derive(Debug, Clone, Copy)] | ||
pub struct Secp256k1; | ||
|
||
/// The Ed25519 curve. | ||
#[derive(Debug, Clone, Copy)] | ||
pub struct Ed25519; | ||
|
||
#[derive(Debug, Clone, Copy)] | ||
pub enum Curve { | ||
Secp256k1(Secp256k1), | ||
Ed25519(Ed25519), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use crate::{Bytes, PublicKey, Signature}; | ||
|
||
#[async_trait::async_trait] | ||
pub trait LocalVerifier { | ||
/// Verifies a signature for a given message and public key. | ||
async fn verify( | ||
message: Bytes, | ||
public_key: PublicKey, | ||
signature: Signature, | ||
) -> Result<bool, anyhow::Error>; | ||
} | ||
|
||
pub mod secp256k1 { | ||
use super::*; | ||
use crate::cryptography::Secp256k1; | ||
use anyhow::Context; | ||
use k256::ecdsa::{self, VerifyingKey}; | ||
use k256::pkcs8::DecodePublicKey; | ||
use ring_compat::signature::Verifier; | ||
|
||
#[async_trait::async_trait] | ||
impl LocalVerifier for Secp256k1 { | ||
async fn verify( | ||
message: Bytes, | ||
public_key: PublicKey, | ||
signature: Signature, | ||
) -> Result<bool, anyhow::Error> { | ||
let verifying_key = VerifyingKey::from_public_key_der(&public_key.0 .0) | ||
.context("Failed to create verifying key")?; | ||
|
||
let signature = ecdsa::Signature::from_der(&signature.0 .0) | ||
.context("Failed to create signature")?; | ||
|
||
match verifying_key.verify(message.0.as_slice(), &signature) { | ||
Ok(_) => Ok(true), | ||
Err(e) => { | ||
println!("Error verifying signature: {:?}", e); | ||
Ok(false) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
pub mod ed25519 { | ||
|
||
use super::*; | ||
use crate::cryptography::Ed25519; | ||
use anyhow::Context; | ||
use ring_compat::signature::{ | ||
ed25519::{self, VerifyingKey}, | ||
Verifier, | ||
}; | ||
|
||
#[async_trait::async_trait] | ||
impl LocalVerifier for Ed25519 { | ||
async fn verify( | ||
message: Bytes, | ||
public_key: PublicKey, | ||
signature: Signature, | ||
) -> Result<bool, anyhow::Error> { | ||
let verifying_key = VerifyingKey::from_slice(public_key.0 .0.as_slice()) | ||
.context("Failed to create verifying key")?; | ||
|
||
let signature = ed25519::Signature::from_slice(signature.0 .0.as_slice()) | ||
.context("Failed to create signature")?; | ||
|
||
Ok(verifying_key.verify(message.0.as_slice(), &signature).is_ok()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
pub mod aws_kms; | ||
pub mod google_kms; | ||
pub mod hashi_corp_vault; | ||
|
||
#[derive(Debug, Clone, Copy)] | ||
pub enum Provider { | ||
AWS, | ||
GCP, | ||
Vault, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
pub mod action_stream; | ||
pub mod cli; | ||
pub mod cryptography; | ||
pub mod hsm; | ||
pub mod server; | ||
|
||
|
Oops, something went wrong.