Search code examples
javascriptmozillapkcs#11

OpenSession with WebExtension (pkcs11)


I am trying to do Web-extension to Mozilla, which will use pkcs11 to sign, encrypt or verify document, mail.

I am using this api to comunicate with my eid cards and get slots from them. https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/pkcs11

Is it somehow possible to OpenSession with this slots in WebExtension plugin? Because this pkcs11 seems like have not supported it yet. I would like to call some function like C_OpenSession and then C_Login.

Thanks for help


Solution

  • The only purpose of PKCS#11 javascript API in Mozilla nowadays is to register and unregister PKCS#11 libraries available to Firefox. It's even stated in the documentation:

    The pkcs11 API enables an extension to enumerate PKCS #11 security modules, and to make them accessible to the browser as sources of keys and certificates.

    Firefox uses registered PKCS#11 libraries to access client SSL certificates. AFAIK there is no public javascript API that would allow you to call other PKCS#11 functions (such as C_OpenSession or C_Login) provided by these modules.

    There used to be window.crypto.signText API available for easy signature creation but Mozilla killed it in Firefox 33. They didn't see it as a big deal because PKCS#11 signing could be implemented with extension and they provided signTextJS extension as a proof. Sadly Mozilla killed it in Firefox 57 when they migrated to WebExtensions and removed support for XPCOM-based add-ons.

    If you want to use PKCS#11 API from Firefox nowadays then you need to use/create extension which will spawn local process and communicate with it via native messaging or you'll need to use/create application which will spawn local web server and communicate with it via web requests or web sockets.