Repository navigation
Save the private key and setup config files with owner-only permissions - #223
Merged
Merged
Conversation
KeyUtils.SaveEcKey wrote the private key with the default permissions. On Linux and macOS that is usually mode 0644, so any local user could read the key. On .NET 7 or later, on Linux and macOS, the file is now created with mode 0600, and an existing file is changed to 0600 before it is overwritten. On Windows and on .NET Framework the file keeps the permissions it inherits from its folder, as before. KeyUtilsTest and ClientTest share a test collection, because both change the key path that KeyUtils keeps in a static field.
The setup tool wrote BitPay.config.json with the default permissions (usually mode 0644 on Linux and macOS). The file holds the API tokens, and with the "plain text" option it also holds the private key. It is now written the same way as the private key file: mode 0600 on Linux and macOS with .NET 7 or later.
swlodarski-sumoheavy
approved these changes
Oct 11, 2026
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.
Summary
KeyUtils.SaveEcKeysaved the private key with the default permissions. On Linux and macOS that is usually mode0644, so any local user could read the key. The setup tool savedBitPay.config.jsonthe same way. That file holds the API tokens, and the private key too when the "plain text" option is used.On Linux and macOS (.NET 7 or later), both files are now saved with mode
0600(only the owner can read and write).On Windows, files get their permissions from the folder (NTFS ACLs), not from a mode, so nothing changes there. The same goes for .NET Framework 4.8, which only runs on Windows.
Changes
KeyUtils: new private helperCreateOwnerOnlyFile, used bySaveEcKey. It creates the file withUnixCreateMode = 0600. If the file already exists, it is changed to0600before it is overwritten, because the create mode only applies to new files. The code is inside#if NET7_0_OR_GREATERand!OperatingSystem.IsWindows(), so it still builds fornet48and passes the platform analyzer (CA1416).BitPaySetup:BitPay.config.jsonis written the same way.KeyUtilsTest. It shares an xUnit collection withClientTest, because both change the key path thatKeyUtilskeeps in a static field, and they must not run in parallel.Testing
6.0.x(mode0644) and pass with this change.dotnet build -f net8.0: no errors, no new warnings.dotnet test BitPayUnitTest -f net8.0: 59 passed.Jira: IM-194