File tree Expand file tree Collapse file tree
src/main/java/com/wolfssl/wolfcrypt Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -47,12 +47,45 @@ public WolfCryptException(String reason) {
4747 * @param code wolfCrypt error code
4848 */
4949 public WolfCryptException (int code ) {
50- super (WolfCryptError . fromInt (code ). getDescription ( ));
50+ super (getErrorMessage (code ));
5151
5252 this .error = WolfCryptError .fromInt (code );
5353 this .code = code ;
5454 }
5555
56+ /**
57+ * Build exception message from error code. For FIPS not allowed errors
58+ * (-197), queries and appends the current FIPS module status to help
59+ * diagnose the root cause.
60+ *
61+ * @param code wolfCrypt error code
62+ * @return descriptive error message string
63+ */
64+ private static String getErrorMessage (int code ) {
65+
66+ String msg = WolfCryptError .fromInt (code ).getDescription ();
67+
68+ /* Get module status for root cause of FIPS not allowed failure */
69+ if (code == WolfCryptError .FIPS_NOT_ALLOWED_E .getCode ()) {
70+ try {
71+ if (Fips .enabled ) {
72+ int status = Fips .wolfCrypt_GetStatus_fips ();
73+ if (status != 0 ) {
74+ String statusDesc =
75+ WolfCryptError .fromInt (status ).getDescription ();
76+ msg += " [FIPS module status: " + status + " (" +
77+ statusDesc + ")]" ;
78+ }
79+ }
80+ }
81+ catch (Exception e ) {
82+ /* FIPS status query not available */
83+ }
84+ }
85+
86+ return msg ;
87+ }
88+
5689 /**
5790 * Create new WolfCryptException from reason and cause
5891 *
You can’t perform that action at this time.
0 commit comments