2019-01-14 20:18:51 +00:00
|
|
|
class Step < Formula
|
|
|
|
desc "Crypto and x509 Swiss-Army-Knife"
|
|
|
|
homepage "https://smallstep.com"
|
2019-02-13 23:06:10 +00:00
|
|
|
url "https://github.com/smallstep/cli/archive/v0.8.6.tar.gz"
|
|
|
|
sha256 "8eb5099550d510b24ba1e5a53ccd4141e545286274c6abceb712be702d428820"
|
2019-01-14 20:18:51 +00:00
|
|
|
|
2019-02-13 00:39:11 +00:00
|
|
|
bottle do
|
|
|
|
cellar :any_skip_relocation
|
|
|
|
sha256 "a5976c545ee6fa5f12fdecc780b8103efff45f609e10a9b661cb2e7dc92b05a4" => :mojave
|
|
|
|
sha256 "b872743868eff23841652da84122397d7f62917e61df68acd12431c75ff60a86" => :high_sierra
|
|
|
|
sha256 "ff3738f3f91a3b376a38a01f4408769e9717ada11d19b1bde876836d5117eae3" => :sierra
|
|
|
|
end
|
|
|
|
|
2019-01-14 20:18:51 +00:00
|
|
|
depends_on "dep" => :build
|
|
|
|
depends_on "go" => :build
|
|
|
|
|
|
|
|
resource "certificates" do
|
2019-02-13 23:06:10 +00:00
|
|
|
url "https://github.com/smallstep/certificates/archive/v0.8.5.tar.gz"
|
|
|
|
sha256 "dc2b007247baeaa020a626813aea2b15fc2eb7f970cf0002a4b421fdf3ab294f"
|
2019-01-14 20:18:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def install
|
|
|
|
ENV["GOPATH"] = buildpath
|
2019-02-13 23:06:10 +00:00
|
|
|
(buildpath/"src/github.com/smallstep/cli").install buildpath.children
|
2019-01-14 20:18:51 +00:00
|
|
|
cd "src/github.com/smallstep/cli" do
|
|
|
|
system "make", "build"
|
|
|
|
bin.install "bin/step" => "step"
|
|
|
|
bash_completion.install "autocomplete/bash_autocomplete" => "step"
|
2019-02-13 23:06:10 +00:00
|
|
|
zsh_completion.install "autocomplete/zsh_autocomplete" => "_step"
|
2019-01-14 20:18:51 +00:00
|
|
|
end
|
|
|
|
|
2019-02-13 23:06:10 +00:00
|
|
|
resource("certificates").stage "#{buildpath}/src/github.com/smallstep/certificates"
|
|
|
|
cd "#{buildpath}/src/github.com/smallstep/certificates" do
|
|
|
|
system "make", "build"
|
|
|
|
bin.install "bin/step-ca" => "step-ca"
|
2019-01-14 20:18:51 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test do
|
|
|
|
# Generate a public / private key pair. Creates foo.pub and foo.priv.
|
|
|
|
system "#{bin}/step", "crypto", "keypair", "foo.pub", "foo.priv", "--no-password", "--insecure"
|
|
|
|
assert_predicate testpath/"foo.pub", :exist?
|
|
|
|
assert_predicate testpath/"foo.priv", :exist?
|
|
|
|
|
|
|
|
# Generate a root certificate and private key with subject baz written to baz.crt and baz.key.
|
|
|
|
system "#{bin}/step", "certificate", "create", "--profile", "root-ca",
|
|
|
|
"--no-password", "--insecure", "baz", "baz.crt", "baz.key"
|
|
|
|
assert_predicate testpath/"baz.crt", :exist?
|
|
|
|
assert_predicate testpath/"baz.key", :exist?
|
|
|
|
baz_crt = File.read(testpath/"baz.crt")
|
|
|
|
assert_match(/^-----BEGIN CERTIFICATE-----.*/, baz_crt)
|
|
|
|
assert_match(/.*-----END CERTIFICATE-----$/, baz_crt)
|
|
|
|
baz_key = File.read(testpath/"baz.key")
|
|
|
|
assert_match(/^-----BEGIN EC PRIVATE KEY-----.*/, baz_key)
|
|
|
|
assert_match(/.*-----END EC PRIVATE KEY-----$/, baz_key)
|
|
|
|
shell_output("#{bin}/step certificate inspect --format json baz.crt > baz_crt.json")
|
|
|
|
baz_crt_json = JSON.parse(File.read(testpath/"baz_crt.json"))
|
|
|
|
assert_equal "CN=baz", baz_crt_json["subject_dn"]
|
|
|
|
assert_equal "CN=baz", baz_crt_json["issuer_dn"]
|
|
|
|
|
|
|
|
# Generate a leaf certificate signed by the previously created root.
|
|
|
|
system "#{bin}/step", "certificate", "create", "--profile", "intermediate-ca",
|
|
|
|
"--no-password", "--insecure", "--ca", "baz.crt", "--ca-key", "baz.key",
|
|
|
|
"zap", "zap.crt", "zap.key"
|
|
|
|
assert_predicate testpath/"zap.crt", :exist?
|
|
|
|
assert_predicate testpath/"zap.key", :exist?
|
|
|
|
zap_crt = File.read(testpath/"zap.crt")
|
|
|
|
assert_match(/^-----BEGIN CERTIFICATE-----.*/, zap_crt)
|
|
|
|
assert_match(/.*-----END CERTIFICATE-----$/, zap_crt)
|
|
|
|
zap_key = File.read(testpath/"zap.key")
|
|
|
|
assert_match(/^-----BEGIN EC PRIVATE KEY-----.*/, zap_key)
|
|
|
|
assert_match(/.*-----END EC PRIVATE KEY-----$/, zap_key)
|
|
|
|
shell_output("#{bin}/step certificate inspect --format json zap.crt > zap_crt.json")
|
|
|
|
zap_crt_json = JSON.parse(File.read(testpath/"zap_crt.json"))
|
|
|
|
assert_equal "CN=zap", zap_crt_json["subject_dn"]
|
|
|
|
assert_equal "CN=baz", zap_crt_json["issuer_dn"]
|
|
|
|
|
|
|
|
# Initialize a PKI and step-ca configuration, boot the CA, and create a
|
|
|
|
# certificate using the API.
|
|
|
|
(testpath/"password.txt").write("password")
|
|
|
|
steppath = "#{testpath}/.step"
|
|
|
|
Dir.mkdir(steppath) unless File.exist?(steppath)
|
|
|
|
ENV["STEPPATH"] = steppath
|
|
|
|
system "#{bin}/step", "ca", "init", "--address", "127.0.0.1:8081",
|
|
|
|
"--dns", "127.0.0.1", "--password-file", "#{testpath}/password.txt",
|
|
|
|
"--provisioner-password-file", "#{testpath}/password.txt", "--name",
|
|
|
|
"homebrew-smallstep-test", "--provisioner", "brew"
|
|
|
|
|
|
|
|
begin
|
|
|
|
pid = fork { exec "#{bin}/step-ca", "--password-file", "#{testpath}/password.txt", "#{steppath}/config/ca.json" }
|
|
|
|
sleep 2
|
|
|
|
shell_output("#{bin}/step ca health > health_response.txt")
|
|
|
|
assert_match(/^ok$/, File.read(testpath/"health_response.txt"))
|
|
|
|
|
|
|
|
shell_output("#{bin}/step ca token --password-file #{testpath}/password.txt homebrew-smallstep-leaf > token.txt")
|
|
|
|
token = File.read(testpath/"token.txt")
|
|
|
|
system "#{bin}/step", "ca", "certificate", "--token", token,
|
|
|
|
"homebrew-smallstep-leaf", "brew.crt", "brew.key"
|
|
|
|
|
|
|
|
assert_predicate testpath/"brew.crt", :exist?
|
|
|
|
assert_predicate testpath/"brew.key", :exist?
|
|
|
|
brew_crt = File.read(testpath/"brew.crt")
|
|
|
|
assert_match(/^-----BEGIN CERTIFICATE-----.*/, brew_crt)
|
|
|
|
assert_match(/.*-----END CERTIFICATE-----$/, brew_crt)
|
|
|
|
brew_key = File.read(testpath/"brew.key")
|
|
|
|
assert_match(/^-----BEGIN EC PRIVATE KEY-----.*/, brew_key)
|
|
|
|
assert_match(/.*-----END EC PRIVATE KEY-----$/, brew_key)
|
|
|
|
shell_output("#{bin}/step certificate inspect --format json brew.crt > brew_crt.json")
|
|
|
|
brew_crt_json = JSON.parse(File.read(testpath/"brew_crt.json"))
|
|
|
|
assert_equal "CN=homebrew-smallstep-leaf", brew_crt_json["subject_dn"]
|
|
|
|
assert_equal "CN=homebrew-smallstep-test Intermediate CA", brew_crt_json["issuer_dn"]
|
|
|
|
ensure
|
|
|
|
Process.kill(9, pid)
|
|
|
|
Process.wait(pid)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|