class OpensslAT3 < Formula desc "Cryptography and SSL/TLS Toolkit" homepage "https://openssl-library.org" url "https://github.com/openssl/openssl/releases/download/openssl-3.5.9/openssl-3.5.9.tar.gz" sha256 "603f5602e2eef00d77fbd429d34dcd5822bb301757a1bc9cdb24c670f1eb859a" license "Apache-2.0" version_scheme 1 compatibility_version 1 livecheck do url "https://openssl-library.org/source/" regex(/href=.*?openssl[._-]v?(3\.5(?:\.\d+)+)\.t/i) end bottle do sha256 arm64_golden_gate: "dcc989315a2efd06ca4a3fac5c33c237897a1059ed74f35c464a8967ffbb8aaf" sha256 arm64_tahoe: "e8d7a91a0599aca7c82b63ff708bde97b6c1535f6b74c951ac89e4e55d571872" sha256 arm64_sequoia: "82b33ce156b289eaf95657b9ec16e8f49cb49c882cdeaeaf57e3e7d67fa85e25" sha256 arm64_linux: "6c0de70f833c6fee4630c17f3412d953eebfe181ef643e7a823633932d30ce16" sha256 x86_64_linux: "279da65bfd7a9d068fd0a21863af4a4ede5bc837130df9acca2729c3d9b9b8ef" end keg_only :versioned_formula # https://openssl-library.org/post/2026-09-16-eol30/ # OpenSSL 3.5 is a LTS version deprecate! date: "2030-04-08", because: :unmaintained disable! date: "2031-04-08", because: :unmaintained depends_on "ca-certificates" => :no_linkage on_linux do resource "Test::Harness" do url "https://cpan.metacpan.org/authors/id/L/LE/LEONT/Test-Harness-3.52.tar.gz" sha256 "8fe65cfc0261ed3c8a4395f0524286f5719669fe305f9b03b16cf3684d62cd70" end resource "Test::More" do url "https://cpan.metacpan.org/authors/id/E/EX/EXODIST/Test-Simple-1.302224.tar.gz" sha256 "6c366b8ab03553976dd1813940770b60bdb4396e7bbae8c263baa6e96ec52fd7" end resource "ExtUtils::MakeMaker" do url "https://cpan.metacpan.org/authors/id/B/BI/BINGOS/ExtUtils-MakeMaker-7.78.tar.gz" sha256 "43b33c20f8d82dba7cc48f8cd702f8fc9811e9d07880886dfd31b7077bd4a3a6" end end # SSLv2 died with 1.1.0, so no-ssl2 no longer required. # SSLv3 & zlib are off by default with 1.1.0 but this may not # be obvious to everyone, so explicitly state it for now to # help debug inevitable breakage. def configure_args args = %W[ --prefix=#{prefix} --openssldir=#{openssldir} --libdir=lib no-ssl3 no-ssl3-method no-zlib ] on_linux do args += (ENV.cflags || "").split args += (ENV.cppflags || "").split args += (ENV.ldflags || "").split end args end # Tests require network access allow_network_access! :build def install if OS.linux? ENV.prepend_create_path "PERL5LIB", buildpath/"lib/perl5" ENV.prepend_path "PATH", buildpath/"bin" %w[ExtUtils::MakeMaker Test::Harness Test::More].each do |r| resource(r).stage do system "perl", "Makefile.PL", "INSTALL_BASE=#{buildpath}" system "make", "PERL5LIB=#{ENV["PERL5LIB"]}", "CC=#{ENV.cc}" system "make", "install" end end end # This ensures where Homebrew's Perl is needed the Cellar path isn't # hardcoded into OpenSSL's scripts, causing them to break every Perl update. # Whilst our env points to opt_bin, by default OpenSSL resolves the symlink. ENV["PERL"] = formula_opt_bin("perl")/"perl" if which("perl") == formula_opt_bin("perl")/"perl" arch_args = [] if OS.mac? arch_args += %W[darwin64-#{Hardware::CPU.arch}-cc enable-ec_nistp_64_gcc_128] elsif Hardware::CPU.intel? arch_args << (Hardware::CPU.is_64_bit? ? "linux-x86_64" : "linux-elf") elsif Hardware::CPU.arm? arch_args << (Hardware::CPU.is_64_bit? ? "linux-aarch64" : "linux-armv4") end openssldir.mkpath system "perl", "./Configure", *(configure_args + arch_args) system "make" system "make", "install", "MANDIR=#{man}", "MANSUFFIX=ssl" # AF_ALG support isn't always enabled (e.g. some containers), which breaks the tests. # AF_ALG is a kernel feature and failures are unlikely to be issues with the formula. # `test_quick_tserver` intermittently fails on CI. # It has been reported upstream with no resolution in over a year, so we skip it. system "make", "HARNESS_JOBS=#{ENV.make_jobs}", "test", "TESTS=-test_afalg -test_quic_tserver" if build.bottle? # Prevent `brew` from pruning the `certs` and `private` directories. touch %w[certs private].map { |subdir| openssldir/subdir/".keepme" } end def openssldir = pkgetc post_install_steps do symlink "{{etc}}/ca-certificates/cert.pem", "{{pkgetc}}/cert.pem", overwrite: true end def caveats <<~EOS To add additional certificates, place .pem files in #{openssldir}/certs and run #{opt_bin}/c_rehash EOS end test do # Make sure the necessary .cnf file exists, otherwise OpenSSL gets moody. assert_path_exists pkgetc/"openssl.cnf", "OpenSSL requires the .cnf file for some functionality" assert_path_exists openssldir/"certs", "OpenSSL throws confusing errors when this directory is missing" # Check OpenSSL itself functions as expected. (testpath/"testfile.txt").write("This is a test file") expected_checksum = "e2d0fe1585a63ec6009c8016ff8dda8b17719a637405a4e23c0ff81339148249" system bin/"openssl", "dgst", "-sha256", "-out", "checksum.txt", "testfile.txt" open("checksum.txt") do |f| checksum = f.read(100).split("=").last.strip assert_equal checksum, expected_checksum end # Invalid cert from superfish.badssl.com bad_cert = <<~PEM -----BEGIN CERTIFICATE----- MIIC9TCCAl6gAwIBAgIJAK5EmlK7Klu5MA0GCSqGSIb3DQEBCwUAMFsxGDAWBgNV BAoTD1N1cGVyZmlzaCwgSW5jLjELMAkGA1UEBxMCU0YxCzAJBgNVBAgTAkNBMQsw CQYDVQQGEwJVUzEYMBYGA1UEAxMPU3VwZXJmaXNoLCBJbmMuMB4XDTE4MDUxNjE3 MTUyM1oXDTIwMDUxNTE3MTUyM1owajELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNh bGlmb3JuaWExFjAUBgNVBAcMDVNhbiBGcmFuY2lzY28xDzANBgNVBAoMBkJhZFNT TDEdMBsGA1UEAwwUc3VwZXJmaXNoLmJhZHNzbC5jb20wggEiMA0GCSqGSIb3DQEB AQUAA4IBDwAwggEKAoIBAQDCBOz4jO4EwrPYUNVwWMyTGOtcqGhJsCK1+ZWesSss dj5swEtgTEzqsrTAD4C2sPlyyYYC+VxBXRMrf3HES7zplC5QN6ZnHGGM9kFCxUbT Focnn3TrCp0RUiYhc2yETHlV5NFr6AY9SBVSrbMo26r/bv9glUp3aznxJNExtt1N wMT8U7ltQq21fP6u9RXSM0jnInHHwhR6bCjqN0rf6my1crR+WqIW3GmxV0TbChKr 3sMPR3RcQSLhmvkbk+atIgYpLrG6SRwMJ56j+4v3QHIArJII2YxXhFOBBcvm/mtU mEAnhccQu3Nw72kYQQdFVXz5ZD89LMOpfOuTGkyG0cqFAgMBAAGjLjAsMAkGA1Ud EwQCMAAwHwYDVR0RBBgwFoIUc3VwZXJmaXNoLmJhZHNzbC5jb20wDQYJKoZIhvcN AQELBQADgYEAKgHH4VD3jfwzxvtWTmIA1nwK+Fjqe9VFXyDwXiBnhqDwJp9J+/2y r7jbXfEKf7WBS6OmnU+HTjxUCFx2ZnA4r7dU5nIsNadKEDVHDOvYEJ6mXHPkrvlt k79iHC0DJiJX36BTXcU649wKEVjgX/kT2yy3YScPdBoN0vtzPN3yFsQ= -----END CERTIFICATE----- PEM output = pipe_output("#{bin}/openssl verify 2>&1", bad_cert, 2) assert_match "verification failed", output refute_match "error:80000002", output end end