Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce GPG operations #6184

Merged
merged 1 commit into from
Dec 1, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions lib/cask/gpg.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
class Cask::GpgCheck
attr_reader :available

def initialize(cask, command=Cask::SystemCommand)
@command = command
@cask = cask
@available = @cask.gpg ? installed? : false
end

def installed?
cmd = @command.run('/usr/bin/type',
:args => ['-p', 'gpg'])

# if `gpg` is found, return its absolute path
cmd.success? ? cmd.stdout : false
end


def fetch_sig(force=false)
unversioned_cask = @cask.version.is_a?(Symbol)
cached = @cask.metadata_subdir('gpg') unless unversioned_cask

meta_dir = cached || @cask.metadata_subdir('gpg', :now, true)
sig_path = meta_dir.join("signature.asc")

curl(@cask.gpg.signature, '-o', sig_path.to_s) unless cached || force

sig_path
end

def import_key
args = case
when @cask.gpg.key_id then ['--recv-keys', @cask.gpg.key_id]
when @cask.gpg.key_url then ['--fetch-key', @cask.gpg.key_url.to_s]
end

@command.run!('gpg', :args => args)
end

def verify(file)
import_key
sig = fetch_sig

ohai "Verifying GPG signature for #{@cask}"

@command.run!('gpg',
:args => ['--verify', sig, file],
:print_stdout => true)
end
end