Search in sources :

Example 66 with SimpleMsg

use of org.jpos.util.SimpleMsg in project jPOS by jpos.

the class BaseSMAdapter method decryptData.

/**
 * Decrypt Data Block.
 *
 * @param cipherMode block cipher mode
 * @param kd DEK or ZEK key used to decrypt data
 * @param data data to be decrypted
 * @param iv initial vector
 * @return decrypted data
 * @throws SMException
 */
@Override
public byte[] decryptData(CipherMode cipherMode, SecureDESKey kd, byte[] data, byte[] iv) throws SMException {
    List<Loggeable> cmdParameters = new ArrayList<>();
    cmdParameters.add(new SimpleMsg("parameter", "Block Cipher Mode", cipherMode));
    if (kd != null)
        cmdParameters.add(new SimpleMsg("parameter", "Data key", kd));
    if (data != null)
        cmdParameters.add(new SimpleMsg("parameter", "Data", ISOUtil.hexString(data)));
    if (iv != null)
        cmdParameters.add(new SimpleMsg("parameter", "Initialization Vector", ISOUtil.hexString(iv)));
    LogEvent evt = new LogEvent(this, "s-m-operation");
    evt.addMessage(new SimpleMsg("command", "Decrypt Data", cmdParameters));
    byte[] decData = null;
    try {
        decData = decryptDataImpl(cipherMode, kd, data, iv);
        List<Loggeable> r = new ArrayList<>();
        r.add(new SimpleMsg("result", "Decrypted Data", decData));
        if (iv != null)
            r.add(new SimpleMsg("result", "Initialization Vector", iv));
        evt.addMessage(new SimpleMsg("results", r));
    } catch (Exception e) {
        evt.addMessage(e);
        throw e instanceof SMException ? (SMException) e : new SMException(e);
    } finally {
        Logger.log(evt);
    }
    return decData;
}
Also used : LogEvent(org.jpos.util.LogEvent) ArrayList(java.util.ArrayList) Loggeable(org.jpos.util.Loggeable) SimpleMsg(org.jpos.util.SimpleMsg) ConfigurationException(org.jpos.core.ConfigurationException) NotFoundException(org.jpos.util.NameRegistrar.NotFoundException)

Example 67 with SimpleMsg

use of org.jpos.util.SimpleMsg in project jPOS by jpos.

the class BaseSMAdapter method verifyPVV.

@Override
public boolean verifyPVV(EncryptedPIN pinUnderKd1, T kd1, T pvkA, T pvkB, int pvki, String pvv) throws SMException {
    List<Loggeable> cmdParameters = new ArrayList<>();
    cmdParameters.add(new SimpleMsg("parameter", "account number", pinUnderKd1.getAccountNumber()));
    cmdParameters.add(new SimpleMsg("parameter", "PIN under Data Key 1", pinUnderKd1));
    cmdParameters.add(new SimpleMsg("parameter", "Data Key 1", kd1));
    cmdParameters.add(new SimpleMsg("parameter", "PVK-A", pvkA == null ? "" : pvkA));
    cmdParameters.add(new SimpleMsg("parameter", "PVK-B", pvkB == null ? "" : pvkB));
    cmdParameters.add(new SimpleMsg("parameter", "pvki", pvki));
    cmdParameters.add(new SimpleMsg("parameter", "pvv", pvv));
    LogEvent evt = new LogEvent(this, "s-m-operation");
    evt.addMessage(new SimpleMsg("command", "Verify a PIN Using the VISA Method", cmdParameters));
    try {
        boolean r = verifyPVVImpl(pinUnderKd1, kd1, pvkA, pvkB, pvki, pvv);
        evt.addMessage(new SimpleMsg("result", "Verification status", r ? "valid" : "invalid"));
        return r;
    } catch (Exception e) {
        evt.addMessage(e);
        throw e instanceof SMException ? (SMException) e : new SMException(e);
    } finally {
        Logger.log(evt);
    }
}
Also used : LogEvent(org.jpos.util.LogEvent) ArrayList(java.util.ArrayList) Loggeable(org.jpos.util.Loggeable) SimpleMsg(org.jpos.util.SimpleMsg) ConfigurationException(org.jpos.core.ConfigurationException) NotFoundException(org.jpos.util.NameRegistrar.NotFoundException)

Example 68 with SimpleMsg

use of org.jpos.util.SimpleMsg in project jPOS by jpos.

the class BaseSMAdapter method translatePINGenerateSM_MAC.

@Override
public Pair<EncryptedPIN, byte[]> translatePINGenerateSM_MAC(MKDMethod mkdm, SKDMethod skdm, PaddingMethod padm, T imksmi, String accountNo, String acctSeqNo, byte[] atc, byte[] arqc, byte[] data, EncryptedPIN currentPIN, EncryptedPIN newPIN, T kd1, T imksmc, T imkac, byte destinationPINBlockFormat) throws SMException {
    List<Loggeable> cmdParameters = new ArrayList<>();
    cmdParameters.add(new SimpleMsg("parameter", "mkd method", mkdm));
    cmdParameters.add(new SimpleMsg("parameter", "skd method", skdm));
    if (padm != null)
        cmdParameters.add(new SimpleMsg("parameter", "padding method", padm));
    cmdParameters.add(new SimpleMsg("parameter", "imk-smi", imksmi));
    cmdParameters.add(new SimpleMsg("parameter", "account number", accountNo));
    cmdParameters.add(new SimpleMsg("parameter", "accnt seq no", acctSeqNo));
    cmdParameters.add(new SimpleMsg("parameter", "atc", atc == null ? "" : ISOUtil.hexString(atc)));
    cmdParameters.add(new SimpleMsg("parameter", "arqc", arqc == null ? "" : ISOUtil.hexString(arqc)));
    cmdParameters.add(new SimpleMsg("parameter", "data", data == null ? "" : ISOUtil.hexString(data)));
    cmdParameters.add(new SimpleMsg("parameter", "Current Encrypted PIN", currentPIN));
    cmdParameters.add(new SimpleMsg("parameter", "New Encrypted PIN", newPIN));
    cmdParameters.add(new SimpleMsg("parameter", "Source PIN Encryption Key", kd1));
    cmdParameters.add(new SimpleMsg("parameter", "imk-smc", imksmc));
    if (imkac != null)
        cmdParameters.add(new SimpleMsg("parameter", "imk-ac", imkac));
    cmdParameters.add(new SimpleMsg("parameter", "Destination PIN Block Format", destinationPINBlockFormat));
    LogEvent evt = new LogEvent(this, "s-m-operation");
    evt.addMessage(new SimpleMsg("command", "Translate PIN block format and Generate Secure Messaging MAC", cmdParameters));
    try {
        Pair<EncryptedPIN, byte[]> r = translatePINGenerateSM_MACImpl(mkdm, skdm, padm, imksmi, accountNo, acctSeqNo, atc, arqc, data, currentPIN, newPIN, kd1, imksmc, imkac, destinationPINBlockFormat);
        List<Loggeable> cmdResults = new ArrayList<>();
        cmdResults.add(new SimpleMsg("result", "Translated PIN block", r.getValue0()));
        cmdResults.add(new SimpleMsg("result", "Generated MAC", r.getValue1() == null ? "" : ISOUtil.hexString(r.getValue1())));
        evt.addMessage(new SimpleMsg("results", "Complex results", cmdResults));
        return r;
    } catch (Exception e) {
        evt.addMessage(e);
        throw e instanceof SMException ? (SMException) e : new SMException(e);
    } finally {
        Logger.log(evt);
    }
}
Also used : LogEvent(org.jpos.util.LogEvent) ArrayList(java.util.ArrayList) Loggeable(org.jpos.util.Loggeable) SimpleMsg(org.jpos.util.SimpleMsg) ConfigurationException(org.jpos.core.ConfigurationException) NotFoundException(org.jpos.util.NameRegistrar.NotFoundException)

Example 69 with SimpleMsg

use of org.jpos.util.SimpleMsg in project jPOS by jpos.

the class BaseSMAdapter method calculateIBMPINOffset.

@Override
public String calculateIBMPINOffset(EncryptedPIN pinUnderLmk, T pvk, String decTab, String pinValData, int minPinLen, List<String> excludes) throws SMException {
    List<Loggeable> cmdParameters = new ArrayList<>();
    cmdParameters.add(new SimpleMsg("parameter", "account number", pinUnderLmk.getAccountNumber()));
    cmdParameters.add(new SimpleMsg("parameter", "PIN under LMK", pinUnderLmk));
    cmdParameters.add(new SimpleMsg("parameter", "PVK", pvk));
    cmdParameters.add(new SimpleMsg("parameter", "decimalisation table", decTab));
    cmdParameters.add(new SimpleMsg("parameter", "PIN validation data", pinValData));
    cmdParameters.add(new SimpleMsg("parameter", "minimum PIN length", minPinLen));
    if (excludes != null && !excludes.isEmpty())
        cmdParameters.add(new SimpleMsg("parameter", "Excluded PINs list", excludes));
    LogEvent evt = new LogEvent(this, "s-m-operation");
    evt.addMessage(new SimpleMsg("command", "Calculate PIN offset", cmdParameters));
    String result = null;
    try {
        result = calculateIBMPINOffsetImpl(pinUnderLmk, pvk, decTab, pinValData, minPinLen, excludes);
        evt.addMessage(new SimpleMsg("result", "Calculated PIN offset", result));
    } catch (Exception e) {
        evt.addMessage(e);
        throw e instanceof SMException ? (SMException) e : new SMException(e);
    } finally {
        Logger.log(evt);
    }
    return result;
}
Also used : LogEvent(org.jpos.util.LogEvent) ArrayList(java.util.ArrayList) Loggeable(org.jpos.util.Loggeable) SimpleMsg(org.jpos.util.SimpleMsg) ConfigurationException(org.jpos.core.ConfigurationException) NotFoundException(org.jpos.util.NameRegistrar.NotFoundException)

Example 70 with SimpleMsg

use of org.jpos.util.SimpleMsg in project jPOS by jpos.

the class BaseSMAdapter method deriveIBMPIN.

@Override
public EncryptedPIN deriveIBMPIN(String accountNo, T pvk, String decTab, String pinValData, int minPinLen, String offset) throws SMException {
    List<Loggeable> cmdParameters = new ArrayList<>();
    cmdParameters.add(new SimpleMsg("parameter", "account number", accountNo));
    cmdParameters.add(new SimpleMsg("parameter", "Offset", offset));
    cmdParameters.add(new SimpleMsg("parameter", "PVK", pvk));
    cmdParameters.add(new SimpleMsg("parameter", "Decimalisation table", decTab));
    cmdParameters.add(new SimpleMsg("parameter", "PIN validation data", pinValData));
    cmdParameters.add(new SimpleMsg("parameter", "Minimum PIN length", minPinLen));
    LogEvent evt = new LogEvent(this, "s-m-operation");
    evt.addMessage(new SimpleMsg("command", "Derive a PIN Using the IBM Method", cmdParameters));
    EncryptedPIN result = null;
    try {
        result = deriveIBMPINImpl(accountNo, pvk, decTab, pinValData, minPinLen, offset);
        evt.addMessage(new SimpleMsg("result", "Derived PIN", result));
    } catch (Exception e) {
        evt.addMessage(e);
        throw e instanceof SMException ? (SMException) e : new SMException(e);
    } finally {
        Logger.log(evt);
    }
    return result;
}
Also used : LogEvent(org.jpos.util.LogEvent) ArrayList(java.util.ArrayList) Loggeable(org.jpos.util.Loggeable) SimpleMsg(org.jpos.util.SimpleMsg) ConfigurationException(org.jpos.core.ConfigurationException) NotFoundException(org.jpos.util.NameRegistrar.NotFoundException)

Aggregations

LogEvent (org.jpos.util.LogEvent)76 SimpleMsg (org.jpos.util.SimpleMsg)76 ConfigurationException (org.jpos.core.ConfigurationException)72 NotFoundException (org.jpos.util.NameRegistrar.NotFoundException)72 ArrayList (java.util.ArrayList)55 Loggeable (org.jpos.util.Loggeable)55 PublicKey (java.security.PublicKey)2 SecretKey (javax.crypto.SecretKey)2