The only way that is reasonably sure is to create an Applet in Java, break out of the sandbox and try to use javax.smartcardio
library. As it is in javax
, it is not certain that it is present, and you might trip some additional access rules.
The Applet should be signed and the user should indicate that the Applet is trusted. Of course, a relatively new Java runtime should be installed on the computer. javax.smartcardio
can by default only use PCSC smart card readers, so you must make sure that one is present. Furthermore, PCSC and javax.smartcardio
do assume ISO 7816 compliant processor cards.
Earlier you could sometimes use a Java applet to install a native library to communicate with the smart card, but with the current operating systems, I would definitely not trust that this is going to work.
Prepare for a lot of work and a lot of testing.
UPDATE 2016-12-24
Applets are on their way out - the plugins that they rely on are deprecated, but not yet removed, in Java 9. Not a direct answer, but using Java Web Start could be a solution to this.
There is a lot of thinking going on with regards to cryptography in a browser, e.g. the Web Crypto API. With regards to direct smart card access it certainly seems to remain thinking rather than acting. At the time of writing access to secure tokens doesn't seem included.
A common but somewhat tricky road to take is to provide smart card plugings to browsers. This however requires browser support (for each separate browser), admin privileges. Many browsers try to migrate away from plugin structures such as these so this kind of solution may not be future proof.
Finally you could use a (signed) native app and refer to it from the browser. The app could be made available in the app. stores of the various operating systems.