class Stunnel < Formula desc "SSL tunneling program" homepage "https://www.stunnel.org/" url "https://www.stunnel.org/downloads/stunnel-5.48.tar.gz" mirror "https://www.usenix.org.uk/mirrors/stunnel/stunnel-5.48.tar.gz" sha256 "1011d5a302ce6a227882d094282993a3187250f42f8a801dcc1620da63b2b8df" bottle do sha256 "01ae73172615ca22749bea0093c5fe89a0a9f92f425c4cef07fa762ea7823aee" => :mojave sha256 "37c2b508385452c8c54c8874818a1a5a20509aa5b2cef2aafe9d45dae9961967" => :high_sierra sha256 "8838a86eb1ebe0bf229a633c12bf1948dc4b7206a4123840b0ecc4fccf638e94" => :sierra sha256 "f64becc5edf56910fd10554209bc3b661be2617a08b050b306fba30e8c055db6" => :el_capitan end depends_on "openssl" def install system "./configure", "--disable-dependency-tracking", "--disable-silent-rules", "--prefix=#{prefix}", "--sysconfdir=#{etc}", "--localstatedir=#{var}", "--mandir=#{man}", "--disable-libwrap", "--disable-systemd", "--with-ssl=#{Formula["openssl"].opt_prefix}" system "make", "install" # This programmatically recreates pem creation used in the tools Makefile # which would usually require interactivity to resolve. cd "tools" do args = %w[req -new -x509 -days 365 -rand stunnel.rnd -config openssl.cnf -out stunnel.pem -keyout stunnel.pem -sha256 -subj /C=PL/ST=Mazovia\ Province/L=Warsaw/O=Stunnel\ Developers/OU=Provisional\ CA/CN=localhost/] system "dd", "if=/dev/urandom", "of=stunnel.rnd", "bs=256", "count=1" system "#{Formula["openssl"].opt_bin}/openssl", *args chmod 0600, "stunnel.pem" (etc/"stunnel").install "stunnel.pem" end end def caveats <<~EOS A bogus SSL server certificate has been installed to: #{etc}/stunnel/stunnel.pem This certificate will be used by default unless a config file says otherwise! Stunnel will refuse to load the sample configuration file if left unedited. In your stunnel configuration, specify a SSL certificate with the "cert =" option for each service. EOS end test do (testpath/"tstunnel.conf").write <<~EOS cert = #{etc}/stunnel/stunnel.pem setuid = nobody setgid = nobody [pop3s] accept = 995 connect = 110 [imaps] accept = 993 connect = 143 EOS assert_match "successful", pipe_output("#{bin}/stunnel #{testpath}/tstunnel.conf 2>&1") end end