Using Java PKCS#11 to read DoD Common Access Card -


i have researched on how use sun pkcs#11 api access dod cac , possibly use cac access (read-only) active directory. problem has been, have found in cases make reference code, never shows referenced code. have found following code, gives error. know of code examples or clear documentation using pkcs11 cacs? or api solution might work?

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 {     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 = c.readpassword("enter pin: ");             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 " + alias);             for(int = 0; < cchain.length; i++) {                 system.out.println(" -subjectdn: " + cchain[i].getsubjectdn());                 system.out.println(" -issuerdn: " + cchain[i].getissuerdn());             }         }     } }  java.security.providerexception: initialization failed         @ sun.security.pkcs11.sunpkcs11.<init>(sunpkcs11.java:374)         @ sun.security.pkcs11.sunpkcs11.<init>(sunpkcs11.java:103)         @ smartcard.smartcard.main(smartcard.java:21) caused by: java.io.ioexception: specified procedure not found.          @ sun.security.pkcs11.wrapper.pkcs11.connect(native method)         @ sun.security.pkcs11.wrapper.pkcs11.<init>(pkcs11.java:137)         @ sun.security.pkcs11.wrapper.pkcs11.getinstance(pkcs11.java:150)         @ sun.security.pkcs11.sunpkcs11.<init>(sunpkcs11.java:312)         ... 2 more 

in following code, configname supposed file path configuration file. not exist, or java unable read it, ioexception being thrown. figure out file supposed , create it, or otherwise ensure java has access file, , code run.

string configname = "pkcs11.properties"; provider p = new sun.security.pkcs11.sunpkcs11(configname); 

reading manual may help: http://docs.oracle.com/javase/8/docs/technotes/guides/security/p11guide.html#config


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

keyboard - C++ GetAsyncKeyState alternative -

android - java.net.UnknownHostException(Unable to resolve host “URL”: No address associated with hostname) -