Skip to content

Commit

Permalink
leading zeros of public exponent need to be dropped for digest
Browse files Browse the repository at this point in the history
  • Loading branch information
eZii-jester-data committed Oct 15, 2014
1 parent d8f2eb2 commit b967280
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ebics.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'ebics'
s.version = '0.0.5'
s.version = '0.1.0'
s.licenses = ['MIT']
s.summary = "EBICS Ruby Client"
s.description = "EBICS 2.5 H004 Implementation in Ruby."
Expand Down
17 changes: 17 additions & 0 deletions keys/example.cer
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-----BEGIN CERTIFICATE-----
MIIDQDCCAiigAwIBAgIBATANBgkqhkiG9w0BAQsFADBOMQswCQYDVQQGEwJGUjEOMAwGA1UEBxMF
UGFyaXMxEzARBgNVBAoTCkUuQi5JLkMuUy4xCTAHBgNVBAsTADEPMA0GA1UEAxMGRS4gQml4MB4X
DTA5MDcyNzA5MDYxNVoXDTE0MDcyNzA5MDYxNVowTjELMAkGA1UEBhMCRlIxDjAMBgNVBAcTBVBh
cmlzMRMwEQYDVQQKEwpFLkIuSS5DLlMuMQkwBwYDVQQLEwAxDzANBgNVBAMTBkUuIEJpeDCCASIw
DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANeOaO2fHl56a7bcS4FAnfTyvGiibmiyed9Jx1wi
fCojuzzLpnSVWnbDm2wyB1/YXK1V/cllK+LCrav48xMnoga0aRcVxrSCtpAW+PB6Wn1hKkNW2m/w
IuP1Vg+LB2EAsAVvCiMrCpyGKUUGNQ5x0Ph913xYUgZ41Rq/CNJ2w4AtuCgbr5KvRTwvKEv4JEJ5
qymedq3Yy1kt6t5HbQkLzMpMOBtMLzUBiZUv1sTApEtK39CdCI8GAEsZdW5ePSdr77y0qsA7QCTx
WliLpNDBx4BOuYJz9IdejqtNT4zAD7sQB6Yai54LzJ0lpHmA3baK3/Y3gBJqxC3WHSBf68x66icC
AwEAAaMpMCcwCwYDVR0PBAQDAgZAMAoGA1UdDgQDBAExMAwGA1UdIwQFMAOAATEwDQYJKoZIhvcN
AQELBQADggEBALo97IHqI3SfAS7rcTRGykCxqImtaDKJ3c77iKaUBIfJtBWuSxMLbLyC5xG5WQmS
/IdjSLp8WWetDylP2mkKvqk601UJGYHTnvUHblVY9MhG5kD6LB6bfjp6PfOm1629Mlmg5BCZ7cO1
+pEbQK2IE1MTreCYPiQyJJeT6umUKfeRgS3WFWCya/zfaLlCZDrRy+N8TVFKauMMKa8AugUn9eAm
7CuKgt89RkH3ERhJUZWb5Rbo6ykvHzbpDjaCedtnobUURjKeiwNR8cM5Tt8yeH4fOh63vbYZWUBv
3jQ5URJX2vHgkOP6sNB/E7/yqYPLxhj3E7Ty2d4/ru3yjJfRiVE=
-----END CERTIFICATE-----
4 changes: 3 additions & 1 deletion lib/ebics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ def public_exponent
end

def public_sha_256
public_key_string = "#{ @rsa.public_key.e.to_s(16) } #{ @rsa.public_key.n.to_s(16) }"
public_key_string = "#{ @rsa.public_key.e.to_s(16).downcase } #{ @rsa.public_key.n.to_s(16).downcase }"
public_key_string.gsub! /\A0/, ''
puts public_key_string
public_key_string.encode!('US-ASCII')
Digest::SHA256.hexdigest(public_key_string)
end
Expand Down
21 changes: 21 additions & 0 deletions test/specification_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'minitest/autorun'
require_relative '../lib/ebics'

class SchemaTest < Minitest::Test
def setup
@user = EBICS::User.new do |key|
key.rsa = OpenSSL::X509::Certificate.new File.read('keys/example.cer')
end

@example_key = @user.key('example')
end

def test_key_digest
assert_equal @example_key.public_exponent, 'AQAB'
assert_equal @example_key.public_sha_256.upcase, "F5ACB7B5CF88DCC80905AAE8783ED725F3AD1DCABB211DB77E58D679F9747739"
end

def test_public_modulus
assert_equal Base64.strict_decode64(@example_key.public_modulus), 'D78E68ED9F1E5E7A6BB6DC4B81409DF4F2BC68A26E68B279DF49C75C227C2A23BB3CCBA674955A76C39B6C32075FD85CAD55FDC9652BE2C2ADABF8F31327A206B4691715C6B482B69016F8F07A5A7D612A4356DA6FF022E3F5560F8B076100B0056F0A232B0A9C86294506350E71D0F87DD77C58520678D51ABF08D276C3802DB8281BAF92AF453C2F284BF8244279AB299E76ADD8CB592DEADE476D090BCCCA4C381B4C2F350189952FD6C4C0A44B4ADFD09D088F06004B19756E5E3D276BEFBCB4AAC03B4024F15A588BA4D0C1C7804EB98273F4875E8EAB4D4F8CC00FBB1007A61A8B9E0BCC9D25A47980DDB68ADFF63780126AC42DD61D205FEBCC7AEA27'
end
end

0 comments on commit b967280

Please sign in to comment.