You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This commit introduces a verify command that enforces signature
validation. The decode command now does not attempt to validate the
token signature and does not expect the parameters `--secret`,
`--ignore_exp` and `--alg` any more.
This commit also includes some additional code cleanups regarding exit
codes.
bunt::println!("{$red+bold}The JWT provided is invalid{/$}")
577
+
bunt::eprintln!("{$red+bold}The JWT provided is invalid{/$}")
570
578
}
571
579
ErrorKind::InvalidSignature => {
572
580
bunt::eprintln!("{$red+bold}The JWT provided has an invalid signature{/$}")
@@ -581,7 +589,7 @@ fn print_decoded_token(
581
589
bunt::eprintln!("{$red+bold}The token has expired (or the `exp` claim is not set). This error can be ignored via the `--ignore-exp` parameter.{/$}")
582
590
}
583
591
ErrorKind::InvalidIssuer => {
584
-
bunt::println!("{$red+bold}The token issuer is invalid{/$}")
592
+
bunt::eprintln!("{$red+bold}The token issuer is invalid{/$}")
585
593
}
586
594
ErrorKind::InvalidAudience => {
587
595
bunt::eprintln!("{$red+bold}The token audience doesn't match the subject{/$}")
@@ -597,15 +605,27 @@ fn print_decoded_token(
597
605
Ok(ref token) => token.header.alg,
598
606
Err(_) => panic!("Error: Invalid token data."),
599
607
};
600
-
bunt::eprintln!("{$red+bold}Error: Invalid Signature! The JWT provided has a different signing algorithm ({:?}) than the one selected for validation ({:?}){/$}",jwt_algorithm, options_algorithm)
608
+
bunt::eprintln!("{$red+bold}Error: Invalid Signature! The JWT provided has a different signing algorithm ({:?}) than the one selected for validation ({:?}){/$}",jwt_algorithm, options_algorithm.unwrap())
601
609
}
602
610
_ => bunt::eprintln!(
603
611
"{$red+bold}The JWT provided is invalid because {:?}{/$}",
604
612
err
605
613
),
606
614
},
607
615
Some(Ok(_)) => bunt::eprintln!("{$green+bold}Success! JWT signature is valid!{/$}"),
608
-
None => bunt::eprintln!("{$red+bold}Warning! JWT signature has not been validated!{/$}"),
616
+
None => {
617
+
// the signature could not be verified
618
+
match token_data {
619
+
Err(ref err) => match err.kind(){
620
+
ErrorKind::InvalidToken => bunt::eprintln!("{$red+bold}Error: The token could not be decoded (invalid token structure).{/$}"),
621
+
ErrorKind::Base64(_) => bunt::eprintln!("{$red+bold}Error: The token could not be decoded (invalid Base64 encoding).{/$}"),
622
+
ErrorKind::Json(_) => bunt::eprintln!("{$red+bold}Error: The token could not be decoded (error while decoding json).{/$}"),
623
+
ErrorKind::Utf8(_) => bunt::eprintln!("{$red+bold}Error: The token could not be decoded (error while decoding UTF8 string).{/$}"),
624
+
_ => bunt::eprintln!("{$red+bold}Error: Unexpected error while decoding the token!{/$}"),
625
+
}
626
+
Ok(_) => bunt::eprintln!("{$red+bold}Warning! JWT signature has not been validated!{/$}"),
0 commit comments