homebrew-core/Formula/openssl@3.rb

140 lines
4.8 KiB
Ruby

class OpensslAT3 < Formula
desc "Cryptography and SSL/TLS Toolkit"
homepage "https://openssl.org/"
url "https://www.openssl.org/source/openssl-3.0.8.tar.gz"
mirror "https://www.mirrorservice.org/sites/ftp.openssl.org/source/openssl-3.0.8.tar.gz"
sha256 "6c13d2bf38fdf31eac3ce2a347073673f5d63263398f1f69d0df4a41253e4b3e"
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: "3a576758de58e46ca049346325742f110e2a84d7ae654122580fa70bcf3a91c3"
sha256 arm64_monterey: "b1177335a5c642149b309216e232ee225d168fa2b6a1a1d3c44ac5dcff2a16a9"
sha256 arm64_big_sur: "67fb79dc4e02d553502da10315c7e4edbb844166c57402dcef0b2efff6e78b08"
sha256 ventura: "5b747cbf1a81b5c36fd2966e4cc43d02178169382e67bbbb96a474b156483a8c"
sha256 monterey: "28092f3942190ca9e52c13e435bd66445591a12049794cd7100851a982c11a66"
sha256 big_sur: "3ad55b2a45721a680a869c8b054f3afaf8a43425fe85af8f1c3d0f90cad59228"
sha256 x86_64_linux: "81893a7f88f4a030857d3d2ded14419cba19300d7c9d4a1da9d16d7f5df039e3"
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
# 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