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{/$}")
562
+
bunt::eprintln!("{$red+bold}The JWT provided is invalid{/$}")
555
563
}
556
564
ErrorKind::InvalidSignature => {
557
565
bunt::eprintln!("{$red+bold}The JWT provided has an invalid signature{/$}")
@@ -566,7 +574,7 @@ fn print_decoded_token(
566
574
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.{/$}")
567
575
}
568
576
ErrorKind::InvalidIssuer => {
569
-
bunt::println!("{$red+bold}The token issuer is invalid{/$}")
577
+
bunt::eprintln!("{$red+bold}The token issuer is invalid{/$}")
570
578
}
571
579
ErrorKind::InvalidAudience => {
572
580
bunt::eprintln!("{$red+bold}The token audience doesn't match the subject{/$}")
@@ -582,15 +590,27 @@ fn print_decoded_token(
582
590
Ok(ref token) => token.header.alg,
583
591
Err(_) => panic!("Error: Invalid token data."),
584
592
};
585
-
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)
593
+
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())
586
594
}
587
595
_ => bunt::eprintln!(
588
596
"{$red+bold}The JWT provided is invalid because {:?}{/$}",
589
597
err
590
598
),
591
599
},
592
600
Some(Ok(_)) => bunt::eprintln!("{$green+bold}Success! JWT signature is valid!{/$}"),
593
-
None => bunt::eprintln!("{$red+bold}Warning! JWT signature has not been validated!{/$}"),
601
+
None => {
602
+
// the signature could not be verified
603
+
match token_data {
604
+
Err(ref err) => match err.kind(){
605
+
ErrorKind::InvalidToken => bunt::eprintln!("{$red+bold}Error: The token could not be decoded (invalid token structure).{/$}"),
606
+
ErrorKind::Base64(_) => bunt::eprintln!("{$red+bold}Error: The token could not be decoded (invalid Base64 encoding).{/$}"),
607
+
ErrorKind::Json(_) => bunt::eprintln!("{$red+bold}Error: The token could not be decoded (error while decoding json).{/$}"),
608
+
ErrorKind::Utf8(_) => bunt::eprintln!("{$red+bold}Error: The token could not be decoded (error while decoding UTF8 string).{/$}"),
609
+
_ => bunt::eprintln!("{$red+bold}Error: Unexpected error while decoding the token!{/$}"),
610
+
}
611
+
Ok(_) => bunt::eprintln!("{$red+bold}Warning! JWT signature has not been validated!{/$}"),
0 commit comments