Search in sources :

Example 1 with SmartcardIoConnection

use of es.gob.jmulticard.jse.smartcardio.SmartcardIoConnection 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 2 with SmartcardIoConnection

use of es.gob.jmulticard.jse.smartcardio.SmartcardIoConnection 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 3 with SmartcardIoConnection

use of es.gob.jmulticard.jse.smartcardio.SmartcardIoConnection 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 SmartcardIoConnection

use of es.gob.jmulticard.jse.smartcardio.SmartcardIoConnection in project jmulticard by ctt-gob-es.

the class TestDnieChangePIN method testChangePIN.

/**
 * Test para probar el cambio de PIN tras la apertura del canal seguro.
 * @throws Exception En cualquier error.
 */
@SuppressWarnings("static-method")
@Test
@Ignore
public void testChangePIN() throws Exception {
    // $NON-NLS-1$
    final CachePasswordCallback cpc = new CachePasswordCallback("password".toCharArray());
    final ApduConnection ac = new SmartcardIoConnection();
    final Dnie dni = DnieFactory.getDnie(ac, cpc, new JseCryptoHelper(), null);
    // $NON-NLS-1$ //$NON-NLS-2$
    dni.changePIN("password", "pinNuevo");
}
Also used : Dnie(es.gob.jmulticard.card.dnie.Dnie) SmartcardIoConnection(es.gob.jmulticard.jse.smartcardio.SmartcardIoConnection) ApduConnection(es.gob.jmulticard.apdu.connection.ApduConnection) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with SmartcardIoConnection

use of es.gob.jmulticard.jse.smartcardio.SmartcardIoConnection in project jmulticard by ctt-gob-es.

the class TestJseProvider method testProviderWithCustomConnection.

static void testProviderWithCustomConnection() throws Exception {
    final Provider p = new DnieProvider(new SmartcardIoConnection());
    Security.addProvider(p);
    // $NON-NLS-1$
    final KeyStore ks = KeyStore.getInstance("DNI");
    final CallbackHandler callbackHandler;
    // $NON-NLS-1$
    callbackHandler = (CallbackHandler) Class.forName("es.gob.jmulticard.ui.passwordcallback.gui.DnieCallbackHandler").getConstructor().newInstance();
    final LoadStoreParameter lsp = new LoadStoreParameter() {

        @Override
        public ProtectionParameter getProtectionParameter() {
            return new KeyStore.CallbackHandlerProtection(callbackHandler);
        }
    };
    ks.load(lsp);
    final Enumeration<String> aliases = ks.aliases();
    while (aliases.hasMoreElements()) {
        System.out.println(aliases.nextElement());
    }
    // $NON-NLS-1$
    final Signature signature = Signature.getInstance("SHA1withRSA");
    // $NON-NLS-1$
    signature.initSign((PrivateKey) ks.getKey("CertFirmaDigital", PASSWORD));
    // $NON-NLS-1$
    signature.update("Hola Mundo!!".getBytes());
    signature.sign();
    // $NON-NLS-1$
    System.out.println("Firma generada correctamente");
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) DnieProvider(es.gob.jmulticard.jse.provider.DnieProvider) Signature(java.security.Signature) SmartcardIoConnection(es.gob.jmulticard.jse.smartcardio.SmartcardIoConnection) KeyStore(java.security.KeyStore) Provider(java.security.Provider) DnieProvider(es.gob.jmulticard.jse.provider.DnieProvider) LoadStoreParameter(java.security.KeyStore.LoadStoreParameter)

Aggregations

SmartcardIoConnection (es.gob.jmulticard.jse.smartcardio.SmartcardIoConnection)14 Ignore (org.junit.Ignore)5 Test (org.junit.Test)5 ApduConnection (es.gob.jmulticard.apdu.connection.ApduConnection)4 PrivateKeyReference (es.gob.jmulticard.card.PrivateKeyReference)3 SmartCafePkcs15Applet (es.gob.jmulticard.card.gide.smartcafe.SmartCafePkcs15Applet)3 KeyStore (java.security.KeyStore)3 Provider (java.security.Provider)3 Signature (java.security.Signature)3 Dnie (es.gob.jmulticard.card.dnie.Dnie)2 Ceres (es.gob.jmulticard.card.fnmt.ceres.Ceres)2 DnieProvider (es.gob.jmulticard.jse.provider.DnieProvider)2 ApduConnectionException (es.gob.jmulticard.apdu.connection.ApduConnectionException)1 CryptoCard (es.gob.jmulticard.card.CryptoCard)1 StCard (es.gob.jmulticard.card.bit4id.stcm.StCard)1 CardOS (es.gob.jmulticard.card.cardos.CardOS)1 TuiR5 (es.gob.jmulticard.card.gemalto.tuir5.TuiR5)1 Iso7816FourCard (es.gob.jmulticard.card.iso7816four.Iso7816FourCard)1 CeresProvider (es.gob.jmulticard.jse.provider.ceres.CeresProvider)1 LoadStoreParameter (java.security.KeyStore.LoadStoreParameter)1