Repository navigation
feat(repeater): sign HTTPS requests with PKCS#11 client certificates - #817
Merged
Merged
Conversation
Requests to a target matched by --pkcs11-cert now use the key on the token through the OpenSSL PKCS#11 provider (pkcs11-provider or libp11). - A pre-flight per certificate, through pkcs11js, checks the token, the PIN and the key once. Concurrent callers share the result, a wrong PIN is never retried, and a locked PIN or one on its final try is not used. - Requests run on a fixed pool of long-lived easy handles per certificate (maxConcurrency). Closing a handle unloads the provider and tears down the module state shared by the process. - The generated OPENSSL_CONF holds paths only; the PIN travels in the key URI in memory. The providers only work under their built-in names, so all entries must use one vendor module. - Failures surface as PKCS11_* error codes in the existing errorCode.
…rking - Remember any failure once C_Login has been called; some vendors report a wrong PIN as a generic error. - Reject a second entry for a token that is already logged in with a different PIN, since the provider would try that PIN on the card. - Address tokens by serial as well as label, and refuse to choose between tokens that share a label. - Make pkcs11js an optional dependency: it compiles at install time and must not break installs on machines without build tools. - Treat a zero timeout as no limit, and report a provider that OpenSSL cannot load as PKCS11_MODULE_LOAD_FAILED.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
HTTPS requests to targets matched by
--pkcs11-certnow present the client certificate with the private key on a PKCS#11 token (smart card, USB token, HSM), through the OpenSSL PKCS#11 provider: libp11pkcs11provon Windows/macOS, pkcs11-provider on Linux. WebSocket targets are not covered.How
Pkcs11Preflight, viapkcs11js). Each certificate is checked once, and concurrent callers share the result. The check covers the token, the PIN, the key and the certificate.C_Loginper token, and the session stays open.C_Loginhas been called, any failure is remembered and never retried.objectnoridis set: the only key with a certificate, then the PIV authentication key, otherwise it fails and lists the keys.CurlHandlePool). curl loads the provider per easy handle and unloads it on close, which tears down the module state shared by the process. PKCS#11 requests therefore run on a fixed pool of handles per certificate (maxConcurrency), usecurl.reset()between requests and use keep-alive connections.Pkcs11OpenSslConfig). The generatedOPENSSL_CONFholds paths only, in a 0700 temp dir that is removed on exit. The PIN travels in the in-memory key URI and is never logged.provider=pkcs11prov/provider=pkcs11). Under any other name they fail withprovider keymgmt failure.--pkcs11-certentries must use the same vendor module. The parser rejects mixed modules.PKCS11_*codes in the existingerrorCode/messagefields. The bridges protocol is unchanged.pkcs11jsis an optional dependency: it compiles at install time, sonpm i -gstill works without build tools (verified innode:24-slim). It is then loaded only when PKCS#11 is used, with a clear message if it is missing.Tests
tests/pkcs11/repeater.spec.tsdrives the realHttpRequestExecutoragainst SoftHSM2. It covers:maxConcurrency2 under 6 concurrent callers;PKCS11_PIN_INCORRECTon every request after a single login attempt;tls-stacktest closed each handle as soon as its own worker finished, while handshakes on other handles were still running. Unloading the provider broke those handshakes in about 1 run out of 5. Handles are now closed after all workers finish.Follow-ups
PKCS11_HANDSHAKE_FAILED.ETIMEDOUT.pkcs11prov.dll,libcrypto-3-x64.dlland thepkcs11jsaddon with the Windows executable.