Search in sources :

Example 1 with Ceres

use of es.gob.jmulticard.card.fnmt.ceres.Ceres 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 2 with Ceres

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

use of es.gob.jmulticard.card.fnmt.ceres.Ceres in project jmulticard by ctt-gob-es.

the class CeresKeyStoreImpl method engineLoad.

/**
 * {@inheritDoc}
 */
@Override
public void engineLoad(final InputStream stream, final char[] password) throws IOException {
    // Aqui se realiza el acceso e inicializacion de la tarjeta
    this.cryptoCard = new Ceres(getApduConnection(), new JseCryptoHelper());
    // Precargamos los alias
    loadAliases();
}
Also used : Ceres(es.gob.jmulticard.card.fnmt.ceres.Ceres) JseCryptoHelper(es.gob.jmulticard.JseCryptoHelper)

Example 4 with Ceres

use of es.gob.jmulticard.card.fnmt.ceres.Ceres in project jmulticard by ctt-gob-es.

the class TestCeres method main.

/**
 * Main.
 * @param args No se usa.
 * @throws Exception En cualquier error.
 */
public static void main(final String[] args) throws Exception {
    final Ceres ceres = new Ceres(new SmartcardIoConnection(), new JseCryptoHelper());
    ceres.setPasswordCallback(new CachePasswordCallback(PIN.toCharArray()));
    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)

Aggregations

Ceres (es.gob.jmulticard.card.fnmt.ceres.Ceres)4 JseCryptoHelper (es.gob.jmulticard.JseCryptoHelper)2 PrivateKeyReference (es.gob.jmulticard.card.PrivateKeyReference)2 SmartcardIoConnection (es.gob.jmulticard.jse.smartcardio.SmartcardIoConnection)2 PasswordCallback (javax.security.auth.callback.PasswordCallback)2 KeyStore (java.security.KeyStore)1 PasswordProtection (java.security.KeyStore.PasswordProtection)1 ProtectionParameter (java.security.KeyStore.ProtectionParameter)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1