Search in sources :

Example 1 with BadPinException

use of es.gob.jmulticard.card.BadPinException in project jmulticard by ctt-gob-es.

the class DnieKeyStoreImpl method engineGetCertificateChain.

/**
 * {@inheritDoc}
 */
@Override
public Certificate[] engineGetCertificateChain(final String alias) {
    if (!engineContainsAlias(alias)) {
        return null;
    }
    final List<X509Certificate> certs = new ArrayList<>();
    certs.add((X509Certificate) engineGetCertificate(alias));
    // La cadena disponible del certificado la componen el propio certificado y el
    // certificado de la CA intermedia. Si no se puede recuperar esta ultima, se obvia
    X509Certificate intermediateCaCert;
    try {
        intermediateCaCert = this.cryptoCard.getCertificate(INTERMEDIATE_CA_CERT_ALIAS);
    } catch (final AuthenticationModeLockedException e) {
        throw e;
    } catch (final BadPinException e) {
        throw new BadPasswordProviderException(e);
    } catch (final Exception e) {
        LOGGER.warning(// $NON-NLS-1$
        "No se ha podido cargar el certificado de la CA intermedia: " + e);
        intermediateCaCert = null;
    }
    X509Certificate sha2DnieRoot = null;
    if (intermediateCaCert != null) {
        certs.add(intermediateCaCert);
        // en el proyecto
        try {
            sha2DnieRoot = (X509Certificate) // $NON-NLS-1$
            CertificateFactory.getInstance("X.509").generateCertificate(// $NON-NLS-1$
            DnieKeyStoreImpl.class.getResourceAsStream("/ACRAIZ-SHA2.crt"));
        } catch (final Exception e) {
            sha2DnieRoot = null;
            LOGGER.warning(// $NON-NLS-1$
            "No se ha podido cargar el certificado de la CA raiz: " + e);
        }
        // Comprobamos que efectivamente sea su raiz
        if (sha2DnieRoot != null) {
            try {
                intermediateCaCert.verify(sha2DnieRoot.getPublicKey());
            } catch (final Exception e) {
                sha2DnieRoot = null;
                LOGGER.info(// $NON-NLS-1$
                "La CA raiz de DNIe precargada no es la emisora de este DNIe: " + e);
            }
        }
    }
    if (sha2DnieRoot != null) {
        certs.add(sha2DnieRoot);
    }
    return certs.toArray(new X509Certificate[0]);
}
Also used : AuthenticationModeLockedException(es.gob.jmulticard.card.AuthenticationModeLockedException) BadPinException(es.gob.jmulticard.card.BadPinException) ArrayList(java.util.ArrayList) X509Certificate(java.security.cert.X509Certificate) AuthenticationModeLockedException(es.gob.jmulticard.card.AuthenticationModeLockedException) CryptoCardException(es.gob.jmulticard.card.CryptoCardException) BadPinException(es.gob.jmulticard.card.BadPinException) ProviderException(java.security.ProviderException) IOException(java.io.IOException) PinException(es.gob.jmulticard.card.PinException)

Example 2 with BadPinException

use of es.gob.jmulticard.card.BadPinException 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 3 with BadPinException

use of es.gob.jmulticard.card.BadPinException in project jmulticard by ctt-gob-es.

the class SmartCafePkcs15Applet 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(psc);
    final ResponseApdu verifyResponse = getConnection().transmit(verifyCommandApdu);
    verifyCommandApdu = null;
    if (!verifyResponse.isOk()) {
        if (verifyResponse.getStatusWord().getMsb() == ERROR_PIN_SW1) {
            throw new BadPinException(verifyResponse.getStatusWord().getLsb() - (byte) 0xC0);
        } else if (verifyResponse.getStatusWord().getMsb() == (byte) 0x69 && verifyResponse.getStatusWord().getLsb() == (byte) 0x83) {
            throw new AuthenticationModeLockedException();
        } 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.gide.VerifyApduCommand) ApduConnectionException(es.gob.jmulticard.apdu.connection.ApduConnectionException)

Example 4 with BadPinException

use of es.gob.jmulticard.card.BadPinException in project jmulticard by ctt-gob-es.

the class TuiR5 method verifyPin.

@Override
public void verifyPin(final PasswordCallback pinPc) throws ApduConnectionException, BadPinException {
    final VerifyApduCommand verifyPinApduCommand = new VerifyApduCommand(CLA, this.passwordCallback);
    final ResponseApdu verifyResponse = getConnection().transmit(verifyPinApduCommand);
    if (!verifyResponse.isOk()) {
        throw new BadPinException(verifyResponse.getStatusWord().getLsb() - (byte) 0xC0);
    }
}
Also used : BadPinException(es.gob.jmulticard.card.BadPinException) ResponseApdu(es.gob.jmulticard.apdu.ResponseApdu) VerifyApduCommand(es.gob.jmulticard.apdu.gemalto.VerifyApduCommand)

Example 5 with BadPinException

use of es.gob.jmulticard.card.BadPinException 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)

Aggregations

BadPinException (es.gob.jmulticard.card.BadPinException)7 ResponseApdu (es.gob.jmulticard.apdu.ResponseApdu)5 AuthenticationModeLockedException (es.gob.jmulticard.card.AuthenticationModeLockedException)5 ApduConnectionException (es.gob.jmulticard.apdu.connection.ApduConnectionException)4 PinException (es.gob.jmulticard.card.PinException)3 Iso7816FourCardException (es.gob.jmulticard.card.iso7816four.Iso7816FourCardException)3 CommandApdu (es.gob.jmulticard.apdu.CommandApdu)2 CryptoCardException (es.gob.jmulticard.card.CryptoCardException)2 IOException (java.io.IOException)2 ProviderException (java.security.ProviderException)2 X509Certificate (java.security.cert.X509Certificate)2 ArrayList (java.util.ArrayList)2 StatusWord (es.gob.jmulticard.apdu.StatusWord)1 VerifyApduCommand (es.gob.jmulticard.apdu.bit4id.stcm.VerifyApduCommand)1 CeresVerifyApduCommand (es.gob.jmulticard.apdu.ceres.CeresVerifyApduCommand)1 VerifyApduCommand (es.gob.jmulticard.apdu.dnie.VerifyApduCommand)1 VerifyApduCommand (es.gob.jmulticard.apdu.gemalto.VerifyApduCommand)1 VerifyApduCommand (es.gob.jmulticard.apdu.gide.VerifyApduCommand)1