Protect locally stored Acount Code on disk with system api - #3508
Open
Mabeeck wants to merge 31 commits into
Open
Protect locally stored Acount Code on disk with system api#3508Mabeeck wants to merge 31 commits into
Mabeeck wants to merge 31 commits into
Conversation
Mabeeck
force-pushed
the
windows-CryptProtectData
branch
2 times, most recently
from
August 12, 2026 19:19
60f2598 to
92890da
Compare
Mabeeck
marked this pull request as ready for review
August 12, 2026 19:56
Wunka
suggested changes
Aug 14, 2026
IntegratedQuantum
requested changes
Aug 16, 2026
Contributor
Author
|
Done |
IntegratedQuantum
requested changes
Aug 20, 2026
Wunka
approved these changes
Aug 20, 2026
Mabeeck
force-pushed
the
windows-CryptProtectData
branch
from
August 23, 2026 12:28
026d0ee to
419ec15
Compare
Contributor
Author
|
Done |
IntegratedQuantum
requested changes
Aug 23, 2026
Contributor
Author
|
Done |
IntegratedQuantum
requested changes
Aug 30, 2026
IntegratedQuantum
left a comment
Member
There was a problem hiding this comment.
Please also include a screenshot (since I cannot test this locally), also please adjust the window height to avoid a scrollbar.
| list.add(Label.init(.{0, 0}, width, "Your Account Code will be stored in your settings to allow you to stay logged in. Please decide how we should store it:", .left)); | ||
| innerList = VerticalList.init(.{0, 0}, 100, 16); | ||
| if (main.network.authentication.protection.canProtect) { | ||
| protectCheckbox = CheckBox.init(.{0, 0}, width, "Protect from theft (recommended)\nForces re-authentication when device changes", protectAccountCode, &protectAccountCodeCallback); |
Member
There was a problem hiding this comment.
I think this is too generic. Protection from theft can mean a lot of things.
I'd suggest to find a non-dev on the discord server to work together on this. Or maybe @ikabod-kee could help here.
Contributor
Author
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.
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.
Consistency. Oh, and better to be safe than sorry.
Must test on linux
If error. Unsupported is raised, then a programmer is using the API incorrectly. Errors like these warrant a panic and do not need to be recoverable.
Mabeeck
force-pushed
the
windows-CryptProtectData
branch
from
August 30, 2026 14:41
9646ce5 to
728c5a7
Compare
As I see it, this is the simplest way to have the defer directly below the recource creation. That makes one more allocation than necessary when shouldProtect is false, but if it improves readability, then that should be fine, since this is not performance critical code.
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