Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion Library/Homebrew/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
curl_args << "--verbose" if Homebrew::EnvConfig.curl_verbose?
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?

Check warning on line 63 in Library/Homebrew/api.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/api.rb#L63

Added line #L63 was not covered by tests
skip_download = target.exist? &&
!target.empty? &&
(!Homebrew.auto_update_command? ||
Expand All @@ -69,6 +72,12 @@
begin
args = curl_args.dup
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")

Check warning on line 79 in Library/Homebrew/api.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/api.rb#L79

Added line #L79 was not covered by tests
end
unless skip_download
ohai "Downloading #{url}" if $stdout.tty? && !Context.current.quiet?
# Disable retries here, we handle them ourselves below.
Expand All @@ -91,7 +100,8 @@
opoo "#{target.basename}: update failed, falling back to cached version."
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)
rescue JSON::ParserError
target.unlink
Expand Down