Search in sources :

Example 6 with PinException

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

the class Ceres method getInternalPasswordCallback.

protected PasswordCallback getInternalPasswordCallback() throws PinException {
    if (this.passwordCallback != null) {
        final int retriesLeft = getPinRetriesLeft();
        if (retriesLeft == 0) {
            throw new AuthenticationModeLockedException();
        }
        return this.passwordCallback;
    }
    if (this.callbackHandler != null) {
        final int retriesLeft = getPinRetriesLeft();
        if (retriesLeft == 0) {
            throw new AuthenticationModeLockedException();
        }
        final PasswordCallback pwc = new PasswordCallback(// $NON-NLS-1$
        CardMessages.getString("Gen.0", Integer.toString(retriesLeft)), false);
        try {
            this.callbackHandler.handle(new Callback[] { pwc });
        } catch (final IOException e) {
            throw new PinException(// $NON-NLS-1$
            "Error obteniendo el PIN del CallbackHandler: " + e, // $NON-NLS-1$
            e);
        } catch (final UnsupportedCallbackException e) {
            throw new PinException(// $NON-NLS-1$
            "El CallbackHandler no soporta pedir el PIN al usuario: " + e, // $NON-NLS-1$
            e);
        }
        return pwc;
    }
    // $NON-NLS-1$
    throw new PinException("No hay ningun metodo para obtener el PIN");
}
Also used : AuthenticationModeLockedException(es.gob.jmulticard.card.AuthenticationModeLockedException) PasswordCallback(javax.security.auth.callback.PasswordCallback) IOException(java.io.IOException) BadPinException(es.gob.jmulticard.card.BadPinException) PinException(es.gob.jmulticard.card.PinException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException)

Example 7 with PinException

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

the class SmartCafePkcs15Applet method getInternalPasswordCallback.

private PasswordCallback getInternalPasswordCallback() throws PinException {
    if (this.passwordCallback != null) {
        final int retriesLeft = getPinRetriesLeft();
        if (retriesLeft == 0) {
            throw new AuthenticationModeLockedException();
        }
        return this.passwordCallback;
    }
    if (this.callbackHandler != null) {
        final int retriesLeft = getPinRetriesLeft();
        if (retriesLeft == 0) {
            throw new AuthenticationModeLockedException();
        }
        final PasswordCallback pwc = new PasswordCallback(// $NON-NLS-1$
        CardMessages.getString("Gen.0", Integer.toString(retriesLeft)), false);
        try {
            this.callbackHandler.handle(new Callback[] { pwc });
        } catch (final IOException e) {
            throw new PinException(// $NON-NLS-1$
            "Error obteniendo el PIN del CallbackHandler: " + e, // $NON-NLS-1$
            e);
        } catch (final UnsupportedCallbackException e) {
            throw new PinException(// $NON-NLS-1$
            "El CallbackHandler no soporta pedir el PIN al usuario: " + e, // $NON-NLS-1$
            e);
        }
        return pwc;
    }
    // $NON-NLS-1$
    throw new PinException("No hay ningun metodo para obtener el PIN");
}
Also used : AuthenticationModeLockedException(es.gob.jmulticard.card.AuthenticationModeLockedException) PasswordCallback(javax.security.auth.callback.PasswordCallback) IOException(java.io.IOException) BadPinException(es.gob.jmulticard.card.BadPinException) PinException(es.gob.jmulticard.card.PinException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException)

Example 8 with PinException

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

the class Dnie method getInternalPasswordCallback.

protected PasswordCallback getInternalPasswordCallback() throws PinException {
    if (this.passwordCallback != null) {
        final int retriesLeft = getPinRetriesLeft();
        if (retriesLeft == 0) {
            throw new AuthenticationModeLockedException();
        }
        return this.passwordCallback;
    }
    if (this.callbackHandler != null) {
        final int retriesLeft = getPinRetriesLeft();
        if (retriesLeft == 0) {
            throw new AuthenticationModeLockedException();
        }
        final PasswordCallback pwc = new PasswordCallback(getPinMessage(retriesLeft), false);
        try {
            this.callbackHandler.handle(new Callback[] { pwc });
        } catch (final IOException e) {
            throw new PinException(// $NON-NLS-1$
            "Error obteniendo el PIN del CallbackHandler: " + e, // $NON-NLS-1$
            e);
        } catch (final UnsupportedCallbackException e) {
            throw new PinException(// $NON-NLS-1$
            "El CallbackHandler no soporta pedir el PIN al usuario: " + e, // $NON-NLS-1$
            e);
        }
        if (pwc.getPassword() == null || pwc.getPassword().toString().isEmpty()) {
            throw new PinException(// $NON-NLS-1$
            "El PIN no puede ser nulo ni vacio");
        }
        return pwc;
    }
    // $NON-NLS-1$
    throw new PinException("No hay ningun metodo para obtener el PIN");
}
Also used : AuthenticationModeLockedException(es.gob.jmulticard.card.AuthenticationModeLockedException) PasswordCallback(javax.security.auth.callback.PasswordCallback) IOException(java.io.IOException) BadPinException(es.gob.jmulticard.card.BadPinException) PinException(es.gob.jmulticard.card.PinException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException)

Example 9 with PinException

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

the class Dnie method signOperation.

/**
 * Realiza la operación de firma.
 * @param data Datos que se desean firmar.
 * @param signAlgorithm Algoritmo de firma (por ejemplo, <code>SHA512withRSA</code>, <code>SHA1withRSA</code>, etc.).
 * @param privateKeyReference Referencia a la clave privada para la firma.
 * @return Firma de los datos.
 * @throws CryptoCardException Cuando se produce un error durante la operaci&oacute;n de firma.
 * @throws PinException Si el PIN proporcionado en la <i>PasswordCallback</i>
 *                      es incorrecto y no estaba habilitado el reintento autom&aacute;tico.
 * @throws es.gob.jmulticard.card.AuthenticationModeLockedException Cuando el DNIe est&aacute; bloqueado.
 */
protected byte[] signOperation(final byte[] data, final String signAlgorithm, 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(signAlgorithm, data, this.cryptoHelper);
        } catch (final IOException e) {
            // $NON-NLS-1$
            throw new DnieCardException("Error en el calculo de la huella 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(), 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, signAlgorithm, 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) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) AuthenticationModeLockedException(es.gob.jmulticard.card.AuthenticationModeLockedException) BadPinException(es.gob.jmulticard.card.BadPinException) PinException(es.gob.jmulticard.card.PinException) Iso7816FourCardException(es.gob.jmulticard.card.iso7816four.Iso7816FourCardException) AccessControlException(java.security.AccessControlException) SecureChannelException(es.gob.jmulticard.apdu.connection.cwa14890.SecureChannelException) CryptoCardException(es.gob.jmulticard.card.CryptoCardException) LostChannelException(es.gob.jmulticard.apdu.connection.LostChannelException) CancelledOperationException(es.gob.jmulticard.CancelledOperationException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) ApduConnectionException(es.gob.jmulticard.apdu.connection.ApduConnectionException)

Example 10 with PinException

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

Aggregations

PinException (es.gob.jmulticard.card.PinException)12 BadPinException (es.gob.jmulticard.card.BadPinException)10 ApduConnectionException (es.gob.jmulticard.apdu.connection.ApduConnectionException)9 CommandApdu (es.gob.jmulticard.apdu.CommandApdu)8 ResponseApdu (es.gob.jmulticard.apdu.ResponseApdu)8 IOException (java.io.IOException)8 AuthenticationModeLockedException (es.gob.jmulticard.card.AuthenticationModeLockedException)7 Iso7816FourCardException (es.gob.jmulticard.card.iso7816four.Iso7816FourCardException)6 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)6 CryptoCardException (es.gob.jmulticard.card.CryptoCardException)5 CertificateException (java.security.cert.CertificateException)4 LostChannelException (es.gob.jmulticard.apdu.connection.LostChannelException)3 Cwa14890Connection (es.gob.jmulticard.apdu.connection.cwa14890.Cwa14890Connection)3 PasswordCallback (javax.security.auth.callback.PasswordCallback)3 CancelledOperationException (es.gob.jmulticard.CancelledOperationException)2 SecureChannelException (es.gob.jmulticard.apdu.connection.cwa14890.SecureChannelException)2 RetriesLeftApduCommand (es.gob.jmulticard.apdu.dnie.RetriesLeftApduCommand)2 PsoSignHashApduCommand (es.gob.jmulticard.apdu.iso7816eight.PsoSignHashApduCommand)2 MseSetComputationApduCommand (es.gob.jmulticard.apdu.iso7816four.MseSetComputationApduCommand)2 Asn1Exception (es.gob.jmulticard.asn1.Asn1Exception)2