From 3668a7abb1af9350b7a2c3816859f5be067a0487 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Wed, 10 May 2017 23:18:42 +0800 Subject: [PATCH 1/5] Support GPG (signed data) container in Homebrew Cask --- Library/Homebrew/cask/lib/hbc/container.rb | 2 + .../Homebrew/cask/lib/hbc/container/gpg.rb | 41 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 Library/Homebrew/cask/lib/hbc/container/gpg.rb diff --git a/Library/Homebrew/cask/lib/hbc/container.rb b/Library/Homebrew/cask/lib/hbc/container.rb index 961e319686..93e825e038 100644 --- a/Library/Homebrew/cask/lib/hbc/container.rb +++ b/Library/Homebrew/cask/lib/hbc/container.rb @@ -6,6 +6,7 @@ require "hbc/container/criteria" require "hbc/container/dmg" require "hbc/container/executable" require "hbc/container/generic_unar" +require "hbc/container/gpg" require "hbc/container/gzip" require "hbc/container/lzma" require "hbc/container/naked" @@ -40,6 +41,7 @@ module Hbc Gzip, # pure gzip Lzma, # pure lzma Xz, # pure xz + Gpg, # GnuPG signed data Executable, ] # for explicit use only (never autodetected): diff --git a/Library/Homebrew/cask/lib/hbc/container/gpg.rb b/Library/Homebrew/cask/lib/hbc/container/gpg.rb new file mode 100644 index 0000000000..d9504f5cb2 --- /dev/null +++ b/Library/Homebrew/cask/lib/hbc/container/gpg.rb @@ -0,0 +1,41 @@ +require "tmpdir" + +require "hbc/container/base" + +module Hbc + class Container + class Gpg < Base + def self.me?(criteria) + criteria.extension(/GPG/n) + end + + def import_key + if @cask.gpg.nil? + raise CaskError, "Expected to find gpg public key in formula. Cask '#{@cask}' must add: key_id or key_url" + end + + args = if @cask.gpg.key_id + ["--recv-keys", @cask.gpg.key_id] + elsif @cask.gpg.key_url + ["--fetch-key", @cask.gpg.key_url.to_s] + end + + @command.run!("gpg", args: args) + end + + def extract + if (gpg = which("gpg")).nil? + raise CaskError, "Expected to find gpg executable. Cask '#{@cask}' must add: depends_on formula: 'gpg'" + end + + import_key + + Dir.mktmpdir do |unpack_dir| + @command.run!(gpg, args: ["--batch", "--yes", "--output", Pathname(unpack_dir).join(File.basename(@path.basename)), "--decrypt", @path]) + + extract_nested_inside(unpack_dir) + end + end + end + end +end From b0987ffb33bbbbd71c0bbf88d2acb24855b75a65 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Thu, 11 May 2017 16:26:16 +0800 Subject: [PATCH 2/5] Support GPG (signed data) container in Homebrew Cask --- Library/Homebrew/cask/lib/hbc/container/gpg.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/container/gpg.rb b/Library/Homebrew/cask/lib/hbc/container/gpg.rb index d9504f5cb2..311dabc258 100644 --- a/Library/Homebrew/cask/lib/hbc/container/gpg.rb +++ b/Library/Homebrew/cask/lib/hbc/container/gpg.rb @@ -6,12 +6,12 @@ module Hbc class Container class Gpg < Base def self.me?(criteria) - criteria.extension(/GPG/n) + criteria.extension(/GPG|SIG/n) end def import_key if @cask.gpg.nil? - raise CaskError, "Expected to find gpg public key in formula. Cask '#{@cask}' must add: key_id or key_url" + raise CaskError, "Expected to find gpg public key in formula. Cask '#{@cask}' must add: 'gpg :embedded, key_id: [Public Key ID]' or 'gpg :embedded, key_url: [Public Key URL]'" end args = if @cask.gpg.key_id From 5c59b3352f94711c2e7ea394074c72c726024ce7 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Thu, 11 May 2017 16:27:45 +0800 Subject: [PATCH 3/5] Support GPG (signed data) container in Homebrew Cask (test case) --- Library/Homebrew/test/cask/installer_spec.rb | 13 +++++++++++++ .../support/fixtures/cask/Casks/container-gpg.rb | 12 ++++++++++++ .../support/fixtures/cask/container.tar.xz.gpg | Bin 0 -> 813 bytes 3 files changed, 25 insertions(+) create mode 100644 Library/Homebrew/test/support/fixtures/cask/Casks/container-gpg.rb create mode 100644 Library/Homebrew/test/support/fixtures/cask/container.tar.xz.gpg diff --git a/Library/Homebrew/test/cask/installer_spec.rb b/Library/Homebrew/test/cask/installer_spec.rb index 59d61bbdde..0ae7c14a5c 100644 --- a/Library/Homebrew/test/cask/installer_spec.rb +++ b/Library/Homebrew/test/cask/installer_spec.rb @@ -161,6 +161,19 @@ describe Hbc::Installer, :cask do expect(Hbc.appdir.join("container-lzma--#{asset.version}")).to be_a_file end + it "works with gpg-based Casks" do + skip("gpg not installed") if which("gpg").nil? + asset = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/container-gpg.rb") + + allow(asset).to receive(:depends_on).and_return(empty_depends_on_stub) + shutup do + Hbc::Installer.new(asset).install + end + + expect(Hbc.caskroom.join("container-gpg", asset.version)).to be_a_directory + expect(Hbc.appdir.join("container")).to be_a_file + end + it "blows up on a bad checksum" do bad_checksum = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/bad-checksum.rb") expect { diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/container-gpg.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/container-gpg.rb new file mode 100644 index 0000000000..630527ce2d --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/container-gpg.rb @@ -0,0 +1,12 @@ +cask 'container-gpg' do + version '1.2.3' + sha256 :no_check + + url "file://#{TEST_FIXTURE_DIR}/cask/container.tar.xz.gpg" + gpg :embedded, key_id: 'B0976E51E5C047AD0FD051294E402EBF7C3C6A71' + + homepage 'https://example.com/container-gpg' + depends_on formula: 'gpg' + + app 'container' +end diff --git a/Library/Homebrew/test/support/fixtures/cask/container.tar.xz.gpg b/Library/Homebrew/test/support/fixtures/cask/container.tar.xz.gpg new file mode 100644 index 0000000000000000000000000000000000000000..be250e8515f41855d770a67980eeef0a031c1968 GIT binary patch literal 813 zcmV+|1JeAE4FdoO0Zu?JzkEDuaRIF6Vi03*ZggR3Ze?;VbYXHXczRhB2HO2MdRSTj z00idNv_=8|ApsTu0049^<)h#y{{W9&05O}&8QQVNg0XlK`pwB=U9&?bHiQC`SVR+R zZbRluRZ<#1CO>?Ib7cra%mG3-S@h}7SI#ovdp$8+!|si}`r964`ify-ip(5f{H)tL zOGE11wV5)ZXjy~n8fy%c3C8Bx3AIJ*sn2VTpSF>jSk`z@fdu4# zrjEDp9nA=J7{jf?Mz5sdA;|UFb73+ z6dyo2PAt;8p1EMG&u_OPj=f`s%*O#3FhISAP@31owiagH8jK$sk?%6*=8qX~dEXn} zsX9L=a!yU58FSYC<@G&LQ;JL_(Hkj(EkbsyJm^*YW$O;Zbk{YK&sH!1*B=v$9vH%V zsfN!u-y2p)yy@_&u^lQipEd%yK!k)>pPW=r=R&|9;w7M+wC!ma5rKtzEtSrWgT}Z%aZ91e(3%%omiLckHgPh;@};rPI__t_A)A``p38lJ>|uDr rcKBINo!7BD8TBE^78!~R5HF%@nc|3f)Tg_SEDbcP_z157!Y^RLSSE5t literal 0 HcmV?d00001 From 6473a90c57412479666cecda1ef3546fde023641 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Thu, 18 May 2017 22:32:00 +0800 Subject: [PATCH 4/5] Extract to name without *.gpg extension --- Library/Homebrew/cask/lib/hbc/container/gpg.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/container/gpg.rb b/Library/Homebrew/cask/lib/hbc/container/gpg.rb index 311dabc258..8d5aaf1843 100644 --- a/Library/Homebrew/cask/lib/hbc/container/gpg.rb +++ b/Library/Homebrew/cask/lib/hbc/container/gpg.rb @@ -6,7 +6,7 @@ module Hbc class Container class Gpg < Base def self.me?(criteria) - criteria.extension(/GPG|SIG/n) + criteria.extension(/gpg/n) end def import_key @@ -31,7 +31,7 @@ module Hbc import_key Dir.mktmpdir do |unpack_dir| - @command.run!(gpg, args: ["--batch", "--yes", "--output", Pathname(unpack_dir).join(File.basename(@path.basename)), "--decrypt", @path]) + @command.run!(gpg, args: ["--batch", "--yes", "--output", Pathname(unpack_dir).join(File.basename(@path.basename, ".gpg")), "--decrypt", @path]) extract_nested_inside(unpack_dir) end From 61db2a58a5232fe67b7f0850d1421af0d38fdb29 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Fri, 19 May 2017 04:24:36 +0800 Subject: [PATCH 5/5] Exactly match extension "gpg" --- Library/Homebrew/cask/lib/hbc/container/gpg.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/container/gpg.rb b/Library/Homebrew/cask/lib/hbc/container/gpg.rb index 8d5aaf1843..3f37b5aa66 100644 --- a/Library/Homebrew/cask/lib/hbc/container/gpg.rb +++ b/Library/Homebrew/cask/lib/hbc/container/gpg.rb @@ -6,7 +6,7 @@ module Hbc class Container class Gpg < Base def self.me?(criteria) - criteria.extension(/gpg/n) + criteria.extension(/^(gpg)$/) end def import_key @@ -31,7 +31,7 @@ module Hbc import_key Dir.mktmpdir do |unpack_dir| - @command.run!(gpg, args: ["--batch", "--yes", "--output", Pathname(unpack_dir).join(File.basename(@path.basename, ".gpg")), "--decrypt", @path]) + @command.run!(gpg, args: ["--batch", "--yes", "--output", Pathname(unpack_dir).join(@path.basename(".gpg")), "--decrypt", @path]) extract_nested_inside(unpack_dir) end