Search in sources :

Example 26 with CommandApdu

use of es.gob.jmulticard.apdu.CommandApdu in project jmulticard by ctt-gob-es.

the class Iso7816FourCard method selectFileByName.

/**
 * Selecciona un fichero por nombre.
 * @param name Nombre del fichero en hexadecimal
 * @throws FileNotFoundException Si el fichero no existe
 * @throws ApduConnectionException Si ocurre algún problema durante la selección
 * @throws Iso7816FourCardException Si el fichero no se puede seleccionar por cualquier otra causa
 */
public void selectFileByName(final byte[] name) throws ApduConnectionException, FileNotFoundException, Iso7816FourCardException {
    final CommandApdu selectCommand = new SelectDfByNameApduCommand(getCla(), name);
    final ResponseApdu response = sendArbitraryApdu(selectCommand);
    if (response.isOk()) {
        return;
    }
    final StatusWord sw = response.getStatusWord();
    if (sw.equals(new StatusWord((byte) 0x6A, (byte) 0x82))) {
        throw new FileNotFoundException(name);
    }
    throw new Iso7816FourCardException(sw, selectCommand);
}
Also used : SelectDfByNameApduCommand(es.gob.jmulticard.apdu.iso7816four.SelectDfByNameApduCommand) CommandApdu(es.gob.jmulticard.apdu.CommandApdu) StatusWord(es.gob.jmulticard.apdu.StatusWord) ResponseApdu(es.gob.jmulticard.apdu.ResponseApdu)

Example 27 with CommandApdu

use of es.gob.jmulticard.apdu.CommandApdu in project jmulticard by ctt-gob-es.

the class TestApduEncrypter method testPinEncryptionDes.

/**
 * Prueba de cifrado 3DES de APDU de verificación de PIN.
 * @throws Exception En cualquier error.
 */
@SuppressWarnings("static-method")
@Test
public void testPinEncryptionDes() throws Exception {
    final CommandApdu verifyCommandApdu = new VerifyApduCommand((byte) 0x00, // $NON-NLS-1$
    new CachePasswordCallback("CRYPTOKI".toCharArray()));
    final ApduEncrypter apduEncrypterDes = new ApduEncrypterDes();
    final byte[] res = apduEncrypterDes.protectAPDU(verifyCommandApdu, KENC, KMAC, SSC_PIN, new JseCryptoHelper()).getBytes();
    Assert.assertEquals(// $NON-NLS-1$
    "0c20000019871101ce1ab937c332f3faee43336d4311ef338e046908df4e", HexUtils.hexify(res, false).toLowerCase());
}
Also used : ApduEncrypterDes(es.gob.jmulticard.apdu.connection.ApduEncrypterDes) CommandApdu(es.gob.jmulticard.apdu.CommandApdu) ApduEncrypter(es.gob.jmulticard.apdu.connection.ApduEncrypter) JseCryptoHelper(es.gob.jmulticard.JseCryptoHelper) VerifyApduCommand(es.gob.jmulticard.apdu.dnie.VerifyApduCommand) Test(org.junit.Test)

Example 28 with CommandApdu

use of es.gob.jmulticard.apdu.CommandApdu in project jmulticard by ctt-gob-es.

the class TestApduEncrypter method testEncryptionAes.

/**
 * Prueba de cifrado AES de una APDU.
 * @throws Exception En cualquier error.
 */
@Test
// Necesita el proveedor BC/SC firmado
@Ignore
public void testEncryptionAes() throws Exception {
    this.paddingLength = 16;
    final CommandApdu apdu = new CommandApdu((byte) 0x00, (byte) 0xa4, (byte) 0x04, (byte) 0x00, new byte[] { (byte) 0x4d, (byte) 0x61, (byte) 0x73, (byte) 0x74, (byte) 0x65, (byte) 0x72, (byte) 0x2e, (byte) 0x46, (byte) 0x69, (byte) 0x6c, (byte) 0x65 }, null);
    System.out.println(HexUtils.hexify(protectAPDU(apdu, KENC2, KMAC2, SSC2, new JseCryptoHelper()).getBytes(), false).toLowerCase());
    System.out.println(HexUtils.hexify(new ApduEncrypterAes().protectAPDU(apdu, KENC2, KMAC2, SSC2, new JseCryptoHelper()).getBytes(), false).toLowerCase());
    // $NON-NLS-1$
    System.out.println("0ca404001d871101f5124ee2f53962e86e66a6d234827f0f8e0870e6de5f679aee64");
}
Also used : CommandApdu(es.gob.jmulticard.apdu.CommandApdu) JseCryptoHelper(es.gob.jmulticard.JseCryptoHelper) ApduEncrypterAes(es.gob.jmulticard.apdu.connection.ApduEncrypterAes) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 29 with CommandApdu

use of es.gob.jmulticard.apdu.CommandApdu in project jmulticard by ctt-gob-es.

the class SmartCafePkcs15Applet method getPinRetriesLeft.

private int getPinRetriesLeft() throws PinException {
    final CommandApdu verifyCommandApdu = new RetriesLeftApduCommand();
    final ResponseApdu verifyResponse;
    try {
        verifyResponse = getConnection().transmit(verifyCommandApdu);
    } catch (final ApduConnectionException e) {
        throw new PinException(// $NON-NLS-1$
        "Error obteniendo el PIN del CallbackHandler: " + e, // $NON-NLS-1$
        e);
    }
    if (verifyResponse.isOk() || verifyResponse.getBytes().length > 2) {
        return verifyResponse.getBytes()[1];
    }
    throw new PinException(// $NON-NLS-1$
    "Error comprobando los intentos restantes de PIN con respuesta: " + HexUtils.hexify(verifyResponse.getBytes(), true));
}
Also used : CommandApdu(es.gob.jmulticard.apdu.CommandApdu) ResponseApdu(es.gob.jmulticard.apdu.ResponseApdu) BadPinException(es.gob.jmulticard.card.BadPinException) PinException(es.gob.jmulticard.card.PinException) RetriesLeftApduCommand(es.gob.jmulticard.apdu.gide.RetriesLeftApduCommand) ApduConnectionException(es.gob.jmulticard.apdu.connection.ApduConnectionException)

Aggregations

CommandApdu (es.gob.jmulticard.apdu.CommandApdu)29 ResponseApdu (es.gob.jmulticard.apdu.ResponseApdu)20 ApduConnectionException (es.gob.jmulticard.apdu.connection.ApduConnectionException)15 BadPinException (es.gob.jmulticard.card.BadPinException)8 PinException (es.gob.jmulticard.card.PinException)8 IOException (java.io.IOException)8 Iso7816FourCardException (es.gob.jmulticard.card.iso7816four.Iso7816FourCardException)7 CertificateException (java.security.cert.CertificateException)6 Test (org.junit.Test)6 StatusWord (es.gob.jmulticard.apdu.StatusWord)5 JseCryptoHelper (es.gob.jmulticard.JseCryptoHelper)4 SecureChannelException (es.gob.jmulticard.apdu.connection.cwa14890.SecureChannelException)4 TlvException (es.gob.jmulticard.asn1.TlvException)4 AuthenticationModeLockedException (es.gob.jmulticard.card.AuthenticationModeLockedException)4 CryptoCardException (es.gob.jmulticard.card.CryptoCardException)4 LostChannelException (es.gob.jmulticard.apdu.connection.LostChannelException)3 Cwa14890Connection (es.gob.jmulticard.apdu.connection.cwa14890.Cwa14890Connection)3 MseSetComputationApduCommand (es.gob.jmulticard.apdu.iso7816four.MseSetComputationApduCommand)3 Asn1Exception (es.gob.jmulticard.asn1.Asn1Exception)3 InvalidCardException (es.gob.jmulticard.card.InvalidCardException)3