Skip to content

Commit

Permalink
api: ignore HTTPS errors if required certs aren't installed
Browse files Browse the repository at this point in the history
  • Loading branch information
EricFromCanada committed Aug 22, 2023
1 parent 5eaa9f9 commit 70e676c
Showing 1 changed file with 11 additions and 1 deletion.
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 @@ def self.fetch_json_api_file(endpoint, target: HOMEBREW_CACHE_API/endpoint,
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 @@ def self.fetch_json_api_file(endpoint, target: HOMEBREW_CACHE_API/endpoint,
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 @@ def self.fetch_json_api_file(endpoint, target: HOMEBREW_CACHE_API/endpoint,
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

0 comments on commit 70e676c

Please sign in to comment.