This repository was archived by the owner on Sep 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 74
NativeMessagingAPI
Rainer Villido edited this page May 15, 2015
·
61 revisions
Native Messaging API describes the extension-host JSON interface that the Chrome extension uses to communicate with the native host. This is internal for chrome-token-signing native host. See hwcrypto.js for web developer interface.
See RFC 2119 for MUST/SHOULD/MAY etc
- The native component:
- Runs in loop, because
- it maintains certificate selection binding (only user-confirmed certificate can be used for signing)
- it checks for the same
originin all the messages after the first technically validCERTrequest containingoriginwas sent
- Uses
originfor checking that the origin is secure- at least
https:andfile:
- at least
- Rejects technically incorrect requests with technically correct JSON response indicating
result: 'invalid_argument'together with API version and quits the process. - Supports messages up to 8192 bytes and rejects messages above this size on technical level
- Supports GUI languages (at least
et,enandru). Defaults toenif language not set or not recognized - Supports backend selection on signing process on Windows (PKCS#11 vs CAPI) with
forcePkcs11andpkcs11ModulePathoptions.
- Runs in loop, because
- The request:
- MUST contain
type - MUST contain
nonce - MUST contain
origin - MAY include other fields, not specified here
- MUST contain
- The response:
- Has a
resultfield (See: error handling) - Contains
nonce(value from request echoed in response) if request contains it - Contains
apiversion (this specification, echoed in response)
- Has a
- The logic:
- VERSION message is always available without secure
originchecks - Missing PKCS#11 module (or failure to C_Initialize) specified one results in
"technical_error"error for operations that require PKCS#11 (SIGNandCERT) - Both PKCS#11 and GUI are initialized on demand (
VERSIONcommand succeeds in headless mode and PKCS#11 module is not listed beforeCERTcommand is received)
- VERSION message is always available without secure
- Request
- MUST have
type=="VERSION"(andoriginandnonce) - Example:
{"type": "VERSION", "nonce": "04jscvu39bm6vfju", "src": "page.js", "origin": "https://open-eid.github.io", "tab": 6} - Response
- Has
version(string in x.y.z format) - Example:
{"api": 1, "nonce": "04jscvu39bm6vfju", "result": "ok", "version": "1.0.0.0" }
- Request
- MUST have
type=="CERT"(andoriginandnonce) - MUST have
lang - Example:
{"type": "CERT", "lang": "en", "nonce": "lt3anao0u54dyq4x", "src": "page.js", "origin": "https://open-eid.github.io", "tab":6} - Response
- Has
cert(DER encoded certificate as hex string) - Example:
{"api": 1, "cert": "308204FD308203E5...CDF738", "nonce": "lt3anao0u54dyq4x", "result": "ok"}
- Request
- MUST have
type=="SIGN"(andoriginandnonce) - MUST have
cert(DER encoded certificate as hex string) - MUST have
hash(plain SHA1/SHA-2 hash as hex string) - MUST have
lang - MAY have
"forcePkcs11":trueto use PKCS#11 on Windows - MAY have
pkcs11ModulePathto specify PKCS#11 module path on Windows if"forcePkcs11":true. May be full path or module file name. Defaults toopensc-pkcs11.dll. - Example:
{"type": "SIGN", "cert": "308204FD308203E5...CDF738", "hash": "413140d543...dd54af2", "hashtype": "SHA-256", "lang": "en", "nonce": "hqq2npwiw4wekq78", "src": "page.js", "origin": "https://open-eid.github.io", "tab": 6, "forcePkcs11": true, "pkcs11ModulePath": "C:\\Downloads\\opensc-pkcs11.dll"} - Response
- Has
signature(resulting signature as hex string) - Example:
{"api": 1, "nonce": "hqq2npwiw4wekq78", "result": "ok", "signature": "562112EB88E9513...E497313A8546"}
- Every response has a
resultfield."ok"is returned with successful responses and a relevant error code string otherwise. - Additional informational message is included with the
"message"field if the result is not"ok"
-
technical_errorin case of any technical error, e.g. - PKCS#11 module could not be loaded.
- Failed to open Cert Store
-
invalid_argumentif the request contains invalid arguments, e.g. - invalid hash value.
- The certificate was not previously selected by the user.
- Request origin has changed between requests.
- Invalid message length.
-
not_allowedif theoriginis not secure, e.g doesn't start withhttps:. -
user_cancelif the user has cancelled the operation, e.g. has pressed cancel on PIN dialog. -
no_certificatesif no certificates were found, e.g. smart card was not inserted into reader. -
pin_blockedif maximum number of PIN entry attempts has been reached.
- If there are no suitable certificates (because there is no card or reader attached), a GUI window is not opened and
"no_certificates"status is returned. - If there is an "inserted card" (definition depends on backend implementation) but all certificates have expired (notAfter is in past)
"no_certificates"is returned. - All responses are sent back to the application after the GUI has been closed (no informative "fire and forget" messages, single serialized interaction)
- Incorrect PIN results in a repeat PIN dialog until correct pin is entered (
"ok"),"pin_blocked"or"user_cancel"has happened.
See DeveloperTips