Search in sources :

Example 91 with LogEvent

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

the class BaseSMAdapter method generateKeyPair.

@Override
public Pair<PublicKey, SecurePrivateKey> generateKeyPair(AlgorithmParameterSpec spec) throws SMException {
    List<Loggeable> cmdParameters = new ArrayList<Loggeable>();
    cmdParameters.add(new SimpleMsg("parameter", "Algorithm Parameter Spec", spec.getClass().getName()));
    LogEvent evt = new LogEvent(this, "s-m-operation");
    evt.addMessage(new SimpleMsg("command", "Generate public/private key pair", cmdParameters));
    Pair<PublicKey, SecurePrivateKey> result = null;
    try {
        result = generateKeyPairImpl(spec);
        SimpleMsg[] cmdResults = { new SimpleMsg("result", "Public Key", result.getValue0().getEncoded()), new SimpleMsg("result", "Private Key", result.getValue1().getKeyBytes()) };
        evt.addMessage(new SimpleMsg("results", "Complex results", cmdResults));
    } 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) PublicKey(java.security.PublicKey) 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 92 with LogEvent

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

the class BaseSMAdapter method verifyCAVV.

@Override
public boolean verifyCAVV(String accountNo, SecureDESKey cvk, String cavv, String upn, String authrc, String sfarc) throws SMException {
    List<Loggeable> cmdParameters = new ArrayList<Loggeable>();
    cmdParameters.add(new SimpleMsg("parameter", "account number", accountNo));
    cmdParameters.add(new SimpleMsg("parameter", "cvk", cvk == null ? "" : cvk));
    cmdParameters.add(new SimpleMsg("parameter", "cavv", cavv == null ? "" : cavv));
    cmdParameters.add(new SimpleMsg("parameter", "unpredictable number", upn));
    cmdParameters.add(new SimpleMsg("parameter", "auth rc", authrc));
    cmdParameters.add(new SimpleMsg("parameter", "second factor auth rc", sfarc));
    LogEvent evt = new LogEvent(this, "s-m-operation");
    evt.addMessage(new SimpleMsg("command", "Verify CAVV/AAV", cmdParameters));
    boolean r = false;
    try {
        r = verifyCAVVImpl(accountNo, cvk, cavv, upn, authrc, sfarc);
        evt.addMessage(new SimpleMsg("result", "Verification status", r));
    } catch (Exception e) {
        evt.addMessage(e);
        throw e instanceof SMException ? (SMException) e : new SMException(e);
    } finally {
        Logger.log(evt);
    }
    return r;
}
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 93 with LogEvent

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

the class BaseSMAdapter method translatePINGenerateSM_MAC.

@Override
public Pair<EncryptedPIN, byte[]> translatePINGenerateSM_MAC(MKDMethod mkdm, SKDMethod skdm, PaddingMethod padm, SecureDESKey imksmi, String accountNo, String acctSeqNo, byte[] atc, byte[] arqc, byte[] data, EncryptedPIN currentPIN, EncryptedPIN newPIN, SecureDESKey kd1, SecureDESKey imksmc, SecureDESKey imkac, byte destinationPINBlockFormat) throws SMException {
    List<Loggeable> cmdParameters = new ArrayList<Loggeable>();
    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.toArray(new Loggeable[cmdParameters.size()])));
    try {
        Pair<EncryptedPIN, byte[]> r = translatePINGenerateSM_MACImpl(mkdm, skdm, padm, imksmi, accountNo, acctSeqNo, atc, arqc, data, currentPIN, newPIN, kd1, imksmc, imkac, destinationPINBlockFormat);
        SimpleMsg[] cmdResults = { new SimpleMsg("result", "Translated PIN block", r.getValue0()), 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 94 with LogEvent

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

the class BaseSMAdapter method encryptData.

/**
 * Encrypt Data Block.
 *
 * @param cipherMode block cipher mode
 * @param kd DEK or ZEK key used to encrypt data
 * @param data data to be encrypted
 * @param iv initial vector
 * @return encrypted data
 * @throws SMException
 */
@Override
public byte[] encryptData(CipherMode cipherMode, SecureDESKey kd, byte[] data, byte[] iv) throws SMException {
    List<Loggeable> cmdParameters = new ArrayList<Loggeable>();
    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", "Encrypt Data", cmdParameters));
    byte[] encData = null;
    try {
        encData = encryptDataImpl(cipherMode, kd, data, iv);
        List<Loggeable> r = new ArrayList<Loggeable>();
        r.add(new SimpleMsg("result", "Encrypted Data", encData));
        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 encData;
}
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 95 with LogEvent

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

the class BaseSMAdapter method exportKey.

@Override
public byte[] exportKey(SecureDESKey key, SecureDESKey kek) throws SMException {
    SimpleMsg[] cmdParameters = { new SimpleMsg("parameter", "Key", key), new SimpleMsg("parameter", "Key-Encrypting Key", kek) };
    LogEvent evt = new LogEvent(this, "s-m-operation");
    evt.addMessage(new SimpleMsg("command", "Export Key", cmdParameters));
    byte[] result = null;
    try {
        result = exportKeyImpl(key, kek);
        evt.addMessage(new SimpleMsg("result", "Exported Key", 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) SimpleMsg(org.jpos.util.SimpleMsg) ConfigurationException(org.jpos.core.ConfigurationException) NotFoundException(org.jpos.util.NameRegistrar.NotFoundException)

Aggregations

LogEvent (org.jpos.util.LogEvent)189 Test (org.junit.Test)78 ConfigurationException (org.jpos.core.ConfigurationException)51 ISOMsg (org.jpos.iso.ISOMsg)41 SimpleMsg (org.jpos.util.SimpleMsg)40 NotFoundException (org.jpos.util.NameRegistrar.NotFoundException)38 ArrayList (java.util.ArrayList)24 IOException (java.io.IOException)18 SimpleConfiguration (org.jpos.core.SimpleConfiguration)14 CSChannel (org.jpos.iso.channel.CSChannel)12 Loggeable (org.jpos.util.Loggeable)11 Map (java.util.Map)9 ISOChannel (org.jpos.iso.ISOChannel)9 PostChannel (org.jpos.iso.channel.PostChannel)9 CTCSubFieldPackager (org.jpos.iso.packager.CTCSubFieldPackager)9 ISOFilter (org.jpos.iso.ISOFilter)8 BASE24TCPChannel (org.jpos.iso.channel.BASE24TCPChannel)8 PADChannel (org.jpos.iso.channel.PADChannel)8 ISOBaseValidatingPackager (org.jpos.iso.packager.ISOBaseValidatingPackager)8 EOFException (java.io.EOFException)7