Search in sources :

Example 81 with PasswordCallback

use of javax.security.auth.callback.PasswordCallback in project jmulticard by ctt-gob-es.

the class SmartCafeKeyStoreImpl method engineGetKey.

/**
 * {@inheritDoc}
 */
@Override
public Key engineGetKey(final String alias, final char[] password) {
    if (!engineContainsAlias(alias)) {
        return null;
    }
    if (password != null) {
        // Establecemos el PasswordCallback
        final PasswordCallback pwc = new CachePasswordCallback(password);
        this.cryptoCard.setPasswordCallback(pwc);
    }
    final PrivateKeyReference pkRef = this.cryptoCard.getPrivateKey(alias);
    if (!(pkRef instanceof SmartCafePrivateKeyReference)) {
        throw new ProviderException(// $NON-NLS-1$
        "La clave obtenida de la tarjeta no es del tipo '" + SmartCafePrivateKeyReference.class.getName() + // $NON-NLS-1$
        "', se ha obtenido: " + // $NON-NLS-1$
        (pkRef != null ? pkRef.getClass().getName() : "null"));
    }
    return new SmartCafePrivateKey((SmartCafePrivateKeyReference) pkRef, this.cryptoCard);
}
Also used : PrivateKeyReference(es.gob.jmulticard.card.PrivateKeyReference) SmartCafePrivateKeyReference(es.gob.jmulticard.card.gide.smartcafe.SmartCafePrivateKeyReference) ProviderException(java.security.ProviderException) PasswordCallback(javax.security.auth.callback.PasswordCallback) SmartCafePrivateKeyReference(es.gob.jmulticard.card.gide.smartcafe.SmartCafePrivateKeyReference)

Example 82 with PasswordCallback

use of javax.security.auth.callback.PasswordCallback in project jmulticard by ctt-gob-es.

the class TestCeres method testCeresUIPasswordCallbackSpecialCharsOnPin.

/**
 * Prueba de introducción de PIN por UI, para comprobación de PIN
 * con caracteres especiales.
 * @throws Exception En cualquier error.
 */
@SuppressWarnings("static-method")
@Test
@Ignore
public void testCeresUIPasswordCallbackSpecialCharsOnPin() throws Exception {
    final Ceres ceres = new Ceres(new SmartcardIoConnection(), new JseCryptoHelper());
    ceres.setPasswordCallback(// $NON-NLS-1$
    new PasswordCallback("PIN de la tarjeta CERES", false));
    System.out.println(ceres.getCardName());
    System.out.println(Arrays.asList(ceres.getAliases()));
    System.out.println(ceres.getCertificate(ceres.getAliases()[0]));
    final PrivateKeyReference pkr = ceres.getPrivateKey(ceres.getAliases()[0]);
    System.out.println(HexUtils.hexify(// $NON-NLS-1$//$NON-NLS-2$
    ceres.sign("hola".getBytes(), "SHA1withRSA", pkr), true));
}
Also used : Ceres(es.gob.jmulticard.card.fnmt.ceres.Ceres) PrivateKeyReference(es.gob.jmulticard.card.PrivateKeyReference) SmartcardIoConnection(es.gob.jmulticard.jse.smartcardio.SmartcardIoConnection) PasswordCallback(javax.security.auth.callback.PasswordCallback) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 83 with PasswordCallback

use of javax.security.auth.callback.PasswordCallback in project jmulticard by ctt-gob-es.

the class Ceres430KeyStoreImpl method engineGetKey.

/**
 * {@inheritDoc}
 */
@Override
public Key engineGetKey(final String alias, final char[] password) {
    if (!engineContainsAlias(alias)) {
        return null;
    }
    if (password != null) {
        // Establecemos el PasswordCallback
        final PasswordCallback pwc = new CachePasswordCallback(password);
        this.cryptoCard.setPasswordCallback(pwc);
    }
    final PrivateKeyReference pkRef = this.cryptoCard.getPrivateKey(alias);
    if (!(pkRef instanceof DniePrivateKeyReference)) {
        throw new ProviderException(// $NON-NLS-1$ //$NON-NLS-2$
        "La clave obtenida de la tarjeta no es del tipo esperado, se ha obtenido: " + (pkRef != null ? pkRef.getClass().getName() : "null"));
    }
    return new DniePrivateKey((DniePrivateKeyReference) pkRef);
}
Also used : DniePrivateKeyReference(es.gob.jmulticard.card.dnie.DniePrivateKeyReference) PrivateKeyReference(es.gob.jmulticard.card.PrivateKeyReference) ProviderException(java.security.ProviderException) CommonPasswordCallback(es.gob.jmulticard.ui.passwordcallback.gui.CommonPasswordCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) DniePrivateKeyReference(es.gob.jmulticard.card.dnie.DniePrivateKeyReference)

Example 84 with PasswordCallback

use of javax.security.auth.callback.PasswordCallback in project jmulticard by ctt-gob-es.

the class CeresKeyStoreImpl method engineLoad.

/**
 * {@inheritDoc}
 */
@Override
public void engineLoad(final KeyStore.LoadStoreParameter param) throws IOException {
    if (param != null) {
        final ProtectionParameter pp = param.getProtectionParameter();
        if (pp instanceof KeyStore.CallbackHandlerProtection) {
            if (((KeyStore.CallbackHandlerProtection) pp).getCallbackHandler() == null) {
                // $NON-NLS-1$
                throw new IllegalArgumentException("El CallbackHandler no puede ser nulo");
            }
            this.cryptoCard = new Ceres(CeresProvider.getDefaultApduConnection(), new JseCryptoHelper());
            this.cryptoCard.setCallbackHandler(((KeyStore.CallbackHandlerProtection) pp).getCallbackHandler());
        } else if (pp instanceof KeyStore.PasswordProtection) {
            final PasswordCallback pwc = new CeresPasswordCallback((PasswordProtection) pp);
            this.cryptoCard = new Ceres(CeresProvider.getDefaultApduConnection(), new JseCryptoHelper());
            this.cryptoCard.setPasswordCallback(pwc);
        } else {
            // $NON-NLS-1$
            Logger.getLogger("es.gob.jmulticard").warning(// $NON-NLS-1$ //$NON-NLS-2$
            "Se ha proporcionado un LoadStoreParameter de tipo no soportado, se ignorara: " + (pp != null ? pp.getClass().getName() : "NULO"));
        }
    } else {
        this.cryptoCard = new Ceres(CeresProvider.getDefaultApduConnection(), new JseCryptoHelper());
    }
    userCertAliases = Arrays.asList(this.cryptoCard.getAliases());
}
Also used : Ceres(es.gob.jmulticard.card.fnmt.ceres.Ceres) PasswordProtection(java.security.KeyStore.PasswordProtection) PasswordCallback(javax.security.auth.callback.PasswordCallback) JseCryptoHelper(es.gob.jmulticard.JseCryptoHelper) KeyStore(java.security.KeyStore) PasswordProtection(java.security.KeyStore.PasswordProtection) ProtectionParameter(java.security.KeyStore.ProtectionParameter)

Example 85 with PasswordCallback

use of javax.security.auth.callback.PasswordCallback in project jmulticard by ctt-gob-es.

the class DnieKeyStoreImpl method engineGetKey.

/**
 * {@inheritDoc}
 */
@Override
public Key engineGetKey(final String alias, final char[] password) {
    if (!engineContainsAlias(alias)) {
        return null;
    }
    if (password != null) {
        // Establecemos el PasswordCallback
        final PasswordCallback pwc = new CachePasswordCallback(password);
        this.cryptoCard.setPasswordCallback(pwc);
    }
    final PrivateKeyReference pkRef = this.cryptoCard.getPrivateKey(alias);
    if (!(pkRef instanceof DniePrivateKeyReference)) {
        throw new ProviderException(// $NON-NLS-1$ //$NON-NLS-2$
        "La clave obtenida de la tarjeta no es del tipo esperado, se ha obtenido: " + (pkRef != null ? pkRef.getClass().getName() : "null"));
    }
    return new DniePrivateKey((DniePrivateKeyReference) pkRef);
}
Also used : DniePrivateKeyReference(es.gob.jmulticard.card.dnie.DniePrivateKeyReference) PrivateKeyReference(es.gob.jmulticard.card.PrivateKeyReference) ProviderException(java.security.ProviderException) PasswordCallback(javax.security.auth.callback.PasswordCallback) DniePrivateKeyReference(es.gob.jmulticard.card.dnie.DniePrivateKeyReference)

Aggregations

PasswordCallback (javax.security.auth.callback.PasswordCallback)316 NameCallback (javax.security.auth.callback.NameCallback)255 Callback (javax.security.auth.callback.Callback)207 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)167 IOException (java.io.IOException)102 LoginException (javax.security.auth.login.LoginException)72 CallbackHandler (javax.security.auth.callback.CallbackHandler)66 LoginContext (javax.security.auth.login.LoginContext)39 FailedLoginException (javax.security.auth.login.FailedLoginException)35 RealmCallback (javax.security.sasl.RealmCallback)35 Subject (javax.security.auth.Subject)31 Test (org.junit.Test)28 ConfirmationCallback (javax.security.auth.callback.ConfirmationCallback)26 AuthorizeCallback (javax.security.sasl.AuthorizeCallback)26 ChoiceCallback (javax.security.auth.callback.ChoiceCallback)24 Principal (java.security.Principal)21 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)18 TextOutputCallback (javax.security.auth.callback.TextOutputCallback)18 HashMap (java.util.HashMap)16 Test (org.testng.annotations.Test)15