Skip to content

build(repeater): bundle the PKCS#11 provider with the Windows executable - #819

Merged
aborovsky merged 3 commits into
feat/pkcs11-smart-cardfrom
feat/pkcs11-windows-bundle
Nov 11, 2026
Merged

aborovsky merged 3 commits into
feat/pkcs11-smart-cardfrom
feat/pkcs11-windows-bundle

Conversation

@aborovsky

@aborovsky aborovsky commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

What

A Windows bundle that a tester can unzip and run against a smart card, with no other install than the card vendor's PKCS#11 module.

The temporary build chain now uploads bright-cli-win-x64-smartcard:

File Source
bright-cli.exe the pkg executable, now including the pkcs11js addon
pkcs11prov.dll libp11 0.4.21 x64 release (SHA-256 pinned), the OpenSSL PKCS#11 provider
libcrypto-3-x64.dll the OpenSSL 3 DLL that pkcs11prov.dll imports (from the runner's OpenSSL install; the version is recorded in the notices)
vcruntime140.dll the VC++ runtime that libcrypto-3-x64.dll imports, so the VC++ redistributable is not required
LICENSE-libp11.txt, LICENSE-OpenSSL.txt, THIRD-PARTY-NOTICES.txt licences: LGPL-2.1+ (libp11) and Apache-2.0 (OpenSSL)

The Repeater already looks for pkcs11prov.dll next to its executable. Windows resolves the provider's libcrypto-3-x64.dll from the same folder.

Smoke test of the real artifact

tests/pkcs11/repeater-smoke.ts stands in for the Bright cloud on localhost:8000: the same socket.io path, namespace and msgpack parser as the bridges. It waits for the Repeater to deploy, sends it one request and checks the result.

On windows-2022, the workflow runs it against the bundled bright-cli.exe with a SoftHSM2 token and an mTLS target. PATH is stripped to Node and Windows, so a DLL missing from the bundle cannot be found elsewhere.

  • right PIN: 200, and the target reports the client certificate from the token;
  • wrong PIN: PKCS11_PIN_INCORRECT.

socket.io is added as a dev dependency for the fake cloud.

Review fixes

  • The bundle now ships vcruntime140.dll. A new step checks that every DLL the bundle imports is either in the bundle or part of Windows.
  • On the arm64 macOS runners, the pkcs11js addon is rebuilt for x64, the architecture of the executable. Before packaging, the architecture of the addon is read from its ELF, Mach-O or PE header and checked. The release deploy.yml gets the same steps.
  • SSLENGINE is set once per pooled handle. curl reloads OPENSSL_CONF into the handle's library context on every call, which on Windows leaks the path each time.
  • repeater-smoke.ts stops the Repeater on every outcome, not only on success, and accepts error for any errorCode without a status.
  • The licence files are pinned by SHA-256, and the smoke step waits until the target is listening instead of sleeping.

Checks

  • Locally on macOS, the harness passes with node dist/index.js (200 and PKCS11_PIN_INCORRECT) and with a pkg executable built from this branch (200).
  • A new workflow step fails the executable build when the pkcs11js addon did not compile. As an optional dependency, a failed compile would otherwise only show up at runtime.

Not in this PR

  • MSI packaging of the DLLs.
  • The pkcs11js prebuilds, the Docker image, Helm and npm docs.
  • Pinning libcrypto-3-x64.dll instead of taking it from the runner image.

- Add the pkcs11js addon to pkg.assets so the executables can use it.
- The temporary build chain now assembles bright-cli-win-x64-smartcard:
  bright-cli.exe, libp11's pkcs11prov.dll, the libcrypto-3-x64.dll it
  imports, and their licence notices.
- tests/pkcs11/repeater-smoke.ts stands in for the Bright cloud and sends
  a built Repeater one request. The workflow runs it against the bundle
  on windows-2022 with a SoftHSM2 token and a PATH stripped to Node and
  Windows, so the executable must find everything next to itself: 200
  with the right PIN, PKCS11_PIN_INCORRECT with a wrong one.
The bundled Windows executable failed with "SSL crypto engine not found":
OpenSSL reads OPENSSL_CONF through the C runtime's getenv(), which on
Windows only sees the environment at process start, so the config the
Repeater generates at runtime was never loaded. The tests passed only
because their environment also set OPENSSL_MODULES and
PKCS11_MODULE_PATH. Set OPENSSL_WIN32_UTF8 so OpenSSL reads variables
through GetEnvironmentVariableW, and run the SoftHSM suite and the
bundle smoke test without those helper variables.

On ubi8, pkcs11js did not compile: node-gyp needs Python 3.8+ and Node
24's headers need C++20, while ubi8 ships Python 3.6 and gcc 8. Build
with python3.11 and gcc-toolset-12, in the release workflow as well.
- Ship vcruntime140.dll in the Windows bundle: libcrypto-3-x64.dll
  imports it, so without the VC++ redistributable the provider would not
  load. A new step checks that every DLL the bundle imports is in the
  bundle or part of Windows.
- Build the pkcs11js addon for x64 on the arm64 macOS runners, and check
  the addon's architecture before packaging, in the release workflow too.
- Set SSLENGINE once per pooled handle: curl reloads OPENSSL_CONF into the
  handle's library context on every call, which on Windows leaks the
  path each time.
- repeater-smoke.ts stops the Repeater on every outcome, not only on
  success, and accepts "error" for any errorCode without a status.
- Pin the licence files by SHA-256 and wait for the smoke target to
  listen instead of sleeping.
@aborovsky
aborovsky merged commit f09f6c5 into feat/pkcs11-smart-card Nov 11, 2026
22 checks passed
@aborovsky
aborovsky deleted the feat/pkcs11-windows-bundle branch November 11, 2026 09:22
aborovsky added a commit that referenced this pull request Nov 11, 2026
…target (#820)

## What

Two scripts that send one request through the Repeater, built from this
checkout, to a **remote** target that requires client certificates. The
client key sits on a throwaway SoftHSM2 token. `setup.sh` and the local
target are not used, and no API key is needed: `repeater-smoke.ts`
stands in for the Bright cloud.

| Script | Certificate on the token | Expected |
|---|---|---|
| `tests/pkcs11/remote/positive.sh <url> <client.p12> [password]
[status]` | the given PKCS#12, issued by a CA the target trusts | HTTP
status (default 200) |
| `tests/pkcs11/remote/negative.sh <url> [client.p12] [password]` | a
self-signed certificate, or the given PKCS#12 from another CA | the
target rejects it in the TLS handshake: an `errorCode`, no HTTP status |

The negative case relies on `repeater-smoke.ts` accepting `error` as the
expected result, which came with #819.

## Checked

Against an `ao-https-with-header` mock that trusts `MyCompany Root CA`
(AWS NLB with TLS passthrough):

- positive, `CN=alice@example.com`: `SMOKE PASSED: 200` (`Certificate is
valid!`);
- negative, self-signed: `SMOKE PASSED: error` (`ECONNRESET`, "Failure
when receiving data from the peer");
- negative, `CN=Hacker` issued by `Evil CA`: `SMOKE PASSED: error`.

shellcheck is clean.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant