Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

aladdin etoken exception on windows 7

862704May 18 2011 — edited Jun 9 2011
I have an applet that I use for signing. I also use aladdin etoken smartcard or usb. It works perfectly on windows 2000, xp but in windows 7 i get the following exception:

The code where i load the etoken dll is the following:


PKCS11Provider = new sun.security.pkcs11.SunPKCS11(new ByteArrayInputStream(generatePKCS11ConfigFile().getBytes()));	
String eIDProviderName = PKCS11Provider.getName();
Security.addProvider(PKCS11Provider);
				
// load eID card (keystore)
//you don't need yet to provide a password (You might use only the public key from it)
//If you try to use the private key, a window asking for the pin will popup
char[] pin = "".toCharArray();
                
KeyStore.ProtectionParameter pp = new KeyStore.PasswordProtection(pin);
               
CallbackHandler cmdLineHdlr = new com.sun.security.auth.callback.DialogCallbackHandler();
KeyStore.Builder builder = KeyStore.Builder.newInstance(
    									    "PKCS11",
    									    PKCS11Provider,
    									    new KeyStore.CallbackHandlerProtection(cmdLineHdlr));
            
keyStore = builder.getKeyStore();        *///in this line the exception is thrown*
keyStore.load(null, pin);


protected String generatePKCS11ConfigFile(){
		System.out.println("in generatePKCS11ConfigFile");
		
		String os = System.getProperty("os.name");
		System.out.println("os: "+os);
		
		if(os.contains("Windows")) {
			if(os.contains("Windows 9"))
				configDir = System.getenv("WinDir");
			else
				configDir = System.getenv("SystemRoot");
		}
		
		
		String content = "name=eToken"+"\n"+"library="+configDir+"\\system32\\eTPKCS11.dll";
		System.out.println("content: "+content);
		
		return content;
}
stacktrace
config dir: C:\Windows
content: name=eToken
library=C:\Windows\system32\eTPKCS11.dll
getting the builder instance: java.security.KeyStore$Builder$2@5dfaf1
java.security.KeyStoreException: KeyStore instantiation failed
at java.security.KeyStore$Builder$2.getKeyStore(Unknown Source)
at EtenderingSigner.loadKeyStoreFromSmartCard(EtenderingSigner.java:168)
at EtenderingSigner$LoadeIDButtonListener.actionPerformed(EtenderingSigner.java:872)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.security.KeyStoreException: PKCS11 not found
at java.security.KeyStore.getInstance(Unknown Source)
at java.security.KeyStore$Builder$2$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
... 39 more
Caused by: java.security.NoSuchAlgorithmException: no such algorithm: PKCS11 for provider SunPKCS11-eToken
at sun.security.jca.GetInstance.getService(Unknown Source)
at sun.security.jca.GetInstance.getInstance(Unknown Source)
at java.security.Security.getImpl(Unknown Source)
... 42 more
java.lang.NullPointerException
at EtenderingSigner.getPrivateKeyAndCertChain(EtenderingSigner.java:199)
at EtenderingSigner.showEIDCertificateDetails(EtenderingSigner.java:423)
at EtenderingSigner$LoadeIDButtonListener.actionPerformed(EtenderingSigner.java:873)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Edited by: sabre150 on 18-May-2011 03:59

Added code tags to aid readability of source code.
This post has been answered by Termas on Jun 9 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 7 2011
Added on May 18 2011
14 comments
4,386 views