简体   繁体   中英

Accessing USB Smart Card data from a browser

I am building an enterprise browser based application, which works on a dedicated PC with a touch screen (think of it as a Kiosk, sort of). So, the application itself is built on NodeJS and the user makes choices on the browser and inserts their Smart Card. Since JavaScript can't directly read and decrypt the Smart Card data, a Java program running on this PC detects the inserted Smart Card and reads the data. Now, the problem is to send this Smart Card details (name, address etc..) to the JS code. I'm not really sure how to solve this, the following are a few ideas:

  1. The Java Smart Card reader, after reading the data, outputs it to as a keyboard input. The JS code then listens to this specific keyboard event and reads all the data. Kind of like how a bar-code scanner works.
  2. The Java Smart Card reader and the browser are connected to a cloud and have a WebSocket channel established. The Java program after reading the data, pushes it to the cloud server and the cloud server then pushes it to the Browser via WebSockets.
  3. Run the Java Smart Card reader as a web-server (localhost) with a self-signed SSL certificate. Add a local domain name to the server in the hosts file. Now, the browser can directly talk to the Java web-server through a Http API.
  4. Run the Java Smart Card reader with gRPC (localhost) and connect the browser to it via gRPC-web. (I have no experience in gRPC, but maybe this is possible?)

Each of the above have their own pitfalls. I'm not sure how other Kiosk based systems work, so any suggestions or improvements on the above ideas would be great.

The best solution here would probably be to host a WebSocket using Jetty in your java application at 127.0.0.1 and have your javascript connect to that directly . No cloud server would be needed as WebSockets aren't bound to the same origin policy or cross origin resource sharing.

Another potential solution is to have an embedded browser in your java program using javafx's webkit or other java browser implementation and share data through that. This is less than ideal because javafx's webkit has it's own weird quirks and commercial embedded browsers for java cost thousands.

I would use the websocket solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM