api: ignore HTTPS errors if required certs aren't installed

This commit is contained in:
Eric Knibbe 2023-08-21 21:48:36 -04:00
parent 5eaa9f995b
commit 70e676c176
No known key found for this signature in database
GPG Key ID: 179D9CDDDB814168

View File

@ -58,6 +58,9 @@ module Homebrew
curl_args << "--verbose" if Homebrew::EnvConfig.curl_verbose? curl_args << "--verbose" if Homebrew::EnvConfig.curl_verbose?
curl_args << "--silent" if !$stdout.tty? || Context.current.quiet? curl_args << "--silent" if !$stdout.tty? || Context.current.quiet?
insecure_download = (ENV["HOMEBREW_SYSTEM_CA_CERTIFICATES_TOO_OLD"].present? ||
ENV["HOMEBREW_FORCE_BREWED_CA_CERTIFICATES"].present?) &&
!(HOMEBREW_PREFIX/"etc/ca-certificates/cert.pem").exist?
skip_download = target.exist? && skip_download = target.exist? &&
!target.empty? && !target.empty? &&
(!Homebrew.auto_update_command? || (!Homebrew.auto_update_command? ||
@ -69,6 +72,12 @@ module Homebrew
begin begin
args = curl_args.dup args = curl_args.dup
args.prepend("--time-cond", target.to_s) if target.exist? && !target.empty? args.prepend("--time-cond", target.to_s) if target.exist? && !target.empty?
if insecure_download
opoo "Using --insecure with curl to download #{endpoint} " \
"because we need it to run `brew install ca-certificates`. " \
"Checksums will still be verified."
args.append("--insecure")
end
unless skip_download unless skip_download
ohai "Downloading #{url}" if $stdout.tty? && !Context.current.quiet? ohai "Downloading #{url}" if $stdout.tty? && !Context.current.quiet?
# Disable retries here, we handle them ourselves below. # Disable retries here, we handle them ourselves below.
@ -91,7 +100,8 @@ module Homebrew
opoo "#{target.basename}: update failed, falling back to cached version." opoo "#{target.basename}: update failed, falling back to cached version."
end end
FileUtils.touch(target) unless skip_download mtime = insecure_download ? Time.new(1970, 1, 1) : Time.now
FileUtils.touch(target, mtime: mtime) unless skip_download
JSON.parse(target.read) JSON.parse(target.read)
rescue JSON::ParserError rescue JSON::ParserError
target.unlink target.unlink