HwangDongJun commented on code in PR #12831: URL: https://github.com/apache/gluten/pull/12831#discussion_r4369322573
########## cpp/velox/utils/TlsTrustStore.cc: ########## @@ -0,0 +1,126 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +#include "utils/TlsTrustStore.h" + +#include <glog/logging.h> +#include <cctype> +#include <cstdlib> +#include <filesystem> + +namespace gluten { + +namespace { + +namespace fs = std::filesystem; + +bool isRegularFile(const std::string& path) { + std::error_code ec; + return fs::is_regular_file(path, ec) && !ec; +} + +// OpenSSL finds certificates in a directory only through files named <8 hex digits>.<digit>, created by +// `openssl rehash`. +bool isHashedCertificateName(const std::string& name) { + if (name.size() < 10 || name[8] != '.') { + return false; + } + for (size_t i = 0; i < 8; ++i) { + if (!std::isxdigit(static_cast<unsigned char>(name[i]))) { + return false; + } + } + for (size_t i = 9; i < name.size(); ++i) { + if (!std::isdigit(static_cast<unsigned char>(name[i]))) { + return false; + } + } + return true; +} + +bool hasHashedCertificate(const std::string& dir) { + std::error_code ec; + fs::directory_iterator it(dir, fs::directory_options::skip_permission_denied, ec); + if (ec) { + return false; + } + for (const auto& entry : it) { + if (isHashedCertificateName(entry.path().filename().string())) { + return true; + } + } + return false; +} + +std::optional<std::string> getEnv(const char* name) { + const char* value = std::getenv(name); + return value != nullptr ? std::optional<std::string>(value) : std::nullopt; +} + +} // namespace + +const TlsSearchPaths& systemTlsSearchPaths() { + static const TlsSearchPaths paths{ + "/etc/ssl/cert.pem", + "/etc/ssl/certs", + { + "/etc/ssl/certs/ca-certificates.crt", // Debian, Ubuntu, Alpine + "/etc/pki/tls/certs/ca-bundle.crt", // RHEL, CentOS, Rocky, Alma, Fedora + "/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem", // RHEL family, what the link above points to + "/etc/ssl/ca-bundle.pem", // openSUSE + }}; + return paths; +} Review Comment: Update: changed after all, in c819e9c1a. The defaults are now read with X509_get_default_cert_file() / X509_get_default_cert_dir(), and the OpenSSL include directories are taken from the OpenSSL::Crypto target (or OPENSSL_INCLUDE_DIR). This matters for a VCPKG_DYNAMIC_OPENSSL=ON build, where the system OpenSSL can have another openssldir. CI on my fork compiles it for x86 and ARM, and the unit tests pass. In the pods the statically linked OpenSSL returns /etc/ssl/cert.pem and /etc/ssl/certs on Rocky 8.9/9.3, AlmaLinux 8.10 and Ubuntu 22.04/24.04, so nothing changes there. I could not test a dynamic OpenSSL build. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
