Implement valid parameter for RemoteCallbacks::certificate_check #1146
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.
In the RemoteCallbacks struct documentation, the certificate_check function has this description:
However, this statement is false. It turns out that this function never actually checks if the certificate is valid using the
cert_valid
parameter passed intocertificate_check_cb
from thecheck_certificate
function in libgit2. As a result, when a callback function is specified, the function will always run regardless if libgit2 marks it valid.I made the change in the function specified to skip the callback if the certificate is valid (
valid = 1
). Before, any SSH remotes would run this callback, and now only hosts that do not appear in my hosts file (~/.ssh/known_hosts
) will result in the callback being ran.If there are any changes I need to make, let me know! :)