Repository navigation
Save private key and setup config files with owner-only permissions - #475
Merged
Merged
Conversation
KeyUtils.saveEcKey and KeyUtils.saveEcKeyAsHex wrote the private key with the default mode (usually 0644), so any local user could read it. Both now write the file with mode 0600 on file systems that support POSIX permissions. If the file already exists, its permissions are tightened before the key is written. On Windows the file keeps the default permissions.
The setup tool wrote BitPay.config.json with the default mode (usually 0644). The file holds the API tokens, and with the "plain text" option it also holds the private key, so any local user could read them. It is now written with mode 0600 on file systems that support POSIX permissions, the same way as the private key file.
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
The SDK saved the merchant's private key with the default mode (usually
0644), so any local user could read it. This happens inKeyUtils.saveEcKeyandKeyUtils.saveEcKeyAsHex, which the setup tool uses and merchants can also call directly.The setup tool also saved
BitPay.config.jsonwith the default mode. That file holds the API tokens, and the private key too when the "plain text" option is used.These files are now saved with mode
0600(only the owner can read and write).Changes
KeyUtils: new private helperwriteOwnerOnlyFile, used bysaveEcKeyandsaveEcKeyAsHex. It creates the file with0600, or sets0600on an existing file before writing, and sets it again after writing.BitPaySetup: savesBitPay.config.jsonthe same way.KeyUtilsTest.On file systems without POSIX permissions (Windows), the files keep the default permissions. The new tests are skipped there. The code only uses Java 7 APIs, so Java 8 is still supported.
Testing
10.3.x(files arerw-r--r--) and pass with this change.mvn teston Java 8 (Corretto 8.0.472): 611 passed, 0 skipped.mvn checkstyle:check: OKJira: IM-192