Protect locally stored Acount Code on disk with system api - #3508
Open
Mabeeck wants to merge 19 commits into
Open
Protect locally stored Acount Code on disk with system api#3508Mabeeck wants to merge 19 commits into
Mabeeck wants to merge 19 commits into
Conversation
Due to line 411 in authentication.zig and some other reasons I have decided to rework this implementation to make use of a `protected` boolean attribute instead of creating tons of extra EncodingTypes.
Obey linter and migrate to protected attribute. protect() and unprotect() now error on unsupported platforms. I felt that it would be bad, if someone assumed that a call to unprotect would always error on bad input or that a call to protect would always encrypt the data. These previously false assumptions are now true.
Mabeeck
force-pushed
the
windows-CryptProtectData
branch
2 times, most recently
from
August 12, 2026 19:19
60f2598 to
92890da
Compare
Apparently errorcode 13 is for strings too short and errorcode 87 is for otherwise gibberish. The real reason I made this commit is that some github service was down when my last test ran and the only way to rerun it is to make another commit.
Wunka
suggested changes
Aug 14, 2026
IntegratedQuantum
requested changes
Aug 16, 2026
Member
There was a problem hiding this comment.
Should not be at the root. main.protect is quite ambiguous.
I'd suggest to put it in main.network.autentication.protect, to emphasize that it belongs thematically to the authentication system.
Member
There was a problem hiding this comment.
I think it should still be put into a separate file, since it will likely grow as we add support for the other operating systems.
Consistency. Oh, and better to be safe than sorry.
Must test on linux
Author
|
Done |
IntegratedQuantum
requested changes
Aug 20, 2026
Comment on lines
+296
to
+298
| pub inline fn canProtect() bool { | ||
| return Impl.canProtect; | ||
| } |
Member
There was a problem hiding this comment.
Suggested change
| pub inline fn canProtect() bool { | |
| return Impl.canProtect; | |
| } | |
| pub const canProtect: bool = Impl.canProtect; |
| return Impl.unprotect(allocator, data); | ||
| } | ||
|
|
||
| const NoImpl = struct { |
Member
There was a problem hiding this comment.
technically these are namespaces (no fields), so they should follow our naming scheme for them: no_impl windows_impl impl
| } | ||
| } | ||
|
|
||
| test "Protect fails on unsupported platforms" { |
Member
There was a problem hiding this comment.
Note that these currently do not run in the CI. I made an issue for this: #3535
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.
This PR adds the
main.protect.protectandmain.protect.unprotectfunctions and integrates them into thePasswordEncodedAccountCodeclass.protectTakes an allocator and a slice of bytes as arguments. The function returns a different slice of bytes that has been allocated with the provided allocator and can be passed tounprotectto get back the original slice of bytes. The function can fail, if the platform Cubyz is currently running on does not have an implementation yet (in which case the error will beerror.Unsupported) or the syscall fails for some undisclosed reason (Windows), in which case the error will beerror.syserr.unprotectTakes an allocator and a slice of bytes that has been previously generated byprotectas arguments. The function returns a different slice of bytes that has been allocated with the provided allocator and is equivalent in value to the slice of bytes that was passed toprotectin order to produce the provided slice. The function can returnerror.Invalidif the provided input was protected on a different device; can no longer be unprotected for some reason; the current platform does not have an implementation. If something unexpected happened the function will fail witherror.syserr.canProtectTakes no arguments and returns a boolean indicating weather the protection functions have an implementation on the current platform.Currently the protection functions only support Windows. They can later be easily expanded to support Linux as well.
Adds a
protectedattribute toPasswordEncodedAccountCodethat indicates weather a call tounprotectis needed, before theAccountCodecan be decrypted.Functions to initialize
PasswordEncodedAccountCodenow take ashouldProtectboolean argument that when set to true will protect the function with the native system api, if available. Setting it to false will prevent usage of the protection api.Contributes to #2551