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 untrusted comments to signatures #39

Merged
merged 2 commits 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
2 changes: 1 addition & 1 deletion lib/minisign/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def self.sign(options)
print 'Password: '
Minisign::PrivateKey.new(File.read(options[:s]), prompt)
end
signature = private_key.sign(options[:m], File.read(options[:m]), options[:t])
signature = private_key.sign(options[:m], File.read(options[:m]), options[:t], options[:c])
File.write(options[:x], signature)
end

Expand Down
14 changes: 7 additions & 7 deletions lib/minisign/private_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ def public_key
#
# @param filename [String] The filename to be used in the trusted comment section
# @param message [String] The file's contents
# @param comment [String] An optional trusted comment to be included in the signature
# @param trusted_comment [String] An optional trusted comment to be included in the signature
# @param untrusted_comment [String] An optional untrusted comment
# @return [Minisign::Signature]
def sign(filename, message, comment = nil)
def sign(filename, message, trusted_comment = nil, untrusted_comment = nil)
signature = ed25519_signing_key.sign(blake2b512(message))
trusted_comment = comment || "timestamp:#{Time.now.to_i}\tfile:#{filename}\thashed"
trusted_comment ||= "timestamp:#{Time.now.to_i}\tfile:#{filename}\thashed"
untrusted_comment ||= 'signature from minisign secret key'
global_signature = ed25519_signing_key.sign("#{signature}#{trusted_comment}")
# TODO: allow setting an untrusted comment, too
Minisign::Signature.new([
'untrusted comment: signature from minisign secret key',
"untrusted comment: #{untrusted_comment}",
Base64.strict_encode64("ED#{@key_id.pack('C*')}#{signature}"),
"trusted comment: #{trusted_comment}",
Base64.strict_encode64(global_signature),
''
"#{Base64.strict_encode64(global_signature)}\n"
].join("\n"))
end

Expand Down
11 changes: 7 additions & 4 deletions spec/minisign/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@
t: 'the trusted comment',
m: 'test/generated/.keep'
}
system(
"test/generated/minisign -Sm test/generated/.keep -s #{options[:s]} -t '#{options[:t]}'"
)
# rubocop:disable Layout/LineLength
command = "test/generated/minisign -Sm test/generated/.keep -s #{options[:s]} -c '#{options[:c]}' -t '#{options[:t]}'"
# rubocop:enable Layout/LineLength
system(command)
jedisct1_signature = File.read('test/generated/.keep.minisig')
File.delete('test/generated/.keep.minisig')
Minisign::CLI.sign(options)
Expand All @@ -121,7 +122,9 @@
m: 'test/generated/.keep'
}
system(
"echo 'password' | test/generated/minisign -Sm test/generated/.keep -s test/minisign.key -t '#{options[:t]}'"
# rubocop:disable Layout/LineLength
"echo 'password' | test/generated/minisign -Sm #{options[:m]} -s #{options[:s]} -t '#{options[:t]}' -c '#{options[:c]}'"
# rubocop:enable Layout/LineLength
)
jedisct1_signature = File.read('test/generated/.keep.minisig')
File.delete('test/generated/.keep.minisig')
Expand Down
6 changes: 5 additions & 1 deletion spec/minisign/private_key_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@
it 'signs a file' do
@filename = 'encrypted-key.txt'
@message = SecureRandom.uuid
signature = @private_key.sign(@filename, @message, 'this is a trusted comment')
trusted_comment = 'this is a trusted comment'
untrusted_comment = 'this is an untrusted comment'
signature = @private_key.sign(@filename, @message, trusted_comment, untrusted_comment)
expect(signature.to_s).to match(trusted_comment)
expect(signature.to_s).to match(untrusted_comment)
@public_key = Minisign::PublicKey.new('RWSmKaOrT6m3TGwjwBovgOmlhSbyBUw3hyhnSOYruHXbJa36xHr8rq2M')
expect(@public_key.verify(signature, @message)).to match('Signature and comment signature verified')
File.write("test/generated/#{@filename}", @message)
Expand Down