Conversation
60f2598 to
92890da
Compare
|
Done |
026d0ee to
419ec15
Compare
|
Done |
|
Done |
IntegratedQuantum
left a comment
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.
9646ce5 to
728c5a7
Compare
8c72e31 to
1611d7a
Compare
|
I think that's all of it. |
|
Please rebase after #3538 to run the tests in the CI |
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.
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.
Oh, it was generic and a non-answer to the implied question. So that's why it felt like disgusting cooperate speak to me.
1611d7a to
e12828e
Compare
|
Done |
That library is already getting linked in the build script and should not be linked here.
| pbDataSlice.ptr = plainblob.pbData; | ||
| defer { | ||
| std.crypto.secureZero(u8, pbDataSlice); | ||
| if (c.LocalFree(plainblob.pbData) != null) std.log.err("LocalFree syscall failed to free previously allocated memory. Errorcode: {}. This should never happen.", .{c.GetLastError()}); |
There was a problem hiding this comment.
defers should always be directly after the thing you are trying to defer, i.e. the defer for LocalFree should be directly after the if (c.CryptUnprotect...) {...} block.
There was a problem hiding this comment.
Well, the thing is that I shouldn't free it without secure-zeroing it first and for that I need to make a slice out of it.
I can't think of a way for the defer to come any earlier.
| @@ -338,6 +358,18 @@ pub const PasswordEncodedAccountCode = struct { // MARK: PasswordEncodedAccountC | |||
| } | |||
|
|
|||
| pub fn decryptFromPassword(self: PasswordEncodedAccountCode, password: []const u8, failureText: *main.ListManaged(u8)) !AccountCode { | |||
There was a problem hiding this comment.
I forgot to add tests for these. Would you mind adding them, including one for protection if available?
Some basic roundtrips (encrypting→decrypting) should suffice.
There was a problem hiding this comment.
I did add them, but they end up blocking eternally on ubuntu in the CI.
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.Adds a checkbox to Account Code saving menu for opt-out.

Contributes to #2551