@@ -3,7 +3,7 @@ use crate::{
33 internal:: { rest:: IronCoreRequest , * } ,
44} ;
55use itertools:: { Either , Itertools } ;
6- use jsonwebtoken:: { Algorithm , DecodingKey , Validation } ;
6+ use jsonwebtoken:: Algorithm ;
77use rand:: rngs:: OsRng ;
88use recrypt:: prelude:: * ;
99use std:: {
@@ -318,29 +318,22 @@ pub struct JwtClaims {
318318/// Must be either ES256 or RS256 and have a payload similar to [JwtClaims](struct.JwtClaims.html), but could be
319319/// generated from an external source.
320320#[ allow( clippy:: derive_partial_eq_without_eq) ]
321- #[ derive( Clone , Debug , PartialEq , Serialize , Deserialize , Hash ) ]
321+ #[ derive( Clone , Debug , PartialEq , Serialize , Deserialize ) ]
322322pub struct Jwt {
323323 jwt : String ,
324324 header : jsonwebtoken:: Header ,
325325 claims : JwtClaims ,
326326}
327+
327328impl Jwt {
328329 /// Constructs a new Jwt.
329330 ///
330331 /// Verifies that the provided jwt uses a compatible algorithm and contains the required claims.
331332 pub fn new ( jwt : & str ) -> Result < Jwt , IronOxideErr > {
332- let bogus_key = DecodingKey :: from_secret ( & [ ] ) ;
333- let validation = {
334- let mut temp: Validation = Default :: default ( ) ;
335- temp. insecure_disable_signature_validation ( ) ;
336- temp. validate_aud = false ;
337- temp. validate_exp = false ;
338- temp
339- } ;
340- // This suspect key/validation is acceptable here because the server will do the actual
333+ // This insecure decode is acceptable here because the server will do the actual
341334 // signature verification and validation. We just want to do a little initial validation
342335 // to catch issues earlier.
343- let token_data = jsonwebtoken:: decode :: < JwtClaims > ( jwt, & bogus_key , & validation )
336+ let token_data = jsonwebtoken:: dangerous :: insecure_decode :: < JwtClaims > ( jwt)
344337 . map_err ( |e| IronOxideErr :: ValidationError ( "jwt" . to_string ( ) , e. to_string ( ) ) ) ?;
345338 let JwtClaims {
346339 pid,
@@ -416,6 +409,12 @@ impl std::fmt::Display for Jwt {
416409 write ! ( f, "{}" , self . jwt)
417410 }
418411}
412+ impl std:: hash:: Hash for Jwt {
413+ fn hash < H : std:: hash:: Hasher > ( & self , state : & mut H ) {
414+ // Header and claims are derived from the string
415+ self . jwt . hash ( state) ;
416+ }
417+ }
419418
420419/// Verify an existing user given a valid JWT.
421420pub async fn user_verify (
0 commit comments