Created
May 7, 2014 10:34
-
-
Save tatac1/74dc81b51bb0e01c50b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.*; | |
import java.security.cert.CertificateException; | |
import java.security.KeyStoreException; | |
import java.security.cert.X509Certificate; | |
import java.security.KeyStore; | |
import java.security.Provider; | |
import java.security.Security; | |
public class SmartCard { | |
/** | |
* @param args | |
*/ | |
public static void main(String[] args) throws Exception { | |
try { | |
String configName = "pkcs11.properties"; | |
Provider p = new sun.security.pkcs11.SunPKCS11(configName); | |
Security.addProvider(p); | |
Console c = System.console(); | |
char[] pin = new String("your_pin_code").toCharArray(); | |
KeyStore cac = null; | |
cac = KeyStore.getInstance("PKCS11"); | |
cac.load(null, pin); | |
showInfoAboutCAC(cac); | |
} | |
catch(Exception ex) { | |
ex.printStackTrace(); | |
System.exit(0); | |
} | |
} | |
public static void showInfoAboutCAC(KeyStore ks) throws KeyStoreException, CertificateException { | |
Enumeration<String> aliases = ks.aliases(); | |
while(aliases.hasMoreElements()) { | |
String alias = aliases.nextElement(); | |
X509Certificate[] cchain = (X509Certificate[]) ks.getCertificateChain(alias); | |
System.out.println("Certificate Chain for " + alias); | |
for(int i = 0; i < cchain.length; i++) { | |
System.out.println(" -getSubjectDN: " + cchain[i].getSubjectDN()); | |
System.out.println(" -getIssuerDN: " + cchain[i].getIssuerDN()); | |
System.out.println(" -getNotAfter: " + cchain[i].getNotAfter()); | |
System.out.println(" -getNotBefore: " + cchain[i].getNotBefore()); | |
System.out.println(" -getSerialNumber: " + cchain[i].getSerialNumber()); | |
System.out.println(" -getSigAlgName: " + cchain[i].getSigAlgName()); | |
System.out.println(" -getSigAlgOID: " + cchain[i].getSigAlgOID()); | |
System.out.println(" -getVersion: " + cchain[i].getVersion()); | |
} | |
} | |
} | |
} |
console
$ keytool -providerClass sun.security.pkcs11.SunPKCS11 -providerArg /tmp/pkcs11.properties -keystore NONE -storetype PKCS11 -list
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
pkcs11.properties ~ this is for gemalto token on Mac
name = OpenSC
description = SunPKCS11 w/ OpenSC Smart card Framework
library = /usr/lib/pkcs11/libgtop11dotnet.dylib
slot = -1