-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
123 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
module Minisign | ||
# Parse ed25519 signing key from minisign private key | ||
class PrivateKey | ||
attr_reader :signature_algorithm, :kdf_algorithm, :cksum_algorithm, :kdf_salt, :kdf_opslimit, :kdf_memlimit, | ||
:key_id, :public_key, :secret_key, :checksum | ||
|
||
# rubocop:disable Metrics/AbcSize | ||
def initialize(str, password = nil) | ||
contents = str.split("\n") | ||
bytes = Base64.decode64(contents.last).bytes | ||
@signature_algorithm, @kdf_algorithm, @cksum_algorithm = | ||
[bytes[0..1], bytes[2..3], bytes[4..5]].map { |a| a.pack('U*') } | ||
@kdf_salt = bytes[6..37] | ||
@kdf_opslimit = bytes[38..45].pack('V*').unpack('N*').sum | ||
@kdf_memlimit = bytes[46..53].pack('V*').unpack('N*').sum | ||
kdf_output = derive_key(password, @kdf_salt, @kdf_opslimit, @kdf_memlimit) | ||
@key_id, @secret_key, @public_key, @checksum = xor(kdf_output, bytes[54..157]) | ||
end | ||
# rubocop:enable Metrics/AbcSize | ||
|
||
def derive_key(password, kdf_salt, kdf_opslimit, kdf_memlimit) | ||
RbNaCl::PasswordHash.scrypt( | ||
password, | ||
kdf_salt.pack('C*'), | ||
kdf_opslimit, | ||
kdf_memlimit, | ||
104 | ||
).bytes | ||
end | ||
|
||
def xor(kdf_output, contents) | ||
xored = kdf_output.each_with_index.map do |b, i| | ||
contents[i] ^ b | ||
end | ||
[xored[0..7], xored[8..39], xored[40..71], xored[72..103]] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# frozen_string_literal: true | ||
|
||
describe Minisign::PrivateKey do | ||
describe '.new' do | ||
before(:all) do | ||
@private_key = Minisign::PrivateKey.new(File.read('test/minisign.key'), 'password') | ||
end | ||
|
||
it 'parses the signature_algorithm' do | ||
expect(@private_key.signature_algorithm).to eq('Ed') | ||
end | ||
|
||
it 'parses the kdf_algorithm' do | ||
expect(@private_key.kdf_algorithm).to eq('Sc') | ||
end | ||
|
||
it 'parses the cksum_algorithm' do | ||
expect(@private_key.cksum_algorithm).to eq('B2') | ||
end | ||
|
||
it 'parses the kdf_salt' do | ||
expect(@private_key.kdf_salt).to eq([17, 255, 178, 97, 174, 94, 1, 125, 252, 62, 7, 107, 35, 116, 204, 199, 12, | ||
190, 222, 200, 51, 166, 7, 25, 89, 5, 225, 56, 170, 157, 127, 219]) | ||
end | ||
|
||
it 'parses the kdf_opslimit' do | ||
expect(@private_key.kdf_opslimit).to eq(33_554_432) | ||
end | ||
|
||
it 'parses the kdf_memlimit' do | ||
expect(@private_key.kdf_memlimit).to eq(1_073_741_824) | ||
end | ||
|
||
it 'parses the key id' do | ||
expect(@private_key.key_id).to eq([166, 41, 163, 171, 79, 169, 183, 76]) | ||
end | ||
|
||
it 'parses the public key' do | ||
expect(@private_key.public_key).to eq([108, 35, 192, 26, 47, 128, 233, 165, 133, 38, 242, 5, 76, 55, 135, 40, | ||
103, 72, 230, 43, 184, 117, 219, 37, 173, 250, 196, 122, 252, 174, 173, 140]) # rubocop:disable Layout/LineLength | ||
end | ||
|
||
it 'parses the secret key' do | ||
expect(@private_key.secret_key).to eq([65, 87, 110, 33, 168, 130, 118, 100, 249, 200, 160, 167, 47, 59, 141, | ||
122, 156, 38, 80, 199, 139, 1, 21, 18, 116, 110, 204, 131, 199, 202, 181, 87]) # rubocop:disable Layout/LineLength | ||
end | ||
|
||
it 'parses the checksum' do | ||
expect(@private_key.checksum).to eq([19, 146, 239, 121, 33, 164, 216, 219, 8, 104, 111, 52, 198, 78, 21, 236, | ||
113, 255, 174, 47, 39, 216, 61, 198, 233, 161, 233, 143, 84, 246, 255, 150]) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
untrusted comment: signature from minisign secret key | ||
RUTg6JXWzv6GDmPMFIE8V3D+S6mi6FBFrUNwvRVZrLNrySSWT8HPLXhN16nSzb3WLTSd59SceVfGtgEP2FMHVAqTc40mLXBbJQ4= | ||
trusted comment: timestamp:1653934067 file:example.txt hashed | ||
YU7xAGNcc5LGLHHyw14S6xtIvhfF3chGJ/rLSauaiPb1jtnt6JHB/ieMIjqEZ8unxxLllXQ2t6uQqzIKsiwAAg== | ||
RUSmKaOrT6m3TM3Pv4f4gwv40qbXWPv+l8LX1741TuRQV1gfnPWQqcRbEhRXzUxaAFTQocrOhC1SLRTV2kQZZSIi6nBK1FC9GgA= | ||
trusted comment: timestamp:1706961104 file:example.txt hashed | ||
LzQ3/VkobtbyEZX95vEJ5kf2brGY/yGpxqT3o1OU2Be4RnWXeRky3lHfwjFHGaLB+egSgrUfntjY3cgACiBxDg== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
untrusted comment: signature from minisign secret key | ||
RUTg6JXWzv6GDmPMFIE8V3D+S6mi6FBFrUNwvRVZrLNrySSWT8HPLXhN16nSzb3WLTSd59SceVfGtgEP2FMHVAqTc40mLXBbJQ4= | ||
trusted comment: timestamp:1653934367 file:example.txt hashed | ||
YU7xAGNcc5LGLHHyw14S6xtIvhfF3chGJ/rLSauaiPb1jtnt6JHB/ieMIjqEZ8unxxLllXQ2t6uQqzIKsiwAAg== | ||
RUSmKaOrT6m3TM3Pv4f4gwv40qbXWPv+l8LX1741TuRQV1gfnPWQqcRbEhRXzUxaAFTQocrOhC1SLRTV2kQZZSIi6nBK1FC9GgA= | ||
trusted comment: timestamp:1706961103 file:example.txt hashed | ||
LzQ3/VkobtbyEZX95vEJ5kf2brGY/yGpxqT3o1OU2Be4RnWXeRky3lHfwjFHGaLB+egSgrUfntjY3cgACiBxDg== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
untrusted comment: signature from minisign secret key | ||
RUTg6JXWzv6GDmPMFIE8V3D+S5mi6FBFrUNwvRVZrLNrySSWT8HPLXhN16nSzb3WLTSd59SceVfGtgEP2FMHVAqTc40mLXBbJQ4= | ||
trusted comment: timestamp:1653934067 file:example.txt hashed | ||
YU7xAGNcc5LGLHHyw14S6xtIvhfF3chGJ/rLSauaiPb1jtnt6JHB/ieMIjqEZ8unxxLllXQ2t6uQqzIKsiwAAg== | ||
RUSmKaOrT6m3TENGp8riRZz/zdCYneGKtF/1JiL23qh/WKfVKzQJhmu5/1IYSZzluvpBRmTm9TvVfvDjPTUHPp80Lrv3mwnB3wU= | ||
trusted comment: timestamp:1706961511 file:example.txt.minisig.tampered hashed | ||
nBME8TuE4sS+q4MGSSDxaacbX/dFTWRaixyKFTSlUNx9jydYgb5Ivg2JnzO0oO5NauHge8L5LG/5wa9RIJriDw== |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
untrusted comment: password is "password" | ||
RWRTY0IyEf+yYa5eAX38PgdrI3TMxwy+3sgzpgcZWQXhOKqdf9sAAAACAAAAAAAAAEAAAAAAHe8Olzttgk6k5pZyT3CyCTcTAV0bLN3kq5CUqhLjqSdYZ6oEWs/S7ztaephS+/jwnuOElLBKkg3Sd56jzyvMwL4qStNUTyPDqckNjniw2SlowmHN8n5NnR47gvqjo96E+vakpw8v5PE= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
untrusted comment: minisign public key 4CB7A94FABA329A6 | ||
RWSmKaOrT6m3TGwjwBovgOmlhSbyBUw3hyhnSOYruHXbJa36xHr8rq2M |