Search in sources :

Example 6 with SimpleMsg

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

the class BaseSMAdapter method generateEDE_MAC.

@Override
public byte[] generateEDE_MAC(byte[] data, SecureDESKey kd) throws SMException {
    SimpleMsg[] cmdParameters = { new SimpleMsg("parameter", "data", data), new SimpleMsg("parameter", "data key", kd) };
    LogEvent evt = new LogEvent(this, "s-m-operation");
    evt.addMessage(new SimpleMsg("command", "Generate EDE-MAC", cmdParameters));
    byte[] result = null;
    try {
        result = generateEDE_MACImpl(data, kd);
        evt.addMessage(new SimpleMsg("result", "EDE-MAC", 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)

Example 7 with SimpleMsg

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

the class JCESecurityModule method formKEYfromThreeClearComponents.

/**
 * Forms a key from 3 clear components and returns it encrypted under its corresponding LMK
 * The corresponding LMK is determined from the keyType
 * @param keyLength e.g. LENGTH_DES, LENGTH_DES3_2, LENGTH_DES3_3, ..
 * @param keyType possible values are those defined in the SecurityModule inteface. e.g., ZMK, TMK,...
 * @param clearComponent1HexString HexString containing the first component
 * @param clearComponent2HexString HexString containing the second component
 * @param clearComponent3HexString HexString containing the second component
 * @return forms an SecureDESKey from two clear components
 * @throws SMException
 */
SecureDESKey formKEYfromThreeClearComponents(short keyLength, String keyType, String clearComponent1HexString, String clearComponent2HexString, String clearComponent3HexString) throws SMException {
    SecureDESKey secureDESKey;
    LogEvent evt = new LogEvent(this, "s-m-operation");
    try {
        byte[] clearComponent1 = ISOUtil.hex2byte(clearComponent1HexString);
        byte[] clearComponent2 = ISOUtil.hex2byte(clearComponent2HexString);
        byte[] clearComponent3 = ISOUtil.hex2byte(clearComponent3HexString);
        byte[] clearKeyBytes = ISOUtil.xor(ISOUtil.xor(clearComponent1, clearComponent2), clearComponent3);
        Key clearKey = jceHandler.formDESKey(keyLength, clearKeyBytes);
        secureDESKey = encryptToLMK(keyLength, keyType, clearKey);
        SimpleMsg[] cmdParameters = { new SimpleMsg("parameter", "Key Length", keyLength), new SimpleMsg("parameter", "Key Type", keyType), new SimpleMsg("parameter", "Component 1 Check Value", calculateKeyCheckValue(jceHandler.formDESKey(keyLength, clearComponent1))), new SimpleMsg("parameter", "Component 2 Check Value", calculateKeyCheckValue(jceHandler.formDESKey(keyLength, clearComponent2))), new SimpleMsg("parameter", "Component 3 Check Value", calculateKeyCheckValue(jceHandler.formDESKey(keyLength, clearComponent3))) };
        evt.addMessage(new SimpleMsg("command", "Form Key from Three Clear Components", cmdParameters));
        evt.addMessage(new SimpleMsg("result", "Formed Key", secureDESKey));
    } catch (JCEHandlerException e) {
        evt.addMessage(e);
        throw e;
    } finally {
        Logger.log(evt);
    }
    return secureDESKey;
}
Also used : LogEvent(org.jpos.util.LogEvent) SimpleMsg(org.jpos.util.SimpleMsg) SecretKey(javax.crypto.SecretKey)

Example 8 with SimpleMsg

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

the class BaseSMAdapter method translateKeyFromOldLMK.

@Override
public SecureDESKey translateKeyFromOldLMK(SecureDESKey kd) throws SMException {
    SimpleMsg[] cmdParameters = { new SimpleMsg("parameter", "Key under old LMK", kd) };
    LogEvent evt = new LogEvent(this, "s-m-operation");
    evt.addMessage(new SimpleMsg("command", "Translate Key from old to new LMK", cmdParameters));
    SecureDESKey result = null;
    try {
        result = translateKeyFromOldLMKImpl(kd);
        evt.addMessage(new SimpleMsg("result", "Translated Key under new LMK", 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)

Example 9 with SimpleMsg

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

the class BaseSMAdapter method decryptPIN.

@Override
public String decryptPIN(EncryptedPIN pinUnderLmk) throws SMException {
    SimpleMsg[] cmdParameters = { new SimpleMsg("parameter", "PIN under LMK", pinUnderLmk) };
    LogEvent evt = new LogEvent(this, "s-m-operation");
    evt.addMessage(new SimpleMsg("command", "Decrypt PIN", cmdParameters));
    String result = null;
    try {
        result = decryptPINImpl(pinUnderLmk);
        evt.addMessage(new SimpleMsg("result", "clear 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) SimpleMsg(org.jpos.util.SimpleMsg) ConfigurationException(org.jpos.core.ConfigurationException) NotFoundException(org.jpos.util.NameRegistrar.NotFoundException)

Example 10 with SimpleMsg

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

the class BaseSMAdapter method deriveIBMPIN.

@Override
public EncryptedPIN deriveIBMPIN(String accountNo, SecureDESKey pvk, String decTab, String pinValData, int minPinLen, String offset) throws SMException {
    SimpleMsg[] cmdParameters = { new SimpleMsg("parameter", "account number", accountNo), new SimpleMsg("parameter", "Offset", offset), new SimpleMsg("parameter", "PVK", pvk), new SimpleMsg("parameter", "Decimalisation table", decTab), new SimpleMsg("parameter", "PIN validation data", pinValData), 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) SimpleMsg(org.jpos.util.SimpleMsg) ConfigurationException(org.jpos.core.ConfigurationException) NotFoundException(org.jpos.util.NameRegistrar.NotFoundException)

Aggregations

LogEvent (org.jpos.util.LogEvent)40 SimpleMsg (org.jpos.util.SimpleMsg)40 ConfigurationException (org.jpos.core.ConfigurationException)38 NotFoundException (org.jpos.util.NameRegistrar.NotFoundException)38 ArrayList (java.util.ArrayList)11 Loggeable (org.jpos.util.Loggeable)11 SecretKey (javax.crypto.SecretKey)2 PublicKey (java.security.PublicKey)1