From b96728030c52284b43aa3f177b53dfaf1dbbee6c Mon Sep 17 00:00:00 2001 From: Manuel Korfmann Date: Wed, 15 Oct 2014 04:49:22 +0200 Subject: [PATCH] leading zeros of public exponent need to be dropped for digest --- ebics.gemspec | 2 +- keys/example.cer | 17 +++++++++++++++++ lib/ebics.rb | 4 +++- test/specification_test.rb | 21 +++++++++++++++++++++ 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 keys/example.cer create mode 100644 test/specification_test.rb diff --git a/ebics.gemspec b/ebics.gemspec index 4fe0cc3..64e17d0 100644 --- a/ebics.gemspec +++ b/ebics.gemspec @@ -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." diff --git a/keys/example.cer b/keys/example.cer new file mode 100644 index 0000000..9a01a1d --- /dev/null +++ b/keys/example.cer @@ -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----- diff --git a/lib/ebics.rb b/lib/ebics.rb index d8e68f6..4449591 100644 --- a/lib/ebics.rb +++ b/lib/ebics.rb @@ -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 diff --git a/test/specification_test.rb b/test/specification_test.rb new file mode 100644 index 0000000..c844893 --- /dev/null +++ b/test/specification_test.rb @@ -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