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());
}
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));
}
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));
}
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());
}
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));
}
Aggregations