Secure keystores with filesystem acl, use pkcs12 #422
Test Results
142 files +1 142 suites +1 3m 48s ⏱️ +49s
921 tests +2 920 ✅ +1 1 💤 +1 0 ❌ ±0
1 053 runs +2 1 046 ✅ +1 7 💤 +1 0 ❌ ±0
Results for commit 1ef33281. ± Comparison against base commit 892e33fb.
[test-results]:data:application/gzip;base64,H4sIAM1x72oC/02NSw7DIAwFrxKx7gLzaaCXqSDFEmoSKgKrqHcvofmwnHnWeCXoR7eQRweC3TqyZJ8afOVokg9zEYypIsqYtlkzOOi55GGoil7q7T9b5BRo/FjEdeFiDHE3Mc/1JZV8p6MJVNxP9W/2BzfJym1xCNPkUwECDjlnCqzSBoRUCNIZyntqENFq6xhKK6gk3x+1P8QxCwEAAA==
:recycle: This comment has been updated with latest results.
Explan what this is checking and how it knows its a jceks?
Non blocking comment - I checked if file utils does this for us. It does not. I dont live introducing a util class but its appropriate here
Per Tonys comments from chat - add a comment in the props file explaining how this is generated if its blank.
This is making my brain itch. I feel like there could be some cyclic problem, maybe with containers? where the keystore is generated and a PW set, then the keystore is retained as a file (like if appdata is a persistent volume) but the generated keystore pass isn't retained because conf isnt in a persistent volume and the env var isn't set.
Instinctively - I'd document this, but theres a massive curse of knowledge problem because I am intimate with my keystores but a more casual, first-time user won't know how to process the big error
Maybe touch to create the file? But then you still gotta mess with perms. https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/FileUtils.html#touch(java.io.File)
I don't see an alternative here for any major portion.
I did on line 28. With pkcs12, there is no need to have a password, so the blank is not a sentinel value - there just is no password.
This is a dirty hack suggested to me by AI. It's checking if the first 4 bytes of the file are cececece - which is the magic signature for a JCEKS keystore (the legacy format that would require the "changeme" default password).
TL;DR: backcompat hack.
I think the local admin group should also be added with full control?
root always has access in linux, but windows does not automatically give permission to local admins.
Should the file extension change to reflect the new file type?
I don't know when I'll get time to test this myself, but does the channel level encryption still work when the keystore type is PKCS12?
The second use of this keystore is to store the symmetric key for channel encryption. I suspect that's why the default type had not been previously changed, but maybe it's fine.
This unresolved issue and comments may be relevant https://github.com/nextgenhealthcare/connect/issues/4158
Requested changes.
I agree in principle, but it is a pain. Added as a separate commit in case we change our minds.
Should the file extension change to reflect the new file type?
Sure. Updated. I don't see a problem with this.
does the channel level encryption still work when the keystore type is PKCS12?
If channel encryption is the "Encrypt message contents" checkbox, then yes, it seems to work fine. Database rows seem to reference some AES key:
{alg=AES/CBC/PKCS5Padding,cs=UTF-8,iv=ubupD9l5A2edZnhMyrE63Q==}zotLK9oahMRMDgLFoU4NHECvDfrRSrpwDD4YAjj6W9AE/89CFjyQCOIgN5N/xJUqr4sUzQTMMwbZ
mYtM8fwrk6T32m30b30TLbsuPXQs6MdbHwBY4Coi/ttOxmc0ZHfR46YBgd1LbUzPQNgwoKGZAlfJ
kI61PV1f8vdIDXB9gD3wNw9VegZTSUrbbYoVGvD6RjZdMHGuKqEBfrZaWqD1VnjV63Ii7TKy3GtR
iyPTKbDkEebzj2zJL3H26/I3n6T8IEw058nyO+gs48fOeZKFfBcH7S/6FX2HmrD8pA38LsxDbL+8
+dHJst+N68NwhyYU
I removed it in favor of a filename check.
sorry. I was off: this is a test resource, not a published asset.
A failed first boot leaves an empty keystore that blocks every later boot.
Tthe new createOwnerOnlyFile call creates keystore.pfx before the encryption key and default certificate are generated and written. Before this PR, the file was only created just before writing.
If key or certificate setup throws (for example, a bad encryption setting), the error is only logged and a 0-byte keystore.pfx stays on disk. On the next start the file exists, loading it fails, and security setup fails on every boot until someone deletes the file by hand.
Fix: create the owner-only file right before writing, or delete it when setup fails.
Requested changes.
Great foundation! I've got suggestions for several commits to layer on top of this at https://github.com/OpenIntegrationEngine/engine/compare/eef989cb7e218d2fe5e88c8ef11d3dbc91566544...cdfafceb994b2496ae095798e681eedd3596c065
This also addresses the issue that Nico raised.
I have not yet tested building and running on windows.
jonbartels
mgaffigan
Related to #307
Sets default access controls for key material created on first boot to only be accessible to the owner (600-equivalent):
Posix:
Windows:
Removes the 81uWxplDtB password in favor of a password-less PKCS12 (pfx) file instead of the deprecated jks format for new installs. Upgrades retain their prior password.