Search in sources :

Example 6 with BadPinException

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

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

the class Ceres430KeyStoreImpl 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$
            Ceres430KeyStoreImpl.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 precargada no es la emisora de esta tarjeta: " + 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)

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