use of es.gob.jmulticard.card.AuthenticationModeLockedException 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");
}
use of es.gob.jmulticard.card.AuthenticationModeLockedException 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");
}
use of es.gob.jmulticard.card.AuthenticationModeLockedException 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()));
}
}
}
use of es.gob.jmulticard.card.AuthenticationModeLockedException 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]);
}
Aggregations