FeatureFuel
1

Improve RSA key file generation and reads

Source: dani-garcia/vaultwarden#4083 · opened by @zacknewman
Currently [main::check_rsa_keys]( [auth::PRIVATE_RSA_KEY]( and [auth::PUBLIC_RSA_KEY]( rely on a lot of separate I/O calls and a few avoidable assumptions which leads to TOCTOU race conditions and a loss in data integrity (e.g., when the public key file exists, there is no validation done to ensure it matches what it should be based on the private key). The change I propose avoids all of those issues. Additionally, integrating the change is highly localized since there is so little code that relies on the RSA key data. Public keys can be generated from private keys which allows us to avoid the public key file altogether. By _always_ generating the public key from the private key data, we don't have to worry about an invalid public key file. The job is then to read or create/write the private key file using only a single operation avoiding TOCTOU race conditions. The below code relies on std::sync::OnceLock, but it would be trivial to adjust it to use once_cell::sync::Lazy. …

No pledges yet. Be the first to back this.

Make a pledge

Pledge your monetary support if this feature is added.

$

Comments

No comments yet.

Replying to

Add a comment

What do you think about this feature request?


Similar requests