From 040f9a000aa8dd5f9217d7865fd3652bdb2bdc65 Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Mon, 13 Feb 2023 15:22:58 +0100 Subject: Git: Add utility method for honoring SSL certification settings in libgit2 calls Due to the fact that the libgit2 library handles envariables and gitconfig entries differently than git, we need to perform these checks ourselves in order to be fully compliant with git. This utility method returns the correct callback tat enables or disables the SSL certificate verification step when interacting with a remote URL via libgit2 calls. --- .../git_operations/git_config_settings.hpp | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/other_tools/git_operations/git_config_settings.hpp (limited to 'src/other_tools/git_operations/git_config_settings.hpp') diff --git a/src/other_tools/git_operations/git_config_settings.hpp b/src/other_tools/git_operations/git_config_settings.hpp new file mode 100644 index 00000000..8aa412e8 --- /dev/null +++ b/src/other_tools/git_operations/git_config_settings.hpp @@ -0,0 +1,49 @@ +// Copyright 2023 Huawei Cloud Computing Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef INCLUDED_SRC_OTHER_TOOLS_GIT_OPERATIONS_GIT_CONFIG_SETTINGS_HPP +#define INCLUDED_SRC_OTHER_TOOLS_GIT_OPERATIONS_GIT_CONFIG_SETTINGS_HPP + +#include +#include +#include +#include + +extern "C" { +struct git_cert; +struct git_config; +using git_transport_certificate_check_cb = auto (*)(git_cert*, + int, + const char*, + void*) -> int; +} + +// Internal type used for logging with AsyncMaps +using anon_logger_t = std::function; +using anon_logger_ptr = std::shared_ptr; + +namespace GitConfigSettings { + +/// \brief Get a custom SSL certificate check callback to honor the existing +/// Git configuration of a repository trying to connect to a remote. +/// A null config snapshot reference will simply be ignored. +/// Returns nullopt if errors. +[[nodiscard]] auto GetSSLCallback(std::shared_ptr const& cfg, + std::string const& url, + anon_logger_ptr const& logger) + -> std::optional; + +} // namespace GitConfigSettings + +#endif // INCLUDED_SRC_OTHER_TOOLS_GIT_OPERATIONS_GIT_CONFIG_SETTINGS_HPP -- cgit v1.2.3