-
Notifications
You must be signed in to change notification settings - Fork 3
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
b34a93d
commit bd2ca9c
Showing
3 changed files
with
62 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use std::str::FromStr as _; | ||
|
||
use base64::{engine::general_purpose::URL_SAFE_NO_PAD, Engine as _}; | ||
use identity_iota::{ | ||
core::{FromJson as _, ToJson as _}, | ||
verification::{ | ||
jwk::Jwk, | ||
jws::{JwsVerifier, SignatureVerificationError, VerificationInput}, | ||
}, | ||
}; | ||
use jsonwebtoken::{crypto::verify, Algorithm, DecodingKey, Validation}; | ||
|
||
/// This `Verifier` uses `jsonwebtoken` under the hood to verify verification input. | ||
pub struct Verifier; | ||
impl JwsVerifier for Verifier { | ||
fn verify(&self, input: VerificationInput, public_key: &Jwk) -> Result<(), SignatureVerificationError> { | ||
let algorithm = Algorithm::from_str(&input.alg.to_string()).unwrap(); | ||
|
||
println!("public_key: {:?}", public_key); | ||
|
||
// Convert the `Jwk` first into a `jsonwebtoken::jwk::Jwk` and then into a `DecodingKey`. | ||
let decoding_key = public_key | ||
.to_json() | ||
.ok() | ||
.and_then(|public_key| jsonwebtoken::jwk::Jwk::from_json(&public_key).ok()) | ||
.and_then(|jwk| DecodingKey::from_jwk(&jwk).ok()) | ||
.unwrap(); | ||
|
||
let mut validation = Validation::new(algorithm); | ||
validation.validate_aud = false; | ||
validation.required_spec_claims.clear(); | ||
|
||
println!("validation: {:?}", validation); | ||
|
||
verify( | ||
&URL_SAFE_NO_PAD.encode(input.decoded_signature), | ||
&input.signing_input, | ||
&decoding_key, | ||
algorithm, | ||
) | ||
.unwrap(); | ||
|
||
Ok(()) | ||
} | ||
} |