Repository navigation
Secure keystores with filesystem acl, use pkcs12 #422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mgaffigan
wants to merge
14
commits into
OpenIntegrationEngine:main
Choose a base branch
from
mgaffigan:fix/keystore-privs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
301c3d4
Secure keystores with filesystem acl, use pkcs12
mgaffigan 7f51d4d
Use SDDL on windows to secure keystore to BA,SY,CO
mgaffigan 40b5d76
Add SPDX headers and fix keystore comments and imports
tonygermano 552cc6f
refactor: modernize keystore file handling with NIO.2 and try-with-re…
tonygermano 8a548c4
Make FilePermissionUtilTest independent of the Windows display language
tonygermano 1b0b1db
Refuse to create a new keystore when a legacy keystore.jks exists
tonygermano f0879ca
Restrict permissions on a downloaded keystore and tidy configure-from…
tonygermano 6c39ab7
Write keystore atomically and only when it changes
tonygermano a972eae
Don't run with an encryption key that couldn't be saved
tonygermano dd091d1
Test creating an owner-only file with a long path on Windows
tonygermano 902be8f
Support long paths when creating an owner-only file on Windows
tonygermano a3c2f23
Create the keystore behind a symlink whose target doesn't exist yet
tonygermano 2a2a8ca
Flush the keystore to disk before moving it into place
tonygermano 399776b
Restrict an existing keystore before downloading over it
tonygermano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
46 changes: 46 additions & 0 deletions
46
server/src/main/java/com/mirth/connect/server/util/FilePermissionUtil.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
| // SPDX-FileCopyrightText: Mitch Gaffigan <mitch@gaffigan.net> | ||
| // SPDX-FileCopyrightText: 2026 Tony Germano <tony@germano.name> | ||
|
|
||
| package com.mirth.connect.server.util; | ||
|
|
||
| import java.io.IOException; | ||
| import java.nio.file.FileAlreadyExistsException; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.attribute.PosixFilePermission; | ||
| import java.nio.file.attribute.PosixFilePermissions; | ||
| import java.util.EnumSet; | ||
| import java.util.Set; | ||
|
|
||
| import com.sun.jna.Platform; | ||
|
|
||
| public class FilePermissionUtil { | ||
|
|
||
| private static final Set<PosixFilePermission> OWNER_ONLY = EnumSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE); | ||
|
|
||
| private FilePermissionUtil() {} | ||
|
|
||
| /** | ||
| * Creates a new file that only the account the server runs as, and whoever administers the | ||
| * machine, may read or write. The permissions are applied as part of the create itself, so the | ||
| * file is never briefly readable by anyone else. | ||
| * | ||
| * @param path The path of the file to create. | ||
| * @throws FileAlreadyExistsException If a file of that name already exists. | ||
| * @throws IOException If an I/O error occurs, or the permissions cannot be applied. | ||
| */ | ||
| public static void createOwnerOnlyFile(Path path) throws FileAlreadyExistsException, IOException { | ||
| Path parent = path.toAbsolutePath().getParent(); | ||
|
|
||
| if (parent != null) { | ||
| Files.createDirectories(parent); | ||
| } | ||
|
|
||
| if (Platform.isWindows()) { | ||
| WindowsFilePermissionUtil.createRestrictedFile(path); | ||
| } else { | ||
| Files.createFile(path, PosixFilePermissions.asFileAttribute(OWNER_ONLY)); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.