Skip to content

Instantly share code, notes, and snippets.

@minacle
Last active September 15, 2023 06:20
Show Gist options
  • Save minacle/e9dedb8c17025a23a453f8f30eced3da to your computer and use it in GitHub Desktop.
Save minacle/e9dedb8c17025a23a453f8f30eced3da to your computer and use it in GitHub Desktop.
**Please read my comment below**
class Chntpw < Formula
desc "The Offline NT Password Editor"
homepage "https://github.com/Tody-Guo/chntpw"
url "https://github.com/sidneys/chntpw/archive/0.99.6.tar.gz"
sha256 "e915f5addc2673317285c6f022c94da7fdee415d9800cd38540a13706706786b"
head "https://github.com/sidneys/chntpw.git"
depends_on "openssl@1.0"
patch do
url "https://gist.githubusercontent.com/minacle/87d11243b135b2041c945f1287d33d7e/raw/b75415c26a6cf55df354e0574543a8cd85caeef7/chntpw-0.99.6-opthomebrew.patch"
sha256 "dbf09ccee4eaf401e2680554990ee924bb0ad1dd7661a3c97d67bf796089fbbe"
end
deprecate! date: "2023-09-11", because: :deprecated_upstream
disable! date: "2023-11-11", because: :unsupported
def install
system "make"
bin.install "chntpw"
end
test do
assert_match "chntpw version 0.99.6 080526 (sixtyfour)", shell_output("#{bin}/chntpw -h")
end
end
class OpensslAT10 < Formula
desc "SSL/TLS cryptography library"
homepage "https://openssl.org/"
url "https://ftp.openssl.org/source/old/1.0.2/openssl-1.0.2u.tar.gz"
mirror "https://www.mirrorservice.org/sites/ftp.openssl.org/source/old/1.0.2/openssl-1.0.2u.tar.gz"
sha256 "ecd0c6ffb493dd06707d38b14bb4d8c2288bb7033735606569d8f90f89669d16"
version_scheme 1
patch do
url "https://gist.githubusercontent.com/felixbuenemann/5f4dcb30ebb3b86e1302e2ec305bac89/raw/b339a33ff072c9747df21e2558c36634dd62c195/openssl-1.0.2u-darwin-arm64.patch"
sha256 "4ad22bcfc85171a25f035b6fc47c7140752b9ed7467bb56081c76a0a3ebf1b9f"
end
bottle do
end
keg_only :provided_by_macos,
"openssl/libressl is provided by macOS so don't link an incompatible version"
# 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-ssl2
no-ssl3
no-zlib
shared
enable-cms
]
end
deprecate! date: "2023-09-11", because: :deprecated_upstream
disable! date: "2023-11-11", because: :unsupported
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.
ENV["PERL"] = Formula["perl"].opt_bin/"perl" if which("perl") == Formula["perl"].opt_bin/"perl"
arch_args = %W[darwin64-#{Hardware::CPU.arch}-cc enable-ec_nistp_64_gcc_128]
ENV.deparallelize
system "perl", "./Configure", *(configure_args + arch_args)
system "make"
system "make", "test"
system "make", "install", "MANDIR=#{man}", "MANSUFFIX=ssl"
end
def openssldir
etc/"openssl@1.0"
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
$CHILD_STATUS.success?
end
openssldir.mkpath
(openssldir/"cert.pem").atomic_write(valid_certs.join("\n") << "\n")
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 HOMEBREW_PREFIX/"etc/openssl@1.0/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
@minacle
Copy link
Author

minacle commented Sep 15, 2023

Thank you for visiting this page. However, please avoid installing chntpw through this gist, and instead use the method below.

brew tap minacle/chntpw
brew install minacle/chntpw/chntpw

If you find an article that guides you to use this gist, please ask the author to change the content to instead guide you through the installation method using tap as mentioned above.

Installation through this gist has now been deprecated and can only be used until November 11, 2023.


Related Links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment