Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #328 from chrisccoulson/remote-argon2-kdf
argon2: Add helpers for running the KDF remotely. As Argon2 is memory intensive, it's not suitable for multiple invocations in long-lived garbage collected processes where multiple invocations may result in the process being unable to perform new allocations, or even worse, triggering the kernel’s OOM killer. For this reason, Argon2 is currently abstracted with an interface (`Argon2KDF`), of which the application sets a global version of this which is intended to proxy KDF requests to a short-lived remote process which uses the real `InProcessArgon2KDF`. This adds some functionality to facilitate this. Then there are JSON serializable types `Argon2OutOfProcessRequest` and `Argon2OutOfProcessResponse`. The request can be fed directly to `RunArgon2OutOfProcessRequest` on the remote side, but this is a fairly low-level API - the application still has to deal with the transport. There is a higher level API - `NewOutOfProcessArgon2KDF`, for use in the application process, and which returns an implementation of `Argon2KDF` which proxies requests to a short-lived remote handler process. The caller supplies a function to construct an appropriate `exec.Cmd` instance for this. This function configures the `exec.Cmd` so that the handler process receives a request on stdin and it expects a response on stdout. The handler process is expected to pass both `os.Stdin` and `os.Stdout` to `WaitForAndRunArgon2OutOfProcessRequest`, although it doesn't hardcode these descriptors for implementations that want to construct their own processes with transports that don't rely on stdin and stdout. Once a handler process has completed a request, it should exit cleanly. Neither `RunArgon2OutOfProcessRequest` or `WaitForAndRunArgon2OutOfProcessRequest` support being called more than once in the same process. The code in cmd/run_argon2 provides an example handler process, although this is mainly useful for unit testing (where it is currently used). It is envisaged that the handler process will be a special mode of snapd and snap-bootstrap in order to avoid adding an additional go binary just for this.
- Loading branch information