diff --git a/src/main/java/com/wolfssl/provider/jce/WolfCryptCipher.java b/src/main/java/com/wolfssl/provider/jce/WolfCryptCipher.java index 03aae7c..43dc699 100644 --- a/src/main/java/com/wolfssl/provider/jce/WolfCryptCipher.java +++ b/src/main/java/com/wolfssl/provider/jce/WolfCryptCipher.java @@ -103,7 +103,6 @@ public class WolfCryptCipher extends CipherSpi { private Rng rng = null; /* for debug logging */ - private WolfCryptDebug debug; private String algString; private String algMode; @@ -147,7 +146,7 @@ public class WolfCryptCipher extends CipherSpi { break; } - if (debug.DEBUG) { + if (WolfCryptDebug.DEBUG) { algString = typeToString(cipherType); algMode = modeToString(cipherMode); } @@ -208,9 +207,7 @@ public class WolfCryptCipher extends CipherSpi { cipherMode = CipherMode.WC_ECB; supported = 1; - if (debug.DEBUG) { - log("set mode to ECB"); - } + log("set mode to ECB"); } } else if (mode.equals("CBC")) { @@ -221,9 +218,7 @@ public class WolfCryptCipher extends CipherSpi { cipherMode = CipherMode.WC_CBC; supported = 1; - if (debug.DEBUG) { - log("set mode to CBC"); - } + log("set mode to CBC"); } } else if (mode.equals("GCM")) { @@ -233,9 +228,7 @@ public class WolfCryptCipher extends CipherSpi { cipherMode = CipherMode.WC_GCM; supported = 1; - if (debug.DEBUG) { - log("set mode to GCM"); - } + log("set mode to GCM"); } } @@ -259,9 +252,7 @@ public class WolfCryptCipher extends CipherSpi { paddingType = PaddingType.WC_NONE; supported = 1; - if (debug.DEBUG) { - log("set padding to NoPadding"); - } + log("set padding to NoPadding"); } } else if (padding.equals("PKCS1Padding")) { @@ -270,9 +261,7 @@ public class WolfCryptCipher extends CipherSpi { paddingType = PaddingType.WC_PKCS1; supported = 1; - if (debug.DEBUG) { - log("set padding to PKCS1Padding"); - } + log("set padding to PKCS1Padding"); } } else if (padding.equals("PKCS5Padding")) { @@ -283,9 +272,7 @@ public class WolfCryptCipher extends CipherSpi { paddingType = PaddingType.WC_PKCS5; supported = 1; - if (debug.DEBUG) { - log("set padding to PKCS5Padding"); - } + log("set padding to PKCS5Padding"); } } @@ -564,9 +551,7 @@ public class WolfCryptCipher extends CipherSpi { wolfCryptCipherInit(opmode, key, null, random); - if (debug.DEBUG) { - log("initialized with key"); - } + log("initialized with key"); } catch (InvalidAlgorithmParameterException iape) { throw new InvalidKeyException("Invalid algorithm parameters"); @@ -580,9 +565,7 @@ public class WolfCryptCipher extends CipherSpi { wolfCryptCipherInit(opmode, key, params, random); - if (debug.DEBUG) { - log("initialized with key and AlgorithmParameterSpec"); - } + log("initialized with key and AlgorithmParameterSpec"); } @Override @@ -601,9 +584,7 @@ public class WolfCryptCipher extends CipherSpi { spec = params.getParameterSpec(IvParameterSpec.class); } - if (debug.DEBUG) { - log("initialized with key and AlgorithmParameters"); - } + log("initialized with key and AlgorithmParameters"); } catch (InvalidParameterSpecException ipe) { throw new InvalidAlgorithmParameterException(ipe); @@ -902,9 +883,7 @@ public class WolfCryptCipher extends CipherSpi { "Cipher has not been initialized yet"); } - if (debug.DEBUG) - log("update (offset: " + inputOffset + ", len: " + - inputLen + ")"); + log("update (offset: " + inputOffset + ", len: " + inputLen + ")"); output = wolfCryptUpdate(input, inputOffset, inputLen); @@ -923,9 +902,8 @@ public class WolfCryptCipher extends CipherSpi { "Cipher has not been initialized yet"); } - if (debug.DEBUG) - log("update (in offset: " + inputOffset + ", len: " + - inputLen + ", out offset: " + outputOffset + ")"); + log("update (in offset: " + inputOffset + ", len: " + + inputLen + ", out offset: " + outputOffset + ")"); tmpOut = wolfCryptUpdate(input, inputOffset, inputLen); if (tmpOut == null) { @@ -957,9 +935,7 @@ public class WolfCryptCipher extends CipherSpi { "Cipher has not been initialized yet"); } - if (debug.DEBUG) - log("final (offset: " + inputOffset + ", len: " + - inputLen + ")"); + log("final (offset: " + inputOffset + ", len: " + inputLen + ")"); return wolfCryptFinal(input, inputOffset, inputLen); } @@ -977,9 +953,8 @@ public class WolfCryptCipher extends CipherSpi { "Cipher has not been initialized yet"); } - if (debug.DEBUG) - log("final (in offset: " + inputOffset + ", len: " + - inputLen + ", out offset: " + outputOffset + ")"); + log("final (in offset: " + inputOffset + ", len: " + + inputLen + ", out offset: " + outputOffset + ")"); tmpOut = wolfCryptFinal(input, inputOffset, inputLen); @@ -1113,7 +1088,8 @@ public class WolfCryptCipher extends CipherSpi { } private void log(String msg) { - debug.print("[Cipher, " + algString + "-" + algMode + "] " + msg); + WolfCryptDebug.print("[Cipher, " + algString + "-" + + algMode + "] " + msg); } @SuppressWarnings("deprecation") diff --git a/src/main/java/com/wolfssl/provider/jce/WolfCryptDebug.java b/src/main/java/com/wolfssl/provider/jce/WolfCryptDebug.java index 7f4af20..f2ee03b 100644 --- a/src/main/java/com/wolfssl/provider/jce/WolfCryptDebug.java +++ b/src/main/java/com/wolfssl/provider/jce/WolfCryptDebug.java @@ -37,7 +37,9 @@ class WolfCryptDebug { } public static void print(String string) { - System.out.println("wolfJCE: " + string); + if (DEBUG) { + System.out.println("wolfJCE: " + string); + } } } diff --git a/src/main/java/com/wolfssl/provider/jce/WolfCryptKeyAgreement.java b/src/main/java/com/wolfssl/provider/jce/WolfCryptKeyAgreement.java index 63a5f7d..5e3dcbf 100644 --- a/src/main/java/com/wolfssl/provider/jce/WolfCryptKeyAgreement.java +++ b/src/main/java/com/wolfssl/provider/jce/WolfCryptKeyAgreement.java @@ -77,8 +77,6 @@ public class WolfCryptKeyAgreement extends KeyAgreementSpi { private KeyAgreeType type; private EngineState state = EngineState.WC_UNINITIALIZED; - - private WolfCryptDebug debug; private String algString; private WolfCryptKeyAgreement(KeyAgreeType type) { @@ -97,8 +95,9 @@ public class WolfCryptKeyAgreement extends KeyAgreementSpi { break; }; - if (debug.DEBUG) + if (WolfCryptDebug.DEBUG) { algString = typeToString(type); + } this.state = EngineState.WC_INIT_DONE; } @@ -109,8 +108,7 @@ public class WolfCryptKeyAgreement extends KeyAgreementSpi { byte[] pubKey = null; - if (debug.DEBUG) - log("engineDoPhase, lastPhase: " + lastPhase); + log("engineDoPhase, lastPhase: " + lastPhase); if (this.state != EngineState.WC_PRIVKEY_DONE) throw new IllegalStateException( @@ -188,8 +186,7 @@ public class WolfCryptKeyAgreement extends KeyAgreementSpi { len = engineGenerateSecret(tmp, 0); - if (debug.DEBUG) - log("generated secret, len: " + len); + log("generated secret, len: " + len); /* may need to truncate */ secret = new byte[len]; @@ -322,8 +319,7 @@ public class WolfCryptKeyAgreement extends KeyAgreementSpi { if (tmp != null) { - if (debug.DEBUG) - log("generated secret, len: " + tmp.length); + log("generated secret, len: " + tmp.length); zeroArray(tmp); return tmp.length; @@ -339,8 +335,7 @@ public class WolfCryptKeyAgreement extends KeyAgreementSpi { byte secret[] = engineGenerateSecret(); - if (debug.DEBUG) - log("generating SecretKey for " + algorithm); + log("generating SecretKey for " + algorithm); if (algorithm.equals("DES")) { return (SecretKey)new DESKeySpec(secret); @@ -450,19 +445,16 @@ public class WolfCryptKeyAgreement extends KeyAgreementSpi { /* look up curve size */ this.curveSize = this.ecPrivate.getCurveSizeFromName( this.curveName); - if (debug.DEBUG) - log("curveName: " + curveName + ", curveSize: " + curveSize); + log("curveName: " + curveName + ", curveSize: " + curveSize); } else if (spec instanceof ECParameterSpec) { ECParameterSpec espec = (ECParameterSpec)spec; this.curveName = this.ecPrivate.getCurveName(espec); - this.curveSize = this.ecPrivate.getCurveSizeFromName( this.curveName); - if (debug.DEBUG) - log("curveName: " + curveName + ", curveSize: " + curveSize); + log("curveName: " + curveName + ", curveSize: " + curveSize); } else { throw new InvalidAlgorithmParameterException( @@ -527,8 +519,7 @@ public class WolfCryptKeyAgreement extends KeyAgreementSpi { SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException { - if (debug.DEBUG) - log("initialized with key and AlgorithmParameterSpec"); + log("initialized with key and AlgorithmParameterSpec"); wcKeyAgreementInit(key, params, random); @@ -540,9 +531,7 @@ public class WolfCryptKeyAgreement extends KeyAgreementSpi { throws InvalidKeyException { try { - - if (debug.DEBUG) - log("initialized with key"); + log("initialized with key"); wcKeyAgreementInit(key, null, random); @@ -575,7 +564,7 @@ public class WolfCryptKeyAgreement extends KeyAgreementSpi { } private void log(String msg) { - debug.print("[KeyAgreement, " + algString + "] " + msg); + WolfCryptDebug.print("[KeyAgreement, " + algString + "] " + msg); } @SuppressWarnings("deprecation") diff --git a/src/main/java/com/wolfssl/provider/jce/WolfCryptKeyPairGenerator.java b/src/main/java/com/wolfssl/provider/jce/WolfCryptKeyPairGenerator.java index 0d72d1e..fd39a28 100644 --- a/src/main/java/com/wolfssl/provider/jce/WolfCryptKeyPairGenerator.java +++ b/src/main/java/com/wolfssl/provider/jce/WolfCryptKeyPairGenerator.java @@ -84,15 +84,15 @@ public class WolfCryptKeyPairGenerator extends KeyPairGeneratorSpi { private final Object rngLock = new Object(); /* for debug logging */ - private WolfCryptDebug debug; private String algString; private WolfCryptKeyPairGenerator(KeyType type) { this.type = type; - if (debug.DEBUG) + if (WolfCryptDebug.DEBUG) { algString = typeToString(type); + } } @Override @@ -118,8 +118,7 @@ public class WolfCryptKeyPairGenerator extends KeyPairGeneratorSpi { } } - if (debug.DEBUG) - log("init with keysize: " + keysize); + log("init with keysize: " + keysize); } @Override @@ -161,10 +160,8 @@ public class WolfCryptKeyPairGenerator extends KeyPairGeneratorSpi { "RSA public exponent value larger than long"); } - if (debug.DEBUG) { - log("init with RSA spec, keysize = " + keysize + - ", public exponent = " + publicExponent); - } + log("init with RSA spec, keysize = " + keysize + + ", public exponent = " + publicExponent); break; @@ -189,9 +186,8 @@ public class WolfCryptKeyPairGenerator extends KeyPairGeneratorSpi { this.curve = curveName; this.keysize = curvesize; - if (debug.DEBUG) - log("init with spec, curve: " + curveName + - ", keysize: " + curvesize); + log("init with spec, curve: " + curveName + + ", keysize: " + curvesize); break; @@ -211,8 +207,9 @@ public class WolfCryptKeyPairGenerator extends KeyPairGeneratorSpi { "Invalid parameters, either p or g is null"); } - if ((this.dhP != null) && debug.DEBUG) + if (this.dhP != null) { log("init with spec, prime len: " + this.dhP.length); + } break; @@ -285,9 +282,7 @@ public class WolfCryptKeyPairGenerator extends KeyPairGeneratorSpi { throw new RuntimeException(e); } - if (debug.DEBUG) { - log("generated RSA KeyPair"); - } + log("generated RSA KeyPair"); break; @@ -344,8 +339,7 @@ public class WolfCryptKeyPairGenerator extends KeyPairGeneratorSpi { throw new RuntimeException(e); } - if (debug.DEBUG) - log("generated ECC KeyPair"); + log("generated ECC KeyPair"); break; @@ -394,8 +388,7 @@ public class WolfCryptKeyPairGenerator extends KeyPairGeneratorSpi { throw new RuntimeException(e.getMessage()); } - if (debug.DEBUG) - log("generated DH KeyPair"); + log("generated DH KeyPair"); break; @@ -421,7 +414,7 @@ public class WolfCryptKeyPairGenerator extends KeyPairGeneratorSpi { } private void log(String msg) { - debug.print("[KeyPairGenerator, " + algString + "] " + msg); + WolfCryptDebug.print("[KeyPairGenerator, " + algString + "] " + msg); } @SuppressWarnings("deprecation") diff --git a/src/main/java/com/wolfssl/provider/jce/WolfCryptMac.java b/src/main/java/com/wolfssl/provider/jce/WolfCryptMac.java index d8695a6..c58d9ff 100644 --- a/src/main/java/com/wolfssl/provider/jce/WolfCryptMac.java +++ b/src/main/java/com/wolfssl/provider/jce/WolfCryptMac.java @@ -58,7 +58,6 @@ public class WolfCryptMac extends MacSpi { private int digestSize = 0; /* for debug logging */ - private WolfCryptDebug debug; private String algString; private WolfCryptMac(HmacType type) @@ -98,8 +97,9 @@ public class WolfCryptMac extends MacSpi { "Unsupported HMAC type"); } - if (debug.DEBUG) + if (WolfCryptDebug.DEBUG) { algString = typeToString(type); + } } @Override @@ -107,12 +107,11 @@ public class WolfCryptMac extends MacSpi { byte[] out = this.hmac.doFinal(); - if (debug.DEBUG) - if (out != null) { - log("final digest generated, len: " + out.length); - } else { - log("final digest was null"); - } + if (out != null) { + log("final digest generated, len: " + out.length); + } else { + log("final digest was null"); + } return out; } @@ -140,32 +139,28 @@ public class WolfCryptMac extends MacSpi { this.hmac.setKey(nativeHmacType, encodedKey); - if (debug.DEBUG) - log("init with key and spec"); + log("init with key and spec"); } @Override protected void engineReset() { this.hmac.reset(); - if (debug.DEBUG) - log("engine reset"); + log("engine reset"); } @Override protected void engineUpdate(byte input) { this.hmac.update(input); - if (debug.DEBUG) - log("update with single byte"); + log("update with single byte"); } @Override protected void engineUpdate(byte[] input, int offset, int len) { this.hmac.update(input, offset, len); - if (debug.DEBUG) - log("update, offset: " + offset + ", len: " + len); + log("update, offset: " + offset + ", len: " + len); } private String typeToString(HmacType type) { @@ -186,7 +181,7 @@ public class WolfCryptMac extends MacSpi { } private void log(String msg) { - debug.print("[Mac, " + algString + "] " + msg); + WolfCryptDebug.print("[Mac, " + algString + "] " + msg); } @SuppressWarnings("deprecation") diff --git a/src/main/java/com/wolfssl/provider/jce/WolfCryptMessageDigestMd5.java b/src/main/java/com/wolfssl/provider/jce/WolfCryptMessageDigestMd5.java index 746924b..a29061a 100644 --- a/src/main/java/com/wolfssl/provider/jce/WolfCryptMessageDigestMd5.java +++ b/src/main/java/com/wolfssl/provider/jce/WolfCryptMessageDigestMd5.java @@ -37,9 +37,6 @@ public final class WolfCryptMessageDigestMd5 /* internal reference to wolfCrypt JNI Md5 object */ private Md5 md5; - /* for debug logging */ - private WolfCryptDebug debug; - /** * Create new WolfCryptMessageDigestMd5 object */ @@ -72,8 +69,7 @@ public final class WolfCryptMessageDigestMd5 throw new RuntimeException(e.getMessage()); } - if (debug.DEBUG) - log("generated final digest, len: " + digest.length); + log("generated final digest, len: " + digest.length); return digest; } @@ -83,8 +79,7 @@ public final class WolfCryptMessageDigestMd5 this.md5.init(); - if (debug.DEBUG) - log("engine reset"); + log("engine reset"); } @Override @@ -95,8 +90,7 @@ public final class WolfCryptMessageDigestMd5 this.md5.update(tmp, 1); - if (debug.DEBUG) - log("update with single byte"); + log("update with single byte"); } @Override @@ -104,12 +98,11 @@ public final class WolfCryptMessageDigestMd5 this.md5.update(input, offset, len); - if (debug.DEBUG) - log("update, offset: " + offset + ", len: " + len); + log("update, offset: " + offset + ", len: " + len); } private void log(String msg) { - debug.print("[MessageDigest, MD5] " + msg); + WolfCryptDebug.print("[MessageDigest, MD5] " + msg); } @Override diff --git a/src/main/java/com/wolfssl/provider/jce/WolfCryptMessageDigestSha.java b/src/main/java/com/wolfssl/provider/jce/WolfCryptMessageDigestSha.java index 206da79..ac92bbe 100644 --- a/src/main/java/com/wolfssl/provider/jce/WolfCryptMessageDigestSha.java +++ b/src/main/java/com/wolfssl/provider/jce/WolfCryptMessageDigestSha.java @@ -37,9 +37,6 @@ public final class WolfCryptMessageDigestSha /* internal reference to wolfCrypt JNI Sha object */ private Sha sha; - /* for debug logging */ - private WolfCryptDebug debug; - /** * Create new WolfCryptMessageDigestSha object */ @@ -72,8 +69,7 @@ public final class WolfCryptMessageDigestSha throw new RuntimeException(e.getMessage()); } - if (debug.DEBUG) - log("generated final digest, len: " + digest.length); + log("generated final digest, len: " + digest.length); return digest; } @@ -83,8 +79,7 @@ public final class WolfCryptMessageDigestSha this.sha.init(); - if (debug.DEBUG) - log("engine reset"); + log("engine reset"); } @Override @@ -95,8 +90,7 @@ public final class WolfCryptMessageDigestSha this.sha.update(tmp, 1); - if (debug.DEBUG) - log("update with single byte"); + log("update with single byte"); } @Override @@ -104,12 +98,11 @@ public final class WolfCryptMessageDigestSha this.sha.update(input, offset, len); - if (debug.DEBUG) - log("update, offset: " + offset + ", len: " + len); + log("update, offset: " + offset + ", len: " + len); } private void log(String msg) { - debug.print("[MessageDigest, SHA] " + msg); + WolfCryptDebug.print("[MessageDigest, SHA] " + msg); } @Override diff --git a/src/main/java/com/wolfssl/provider/jce/WolfCryptMessageDigestSha256.java b/src/main/java/com/wolfssl/provider/jce/WolfCryptMessageDigestSha256.java index f411f99..3998c07 100644 --- a/src/main/java/com/wolfssl/provider/jce/WolfCryptMessageDigestSha256.java +++ b/src/main/java/com/wolfssl/provider/jce/WolfCryptMessageDigestSha256.java @@ -37,9 +37,6 @@ public final class WolfCryptMessageDigestSha256 /* internal reference to wolfCrypt JNI Sha object */ private Sha256 sha; - /* for debug logging */ - private WolfCryptDebug debug; - /** * Create new WolfCryptMessageDigestSha256 object */ @@ -72,8 +69,7 @@ public final class WolfCryptMessageDigestSha256 throw new RuntimeException(e.getMessage()); } - if (debug.DEBUG) - log("generated final digest, len: " + digest.length); + log("generated final digest, len: " + digest.length); return digest; } @@ -83,8 +79,7 @@ public final class WolfCryptMessageDigestSha256 this.sha.init(); - if (debug.DEBUG) - log("engine reset"); + log("engine reset"); } @Override @@ -95,8 +90,7 @@ public final class WolfCryptMessageDigestSha256 this.sha.update(tmp, 1); - if (debug.DEBUG) - log("update with single byte"); + log("update with single byte"); } @Override @@ -104,8 +98,7 @@ public final class WolfCryptMessageDigestSha256 this.sha.update(input, offset, len); - if (debug.DEBUG) - log("update, offset: " + offset + ", len: " + len); + log("update, offset: " + offset + ", len: " + len); } @Override @@ -114,7 +107,7 @@ public final class WolfCryptMessageDigestSha256 } private void log(String msg) { - debug.print("[MessageDigest, SHA256] " + msg); + WolfCryptDebug.print("[MessageDigest, SHA256] " + msg); } @Override diff --git a/src/main/java/com/wolfssl/provider/jce/WolfCryptMessageDigestSha384.java b/src/main/java/com/wolfssl/provider/jce/WolfCryptMessageDigestSha384.java index 32a905b..ee0e2e8 100644 --- a/src/main/java/com/wolfssl/provider/jce/WolfCryptMessageDigestSha384.java +++ b/src/main/java/com/wolfssl/provider/jce/WolfCryptMessageDigestSha384.java @@ -37,9 +37,6 @@ public final class WolfCryptMessageDigestSha384 /* internal reference to wolfCrypt JNI Sha object */ private Sha384 sha; - /* for debug logging */ - private WolfCryptDebug debug; - /** * Create new WolfCryptMessageDigestSha384 object */ @@ -72,8 +69,7 @@ public final class WolfCryptMessageDigestSha384 throw new RuntimeException(e.getMessage()); } - if (debug.DEBUG) - log("generated final digest, len: " + digest.length); + log("generated final digest, len: " + digest.length); return digest; } @@ -83,8 +79,7 @@ public final class WolfCryptMessageDigestSha384 this.sha.init(); - if (debug.DEBUG) - log("engine reset"); + log("engine reset"); } @Override @@ -95,8 +90,7 @@ public final class WolfCryptMessageDigestSha384 this.sha.update(tmp, 1); - if (debug.DEBUG) - log("update with single byte"); + log("update with single byte"); } @Override @@ -104,8 +98,7 @@ public final class WolfCryptMessageDigestSha384 this.sha.update(input, offset, len); - if (debug.DEBUG) - log("update, offset: " + offset + ", len: " + len); + log("update, offset: " + offset + ", len: " + len); } @Override @@ -114,7 +107,7 @@ public final class WolfCryptMessageDigestSha384 } private void log(String msg) { - debug.print("[MessageDigest, SHA384] " + msg); + WolfCryptDebug.print("[MessageDigest, SHA384] " + msg); } @Override diff --git a/src/main/java/com/wolfssl/provider/jce/WolfCryptMessageDigestSha512.java b/src/main/java/com/wolfssl/provider/jce/WolfCryptMessageDigestSha512.java index e5ae79e..9bc566f 100644 --- a/src/main/java/com/wolfssl/provider/jce/WolfCryptMessageDigestSha512.java +++ b/src/main/java/com/wolfssl/provider/jce/WolfCryptMessageDigestSha512.java @@ -37,9 +37,6 @@ public final class WolfCryptMessageDigestSha512 /* internal reference to wolfCrypt JNI Sha object */ private Sha512 sha; - /* for debug logging */ - private WolfCryptDebug debug; - /** * Create new WolfCryptMessageDigestSha512 object */ @@ -72,8 +69,7 @@ public final class WolfCryptMessageDigestSha512 throw new RuntimeException(e.getMessage()); } - if (debug.DEBUG) - log("generated final digest, len: " + digest.length); + log("generated final digest, len: " + digest.length); return digest; } @@ -83,8 +79,7 @@ public final class WolfCryptMessageDigestSha512 this.sha.init(); - if (debug.DEBUG) - log("engine reset"); + log("engine reset"); } @Override @@ -95,8 +90,7 @@ public final class WolfCryptMessageDigestSha512 this.sha.update(tmp, 1); - if (debug.DEBUG) - log("update with single byte"); + log("update with single byte"); } @Override @@ -104,8 +98,7 @@ public final class WolfCryptMessageDigestSha512 this.sha.update(input, offset, len); - if (debug.DEBUG) - log("update, offset: " + offset + ", len: " + len); + log("update, offset: " + offset + ", len: " + len); } @Override @@ -114,7 +107,7 @@ public final class WolfCryptMessageDigestSha512 } private void log(String msg) { - debug.print("[MessageDigest, SHA512] " + msg); + WolfCryptDebug.print("[MessageDigest, SHA512] " + msg); } @Override diff --git a/src/main/java/com/wolfssl/provider/jce/WolfCryptPBEKey.java b/src/main/java/com/wolfssl/provider/jce/WolfCryptPBEKey.java index a6bff88..d04382b 100644 --- a/src/main/java/com/wolfssl/provider/jce/WolfCryptPBEKey.java +++ b/src/main/java/com/wolfssl/provider/jce/WolfCryptPBEKey.java @@ -26,8 +26,6 @@ import java.security.spec.InvalidKeySpecException; import javax.security.auth.Destroyable; import javax.crypto.interfaces.PBEKey; -import com.wolfssl.provider.jce.WolfCryptDebug; - /** * wolfCrypt PBEKey implementation. */ diff --git a/src/main/java/com/wolfssl/provider/jce/WolfCryptPKIXCertPathValidator.java b/src/main/java/com/wolfssl/provider/jce/WolfCryptPKIXCertPathValidator.java index b4dc660..8d193b6 100644 --- a/src/main/java/com/wolfssl/provider/jce/WolfCryptPKIXCertPathValidator.java +++ b/src/main/java/com/wolfssl/provider/jce/WolfCryptPKIXCertPathValidator.java @@ -71,15 +71,11 @@ import com.wolfssl.provider.jce.WolfCryptDebug; */ public class WolfCryptPKIXCertPathValidator extends CertPathValidatorSpi { - private WolfCryptDebug debug; - /** * Create new WolfCryptPKIXCertPathValidator object. */ public WolfCryptPKIXCertPathValidator() { - if (debug.DEBUG) { - log("created new WolfCryptPKIXCertPathValidator"); - } + log("created new WolfCryptPKIXCertPathValidator"); } /** @@ -93,9 +89,7 @@ public class WolfCryptPKIXCertPathValidator extends CertPathValidatorSpi { private void sanitizeCertPathParameters(CertPathParameters params) throws InvalidAlgorithmParameterException { - if (debug.DEBUG) { - log("sanitizing CertPathParameters"); - } + log("sanitizing CertPathParameters"); if (params == null) { throw new InvalidAlgorithmParameterException( @@ -123,9 +117,7 @@ public class WolfCryptPKIXCertPathValidator extends CertPathValidatorSpi { boolean pkiPathEncodingSupported = false; Iterator supportedCertEncodings = null; - if (debug.DEBUG) { - log("sanitizing CertPath"); - } + log("sanitizing CertPath"); /* Verify CertPath type is X.509 */ if (!path.getType().equals("X.509")) { @@ -167,9 +159,7 @@ public class WolfCryptPKIXCertPathValidator extends CertPathValidatorSpi { /* Use CertSelector to check target cert */ selector = params.getTargetCertConstraints(); if (selector != null) { - if (debug.DEBUG) { - log("checking target cert constraints against CertSelector"); - } + log("checking target cert constraints against CertSelector"); if (!(selector instanceof X509CertSelector)) { throw new CertPathValidatorException( @@ -183,9 +173,7 @@ public class WolfCryptPKIXCertPathValidator extends CertPathValidatorSpi { } } else { - if (debug.DEBUG) { - log("no cert constraints in params, not checking CertSelector"); - } + log("no cert constraints in params, not checking CertSelector"); } } @@ -204,13 +192,11 @@ public class WolfCryptPKIXCertPathValidator extends CertPathValidatorSpi { "not empty"); } - if (debug.DEBUG) { - /* Ignored, but log for debugging */ - log("PKIXParameters.getPolicyQualifiersRejected(): " + - params.getPolicyQualifiersRejected()); - log("PKIXParameters.isPolicyMappingInhibited(): " + - params.isPolicyMappingInhibited()); - } + /* Ignored, but log for debugging */ + log("PKIXParameters.getPolicyQualifiersRejected(): " + + params.getPolicyQualifiersRejected()); + log("PKIXParameters.isPolicyMappingInhibited(): " + + params.isPolicyMappingInhibited()); /* Should the any policy OID be processed if it is included in * a certificate? Default is false, don't allow enablement since @@ -296,9 +282,8 @@ public class WolfCryptPKIXCertPathValidator extends CertPathValidatorSpi { } for (i = 0; i < pathCheckers.size(); i++) { - if (debug.DEBUG) { - log("calling CertPathChecker: " + pathCheckers.get(i)); - } + log("calling CertPathChecker: " + pathCheckers.get(i)); + /* Throws CertPathValidatorException on error */ pathCheckers.get(i).check((Certificate)cert); } @@ -320,9 +305,7 @@ public class WolfCryptPKIXCertPathValidator extends CertPathValidatorSpi { Set trustAnchors = null; Iterator trustIterator = null; - if (debug.DEBUG) { - log("loading TrustAnchors into native WolfSSLCertManager"); - } + log("loading TrustAnchors into native WolfSSLCertManager"); if (params == null || cm == null) { throw new CertPathValidatorException( @@ -346,10 +329,9 @@ public class WolfCryptPKIXCertPathValidator extends CertPathValidatorSpi { try { cm.CertManagerLoadCA(anchorCert); - if (debug.DEBUG) { - log("loaded TrustAnchor: " + - anchorCert.getSubjectX500Principal().getName()); - } + log("loaded TrustAnchor: " + + anchorCert.getSubjectX500Principal().getName()); + } catch (WolfCryptException e) { throw new CertPathValidatorException(e); } @@ -374,10 +356,7 @@ public class WolfCryptPKIXCertPathValidator extends CertPathValidatorSpi { "Input args to verifyCertChain are null"); } - if (debug.DEBUG) { - log("verifying certificate chain (chain size: " + - certs.size() + ")"); - } + log("verifying certificate chain (chain size: " + certs.size() + ")"); /* Process certs from List in reverse order (top to peer) */ for (i = certs.size()-1; i >= 0; i--) { @@ -387,16 +366,13 @@ public class WolfCryptPKIXCertPathValidator extends CertPathValidatorSpi { /* Try to verify cert */ cm.CertManagerVerify(cert); - if (debug.DEBUG) { - log("verified chain [" + i + "]: " + - cert.getSubjectX500Principal().getName()); - } + log("verified chain [" + i + "]: " + + cert.getSubjectX500Principal().getName()); } catch (WolfCryptException e) { - if (debug.DEBUG) { - log("failed verification chain [" + i + "]: " + - cert.getSubjectX500Principal().getName()); - } + log("failed verification chain [" + i + "]: " + + cert.getSubjectX500Principal().getName()); + throw new CertPathValidatorException( "Failed verification on certificate", e, path, i); } @@ -407,16 +383,12 @@ public class WolfCryptPKIXCertPathValidator extends CertPathValidatorSpi { try { cm.CertManagerLoadCA(cert); - if (debug.DEBUG) { - log("chain [" + i + "] is intermediate, " + - "loading as root"); - } + log("chain [" + i + "] is intermediate, loading as root"); + } catch (WolfCryptException e) { - if (debug.DEBUG) { - log("chain [" + i + "] is CA, but failed " + - "to load as trusted root, not loading"); - } + log("chain [" + i + "] is CA, but failed to load as " + + "trusted root, not loading"); } } } @@ -544,10 +516,8 @@ public class WolfCryptPKIXCertPathValidator extends CertPathValidatorSpi { } if (params.isRevocationEnabled()) { - if (debug.DEBUG) { - log("revocation enabled in PKIXParameters, checking " + - "for CRLs to load"); - } + log("revocation enabled in PKIXParameters, checking " + + "for CRLs to load"); if (!WolfCrypt.CrlEnabled()) { throw new CertPathValidatorException( @@ -558,15 +528,11 @@ public class WolfCryptPKIXCertPathValidator extends CertPathValidatorSpi { /* Enable CRL in native WolfSSLCertManager */ cm.CertManagerEnableCRL(WolfCrypt.WOLFSSL_CRL_CHECK); - if (debug.DEBUG) { - log("CRL support enabled in native WolfSSLCertManager"); - } + log("CRL support enabled in native WolfSSLCertManager"); stores = params.getCertStores(); if (stores == null || stores.isEmpty()) { - if (debug.DEBUG) { - log("no CertStores in PKIXParameters to load CRLs"); - } + log("no CertStores in PKIXParameters to load CRLs"); return; } @@ -589,14 +555,10 @@ public class WolfCryptPKIXCertPathValidator extends CertPathValidatorSpi { throw new CertPathValidatorException(e); } - if (debug.DEBUG) { - log("loaded " + loadedCount + " CRLs into WolfSSLCertManager"); - } + log("loaded " + loadedCount + " CRLs into WolfSSLCertManager"); } else { - if (debug.DEBUG) { - log("revocation not enabled in PKIXParameters"); - } + log("revocation not enabled in PKIXParameters"); } } @@ -644,9 +606,7 @@ public class WolfCryptPKIXCertPathValidator extends CertPathValidatorSpi { WolfSSLCertManager cm = null; TrustAnchor trustAnchor = null; - if (debug.DEBUG) { - log("entered engineValidate(), FIPS enabled: " + Fips.enabled); - } + log("entered engineValidate(), FIPS enabled: " + Fips.enabled); sanitizeCertPathParameters(params); sanitizeCertPath(certPath); @@ -752,7 +712,7 @@ public class WolfCryptPKIXCertPathValidator extends CertPathValidatorSpi { * @param msg Log message to be printed */ private void log(String msg) { - debug.print("[CertPathValidator] " + msg); + WolfCryptDebug.print("[CertPathValidator] " + msg); } } diff --git a/src/main/java/com/wolfssl/provider/jce/WolfCryptRandom.java b/src/main/java/com/wolfssl/provider/jce/WolfCryptRandom.java index 4b70ba4..f4ca145 100644 --- a/src/main/java/com/wolfssl/provider/jce/WolfCryptRandom.java +++ b/src/main/java/com/wolfssl/provider/jce/WolfCryptRandom.java @@ -34,9 +34,6 @@ public final class WolfCryptRandom extends SecureRandomSpi { /** internal reference to wolfCrypt JNI RNG object */ private Rng rng; - /** for debug logging */ - private WolfCryptDebug debug; - /** * Create new WolfCryptRandom object */ @@ -44,8 +41,7 @@ public final class WolfCryptRandom extends SecureRandomSpi { this.rng = new Rng(); this.rng.init(); - if (debug.DEBUG) - log("initialized new object"); + log("initialized new object"); } @Override @@ -63,12 +59,11 @@ public final class WolfCryptRandom extends SecureRandomSpi { @Override protected void engineSetSeed(byte[] seed) { /* wolfCrypt reseeds internally automatically */ - if (debug.DEBUG) - log("setSeed() not supported by wolfJCE"); + log("setSeed() not supported by wolfJCE"); } private void log(String msg) { - debug.print("[Random] " + msg); + WolfCryptDebug.print("[Random] " + msg); } @SuppressWarnings("deprecation") diff --git a/src/main/java/com/wolfssl/provider/jce/WolfCryptSecretKeyFactory.java b/src/main/java/com/wolfssl/provider/jce/WolfCryptSecretKeyFactory.java index e9e8d20..da68123 100644 --- a/src/main/java/com/wolfssl/provider/jce/WolfCryptSecretKeyFactory.java +++ b/src/main/java/com/wolfssl/provider/jce/WolfCryptSecretKeyFactory.java @@ -64,8 +64,6 @@ public class WolfCryptSecretKeyFactory extends SecretKeyFactorySpi { /* wolfCrypt int representing hash used in this factory */ private int hashType; - private WolfCryptDebug debug; - private WolfCryptSecretKeyFactory(FactoryType type) throws NoSuchAlgorithmException { @@ -124,9 +122,7 @@ public class WolfCryptSecretKeyFactory extends SecretKeyFactorySpi { * @param msg message to be logged */ private void log(String msg) { - if (debug.DEBUG) { - debug.print("[SecretKeyFactory, " + typeString + "] " + msg); - } + WolfCryptDebug.print("[SecretKeyFactory, " + typeString + "] " + msg); } /** diff --git a/src/main/java/com/wolfssl/provider/jce/WolfCryptSignature.java b/src/main/java/com/wolfssl/provider/jce/WolfCryptSignature.java index 40b678f..7b2a576 100644 --- a/src/main/java/com/wolfssl/provider/jce/WolfCryptSignature.java +++ b/src/main/java/com/wolfssl/provider/jce/WolfCryptSignature.java @@ -97,7 +97,6 @@ public class WolfCryptSignature extends SignatureSpi { private int digestSz; /* digest size in bytes */ /* for debug logging */ - private WolfCryptDebug debug; private String keyString; private String digestString; @@ -162,7 +161,7 @@ public class WolfCryptSignature extends SignatureSpi { "Unsupported signature algorithm digest type"); } - if (debug.DEBUG) { + if (WolfCryptDebug.DEBUG) { keyString = typeToString(ktype); digestString = digestToString(dtype); } @@ -287,8 +286,7 @@ public class WolfCryptSignature extends SignatureSpi { break; } - if (debug.DEBUG) - log("init sign with PrivateKey"); + log("init sign with PrivateKey"); } @Override @@ -356,8 +354,7 @@ public class WolfCryptSignature extends SignatureSpi { break; } - if (debug.DEBUG) - log("init verify with PublicKey"); + log("init verify with PublicKey"); } @Deprecated @@ -443,12 +440,10 @@ public class WolfCryptSignature extends SignatureSpi { "Invalid signature algorithm type"); } - if (debug.DEBUG) { - if (signature != null) { - log("generated signature, len: " + signature.length); - } else { - log("generated signature was null"); - } + if (signature != null) { + log("generated signature, len: " + signature.length); + } else { + log("generated signature was null"); } return signature; @@ -462,8 +457,7 @@ public class WolfCryptSignature extends SignatureSpi { engineUpdate(tmp, 0, 1); - if (debug.DEBUG) - log("update with single byte"); + log("update with single byte"); } @Override @@ -492,8 +486,7 @@ public class WolfCryptSignature extends SignatureSpi { break; } - if (debug.DEBUG) - log("update, offset: " + off + ", len: " + len); + log("update, offset: " + off + ", len: " + len); } @Override @@ -575,11 +568,9 @@ public class WolfCryptSignature extends SignatureSpi { break; } - if (debug.DEBUG) { - if (sigBytes != null) { - log("finished verify of sig len: " + sigBytes.length + - ", verified: " + verified); - } + if (sigBytes != null) { + log("finished verify of sig len: " + sigBytes.length + + ", verified: " + verified); } return verified; @@ -624,8 +615,8 @@ public class WolfCryptSignature extends SignatureSpi { } private void log(String msg) { - debug.print("[Signature, " + keyString + "-" + - digestString + "] " + msg); + WolfCryptDebug.print("[Signature, " + keyString + "-" + + digestString + "] " + msg); } @SuppressWarnings("deprecation") diff --git a/src/main/java/com/wolfssl/provider/jce/WolfSSLKeyStore.java b/src/main/java/com/wolfssl/provider/jce/WolfSSLKeyStore.java index 74af11a..1e9cd8f 100644 --- a/src/main/java/com/wolfssl/provider/jce/WolfSSLKeyStore.java +++ b/src/main/java/com/wolfssl/provider/jce/WolfSSLKeyStore.java @@ -169,8 +169,6 @@ import com.wolfssl.provider.jce.WolfCryptDebug; */ public class WolfSSLKeyStore extends KeyStoreSpi { - private static WolfCryptDebug debug; - /* RNG used for generating random IVs and salts */ private SecureRandom rand = null; private static final Object randLock = new Object(); @@ -1823,9 +1821,7 @@ public class WolfSSLKeyStore extends KeyStoreSpi { * @param msg message to be logged */ private static synchronized void log(String msg) { - if (debug.DEBUG) { - debug.print("[WolfSSLKeyStore] " + msg); - } + WolfCryptDebug.print("[WolfSSLKeyStore] " + msg); } /**