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

add password to unencrypted key #37

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
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
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