Search in sources :

Example 1 with StatusWord

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

the class Iso7816FourCard method selectFileById.

/**
 * Selecciona un fichero (DF o EF).
 * @param id Identificador del fichero a seleccionar.
 * @return Tamaño del fichero seleccionado.
 * @throws ApduConnectionException Si hay problemas en el envío de la APDU.
 * @throws Iso7816FourCardException Si falla la selección de fichero.
 */
public int selectFileById(final byte[] id) throws ApduConnectionException, Iso7816FourCardException {
    final CommandApdu selectCommand = new SelectFileByIdApduCommand(getCla(), id);
    final ResponseApdu res = getConnection().transmit(selectCommand);
    if (HexUtils.arrayEquals(res.getBytes(), new byte[] { (byte) 0x6a, (byte) 0x82 })) {
        throw new FileNotFoundException(id);
    }
    final SelectFileApduResponse response = new SelectFileApduResponse(res);
    if (response.isOk()) {
        return response.getFileLength();
    }
    final StatusWord sw = response.getStatusWord();
    if (sw.equals(new StatusWord((byte) 0x6A, (byte) 0x82))) {
        throw new FileNotFoundException(id);
    }
    throw new Iso7816FourCardException(sw, selectCommand);
}
Also used : SelectFileByIdApduCommand(es.gob.jmulticard.apdu.iso7816four.SelectFileByIdApduCommand) SelectFileApduResponse(es.gob.jmulticard.apdu.iso7816four.SelectFileApduResponse) CommandApdu(es.gob.jmulticard.apdu.CommandApdu) StatusWord(es.gob.jmulticard.apdu.StatusWord) ResponseApdu(es.gob.jmulticard.apdu.ResponseApdu)

Example 2 with StatusWord

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

the class Iso7816FourCard method readAllRecords.

/**
 * Lee todos los registros del binario actualmente seleccionado.
 * @return Lista de registros leidos del binario actualmente seleccionado.
 * @throws ApduConnectionException Si hay problemas en el envío de la APDU.
 * @throws Iso7816FourCardException SI ocurren problemas durante la lectura de los registros.
 */
public List<byte[]> readAllRecords() throws ApduConnectionException, Iso7816FourCardException {
    final List<byte[]> ret = new ArrayList<>();
    StatusWord readedResponseSw;
    final CommandApdu readRecordApduCommand = new ReadRecordApduCommand(getCla());
    do {
        final ResponseApdu readedResponse = sendArbitraryApdu(readRecordApduCommand);
        readedResponseSw = readedResponse.getStatusWord();
        if (!readedResponse.isOk() && !ReadRecordApduCommand.RECORD_NOT_FOUND.equals(readedResponseSw)) {
            throw new Iso7816FourCardException(// $NON-NLS-1$
            "Error en la lectura de registro", // $NON-NLS-1$
            readedResponseSw);
        }
        ret.add(readedResponse.getData());
    } while (!ReadRecordApduCommand.RECORD_NOT_FOUND.equals(readedResponseSw));
    return ret;
}
Also used : CommandApdu(es.gob.jmulticard.apdu.CommandApdu) ReadRecordApduCommand(es.gob.jmulticard.apdu.iso7816four.ReadRecordApduCommand) StatusWord(es.gob.jmulticard.apdu.StatusWord) ArrayList(java.util.ArrayList) ResponseApdu(es.gob.jmulticard.apdu.ResponseApdu)

Example 3 with StatusWord

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

the class Ceres method verifyPin.

@Override
public void verifyPin(final PasswordCallback pinPc) throws ApduConnectionException, PinException {
    if (pinPc == null) {
        // $NON-NLS-1$
        throw new PinException("No se ha establecido un PasswordCallback");
    }
    final CommandApdu chv = new CeresVerifyApduCommand(CLA, pinPc);
    final ResponseApdu verifyResponse = sendArbitraryApdu(chv);
    if (!verifyResponse.isOk()) {
        if (verifyResponse.getStatusWord().getMsb() == ERROR_PIN_SW1 || verifyResponse.getStatusWord().getMsb() == ERROR_PIN_SW2) {
            if (AUTO_RETRY) {
                this.passwordCallback = null;
                verifyPin(getInternalPasswordCallback());
                return;
            }
            throw new BadPinException(verifyResponse.getStatusWord().getLsb() - (byte) 0xC0);
        } else if (new StatusWord((byte) 0x69, (byte) 0x83).equals(verifyResponse.getStatusWord())) {
            throw new AuthenticationModeLockedException();
        }
        throw new ApduConnectionException(new Iso7816FourCardException(// $NON-NLS-1$ //$NON-NLS-2$
        "Error en la verificacion de PIN (" + verifyResponse.getStatusWord() + ")", verifyResponse.getStatusWord()));
    }
}
Also used : AuthenticationModeLockedException(es.gob.jmulticard.card.AuthenticationModeLockedException) Iso7816FourCardException(es.gob.jmulticard.card.iso7816four.Iso7816FourCardException) CommandApdu(es.gob.jmulticard.apdu.CommandApdu) CeresVerifyApduCommand(es.gob.jmulticard.apdu.ceres.CeresVerifyApduCommand) BadPinException(es.gob.jmulticard.card.BadPinException) StatusWord(es.gob.jmulticard.apdu.StatusWord) ResponseApdu(es.gob.jmulticard.apdu.ResponseApdu) BadPinException(es.gob.jmulticard.card.BadPinException) PinException(es.gob.jmulticard.card.PinException) ApduConnectionException(es.gob.jmulticard.apdu.connection.ApduConnectionException)

Example 4 with StatusWord

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

the class SmartCafePkcs15Applet method selectFileById.

/**
 * Selecciona un fichero (DF o EF).
 * @param id Identificador del fichero a seleccionar.
 * @return Tama&ntilde;o del fichero seleccionado.
 * @throws ApduConnectionException Si hay problemas en el env&iacute;o de la APDU.
 * @throws Iso7816FourCardException Si falla la selecci&oacute;n de fichero.
 */
@Override
public int selectFileById(final byte[] id) throws ApduConnectionException, Iso7816FourCardException {
    final CommandApdu selectCommand = new SelectFileByIdApduCommand(getCla(), id);
    final ResponseApdu res = getConnection().transmit(selectCommand);
    if (HexUtils.arrayEquals(res.getBytes(), new byte[] { (byte) 0x6a, (byte) 0x82 })) {
        throw new FileNotFoundException(id);
    }
    final SelectFileApduResponse response = new SelectFileApduResponse(res);
    if (response.isOk()) {
        return HexUtils.getUnsignedInt(new byte[] { response.getData()[4], response.getData()[5] }, // Offset
        0);
    }
    final StatusWord sw = response.getStatusWord();
    if (sw.equals(new StatusWord((byte) 0x6A, (byte) 0x82))) {
        throw new FileNotFoundException(id);
    }
    throw new Iso7816FourCardException(sw, selectCommand);
}
Also used : SelectFileByIdApduCommand(es.gob.jmulticard.apdu.iso7816four.SelectFileByIdApduCommand) SelectFileApduResponse(es.gob.jmulticard.apdu.iso7816four.SelectFileApduResponse) Iso7816FourCardException(es.gob.jmulticard.card.iso7816four.Iso7816FourCardException) CommandApdu(es.gob.jmulticard.apdu.CommandApdu) StatusWord(es.gob.jmulticard.apdu.StatusWord) FileNotFoundException(es.gob.jmulticard.card.iso7816four.FileNotFoundException) ResponseApdu(es.gob.jmulticard.apdu.ResponseApdu)

Example 5 with StatusWord

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

the class TestStatusWord method testGetBytes.

/**
 * Prueba el funcionamiento de getBytes
 */
public static final void testGetBytes() {
    final StatusWord sw = new StatusWord((byte) 0x90, (byte) 0x00);
    final byte[] respuestaEsperada = new byte[] { (byte) 0x90, (byte) 0x00 };
    for (int i = 0; i < sw.getBytes().length; i++) {
        Assert.assertEquals(respuestaEsperada[i], sw.getBytes()[i]);
    }
}
Also used : StatusWord(es.gob.jmulticard.apdu.StatusWord)

Aggregations

StatusWord (es.gob.jmulticard.apdu.StatusWord)8 CommandApdu (es.gob.jmulticard.apdu.CommandApdu)5 ResponseApdu (es.gob.jmulticard.apdu.ResponseApdu)5 SelectFileApduResponse (es.gob.jmulticard.apdu.iso7816four.SelectFileApduResponse)2 SelectFileByIdApduCommand (es.gob.jmulticard.apdu.iso7816four.SelectFileByIdApduCommand)2 Iso7816FourCardException (es.gob.jmulticard.card.iso7816four.Iso7816FourCardException)2 CeresVerifyApduCommand (es.gob.jmulticard.apdu.ceres.CeresVerifyApduCommand)1 ApduConnectionException (es.gob.jmulticard.apdu.connection.ApduConnectionException)1 ReadRecordApduCommand (es.gob.jmulticard.apdu.iso7816four.ReadRecordApduCommand)1 SelectDfByNameApduCommand (es.gob.jmulticard.apdu.iso7816four.SelectDfByNameApduCommand)1 AuthenticationModeLockedException (es.gob.jmulticard.card.AuthenticationModeLockedException)1 BadPinException (es.gob.jmulticard.card.BadPinException)1 PinException (es.gob.jmulticard.card.PinException)1 FileNotFoundException (es.gob.jmulticard.card.iso7816four.FileNotFoundException)1 ArrayList (java.util.ArrayList)1