Search in sources :

Example 21 with ResponseApdu

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

the class Dnie method verifyPin.

@Override
public void verifyPin(final PasswordCallback psc) throws ApduConnectionException, PinException {
    if (psc == null) {
        throw new IllegalArgumentException(// $NON-NLS-1$
        "No se puede verificar el titular con un PasswordCallback nulo");
    }
    VerifyApduCommand verifyCommandApdu = new VerifyApduCommand((byte) 0x00, psc);
    final ResponseApdu verifyResponse = getConnection().transmit(verifyCommandApdu);
    verifyCommandApdu = null;
    // a pedir si es necesario
    if (!verifyResponse.isOk()) {
        if (verifyResponse.getStatusWord().getMsb() == ERROR_PIN_SW1) {
            // Cliente @firma, que derivaria en DNI bloqueado
            if (!PIN_AUTO_RETRY || psc.getClass().getName().endsWith("CachePasswordCallback")) {
                // $NON-NLS-1$
                throw new BadPinException(verifyResponse.getStatusWord().getLsb() - (byte) 0xC0);
            }
            // Si hay reintento automatico volvemos a pedir el PIN con la misma CallBack
            verifyPin(getInternalPasswordCallback());
        } else if (verifyResponse.getStatusWord().getMsb() == (byte) 0x69 && verifyResponse.getStatusWord().getLsb() == (byte) 0x83) {
            throw new AuthenticationModeLockedException();
        } else if (verifyResponse.getStatusWord().getMsb() == (byte) 0x00 && verifyResponse.getStatusWord().getLsb() == (byte) 0x00) {
            // $NON-NLS-1$
            throw new ApduConnectionException("Se ha perdido el canal NFC");
        } else {
            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) BadPinException(es.gob.jmulticard.card.BadPinException) ResponseApdu(es.gob.jmulticard.apdu.ResponseApdu) VerifyApduCommand(es.gob.jmulticard.apdu.dnie.VerifyApduCommand) ApduConnectionException(es.gob.jmulticard.apdu.connection.ApduConnectionException)

Example 22 with ResponseApdu

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

the class Ceres 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);
    }
    return verifyResponse.getStatusWord().getLsb() - (byte) 0xC0;
}
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.dnie.RetriesLeftApduCommand) ApduConnectionException(es.gob.jmulticard.apdu.connection.ApduConnectionException)

Example 23 with ResponseApdu

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

the class StCard method verifyPin.

@Override
public void verifyPin(final PasswordCallback pinPc) throws ApduConnectionException, PinException {
    if (pinPc == null) {
        // $NON-NLS-1$
        throw new BadPinException("No se ha establecido un PasswordCallback");
    }
    final CommandApdu chv = new VerifyApduCommand(CLA, pinPc);
    final ResponseApdu verifyResponse = sendArbitraryApdu(chv);
    if (!verifyResponse.isOk()) {
        if (verifyResponse.getStatusWord().getMsb() == ERROR_PIN_SW1) {
            throw new BadPinException(verifyResponse.getStatusWord().getLsb() - (byte) 0xC0);
        }
        throw new ApduConnectionException(// $NON-NLS-1$
        "Error en el envio de la verificacion de PIN con respuesta: " + verifyResponse.getStatusWord());
    }
}
Also used : CommandApdu(es.gob.jmulticard.apdu.CommandApdu) BadPinException(es.gob.jmulticard.card.BadPinException) ResponseApdu(es.gob.jmulticard.apdu.ResponseApdu) VerifyApduCommand(es.gob.jmulticard.apdu.bit4id.stcm.VerifyApduCommand) ApduConnectionException(es.gob.jmulticard.apdu.connection.ApduConnectionException)

Example 24 with ResponseApdu

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

the class CeresSc method signOperation.

@Override
protected byte[] signOperation(final byte[] data, final String algorithm, final PrivateKeyReference privateKeyReference) throws CryptoCardException, PinException {
    openSecureChannelIfNotAlreadyOpened();
    ResponseApdu res;
    try {
        CommandApdu apdu = new MseSetComputationApduCommand((byte) 0x00, ((DniePrivateKeyReference) privateKeyReference).getKeyPath().getLastFilePath(), null);
        res = getConnection().transmit(apdu);
        if (!res.isOk()) {
            throw new DnieCardException(// $NON-NLS-1$
            "Error en el establecimiento de las clave de firma con respuesta: " + res.getStatusWord(), // $NON-NLS-1$
            res.getStatusWord());
        }
        final byte[] digestInfo;
        try {
            digestInfo = DigestInfo.encode(algorithm, data, this.cryptoHelper);
        } catch (final IOException e) {
            // $NON-NLS-1$
            throw new DnieCardException("Error en el calculo del hash para firmar: " + e, e);
        }
        apdu = new PsoSignHashApduCommand((byte) 0x00, digestInfo);
        res = getConnection().transmit(apdu);
        if (!res.isOk()) {
            throw new DnieCardException(// $NON-NLS-1$
            "Error durante la operacion de firma con respuesta: " + res.getStatusWord(), // $NON-NLS-1$
            res.getStatusWord());
        }
    } catch (final LostChannelException e) {
        try {
            getConnection().close();
            if (getConnection() instanceof Cwa14890Connection) {
                setConnection(((Cwa14890Connection) getConnection()).getSubConnection());
            }
        } catch (final Exception ex) {
            // $NON-NLS-1$
            throw new DnieCardException("No se pudo recuperar el canal seguro para firmar: " + ex, ex);
        }
        return signOperation(data, algorithm, privateKeyReference);
    } catch (final ApduConnectionException e) {
        // $NON-NLS-1$
        throw new DnieCardException("Error en la transmision de comandos a la tarjeta: " + e, e);
    }
    return res.getData();
}
Also used : LostChannelException(es.gob.jmulticard.apdu.connection.LostChannelException) MseSetComputationApduCommand(es.gob.jmulticard.apdu.iso7816four.MseSetComputationApduCommand) CommandApdu(es.gob.jmulticard.apdu.CommandApdu) PsoSignHashApduCommand(es.gob.jmulticard.apdu.iso7816eight.PsoSignHashApduCommand) Cwa14890Connection(es.gob.jmulticard.apdu.connection.cwa14890.Cwa14890Connection) ResponseApdu(es.gob.jmulticard.apdu.ResponseApdu) IOException(java.io.IOException) ApduConnectionException(es.gob.jmulticard.apdu.connection.ApduConnectionException) CryptoCardException(es.gob.jmulticard.card.CryptoCardException) LostChannelException(es.gob.jmulticard.apdu.connection.LostChannelException) InvalidCardException(es.gob.jmulticard.card.InvalidCardException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) PinException(es.gob.jmulticard.card.PinException) TlvException(es.gob.jmulticard.asn1.TlvException) Iso7816FourCardException(es.gob.jmulticard.card.iso7816four.Iso7816FourCardException) Asn1Exception(es.gob.jmulticard.asn1.Asn1Exception) ApduConnectionException(es.gob.jmulticard.apdu.connection.ApduConnectionException)

Example 25 with ResponseApdu

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

the class Dnie method setKeysToAuthentication.

/**
 * {@inheritDoc}
 */
@Override
public void setKeysToAuthentication(final byte[] refPublicKey, final byte[] refPrivateKey) throws ApduConnectionException {
    final CommandApdu apdu = new MseSetAuthenticationKeyApduCommand((byte) 0x00, refPublicKey, refPrivateKey);
    final ResponseApdu res = getConnection().transmit(apdu);
    if (!res.isOk()) {
        throw new SecureChannelException(// $NON-NLS-1$
        "Error durante el establecimiento de las claves publica y privada " + "para atenticacion (error: " + HexUtils.hexify(res.getBytes(), true) + // $NON-NLS-1$ //$NON-NLS-2$
        ")");
    }
}
Also used : CommandApdu(es.gob.jmulticard.apdu.CommandApdu) MseSetAuthenticationKeyApduCommand(es.gob.jmulticard.apdu.iso7816four.MseSetAuthenticationKeyApduCommand) SecureChannelException(es.gob.jmulticard.apdu.connection.cwa14890.SecureChannelException) ResponseApdu(es.gob.jmulticard.apdu.ResponseApdu)

Aggregations

ResponseApdu (es.gob.jmulticard.apdu.ResponseApdu)32 ApduConnectionException (es.gob.jmulticard.apdu.connection.ApduConnectionException)23 CommandApdu (es.gob.jmulticard.apdu.CommandApdu)20 BadPinException (es.gob.jmulticard.card.BadPinException)13 IOException (java.io.IOException)12 PinException (es.gob.jmulticard.card.PinException)10 Iso7816FourCardException (es.gob.jmulticard.card.iso7816four.Iso7816FourCardException)10 AuthenticationModeLockedException (es.gob.jmulticard.card.AuthenticationModeLockedException)7 CryptoCardException (es.gob.jmulticard.card.CryptoCardException)7 CertificateException (java.security.cert.CertificateException)7 SecureChannelException (es.gob.jmulticard.apdu.connection.cwa14890.SecureChannelException)6 StatusWord (es.gob.jmulticard.apdu.StatusWord)5 LostChannelException (es.gob.jmulticard.apdu.connection.LostChannelException)4 TlvException (es.gob.jmulticard.asn1.TlvException)4 InvalidCardException (es.gob.jmulticard.card.InvalidCardException)4 FileNotFoundException (es.gob.jmulticard.card.iso7816four.FileNotFoundException)4 CardNotPresentException (es.gob.jmulticard.apdu.connection.CardNotPresentException)3 Cwa14890Connection (es.gob.jmulticard.apdu.connection.cwa14890.Cwa14890Connection)3 PsoSignHashApduCommand (es.gob.jmulticard.apdu.iso7816eight.PsoSignHashApduCommand)3 GetResponseApduCommand (es.gob.jmulticard.apdu.iso7816four.GetResponseApduCommand)3