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 minimum curl version isn't installed #16078

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions Library/Homebrew/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ def self.fetch_json_api_file(endpoint, target: HOMEBREW_CACHE_API/endpoint,
--speed-time #{ENV.fetch("HOMEBREW_CURL_SPEED_TIME")}
]

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?
insecure_download = DevelopmentTools.ca_file_substitution_required? ||
DevelopmentTools.curl_substitution_required?
skip_download = target.exist? &&
!target.empty? &&
(!Homebrew.auto_update_command? ||
Expand All @@ -69,9 +68,7 @@ def self.fetch_json_api_file(endpoint, target: HOMEBREW_CACHE_API/endpoint,
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."
opoo DevelopmentTools.insecure_download_warning(endpoint)
args.append("--insecure")
end
unless skip_download
Expand Down
19 changes: 19 additions & 0 deletions Library/Homebrew/development_tools.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ def custom_installation_instructions
installation_instructions
end

sig { params(resource: String).returns(String) }
def insecure_download_warning(resource)
package = curl_handles_most_https_certificates? ? "ca-certificates" : "curl"
"Using `--insecure` with curl to download #{resource} because we need it to run " \
"`brew install #{package}` in order to download securely from now on. " \
"Checksums will still be verified."
end

sig { returns(Symbol) }
def default_compiler
:clang
Expand Down Expand Up @@ -123,6 +131,17 @@ def curl_handles_most_https_certificates?
true
end

sig { returns(T::Boolean) }
def ca_file_substitution_required?
(!ca_file_handles_most_https_certificates? || ENV["HOMEBREW_FORCE_BREWED_CA_CERTIFICATES"].present?) &&
!(HOMEBREW_PREFIX/"etc/ca-certificates/cert.pem").exist?
end

sig { returns(T::Boolean) }
def curl_substitution_required?
!curl_handles_most_https_certificates? && !HOMEBREW_BREWED_CURL_PATH.exist?
end

sig { returns(T::Boolean) }
def subversion_handles_most_https_certificates?
true
Expand Down
4 changes: 1 addition & 3 deletions Library/Homebrew/download_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -577,9 +577,7 @@ def _curl_args

if meta[:insecure]
unless @insecure_warning_shown
opoo "Using --insecure with curl to download `ca-certificates` " \
"because we need it installed to download securely from now on. " \
"Checksums will still be verified."
opoo DevelopmentTools.insecure_download_warning("an updated certificates file")
@insecure_warning_shown = true
end
args += ["--insecure"]
Expand Down
3 changes: 2 additions & 1 deletion Library/Homebrew/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def owner=(owner)
return if !owner.respond_to?(:full_name) || owner.full_name != "ca-certificates"
return if Homebrew::EnvConfig.no_insecure_redirect?

@insecure = !specs[:bottle] && !DevelopmentTools.ca_file_handles_most_https_certificates?
@insecure = !specs[:bottle] && (DevelopmentTools.ca_file_substitution_required? ||
DevelopmentTools.curl_substitution_required?)
return if @url.nil?

specs = if @insecure
Expand Down