Search in sources :

Example 16 with Loggeable

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

the class BaseSMAdapter method calculateCVD.

@Override
public String calculateCVD(String accountNo, T cvkA, T cvkB, String expDate, String serviceCode) throws SMException {
    List<Loggeable> cmdParameters = new ArrayList<>();
    cmdParameters.add(new SimpleMsg("parameter", "account number", accountNo));
    cmdParameters.add(new SimpleMsg("parameter", "cvk-a", cvkA == null ? "" : cvkA));
    cmdParameters.add(new SimpleMsg("parameter", "cvk-b", cvkB == null ? "" : cvkB));
    cmdParameters.add(new SimpleMsg("parameter", "Exp date", expDate));
    cmdParameters.add(new SimpleMsg("parameter", "Service code", serviceCode));
    LogEvent evt = new LogEvent(this, "s-m-operation");
    evt.addMessage(new SimpleMsg("command", "Calculate CVV/CVC", cmdParameters));
    String result = null;
    try {
        result = calculateCVDImpl(accountNo, cvkA, cvkB, expDate, serviceCode);
        evt.addMessage(new SimpleMsg("result", "Calculated CVV/CVC", 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 17 with Loggeable

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

the class BaseSMAdapter method generateKey.

@Override
public SecureDESKey generateKey(short keyLength, String keyType) throws SMException {
    List<Loggeable> cmdParameters = new ArrayList<>();
    cmdParameters.add(new SimpleMsg("parameter", "Key Length", keyLength));
    cmdParameters.add(new SimpleMsg("parameter", "Key Type", keyType));
    LogEvent evt = new LogEvent(this, "s-m-operation");
    evt.addMessage(new SimpleMsg("command", "Generate Key", cmdParameters));
    SecureDESKey result = null;
    try {
        result = generateKeyImpl(keyLength, keyType);
        evt.addMessage(new SimpleMsg("result", "Generated 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) 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 18 with Loggeable

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

the class BaseSMAdapter method importKey.

@Override
public SecureDESKey importKey(short keyLength, String keyType, byte[] encryptedKey, SecureDESKey kek, boolean checkParity) throws SMException {
    List<Loggeable> cmdParameters = new ArrayList<>();
    cmdParameters.add(new SimpleMsg("parameter", "Key Length", keyLength));
    cmdParameters.add(new SimpleMsg("parameter", "Key Type", keyType));
    cmdParameters.add(new SimpleMsg("parameter", "Encrypted Key", encryptedKey));
    cmdParameters.add(new SimpleMsg("parameter", "Key-Encrypting Key", kek));
    cmdParameters.add(new SimpleMsg("parameter", "Check Parity", checkParity));
    LogEvent evt = new LogEvent(this, "s-m-operation");
    evt.addMessage(new SimpleMsg("command", "Import Key", cmdParameters));
    SecureDESKey result = null;
    try {
        result = importKeyImpl(keyLength, keyType, encryptedKey, kek, checkParity);
        evt.addMessage(new SimpleMsg("result", "Imported 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) 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 19 with Loggeable

use of org.jpos.util.Loggeable 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<>();
    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);
        List<Loggeable> cmdResults = new ArrayList<>();
        cmdResults.add(new SimpleMsg("result", "Public Key", result.getValue0().getEncoded()));
        cmdResults.add(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 20 with Loggeable

use of org.jpos.util.Loggeable 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<>();
    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<>();
        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)

Aggregations

Loggeable (org.jpos.util.Loggeable)56 ArrayList (java.util.ArrayList)55 LogEvent (org.jpos.util.LogEvent)55 SimpleMsg (org.jpos.util.SimpleMsg)55 ConfigurationException (org.jpos.core.ConfigurationException)53 NotFoundException (org.jpos.util.NameRegistrar.NotFoundException)53 PublicKey (java.security.PublicKey)2 Iterator (java.util.Iterator)1 Map (java.util.Map)1 NameRegistrar (org.jpos.util.NameRegistrar)1