homebrew-core/Formula/openssl@1.1.rb
Mike McQuaid da92c2e244 openssl@1.1: don't print certificate messages. (#6800)
Otherwise you get screenfuls of "Certificate will (not) expire".
2016-11-11 07:29:32 +00:00

177 lines
5.7 KiB
Ruby

class OpensslAT11 < Formula
desc "Cryptography and SSL/TLS Toolkit"
homepage "https://openssl.org/"
url "https://www.openssl.org/source/openssl-1.1.0c.tar.gz"
mirror "https://www.mirrorservice.org/sites/ftp.openssl.org/source/openssl-1.1.0c.tar.gz"
sha256 "fc436441a2e05752d31b4e46115eb89709a28aef96d4fe786abe92409b2fd6f5"
version_scheme 1
bottle do
sha256 "bd582f23920475e5dee6aeaab79d9af9d6bd5592f534bc07e10cf41d1bc1ac43" => :sierra
sha256 "528ab5f19b4f5b08d8cc921ee0675515c50f1e870a10de7bac2fea1a4062c0c1" => :el_capitan
sha256 "34d106f1b300d4b192757941febde26cba194d903c5683d09df8b7328ce04215" => :yosemite
end
keg_only :provided_by_osx,
"Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries"
option :universal
option "without-test", "Skip build-time tests (not recommended)"
# Only needs 5.10 to run, but needs >5.13.4 to run the testsuite.
# https://github.com/openssl/openssl/blob/4b16fa791d3ad8/README.PERL
# The MacOS ML tag is same hack as the way we handle most :python deps.
if build.with? "test"
depends_on :perl => "5.14" if MacOS.version <= :mountain_lion
else
depends_on :perl => "5.10"
end
def arch_args
{
:x86_64 => %w[darwin64-x86_64-cc enable-ec_nistp_64_gcc_128],
:i386 => %w[darwin-i386-cc],
}
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; %W[
--prefix=#{prefix}
--openssldir=#{openssldir}
no-ssl3
no-ssl3-method
no-zlib
]
end
def install
# 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.
if which("perl") == Formula["perl"].opt_bin/"perl"
ENV["PERL"] = Formula["perl"].opt_bin/"perl"
end
if build.universal?
ENV.permit_arch_flags
archs = Hardware::CPU.universal_archs
elsif MacOS.prefer_64_bit?
archs = [Hardware::CPU.arch_64_bit]
else
archs = [Hardware::CPU.arch_32_bit]
end
dirs = []
archs.each do |arch|
if build.universal?
dir = "build-#{arch}"
dirs << dir
mkdir dir
mkdir "#{dir}/engines"
end
ENV.deparallelize
system "perl", "./Configure", *(configure_args + arch_args[arch])
system "make", "clean" if build.universal?
system "make"
system "make", "test" if build.with?("test")
next unless build.universal?
cp "include/openssl/opensslconf.h", dir
cp Dir["*.?.?.dylib", "*.a", "apps/openssl"], dir
cp Dir["engines/**/*.dylib"], "#{dir}/engines"
end
system "make", "install", "MANDIR=#{man}", "MANSUFFIX=ssl"
if build.universal?
%w[libcrypto libssl].each do |libname|
system "lipo", "-create", "#{dirs.first}/#{libname}.1.1.dylib",
"#{dirs.last}/#{libname}.1.1.dylib",
"-output", "#{lib}/#{libname}.1.1.dylib"
system "lipo", "-create", "#{dirs.first}/#{libname}.a",
"#{dirs.last}/#{libname}.a",
"-output", "#{lib}/#{libname}.a"
end
Dir.glob("#{dirs.first}/engines/*.dylib") do |engine|
libname = File.basename(engine)
system "lipo", "-create", "#{dirs.first}/engines/#{libname}",
"#{dirs.last}/engines/#{libname}",
"-output", "#{lib}/engines-1.1/#{libname}"
end
system "lipo", "-create", "#{dirs.first}/openssl",
"#{dirs.last}/openssl",
"-output", "#{bin}/openssl"
confs = archs.map do |arch|
<<-EOS.undent
#ifdef __#{arch}__
#{(buildpath/"build-#{arch}/opensslconf.h").read}
#endif
EOS
end
(include/"openssl/opensslconf.h").atomic_write confs.join("\n")
end
end
def openssldir
etc/"openssl@1.1"
end
def post_install
keychains = %w[
/System/Library/Keychains/SystemRootCertificates.keychain
]
certs_list = `security find-certificate -a -p #{keychains.join(" ")}`
certs = certs_list.scan(
/-----BEGIN CERTIFICATE-----.*?-----END CERTIFICATE-----/m
)
valid_certs = certs.select do |cert|
IO.popen("#{bin}/openssl x509 -inform pem -checkend 0 -noout >/dev/null", "w") do |openssl_io|
openssl_io.write(cert)
openssl_io.close_write
end
$?.success?
end
openssldir.mkpath
(openssldir/"cert.pem").atomic_write(valid_certs.join("\n"))
end
def caveats; <<-EOS.undent
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 (HOMEBREW_PREFIX/"etc/openssl@1.1/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