Search in sources :

Example 1 with SmartCafePkcs15Applet

use of es.gob.jmulticard.card.gide.smartcafe.SmartCafePkcs15Applet in project jmulticard by ctt-gob-es.

the class SmartCafeKeyStoreImpl method engineLoad.

/**
 * {@inheritDoc}
 */
@Override
public void engineLoad(final KeyStore.LoadStoreParameter param) throws IOException {
    final ApduConnection conn = new es.gob.jmulticard.jse.smartcardio.SmartcardIoConnection();
    this.cryptoCard = new SmartCafePkcs15Applet(conn, new JseCryptoHelper());
    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.setCallbackHandler(((KeyStore.CallbackHandlerProtection) pp).getCallbackHandler());
        } else if (pp instanceof KeyStore.PasswordProtection) {
            final PasswordCallback pwc = new CachePasswordCallback(((PasswordProtection) pp).getPassword());
            this.cryptoCard.setPasswordCallback(pwc);
        } else {
            LOGGER.warning(// $NON-NLS-1$ //$NON-NLS-2$
            "Se ha proporcionado un LoadStoreParameter de tipo no soportado, se ignorara: " + (pp != null ? pp.getClass().getName() : "NULO"));
        }
    }
    this.aliases = Arrays.asList(this.cryptoCard.getAliases());
}
Also used : SmartCafePkcs15Applet(es.gob.jmulticard.card.gide.smartcafe.SmartCafePkcs15Applet) PasswordProtection(java.security.KeyStore.PasswordProtection) KeyStore(java.security.KeyStore) PasswordCallback(javax.security.auth.callback.PasswordCallback) JseCryptoHelper(es.gob.jmulticard.JseCryptoHelper) ApduConnection(es.gob.jmulticard.apdu.connection.ApduConnection) PasswordProtection(java.security.KeyStore.PasswordProtection) ProtectionParameter(java.security.KeyStore.ProtectionParameter)

Example 2 with SmartCafePkcs15Applet

use of es.gob.jmulticard.card.gide.smartcafe.SmartCafePkcs15Applet in project jmulticard by ctt-gob-es.

the class TestAccv method testVerifyPin.

/**
 * Prueba de verificación de PIN.
 * @throws Exception En cualquier error.
 */
@SuppressWarnings("static-method")
@Test
@Ignore
public void testVerifyPin() throws Exception {
    // $NON-NLS-1$
    final char[] pin = "11111111".toCharArray();
    final Iso7816FourCard card = new SmartCafePkcs15Applet(new SmartcardIoConnection(), new JseCryptoHelper());
    card.verifyPin(new CachePasswordCallback(pin));
}
Also used : Iso7816FourCard(es.gob.jmulticard.card.iso7816four.Iso7816FourCard) SmartCafePkcs15Applet(es.gob.jmulticard.card.gide.smartcafe.SmartCafePkcs15Applet) SmartcardIoConnection(es.gob.jmulticard.jse.smartcardio.SmartcardIoConnection) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with SmartCafePkcs15Applet

use of es.gob.jmulticard.card.gide.smartcafe.SmartCafePkcs15Applet in project jmulticard by ctt-gob-es.

the class TestAccv method testSign.

/**
 * Prueba de firma.
 * @throws Exception En cualquier error.
 */
@SuppressWarnings("static-method")
@Test
@Ignore
public void testSign() throws Exception {
    // $NON-NLS-1$
    final char[] pin = "11111111".toCharArray();
    final SmartCafePkcs15Applet card = new SmartCafePkcs15Applet(new SmartcardIoConnection(), new JseCryptoHelper());
    card.setPasswordCallback(new CachePasswordCallback(pin));
    final PrivateKeyReference pkr = card.getPrivateKey(card.getAliases()[0]);
    // $NON-NLS-1$ //$NON-NLS-2$
    final byte[] sign = card.sign("Hola mundo!".getBytes(), "SHA512withRSA", pkr);
    System.out.println(HexUtils.hexify(sign, false));
}
Also used : SmartCafePkcs15Applet(es.gob.jmulticard.card.gide.smartcafe.SmartCafePkcs15Applet) PrivateKeyReference(es.gob.jmulticard.card.PrivateKeyReference) SmartcardIoConnection(es.gob.jmulticard.jse.smartcardio.SmartcardIoConnection) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with SmartCafePkcs15Applet

use of es.gob.jmulticard.card.gide.smartcafe.SmartCafePkcs15Applet in project jmulticard by ctt-gob-es.

the class SmartCafeKeyStoreImpl method engineLoad.

/**
 * {@inheritDoc}
 */
@Override
public void engineLoad(final InputStream stream, final char[] password) throws IOException {
    // Ponemos la conexion por defecto
    final ApduConnection conn = new es.gob.jmulticard.jse.smartcardio.SmartcardIoConnection();
    // Aqui se realiza el acceso e inicializacion de la tarjeta
    this.cryptoCard = new SmartCafePkcs15Applet(conn, new JseCryptoHelper());
    if (password != null) {
        this.cryptoCard.setPasswordCallback(new CachePasswordCallback(password));
    }
    this.aliases = Arrays.asList(this.cryptoCard.getAliases());
}
Also used : SmartCafePkcs15Applet(es.gob.jmulticard.card.gide.smartcafe.SmartCafePkcs15Applet) JseCryptoHelper(es.gob.jmulticard.JseCryptoHelper) ApduConnection(es.gob.jmulticard.apdu.connection.ApduConnection)

Example 5 with SmartCafePkcs15Applet

use of es.gob.jmulticard.card.gide.smartcafe.SmartCafePkcs15Applet in project jmulticard by ctt-gob-es.

the class TestAccv method testReadCertificates.

/**
 * Prueba de lectura de certificados.
 * @throws Exception En cualquier error.
 */
@SuppressWarnings("static-method")
@Test
@Ignore
public void testReadCertificates() throws Exception {
    final CryptoCard card = new SmartCafePkcs15Applet(new SmartcardIoConnection(), new JseCryptoHelper());
    final String[] aliases = card.getAliases();
    if (aliases.length < 1) {
        // $NON-NLS-1$
        System.out.println("La tarjeta no tiene certificados");
        return;
    }
    final String selectedAlias = aliases[0];
    // $NON-NLS-1$
    System.out.println("Alias encontrados:");
    for (final String alias : aliases) {
        // $NON-NLS-1$
        System.out.println("  " + alias);
    }
    System.out.println();
    final X509Certificate c = card.getCertificate(selectedAlias);
    // $NON-NLS-1$
    System.out.println("Primer certificado encontrado: " + AOUtil.getCN(c));
}
Also used : SmartCafePkcs15Applet(es.gob.jmulticard.card.gide.smartcafe.SmartCafePkcs15Applet) CryptoCard(es.gob.jmulticard.card.CryptoCard) SmartcardIoConnection(es.gob.jmulticard.jse.smartcardio.SmartcardIoConnection) X509Certificate(java.security.cert.X509Certificate) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

SmartCafePkcs15Applet (es.gob.jmulticard.card.gide.smartcafe.SmartCafePkcs15Applet)5 SmartcardIoConnection (es.gob.jmulticard.jse.smartcardio.SmartcardIoConnection)3 Ignore (org.junit.Ignore)3 Test (org.junit.Test)3 JseCryptoHelper (es.gob.jmulticard.JseCryptoHelper)2 ApduConnection (es.gob.jmulticard.apdu.connection.ApduConnection)2 CryptoCard (es.gob.jmulticard.card.CryptoCard)1 PrivateKeyReference (es.gob.jmulticard.card.PrivateKeyReference)1 Iso7816FourCard (es.gob.jmulticard.card.iso7816four.Iso7816FourCard)1 KeyStore (java.security.KeyStore)1 PasswordProtection (java.security.KeyStore.PasswordProtection)1 ProtectionParameter (java.security.KeyStore.ProtectionParameter)1 X509Certificate (java.security.cert.X509Certificate)1 PasswordCallback (javax.security.auth.callback.PasswordCallback)1