Repository navigation
Conversation
The Windows branch of wolfPKCS11_Store_Name() looked up the default
token directory with getenv("%APPDIR%"). getenv() does not expand %VAR%
syntax and APPDIR is not a standard Windows variable, so the lookup
always failed and Windows had no per-user default: token data went to
WOLFPKCS11_DEFAULT_TOKEN_PATH, or storage failed if it was not set.
Read APPDATA instead, giving %APPDATA%\wolfPKCS11. There is no
USERPROFILE fallback, mirroring the POSIX branch which only reads HOME.
Update token_path_test and the README to match, and note in the README
that Windows deployments with existing tokens in the build-time default
directory need to set WOLFPKCS11_TOKEN_PATH or move the files.
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The Windows-specific regression test is not runnable or executed in Windows CI.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Updates Windows token storage to use the standard per-user APPDATA directory.
Changes:
- Uses
%APPDATA%\wolfPKCS11as the Windows default. - Updates path expectations and migration documentation.
- Removes obsolete
APPDIRhandling.
| File | Description |
|---|---|
src/internal.c |
Reads APPDATA for Windows storage. |
tests/token_path_test.c |
Updates Windows path expectations. |
README.md |
Documents behavior and migration impact. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
The Windows CI job only builds the Visual Studio solution, which enables wolfTPM and so cannot run tests on runners without a TPM. Nothing exercised the Windows default token path, which is how the %APPDIR% lookup went unnoticed. Add a job that builds wolfSSL and wolfPKCS11 with CMake and MSVC as static libraries without wolfTPM, and runs token_path_test. Add an unsetenv() shim next to the existing Windows setenv() shim in testdata.h and include io.h for _access() so the test builds on Windows.
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.

On Windows,
wolfPKCS11_Store_Name()looked up the default token directory withgetenv("%APPDIR%").getenv()does not expand%VAR%syntax andAPPDIRis not a standard Windows variable, so the lookup always returned NULL. Since 2.0, Windows has had no per-user default: token data went toWOLFPKCS11_DEFAULT_TOKEN_PATH, or token storage failed if that was not set.APPDATAinstead, so the default is%APPDATA%\wolfPKCS11. There is noUSERPROFILEfallback, mirroring the POSIX branch which only readsHOME. A single lookup keeps the token location deterministic rather than depending on which variables a given process inherited.token_path_testnow expects only%APPDATA%\wolfPKCS11(it previously also accepted aUSERPROFILEfallback the library never had) and no longer unsetsAPPDIR.%APPDATA%\wolfPKCS11and notes the behavior change.token_path_test. The existing job builds the Visual Studio solution, which enables wolfTPM, so its tests cannot run on runners without a TPM; nothing exercised this path, which is how the bug went unnoticed. A newcmake-token-pathjob inwin-test.ymlbuilds wolfSSL and wolfPKCS11 with CMake and MSVC as static libraries without wolfTPM and runstoken_path_testviactest. To build the test on Windows,testdata.hgains anunsetenv()shim next to its existingsetenv()shim, andtoken_path_test.cincludesio.hfor_access().Behavior change on Windows:
%APPDATA%\wolfPKCS11is checked beforeWOLFPKCS11_DEFAULT_TOKEN_PATH, so Windows builds that relied on the build-time default will now use the per-user directory. Deployments with existing tokens there need to setWOLFPKCS11_TOKEN_PATHto that directory or move the token files. This is called out in the README and should go in the next release notes.Testing:
debian:trixiecontainer, wolfSSL master with the CI configure flags):./configure && make && make -j1 checkpasses (55 pass, 4 skip, 0 fail), includingtoken_path_test.make testpasses (55 pass, 4 skip, 0 fail).token_path_test.exeunder Wine. All 9 checks pass and the token file is created inC:\users\<user>\AppData\Roaming\wolfPKCS11. As a negative control, restoring the old%APPDIR%lookup makesC_Initializefail and the test exit 1, so the new job would have caught the original bug.cmake-token-pathCI job on this PR.