Skip to content
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

argon2: Add helpers for running the KDF remotely #328

Merged
merged 43 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
017287b
argon2: Add helpers for running the KDF remotely
chrisccoulson Sep 3, 2024
bb46af8
argon2: address some review comments
chrisccoulson Sep 6, 2024
93292cd
argon2: add in-process test for WaitForAndRunArgon2OutOfProcessRequest
chrisccoulson Sep 6, 2024
844021f
[WIP] address review comments
chrisccoulson Sep 9, 2024
fd31de5
Merge branch 'master' into remote-argon2-kdf
chrisccoulson Nov 21, 2024
fe291c5
Argon2 remoting cleanups
chrisccoulson Nov 27, 2024
a097997
Fix a couplke of data races
chrisccoulson Dec 2, 2024
ef2c8e4
argon2: increase timeout for github
chrisccoulson Dec 2, 2024
dce2200
reduce memory usage of tests that fail in github to see if they will …
chrisccoulson Dec 2, 2024
8f57b45
argon2: add a missing comment
chrisccoulson Dec 2, 2024
3c64825
argon2: replace the use of sync.WaitGroup with a channel
chrisccoulson Dec 2, 2024
35fd6f1
argon2: reduce memory usage for github
chrisccoulson Dec 2, 2024
8b5c902
reduce memory usage in a couple more argon2 tests
chrisccoulson Dec 2, 2024
9d6d0e4
Change the backoff time to 100ms and refactor the code to make the te…
chrisccoulson Dec 3, 2024
d1f97b3
close the channel to unblock the receiving routine
chrisccoulson Dec 4, 2024
fabe880
complete a doc comment
chrisccoulson Dec 4, 2024
0c869e8
Update x/crypto
chrisccoulson Dec 4, 2024
e18c47b
Don't use json.Decoder.DisallowUnknownFields
chrisccoulson Dec 4, 2024
513d782
Fix various race conditions with the Argon2 remoting
chrisccoulson Dec 6, 2024
b803ecf
Close both ends of the request channel on error
chrisccoulson Dec 6, 2024
d38ab1c
Remove a bit of unnecessary test code
chrisccoulson Dec 6, 2024
093b6ee
Test WaitForAndRunArgon2OutOfProcessRequest closes its end of the res…
chrisccoulson Dec 6, 2024
c8d71ba
Improve the argon2 remoting system-lock tests
chrisccoulson Dec 6, 2024
a1e15a7
Make use of strings.Builder
chrisccoulson Dec 6, 2024
9c9d5ca
remove some unnecessary channel usage
chrisccoulson Dec 6, 2024
327f235
Try running some tests with a memory consumption of 2GiB again
chrisccoulson Dec 6, 2024
afca4f4
Simplify the HMACArgon2OutOfProcessWatchdogMonitor function
chrisccoulson Dec 6, 2024
ba7c52f
Move all tests that run Argon2 to the expensive suites
chrisccoulson Dec 6, 2024
6270d98
Add some debugging fmt.Printf statements
chrisccoulson Dec 6, 2024
88d8658
Reenable the watchdog timeout again
chrisccoulson Dec 6, 2024
d6cabb3
try disabling the GC during the failing test
chrisccoulson Dec 6, 2024
4cdec5f
remove debug fmt.Printfs
chrisccoulson Dec 6, 2024
57a5694
Ensure WaitForAndRunArgon2OutOfProcessRequest will only process a sin…
chrisccoulson Dec 7, 2024
586bc6b
argon2: Add a comment about not launching sub-processes
chrisccoulson Jan 17, 2025
7a87d2b
argon2: Ensure a panic in the KDF is handled correctly
chrisccoulson Jan 17, 2025
625db26
internal/paths: Use a snapd agnostic path for the Argon2 lock file
chrisccoulson Jan 17, 2025
8883d04
argon2: Add a note explaining why we don't validate the MemoryKiB cos…
chrisccoulson Jan 17, 2025
e094dfa
argon2: Don't use type aliases for the watchdog function templates
chrisccoulson Jan 17, 2025
a264de8
argon2: Pass O_NOFOLLOW when opening the lock file
chrisccoulson Jan 17, 2025
0e6e386
argon2: make sure the lock file is a regular file
chrisccoulson Jan 17, 2025
71a9050
Merge branch 'master' into remote-argon2-kdf
chrisccoulson Jan 17, 2025
d11584e
Merge branch 'master' into remote-argon2-kdf
chrisccoulson Jan 21, 2025
77dcb36
internal/paths: update the Argon2 lock filename
chrisccoulson Jan 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
run_argon2
vendor/*/
38 changes: 0 additions & 38 deletions argon2.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,44 +225,6 @@ type Argon2KDF interface {
Time(mode Argon2Mode, params *Argon2CostParams) (time.Duration, error)
}

type inProcessArgon2KDFImpl struct{}

func (_ inProcessArgon2KDFImpl) Derive(passphrase string, salt []byte, mode Argon2Mode, params *Argon2CostParams, keyLen uint32) ([]byte, error) {
switch {
case mode != Argon2i && mode != Argon2id:
return nil, errors.New("invalid mode")
case params == nil:
return nil, errors.New("nil params")
case params.Time == 0:
return nil, errors.New("invalid time cost")
case params.Threads == 0:
return nil, errors.New("invalid number of threads")
}

return argon2.Key(passphrase, salt, argon2.Mode(mode), params.internalParams(), keyLen), nil
}

func (_ inProcessArgon2KDFImpl) Time(mode Argon2Mode, params *Argon2CostParams) (time.Duration, error) {
switch {
case mode != Argon2i && mode != Argon2id:
return 0, errors.New("invalid mode")
case params == nil:
return 0, errors.New("nil params")
case params.Time == 0:
return 0, errors.New("invalid time cost")
case params.Threads == 0:
return 0, errors.New("invalid number of threads")
}

return argon2.KeyDuration(argon2.Mode(mode), params.internalParams()), nil
}

// InProcessArgon2KDF is the in-process implementation of the Argon2 KDF. This
// shouldn't be used in long-lived system processes - these processes should
// instead provide their own KDF implementation which delegates to a short-lived
// utility process which will use the in-process implementation.
var InProcessArgon2KDF = inProcessArgon2KDFImpl{}

type nullArgon2KDFImpl struct{}

func (_ nullArgon2KDFImpl) Derive(passphrase string, salt []byte, mode Argon2Mode, params *Argon2CostParams, keyLen uint32) ([]byte, error) {
Expand Down
Loading
Loading