cloudflare / quiche

🥧 Savoury implementation of the QUIC transport protocol and HTTP/3
https://docs.quic.tech/quiche/
BSD 2-Clause "Simplified" License
9.4k stars 709 forks source link

Private key files from boringSSL filling up /tmp #1181

Open amituttam opened 2 years ago

amituttam commented 2 years ago

In our project, we notice /tmp is being filled up with private key files, seemingly from boringssl and coming from the wrapper here: https://github.com/cloudflare/quiche/blob/bc963d1804d6c74c3a5011d4b498e008bbb35333/quiche/src/tls.rs#L206

So quiche wraps boringssl directly, and only wraps SSL_CTX_use_PrivateKey_file. The API in boringssl for loading from memory is a little funky, but it's approximately:

  BIO *bio = BIO_new_mem_buf(buf, len);
  EVP_PKEY pkey = PEM_read_bio_PrivateKey(bio, &pkey, NULL, NULL);

This could potentially also be temporarily hacked into our implementation, as quiche's tls::Context is a single element struct "newtype" around a boringssl context type, so it shares an ABI with the boringssl context type directly.

But wanted to reach out first in case there is a better way to handle our issue above.

I also noticed: https://github.com/cloudflare/quiche/commit/3204f89beed236f0ea458380ff0e196cbb4bf78e. Maybe that will help our case here?

SkateScout commented 2 years ago

The problem is not only in the interface from quiche to boringSSL. The same problem is also valid for jetty and any other tools that use quiche library. They need to store the private key on the filesystem in an decrypted form. This is an security issue since the private key should normally never be stored in decrypted form on the disc.

ghedo commented 2 years ago

I'd be ok to add methods to take certificates/keys from a memory buffer instead of disk, though I don't have time to look into it right now, but feel free to create a PR if you'd like to work on this.

kckeiks commented 2 years ago

After https://github.com/cloudflare/quiche/commit/3204f89beed236f0ea458380ff0e196cbb4bf78e was merged, you can just use boring's PKey::private_key_from_pem to read a private key from memory. In addition, there is also methods for reading the public key and certificates from memory. Would we still want to expose some methods to take certificates/keys from memory? It might not be necessary anymore.