diff --git a/jpos/src/main/java/org/jpos/security/BaseSMAdapter.java b/jpos/src/main/java/org/jpos/security/BaseSMAdapter.java index dd1b65b7a2..3b08c658ca 100644 --- a/jpos/src/main/java/org/jpos/security/BaseSMAdapter.java +++ b/jpos/src/main/java/org/jpos/security/BaseSMAdapter.java @@ -39,7 +39,6 @@ import java.util.List; import java.util.Map; - /** *

* Provides base functionality for the actual Security Module Adapter. @@ -56,6 +55,7 @@ public class BaseSMAdapter protected String realm = null; protected Configuration cfg; private String name; + private boolean debug; public BaseSMAdapter () { super(); @@ -71,6 +71,7 @@ public BaseSMAdapter (Configuration cfg, Logger logger, String realm) throws Con @Override public void setConfiguration (Configuration cfg) throws ConfigurationException { this.cfg = cfg; + debug = cfg.getBoolean("debug", false); } @Override @@ -112,8 +113,8 @@ public String getName () { * @throws NotFoundException * @see NameRegistrar */ - public static SMAdapter getSMAdapter (String name) throws NameRegistrar.NotFoundException { - return (SMAdapter)NameRegistrar.get("s-m-adapter." + name); + public static SMAdapter getSMAdapter (String name) throws NameRegistrar.NotFoundException { + return NameRegistrar.get("s-m-adapter." + name); } @Override @@ -131,7 +132,7 @@ public SecureDESKey generateKey (short keyLength, String keyType) throws SMExcep evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } return result; } @@ -150,7 +151,7 @@ public SecureKey generateKey(SecureKeySpec keySpec) throws SMException { evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } return result; } @@ -169,7 +170,7 @@ public byte[] generateKeyCheckValue(T kd) throws SMException { evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } return result; } @@ -190,7 +191,7 @@ public SecureDESKey translateKeyScheme(SecureDESKey key, KeyScheme destKeyScheme evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } return result; } @@ -214,7 +215,7 @@ public SecureDESKey importKey (short keyLength, String keyType, byte[] encrypted evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } return result; } @@ -237,7 +238,7 @@ public SecureKey importKey(SecureKey kek, SecureKey key, SecureKeySpec keySpec evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } return result; } @@ -257,7 +258,7 @@ public byte[] exportKey (SecureDESKey key, SecureDESKey kek) throws SMException evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } return result; } @@ -279,7 +280,7 @@ public SecureKey exportKey(SecureKey kek, SecureKey key, SecureKeySpec keySpec) evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } return result; } @@ -300,7 +301,7 @@ public EncryptedPIN encryptPIN (String pin, String accountNumber, boolean extrac evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } return result; } @@ -328,7 +329,7 @@ public EncryptedPIN encryptPIN(String pin, String accountNumber, T pek) throws S throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } return result; } @@ -347,7 +348,7 @@ public String decryptPIN (EncryptedPIN pinUnderLmk) throws SMException { evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } return result; } @@ -367,7 +368,7 @@ public EncryptedPIN importPIN(EncryptedPIN pinUnderKd1, T kd1) throws SMExceptio evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } return result; } @@ -391,7 +392,7 @@ public EncryptedPIN translatePIN(EncryptedPIN pinUnderKd1, T kd1, evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } return result; } @@ -419,7 +420,7 @@ public EncryptedPIN importPIN(EncryptedPIN pinUnderDuk, KeySerialNumber ksn, evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } return result; } @@ -449,7 +450,7 @@ public EncryptedPIN translatePIN(EncryptedPIN pinUnderDuk, KeySerialNumber ksn, evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } return result; } @@ -470,7 +471,7 @@ public EncryptedPIN exportPIN(EncryptedPIN pinUnderLmk, T kd2, byte destinationP evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } return result; } @@ -500,7 +501,7 @@ public EncryptedPIN generatePIN(String accountNumber, int pinLen, List e evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } return result; } @@ -525,7 +526,7 @@ public void printPIN(String accountNo, EncryptedPIN pinUnderKd1, T kd1 evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } } @@ -557,7 +558,7 @@ public String calculatePVV(EncryptedPIN pinUnderLMK, T pvkA, evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } return result; } @@ -592,7 +593,7 @@ public String calculatePVV(EncryptedPIN pinUnderKd1, T kd1, evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } return result; } @@ -619,7 +620,7 @@ public boolean verifyPVV(EncryptedPIN pinUnderKd1, T kd1, T pvkA, evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } } @@ -654,7 +655,7 @@ public String calculateIBMPINOffset(EncryptedPIN pinUnderLmk, T pvk, evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } return result; } @@ -692,7 +693,7 @@ public String calculateIBMPINOffset(EncryptedPIN pinUnderKd1, T kd1, evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } return result; } @@ -723,7 +724,7 @@ public boolean verifyIBMPINOffset(EncryptedPIN pinUnderKd1, T kd1, T pvk, evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } } @@ -748,7 +749,7 @@ public EncryptedPIN deriveIBMPIN(String accountNo, T pvk, evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } return result; } @@ -773,7 +774,7 @@ public String calculateCVV(String accountNo, T cvkA, T cvkB, evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } return result; } @@ -798,7 +799,7 @@ public String calculateCVD(String accountNo, T cvkA, T cvkB, evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } return result; } @@ -823,7 +824,7 @@ public String calculateCAVV(String accountNo, T cvk, String upn, evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } return result; } @@ -849,7 +850,7 @@ public boolean verifyCVV(String accountNo , T cvkA, T cvkB, evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } } @@ -874,7 +875,7 @@ public boolean verifyCVD(String accountNo, T cvkA, T cvkB, evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } } @@ -899,7 +900,7 @@ public boolean verifyCAVV(String accountNo, T cvk, String cavv, evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } return r; } @@ -927,7 +928,7 @@ public boolean verifydCVV(String accountNo, T imkac, String dcvv, evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } } @@ -957,7 +958,7 @@ public boolean verifydCVV(String accountNo, T imkac, String dcvv, evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } } @@ -1000,7 +1001,7 @@ public boolean verifyCVC3(T imkcvc3, String accountNo, String acctSeqNo, evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } } @@ -1029,7 +1030,7 @@ public boolean verifyARQC(MKDMethod mkdm, SKDMethod skdm, T imkac evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } } @@ -1064,7 +1065,7 @@ public byte[] generateARPC(MKDMethod mkdm, SKDMethod skdm, T imkac evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } } @@ -1102,7 +1103,7 @@ public byte[] verifyARQCGenerateARPC(MKDMethod mkdm, SKDMethod skdm, T imkac evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } } @@ -1130,7 +1131,7 @@ public byte[] generateSM_MAC(MKDMethod mkdm, SKDMethod skdm evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } } @@ -1178,7 +1179,7 @@ public Pair translatePINGenerateSM_MAC(MKDMethod mkdm evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } } @@ -1219,7 +1220,7 @@ public byte[] encryptData(CipherMode cipherMode, SecureDESKey kd evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } return encData; } @@ -1261,7 +1262,7 @@ public byte[] decryptData(CipherMode cipherMode, SecureDESKey kd evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } return decData; } @@ -1281,7 +1282,7 @@ public byte[] generateCBC_MAC(byte[] data, T kd) throws SMException { evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } return result; } @@ -1301,7 +1302,7 @@ public byte[] generateEDE_MAC(byte[] data, T kd) throws SMException { evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } return result; } @@ -1320,7 +1321,7 @@ public SecureDESKey translateKeyFromOldLMK(SecureDESKey kd) throws SMException { evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } return result; } @@ -1340,7 +1341,7 @@ public SecureKey translateKeyFromOldLMK(SecureKey key, SecureKeySpec keySpec) th evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } return result; } @@ -1364,7 +1365,7 @@ public Pair generateKeyPair(AlgorithmParameterSpec evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } return result; } @@ -1388,7 +1389,7 @@ public Pair generateKeyPair(SecureKeySpec keySpec) evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } return result; } @@ -1411,7 +1412,7 @@ public byte[] calculateSignature(MessageDigest hash, SecureKey privateKey evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } return result; } @@ -1443,7 +1444,7 @@ public byte[] encryptData(SecureKey encKey, byte[] data evt.addMessage(ex); throw new SMException(ex); } finally { - Logger.log(evt); + logEvent(evt); } return result; } @@ -1475,7 +1476,7 @@ public byte[] decryptData(SecureKey privKey, byte[] data evt.addMessage(ex); throw new SMException(ex); } finally { - Logger.log(evt); + logEvent(evt); } return result; } @@ -1491,7 +1492,7 @@ public void eraseOldLMK () throws SMException { evt.addMessage(e); throw e instanceof SMException ? (SMException) e : new SMException(e); } finally { - Logger.log(evt); + logEvent(evt); } } @@ -2310,4 +2311,8 @@ public SecureDESKey formKEYfromClearComponents(short keyLength, String keyType, throw new SMException("Operation not supported in: " + this.getClass().getName()); } + private void logEvent(LogEvent evt) { + if (debug) + Logger.log(evt); + } }