use of es.gob.jmulticard.jse.provider.DnieProvider in project jmulticard by ctt-gob-es.
the class TestJseProvider method testGetCertificateChain.
/**
* prueba de obtención de la cadena de certificados.
* @throws Exception En cualquier error.
*/
@SuppressWarnings("static-method")
@Test
@Ignore
public void testGetCertificateChain() throws Exception {
final Provider p = new DnieProvider();
Security.addProvider(p);
// $NON-NLS-1$
final KeyStore ks = KeyStore.getInstance("DNI");
ks.load(null, PASSWORD);
final Enumeration<String> aliases = ks.aliases();
while (aliases.hasMoreElements()) {
final String alias = aliases.nextElement();
for (final Certificate cert : ks.getCertificateChain(alias)) {
System.out.println(// $NON-NLS-1$
"XXX: " + ((X509Certificate) cert).getSubjectX500Principal());
}
}
}
use of es.gob.jmulticard.jse.provider.DnieProvider 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");
}
use of es.gob.jmulticard.jse.provider.DnieProvider in project jmulticard by ctt-gob-es.
the class TestJseProvider method testProviderWithDefaultConnection.
static void testProviderWithDefaultConnection() throws Exception {
final Provider p = new DnieProvider();
Security.addProvider(p);
// $NON-NLS-1$
final KeyStore ks = KeyStore.getInstance("DNI");
ks.load(null, PASSWORD);
final Enumeration<String> aliases = ks.aliases();
String alias = null;
while (aliases.hasMoreElements()) {
alias = aliases.nextElement();
System.out.println(alias);
}
// $NON-NLS-1$
Assert.assertNotNull("La tarjeta debe tener al menos un certificado", alias);
// $NON-NLS-1$
final Signature signature = Signature.getInstance("SHA1withRSA");
signature.initSign((PrivateKey) ks.getKey(alias, PASSWORD));
// $NON-NLS-1$
signature.update("Hola Mundo!!".getBytes());
signature.sign();
// $NON-NLS-1$
System.out.println("Firma generada correctamente");
System.out.println(((X509Certificate) ks.getCertificate(alias)).getIssuerX500Principal().toString());
}
use of es.gob.jmulticard.jse.provider.DnieProvider in project jmulticard by ctt-gob-es.
the class TestDoubleSign method testDoubleSign.
static void testDoubleSign() throws Exception {
final Provider p = new DnieProvider(new SmartcardIoConnection());
Security.addProvider(p);
// $NON-NLS-1$
final KeyStore ks = KeyStore.getInstance("DNI");
ks.load(null, PASSWORD);
final Enumeration<String> aliases = ks.aliases();
while (aliases.hasMoreElements()) {
System.out.println(aliases.nextElement());
}
// $NON-NLS-1$
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("Primera firma generada correctamente");
// $NON-NLS-1$
signature = Signature.getInstance("SHA1withRSA");
// $NON-NLS-1$
signature.initSign((PrivateKey) ks.getKey("CertFirmaDigital", PASSWORD));
// $NON-NLS-1$
signature.update("Hola Mundo 2!!".getBytes());
signature.sign();
// $NON-NLS-1$
System.out.println("Segunda firma generada correctamente");
}
use of es.gob.jmulticard.jse.provider.DnieProvider in project jmulticard by ctt-gob-es.
the class TestKeyStoreBuilder method testKeyStoreBuilderCreation.
/**
* Prueba de construcción de KeyStore mediante <code>KeyStore.Builder</code>.
* @throws Exception En cualquier error.
*/
@SuppressWarnings("static-method")
@Test
@Ignore
public void testKeyStoreBuilderCreation() throws Exception {
final KeyStore.Builder builder = KeyStore.Builder.newInstance(// $NON-NLS-1$
"DNI", new DnieProvider(), new KeyStore.CallbackHandlerProtection(// $NON-NLS-1$ //$NON-NLS-2$
new TestingDnieCallbackHandler("can", "pin")));
final KeyStore ks = builder.getKeyStore();
// $NON-NLS-1$
System.out.println("Numero de certificados: " + ks.size());
System.out.println(ks.getCertificate(ks.aliases().nextElement()));
}
Aggregations