Search in sources :

Example 1 with SecureDESKey

use of org.jpos.security.SecureDESKey in project jPOS by jpos.

the class JCESecurityModuleTest method testImportPINImplThrowsNullPointerException1.

@Test
public void testImportPINImplThrowsNullPointerException1() throws Throwable {
    byte[] keyBytes = new byte[0];
    try {
        new JCESecurityModule().importPINImpl(new EncryptedPIN("testJCESecurityModulePinBlockHexString", (byte) 0, "testJCESecurityModuleAccountNumber"), new SecureDESKey((short) 100, "testJCESecurityModuleKeyType", keyBytes, "testString".getBytes()));
        fail("Expected NullPointerException to be thrown");
    } catch (NullPointerException ex) {
        if (isJavaVersionAtMost(JAVA_14)) {
            assertNull(ex.getMessage(), "ex.getMessage()");
        } else {
            assertEquals("Cannot invoke \"java.util.Map.containsKey(Object)\" because \"this.keyTypeToLMKIndex\" is null", ex.getMessage(), "ex.getMessage()");
        }
    }
}
Also used : SecureDESKey(org.jpos.security.SecureDESKey) EncryptedPIN(org.jpos.security.EncryptedPIN) Test(org.junit.jupiter.api.Test)

Example 2 with SecureDESKey

use of org.jpos.security.SecureDESKey in project jPOS by jpos.

the class JCESecurityModuleTest method testTranslatePINImplThrowsNullPointerException.

@Test
public void testTranslatePINImplThrowsNullPointerException() throws Throwable {
    try {
        new JCESecurityModule().translatePINImpl(new EncryptedPIN("testString".getBytes(), (byte) 0, "testJCESecurityModuleAccountNumber"), null, new SecureDESKey(), (byte) 0);
        fail("Expected NullPointerException to be thrown");
    } catch (NullPointerException ex) {
        if (isJavaVersionAtMost(JAVA_14)) {
            assertNull(ex.getMessage(), "ex.getMessage()");
        } else {
            assertEquals("Cannot invoke \"org.jpos.security.SecureDESKey.getKeyBytes()\" because \"secureDESKey\" is null", ex.getMessage(), "ex.getMessage()");
        }
    }
}
Also used : SecureDESKey(org.jpos.security.SecureDESKey) EncryptedPIN(org.jpos.security.EncryptedPIN) Test(org.junit.jupiter.api.Test)

Example 3 with SecureDESKey

use of org.jpos.security.SecureDESKey in project jPOS by jpos.

the class DUKPTTest method test_DUKPT.

private void test_DUKPT(String keyName, KeySerialNumber ksn, byte[] pinUnderDukpt, String pan, boolean tdes) throws Exception {
    LogEvent evt = log.createInfo("test_DUKPT " + ksn);
    evt.addMessage(ksn);
    EncryptedPIN pin = new EncryptedPIN(pinUnderDukpt, SMAdapter.FORMAT01, pan);
    SecureDESKey bdk = ks.getKey(keyName);
    evt.addMessage(pin);
    evt.addMessage(ksn);
    evt.addMessage(bdk);
    EncryptedPIN pinUnderLMK = sm.importPIN(pin, ksn, bdk, tdes);
    evt.addMessage(pinUnderLMK);
    evt.addMessage("<decrypted-pin>" + sm.decryptPIN(pinUnderLMK) + "</decrypted-pin>");
    Logger.log(evt);
}
Also used : LogEvent(org.jpos.util.LogEvent) SecureDESKey(org.jpos.security.SecureDESKey) EncryptedPIN(org.jpos.security.EncryptedPIN)

Example 4 with SecureDESKey

use of org.jpos.security.SecureDESKey in project jPOS by jpos.

the class DUKPTTest method test_dataEncrypt.

@Test
public void test_dataEncrypt() throws Exception {
    SecureDESKey bdk = (SecureDESKey) ks.getKey("test-bdk");
    byte[] original = "The quick brown fox jumps over the lazy dog".getBytes();
    byte[] cryptogram = sm.dataEncrypt(bdk, original);
    byte[] cleartext = sm.dataDecrypt(bdk, cryptogram);
    assertEqual(original, cleartext);
    cryptogram[0] = (byte) (cryptogram[0] ^ 0xAA);
    try {
        sm.dataDecrypt(bdk, cryptogram);
        fail("SMException not raised");
    } catch (Exception ignored) {
    }
}
Also used : SecureDESKey(org.jpos.security.SecureDESKey) ConfigurationException(org.jpos.core.ConfigurationException) Test(org.junit.jupiter.api.Test)

Example 5 with SecureDESKey

use of org.jpos.security.SecureDESKey in project jPOS by jpos.

the class JCESecurityModuleTest method translateKeySchemeImpl_Convert.

@Test
public void translateKeySchemeImpl_Convert() throws Throwable {
    SecureDESKey pvk = new SecureDESKey(SMAdapter.LENGTH_DES3_2KEY, SMAdapter.TYPE_PVK + ":0X", "141E1DA3D2D7F3F4141E1DA3D2D7F3F4", "6FB1C8");
    SecureDESKey conv = jcesecmod.translateKeySchemeImpl(pvk, KeyScheme.U);
    assertEquals(pvk.getKeyLength(), conv.getKeyLength());
    assertEquals(SMAdapter.TYPE_PVK + ":0U", conv.getKeyType());
    assertArrayEquals(pvk.getKeyCheckValue(), conv.getKeyCheckValue());
    assertEquals(KeyScheme.U, conv.getScheme());
    assertEquals(pvk.getVariant(), conv.getVariant());
    // TPK and ZPK uses same encription variant
    assertArrayEquals(tpk.getKeyBytes(), conv.getKeyBytes());
}
Also used : SecureDESKey(org.jpos.security.SecureDESKey) Test(org.junit.jupiter.api.Test)

Aggregations

SecureDESKey (org.jpos.security.SecureDESKey)20 Test (org.junit.jupiter.api.Test)15 EncryptedPIN (org.jpos.security.EncryptedPIN)4 ConfigurationException (org.jpos.core.ConfigurationException)2 Properties (java.util.Properties)1 SimpleConfiguration (org.jpos.core.SimpleConfiguration)1 SMException (org.jpos.security.SMException)1 LogEvent (org.jpos.util.LogEvent)1 Logger (org.jpos.util.Logger)1 SimpleLogListener (org.jpos.util.SimpleLogListener)1