Search in sources :

Example 1 with EncryptedPIN

use of org.jpos.security.EncryptedPIN 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 EncryptedPIN

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

the class JCESecurityModuleTest method testTranslatePINImpl.

@Test
public void testTranslatePINImpl() throws Throwable {
    EncryptedPIN pinUnderZPK = new EncryptedPIN("3C0CA40863092C3A", SMAdapter.FORMAT01, "1234567890120");
    EncryptedPIN pinUnderTPK = jcesecmod.translatePINImpl(pinUnderZPK, zpk, tpk, SMAdapter.FORMAT01);
    // Clear keys are that same so after translation expected result must be unchanged
    byte[] expected = ISOUtil.hex2byte("3C0CA40863092C3A");
    assertArrayEquals(expected, pinUnderTPK.getPINBlock());
    assertEquals(SMAdapter.FORMAT01, pinUnderTPK.getPINBlockFormat());
    assertEquals("123456789012", pinUnderTPK.getAccountNumber());
}
Also used : EncryptedPIN(org.jpos.security.EncryptedPIN) Test(org.junit.jupiter.api.Test)

Example 3 with EncryptedPIN

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

the class JCESecurityModuleTest method testTranslatePINGenerateSM_MACImpl5.

@Test
public void testTranslatePINGenerateSM_MACImpl5() throws Throwable {
    String accountNo = accountNoA;
    String accntSeqNo = accountNoA_CSN;
    byte[] apdu = apdu01;
    byte[] atc = atc01;
    byte[] arqc = arqc01;
    EncryptedPIN pin = pinUnderZPK;
    apdu = ISOUtil.concat(apdu, atc);
    apdu = ISOUtil.concat(apdu, arqc);
    EncryptedPIN expectdPIN = new EncryptedPIN("EF0F091EDA14326440C47C0F7C572473", SMAdapter.FORMAT41, accountNo);
    Pair<EncryptedPIN, byte[]> result = jcesecmod.translatePINGenerateSM_MAC(MKDMethod.OPTION_A, SKDMethod.VSDC, null, imksmi, accountNo, accntSeqNo, atc, arqc, apdu, null, pin, zpk, imksmc, imkac, SMAdapter.FORMAT41);
    assertArrayEquals(expectdPIN.getPINBlock(), result.getValue0().getPINBlock());
    assertArrayEquals(ISOUtil.hex2byte("9F1B829D179E55C2"), result.getValue1());
}
Also used : EncryptedPIN(org.jpos.security.EncryptedPIN) Test(org.junit.jupiter.api.Test)

Example 4 with EncryptedPIN

use of org.jpos.security.EncryptedPIN 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 5 with EncryptedPIN

use of org.jpos.security.EncryptedPIN 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)

Aggregations

EncryptedPIN (org.jpos.security.EncryptedPIN)20 Test (org.junit.jupiter.api.Test)18 SecureDESKey (org.jpos.security.SecureDESKey)4 LogEvent (org.jpos.util.LogEvent)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1