Skip to content
This repository has been archived by the owner on Sep 29, 2024. It is now read-only.

Avoid caching PEMs on disk #213

Merged
merged 7 commits into from
Oct 13, 2021

Conversation

roop
Copy link
Contributor

@roop roop commented Aug 24, 2021

Previously, the CA key, the client certificate and client key were stored as PEMs on disk for invoking OpenSSL calls.

This PR uses the equivalent OpenSSL calls that operate on in-memory data, thereby avoiding writing these sensitive data to disk at all. (Previously discussed in PR #203.)

@keeshux keeshux self-assigned this Aug 25, 2021
@keeshux keeshux added this to the 3.5.0 milestone Aug 25, 2021
@keeshux keeshux added the enhancement New feature or request label Aug 25, 2021
@keeshux keeshux merged commit 00d908c into passepartoutvpn:master Oct 13, 2021
keeshux added a commit that referenced this pull request Nov 18, 2021
if (error) {
*error = TunnelKitErrorWithCode(TunnelKitErrorCodeTLSCertificateAuthority);

if (self.caPEM) {
Copy link
Member

@keeshux keeshux Nov 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roop I trusted you on this bit (L249-261), but the replaced logic doesn't seem equivalent. The change broke TLS handshake on certain devices (Synology, pfSense etc.):

https://www.reddit.com/r/passepartout/comments/qvegv3/unable_to_connect_after_update_to_1170/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@keeshux Sorry about the regression.

This is my understanding:

  • Old: SSL_CTX_load_verify_locations(ctx, caPath, NULL) says that the file at caPath should be trusted when performing verification
  • New: Use SSL_CTX_get_cert_store to get the trusted store and add the ca to it with X509_STORE_add_cert

The man page for SSL_CTX_get_cert_store says:

Typically the trusted certificate store is handled indirectly via using SSL_CTX_load_verify_locations(3). Using the SSL_CTX_set_cert_store() and SSL_CTX_get_cert_store() functions it is possible to manipulate the X509_STORE object beyond the SSL_CTX_load_verify_locations(3) call.

That's why I thought this was the appropriate replacement.

if (error) {
*error = TunnelKitErrorWithCode(TunnelKitErrorCodeTLSCertificateAuthority);
}
return NO;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to L274, ca should also be deallocated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Good catch.

keeshux added a commit that referenced this pull request Nov 25, 2021
keeshux added a commit that referenced this pull request Nov 26, 2021
Revert part of #213 again, because `SSL_CTX_load_verify_locations`
is just more reliable at setting up the trust store.

It looks like it's able to reference the .pem multiple times in
those cases where the root issuer of the CA is also embedded in
the file (which is the case with e.g. Let's Encrypt).

This is better than the current implementation, and I couldn't
easily find a way to do the same in-memory. I'd rather use the
standard API here.

See 7a85d3c
keeshux added a commit that referenced this pull request Nov 27, 2021
* Verify CA from on-disk file

Revert part of #213 again, because `SSL_CTX_load_verify_locations`
is just more reliable at setting up the trust store.

It looks like it's able to reference the .pem multiple times in
those cases where the root issuer of the CA is also embedded in
the file (which is the case with e.g. Let's Encrypt).

This is better than the current implementation, and I couldn't
easily find a way to do the same in-memory. I'd rather use the
standard API here.

See 7a85d3c
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants