WIP: Add ability to find the system CACert or explicitly define one yourself #57
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR defines two new functions, two lists, and two types.
Two consts:
cert_files
andcert_directories
which contain paths to the most common locations for Certificate Authority Certificates on various OS types.Since LibCURL isn't compiled to naturally know where the certs are on any given machine, I have written
find_system_cacert
as a way to search for a system cert based on known locations on various OS's/installations2 new types have been created for this.
CACertFile
which contains a string that defines a path to a specific pem/crt file, andCACertPath
which contains a string that defines a path to a directory that contains pem/crt files. I decided to use two different types as there are 2 different commands in LibCURL to set the file path vs the directory path, and thus by using these types we can leverage multiple dispatch to use the correct function.find_system_cacert
will return aCACertFile
or aCACertPath
depending on what location it finds the certs in. If it can't seem to find any system certs at all, it will return withnothing
, and the user must check against it returning nothing and handle the errors themselves.On top of this, I have defined
enable_cacert
which is a function that takes in a curlhandle
and either aCACertFile
orCACertPath
and applies the path using the correct LibCURL function to the handle so that any future requests with that handle will use the certificate that was found.