homebrew-core/Formula/openssl@3.rb

147 lines
5.1 KiB
Ruby

class OpensslAT3 < Formula
desc "Cryptography and SSL/TLS Toolkit"
homepage "https://openssl.org/"
url "https://www.openssl.org/source/openssl-3.0.5.tar.gz"
mirror "https://www.mirrorservice.org/sites/ftp.openssl.org/source/openssl-3.0.5.tar.gz"
sha256 "aa7d8d9bef71ad6525c55ba11e5f4397889ce49c2c9349dcea6d3e4f0b024a7a"
license "Apache-2.0"
livecheck do
url "https://www.openssl.org/source/"
regex(/href=.*?openssl[._-]v?(\d+(?:\.\d+)+)\.t/i)
end
bottle do
sha256 arm64_ventura: "b6194e7a041f88680476e04db1ac8b96b5fd5ff0b824fe24d84405f92763f00f"
sha256 arm64_monterey: "d0cc00946bd11f14e1e0f94ce7c29ca63e7fdff96afb3f96951c14f4dbfc482e"
sha256 arm64_big_sur: "60950a4abfbe517a6963d942ae4c9e0b3a80f1ed5f5b1fcf9a0b1630a53db1e8"
sha256 monterey: "c4de05580e98de88ece952f04d2ea019d89043379d44a18970cf4a1e9d93c825"
sha256 big_sur: "48baa0e598f96f1dd372f6b77b39a1469d8fc45cff16117352765e180722e072"
sha256 catalina: "2466bab3013e761e6e4f0ef1aae456c5fe7421a17c9510b415542182dad36e04"
sha256 x86_64_linux: "9e4c842e82226949373f642476bc26ec7a04ed5e7714d6c4f8d79041eabd0220"
end
keg_only :shadowed_by_macos, "macOS provides LibreSSL"
depends_on "ca-certificates"
on_linux do
keg_only "it conflicts with the `openssl@1.1` formula"
resource "Test::Harness" do
url "https://cpan.metacpan.org/authors/id/L/LE/LEONT/Test-Harness-3.42.tar.gz"
sha256 "0fd90d4efea82d6e262e6933759e85d27cbcfa4091b14bf4042ae20bab528e53"
end
resource "Test::More" do
url "https://cpan.metacpan.org/authors/id/E/EX/EXODIST/Test-Simple-1.302186.tar.gz"
sha256 "2895c8da7c3fe632e5714c7cc548705202cdbf3afcbc0e929bc5e6a5172265d4"
end
resource "ExtUtils::MakeMaker" do
url "https://cpan.metacpan.org/authors/id/B/BI/BINGOS/ExtUtils-MakeMaker-7.62.tar.gz"
sha256 "5022ad857fd76bd3f6b16af099fe2324639d9932e08f21e891fb313d9cae1705"
end
end
# Fix compile on older macOS (Xcode 10.1 and earlier).
# Remove with the next release.
patch do
url "https://github.com/openssl/openssl/commit/c95e2030c34646176b4843b5f0f48720d896f427.patch?full_index=1"
sha256 "91b4ef7049aec75bd3c2784472b70652cc1bad60e66f6a7129d5061d6004af43"
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
def install
if OS.linux?
ENV.prepend_create_path "PERL5LIB", libexec/"lib/perl5"
%w[ExtUtils::MakeMaker Test::Harness Test::More].each do |r|
resource(r).stage do
system "perl", "Makefile.PL", "INSTALL_BASE=#{libexec}"
system "make", "PERL5LIB=#{ENV["PERL5LIB"]}", "CC=#{ENV.cc}"
system "make", "install"
end
end
end
# This could interfere with how we expect OpenSSL to build.
ENV.delete("OPENSSL_LOCAL_CONFIG_DIR")
# 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["perl"].opt_bin/"perl" if which("perl") == Formula["perl"].opt_bin/"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"
system "make", "test"
end
def openssldir
etc/"openssl@3"
end
def post_install
rm_f openssldir/"cert.pem"
openssldir.install_symlink Formula["ca-certificates"].pkgetc/"cert.pem"
end
def caveats
<<~EOS
A CA file has been bootstrapped using certificates from the system
keychain. 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_predicate pkgetc/"openssl.cnf", :exist?,
"OpenSSL requires the .cnf file for some functionality"
# 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
end
end