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

Updates for webauthn-rs #32

Merged
merged 1 commit into from
Jul 19, 2024
Merged
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "compact_jwt"
version = "0.4.1"
version = "0.4.2"
edition = "2021"
authors = ["William Brown <[email protected]>"]
description = "Minimal implementation of JWT for OIDC and other applications"
Expand Down
20 changes: 20 additions & 0 deletions src/crypto/x509.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,26 @@ pub struct JwsX509Verifier {
pkey: x509::X509,
}

impl JwsX509Verifier {
/// Create a new Jws Verifier directly from an x509 certificate. Note that this bypasses
/// any verification of the trust chain in the x5c attribute. If possible, you should use
/// [JwsX509VerifierBuilder] instead.
pub fn from_x509(pkey: x509::X509) -> Result<Self, JwtError> {
let digest = hash::MessageDigest::sha256();
let kid = pkey
.public_key()
.and_then(|pkey| pkey.public_key_to_der())
.and_then(|der| hash::hash(digest, &der))
.map(hex::encode)
.map_err(|e| {
debug!(?e);
JwtError::OpenSSLError
})?;

Ok(JwsX509Verifier { kid, pkey })
}
}

impl JwsVerifier for JwsX509Verifier {
fn get_kid(&self) -> &str {
&self.kid
Expand Down
2 changes: 2 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ pub enum JwtError {
AlgorithmUnavailable,
/// The request to release the key is unable to be satisfied.
UnableToReleaseKey,
/// Serialisation / Deserialisation error
Serde,
}

impl fmt::Display for JwtError {
Expand Down
Loading