Skip to content

Commit

Permalink
add password to unencrypted key (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
jshawl authored Feb 16, 2024
1 parent 21e3e5f commit a8bb493
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
8 changes: 6 additions & 2 deletions lib/minisign/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,12 @@ def self.recreate(options)

def self.change_password(options)
options[:s] ||= "#{Dir.home}/.minisign/minisign.key"
print 'Password: '
private_key = Minisign::PrivateKey.new(File.read(options[:s]), prompt)
private_key = begin
Minisign::PrivateKey.new(File.read(options[:s]))
rescue Minisign::PasswordMissingError
print 'Password: '
Minisign::PrivateKey.new(File.read(options[:s]), prompt)
end
print 'New Password: '
new_password = options[:W] ? nil : prompt
private_key.change_password! new_password
Expand Down
13 changes: 12 additions & 1 deletion spec/minisign/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,18 @@
end.not_to raise_error
end

it 'changes the password for the private key without a password'
it 'changes the password for the private key without a password' do
FileUtils.cp('test/unencrypted.key', 'test/generated/unencrypted.key')
new_password = SecureRandom.uuid
options = {
s: 'test/generated/unencrypted.key'
}
allow(Minisign::CLI).to receive(:prompt).and_return(new_password)
Minisign::CLI.change_password(options)
expect do
Minisign::PrivateKey.new(File.read(options[:s]), new_password)
end.not_to raise_error
end

it 'removes the password for the private key' do
allow(Minisign::CLI).to receive(:prompt).and_return(@old_password)
Expand Down

0 comments on commit a8bb493

Please sign in to comment.