164 lines
5.2 KiB
Ruby
164 lines
5.2 KiB
Ruby
class Gnutls < Formula
|
|
desc "GNU Transport Layer Security (TLS) Library"
|
|
homepage "https://gnutls.org/"
|
|
url "https://www.gnupg.org/ftp/gcrypt/gnutls/v3.6/gnutls-3.6.15.tar.xz"
|
|
mirror "https://www.mirrorservice.org/sites/ftp.gnupg.org/gcrypt/gnutls/v3.6/gnutls-3.6.15.tar.xz"
|
|
sha256 "0ea8c3283de8d8335d7ae338ef27c53a916f15f382753b174c18b45ffd481558"
|
|
# license "LGPL-2.1-or-later AND GPL-3.0-only" - review syntax after resolving https://github.com/Homebrew/brew/pull/8260
|
|
license "GPL-3.0-only"
|
|
|
|
livecheck do
|
|
url "https://www.gnupg.org/ftp/gcrypt/gnutls/v3.6/"
|
|
regex(/href=.*?gnutls[._-]v?(\d+(?:\.\d+)+)\.t/i)
|
|
end
|
|
|
|
bottle do
|
|
rebuild 1
|
|
sha256 arm64_big_sur: "2be786f86b84f77ce5d9c15d4f059a240b4284039109a383b3a1d47f32ace17f"
|
|
sha256 big_sur: "72bc4290e20b342e85f6cc0e02f2d780eeff11bb1a9c40a4eb4473512ff09d9b"
|
|
sha256 catalina: "774fe85d6dfd00e5882258eeaf5edc81e98bf4d074b7fe49a52bcf116e50bc8a"
|
|
sha256 mojave: "0add13d231debe9e8a941f0295c09b87446127ca69bb2c67a069ac17cf6da858"
|
|
end
|
|
|
|
depends_on "autoconf" => :build
|
|
depends_on "automake" => :build
|
|
depends_on "pkg-config" => :build
|
|
depends_on "gmp"
|
|
depends_on "guile"
|
|
depends_on "libidn2"
|
|
depends_on "libtasn1"
|
|
depends_on "libunistring"
|
|
depends_on "nettle"
|
|
depends_on "p11-kit"
|
|
depends_on "unbound"
|
|
|
|
on_linux do
|
|
depends_on "autogen" => :build
|
|
|
|
resource "cacert" do
|
|
# homepage "http://curl.haxx.se/docs/caextract.html"
|
|
url "https://curl.haxx.se/ca/cacert-2020-01-01.pem"
|
|
mirror "https://gist.githubusercontent.com/dawidd6/16d94180a019f31fd31bc679365387bc/raw/ef02c78b9d6427585d756528964d18a2b9e318f7/cacert-2020-01-01.pem"
|
|
sha256 "adf770dfd574a0d6026bfaa270cb6879b063957177a991d453ff1d302c02081f"
|
|
end
|
|
end
|
|
|
|
def install
|
|
# Fix build with Xcode 12
|
|
# https://gitlab.com/gnutls/gnutls/-/issues/1116
|
|
ENV.append "CFLAGS", "-Wno-implicit-function-declaration"
|
|
|
|
args = %W[
|
|
--disable-dependency-tracking
|
|
--disable-silent-rules
|
|
--disable-static
|
|
--prefix=#{prefix}
|
|
--sysconfdir=#{etc}
|
|
--with-default-trust-store-file=#{pkgetc}/cert.pem
|
|
--with-guile-site-dir=#{share}/guile/site/3.0
|
|
--with-guile-site-ccache-dir=#{lib}/guile/3.0/site-ccache
|
|
--with-guile-extension-dir=#{lib}/guile/3.0/extensions
|
|
--disable-heartbeat-support
|
|
--with-p11-kit
|
|
]
|
|
|
|
system "./configure", *args
|
|
# Adding LDFLAGS= to allow the build on Catalina 10.15.4
|
|
# See https://gitlab.com/gnutls/gnutls/-/issues/966
|
|
system "make", "LDFLAGS=", "install"
|
|
|
|
# certtool shadows the macOS certtool utility
|
|
mv bin/"certtool", bin/"gnutls-certtool"
|
|
mv man1/"certtool.1", man1/"gnutls-certtool.1"
|
|
end
|
|
|
|
def post_install
|
|
on_macos(&method(:macos_post_install))
|
|
on_linux(&method(:linux_post_install))
|
|
end
|
|
|
|
def macos_post_install
|
|
ohai "Regenerating CA certificate bundle from keychain, this may take a while..."
|
|
|
|
keychains = %w[
|
|
/Library/Keychains/System.keychain
|
|
/System/Library/Keychains/SystemRootCertificates.keychain
|
|
]
|
|
|
|
certs_list = `security find-certificate -a -p #{keychains.join(" ")}`
|
|
certs = certs_list.scan(
|
|
/-----BEGIN CERTIFICATE-----.*?-----END CERTIFICATE-----/m,
|
|
)
|
|
|
|
# Check that the certificate has not expired
|
|
valid_certs = certs.select do |cert|
|
|
IO.popen("openssl x509 -inform pem -checkend 0 -noout &>/dev/null", "w") do |openssl_io|
|
|
openssl_io.write(cert)
|
|
openssl_io.close_write
|
|
end
|
|
|
|
$CHILD_STATUS.success?
|
|
end
|
|
|
|
# Check that the certificate is trusted in keychain
|
|
trusted_certs = begin
|
|
tmpfile = Tempfile.new
|
|
|
|
valid_certs.select do |cert|
|
|
tmpfile.rewind
|
|
tmpfile.write cert
|
|
tmpfile.truncate cert.size
|
|
tmpfile.flush
|
|
IO.popen("/usr/bin/security verify-cert -l -L -R offline -c #{tmpfile.path} &>/dev/null")
|
|
|
|
$CHILD_STATUS.success?
|
|
end
|
|
ensure
|
|
tmpfile&.close!
|
|
end
|
|
|
|
pkgetc.mkpath
|
|
(pkgetc/"cert.pem").atomic_write(trusted_certs.join("\n") << "\n")
|
|
|
|
# Touch gnutls.go to avoid Guile recompilation.
|
|
# See https://github.com/Homebrew/homebrew-core/pull/60307#discussion_r478917491
|
|
touch "#{lib}/guile/3.0/site-ccache/gnutls.go"
|
|
end
|
|
|
|
def linux_post_install
|
|
# Download and install cacert.pem from curl.haxx.se
|
|
cacert = resource("cacert")
|
|
cacert.fetch
|
|
|
|
rm_f pkgetc/"cert.pem"
|
|
filename = Pathname.new(cacert.url).basename
|
|
pkgetc.install cacert.files(filename => "cert.pem")
|
|
end
|
|
|
|
def caveats
|
|
<<~EOS
|
|
If you are going to use the Guile bindings you will need to add the following
|
|
to your .bashrc or equivalent in order for Guile to find the TLS certificates
|
|
database:
|
|
export GUILE_TLS_CERTIFICATE_DIRECTORY=#{pkgetc}/
|
|
EOS
|
|
end
|
|
|
|
test do
|
|
system bin/"gnutls-cli", "--version"
|
|
|
|
gnutls = testpath/"gnutls.scm"
|
|
gnutls.write <<~EOS
|
|
(use-modules (gnutls))
|
|
(gnutls-version)
|
|
EOS
|
|
|
|
ENV["GUILE_AUTO_COMPILE"] = "0"
|
|
ENV["GUILE_LOAD_PATH"] = HOMEBREW_PREFIX/"share/guile/site/3.0"
|
|
ENV["GUILE_LOAD_COMPILED_PATH"] = HOMEBREW_PREFIX/"lib/guile/3.0/site-ccache"
|
|
ENV["GUILE_SYSTEM_EXTENSIONS_PATH"] = HOMEBREW_PREFIX/"lib/guile/3.0/extensions"
|
|
|
|
system "guile", gnutls
|
|
end
|
|
end
|