2

I have got ePass2003 Auto token loaded with self signed certificate. I got lib**.so file to load into firefox and now firefox can list the certificate in token. My requirement is to access the keystore for signing, encryption and decryption i.e public and private key for cryptographic operation on them. May i request guidance on javascript API for doing above cryptographic operation.

Mitz
  • 23
  • 1
  • 1
  • 6

1 Answers1

5

Disclosure: I work for CISPL

To access ePass2003 or any Smartcard or Cryptographic USB Token, you need to use Browser Extension. As far as I know, browsers may use the keys from crypto device for TLS handshake. My company provides such extension Signer.Digital Browser Extension. Chrome and Firefox

Windows Host may be downloaded from https://signer.digital/downloads/Signer.Digital.Browser.Extension.Setup.msi

On windows, we don't need PKCS#11 but we use Windows CSP. Thus, USB token driver must be installed on Windows client device for this to work from web browser. lib**.so file is not for Windows but it's for Linux.

Linux host uses this .so file and PKCS#11 to accomplish the task but this is transparent to ePass2003 users and Host application takes care of this.

My requirement is to access the keystore for signing, encryption and decryption i.e public and private key for cryptographic operation on them. May i request guidance on javascript API for doing above cryptographic operation.

I am listing the javascript API (Signer.Digital Version 1.8.0) provides below promises:

  1. Select Certificate: This will open popup window to select certificate. certThumbPrint paramater may be provided to select certificate silently.

SignerDigital.getSelectedCertificate(certThumbPrint = "", showExpired = false, keyUsageFilter = 128)

keyUsageFilter values would be as per System.Security.Cryptography.X509Certificates.X509KeyUsageFlags Enum and multiple values may be added (summed).

  1. Sign Hash:

SignerDigital.signHash(hash, certAlgorithm, certThumbPrint = "")

  1. Sign Authtoken / Data: calculate hash of data and then sign hash.

SignerDigital.signAuthToken(authtoken, certAlgorithm, certThumbPrint = "", showExpired = false)

certAlgorithm is hasing algorithm to be used. ex: "SHA256" or "SHA-256"

showExpired flag may be used here to allow user just login with expired certificate and provide only access to area where user can upload his new certificate.

  1. Sign PDF: - Returns PKCS7 signature container

SignerDigital.signPdfHash(hash, certThumbPrint, certAlgorithm)

SignerDigital.signHashCAdESBr(hash, certThumbPrint, certAlgorithm) //for ICP-Brazil

Working of PDF Signing and Digital Signature based Authentication may be tested at https://web.signer.digital/

  1. Sign XML:

SignerDigital.signXML(xmlDoc, xmlSignParms, certThumbPrint)

xmlSignParms has wider range of parameters and we provide support for integration on efforts basis.

  1. RSA Encrypt: (Using private key of user)

SignerDigital.encryptB64Data(b64Data, useOAEPPadding, certThumbPrint = "", showExpired = false, keyUsageFilter = 32)

Example:

var strToEnc = "Clear Text String to Encrypt.";
var strB64Data = btoa(strToEnc);
console.log("Base64 String of Clear Text String: " + strB64Data);

//Do not provide last parm - certThumbPrint to open dialog to select certificate.
SignerDigital.encryptB64Data(strB64Data, false, "224D7F695ABF0E22EA8D314497F5B56AEFA96FFE") //false for PKCS1 padding, true for OAEP padding
  .then(
    function(EncryptedB64String) { //Success returns xmlSign
      console.log("Encrypted Base64 String: " + EncryptedB64String);
      console.log("Encrypted String: " + atob(EncryptedB64String));
    },
    function(ErrMsg) {
      console.log(ErrMsg);
    }
  )
  1. RSA Decrypt: (Using private key of user)

SignerDigital.decryptB64Data(b64Data, useOAEPPadding, certThumbPrint = "", showExpired = false, keyUsageFilter = 32)

Example:

console.log("Encrypted B64 string from server: " + EncB64String);
SignerDigital.decryptB64Data(EncB64String, false, "224D7F695ABF0E22EA8D314497F5B56AEFA96FFE")
  .then(
    function(DecryptedB64String) { //Success returns xmlSign
      console.log("Decrypted Base64 String: " + DecryptedB64String);
      console.log("Decrypted String: " + atob(DecryptedB64String));
    },
    function(ErrMsg) {
      console.log(ErrMsg);
    }
  )
},
error: function(msg) {
  console.debug(msg);
}
  1. Sign IT/eTDS Return: (Sign Indian Income Tax/eTDS Return - Same as signHash method, except additional optional param: PAN)

SignerDigital.signITHash(hash, PAN, certThumbPrint = "")

Pass PAN blank to open Select Certificate Dialog. If PAN is nonempty, and certificate for PAN is present, will silently select certerficate.

  1. Sign CMS: (Digitally Sign India GST Return)

SignerDigital.signHashCms(hash, certAlgorithm, certIncludeOptions = 2, certThumbPrint = "")

Use method SignerDigital.signHashCAdESBr for ICP-Brazil signature and method SignerDigital.signHashCAdESEg for Egypt ITIDA CAdES-BES signatures.

  1. Sign IceGate Data: (Sign IceGate - Indian Customs Data - Json, text, XML)

SignerDigital.signIceGate(b64Data, certThumbPrint = "")

July 2021 Below APIs added for use by Certifying Authorities (CA needs to be enrolled with Signer.Digital Browser Extension)

  1. Detect connected smartcard: (Autodetect connected Smartcard or USB Token)

SignerDigital.getPCSCReaders(onlyConnected = true) //List PCSC Readers, set parameter to false if you want to list all available readers

  1. Generate CSR: (for Certificate Enrollment in Smartcard or USB Token)

SignerDigital.genCSR(PKCS11Lib, certSubject, certIssuer, keyBits = 2048, hasgAlgorithm = "SHA256", forceUserPinChangeIfDefault = false)

  1. Import / Download Certificate (Import User Certificate and Trust Certificate Chain to Smartcard or USB Token)

SignerDigital.importCer(PKCS11Lib, b64Payload, certIssuer)

For more details, code examples of Auto SmartCard detection, genCSR and importCer refer Answer with flow diagram

Update June 2021

Signer.Digital Browser Extension Host Version 1.7.0 now offers better user control to enhance security by asking user about Allowed Origin (website) which is trying to access certificates/keys. Also this version has Auto Update feature so that user automatically gets any security updates/enhancements after approving update by User Account Control dialog.

Signer.Digital Browser Extension Allowed Origins Dialog

Bharat Vasant
  • 850
  • 3
  • 12
  • 46
  • Thank you for answering the question in most lucid and complete manner. I am now able to encrypt text using the public key from token based on script given above. My project had got stall due to above issue and thanks to you, it has now got wheels. I have tested above script, if anybody wants it in small implementation, ping me. Thanks again. – Mitz Jul 30 '20 at 16:17
  • Hi @BharatVasant can you provide this for .net core also? – صفي Nov 06 '20 at 13:40
  • Yes. We have .NET Core library as well as Ready Application. – Bharat Vasant Nov 06 '20 at 13:51
  • Is there some strong restriction to what sites can use this? Without that, this extension is a *COLOSSAL* security vulnerability to install: it gives totally untrustworthy code (arbitrary javascript) the ability to use my personal private keys! All the attacker needs is the fingerprint of a private key's cert (which is easy to get, because certs are *public*), and a watering hole attack. There are extremely good reasons the default JS API doesn't allow access to these keys!! – CBHacking May 21 '21 at 11:19
  • Like, your web page even says it - "[as of now, WebCrypto API does not provide access to (Windows) or any other Key stores or local crypto USB/Smartcard device](https://signer.digital/SignerDigitalBrowserExtensions)" - did you take into consideration the reasons for this omission? Are there sufficiently strong protections against misuse of this functionality? Because if not, ***THE PRIVATE KEYS OF EVERYBODY WHO INSTALLS SUCH AN EXTENSION MUST BE CONSIDERED COMPROMISED!*** – CBHacking May 21 '21 at 11:21
  • @CBHacking I appreciate your concern. This is solution for accessing keys form USB device where password needs to be entered for using keys. In India and many countries, CAs are not issuing certificates in files but only on crypto device. For Users, there is feature in Chrome (and Edge) which allows users to restrict use of Extension for specific sites: (I would update my answer also with this) https://support.google.com/chrome_webstore/answer/2664769?hl=en Hope other browsers also have it or will provide it in future. – Bharat Vasant May 22 '21 at 00:46
  • 2
    You don't need browsers to access hardware keys; local apps are perfectly fine at doing so (as, indeed, your extension proves; it uses a local app as a "native messaging" server to breach the browser sandbox). Users shouldn't need to take action to make stuff they download safe; it should be - needs to be - safe *by default*. I'm glad to hear you're making improvements, though. Consider also disabling transparent access to the keys, at least for the first access of a key by a given site, and especially don't use public data (cert thumbprints) to identify the secret keys for transparent access. – CBHacking May 22 '21 at 07:26
  • @CBHacking, we have now updated Extension Host to ask user every time new website tries to access any extension action and user has option to **Deny**, *Allow Once* or *Always Allow* and *Manage* Allowed Origins. Hope this meets security expectations now and you would have no hesitation to recommend our extension now ;) Thanks for your constructive critic. – Bharat Vasant Jun 09 '21 at 08:12
  • 1
    That sounds like a great improvement! I'll check it out. – CBHacking Jun 09 '21 at 09:12