saml_idp 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,23 @@ require 'builder'
2
2
  module SamlIdp
3
3
  class SignedInfoBuilder
4
4
  include Algorithmable
5
+
6
+ SIGNATURE_METHODS = {
7
+ "sha1" => "http://www.w3.org/2000/09/xmldsig#rsa-sha1",
8
+ "sha224" => "http://www.w3.org/2001/04/xmldsig-more#rsa-sha224",
9
+ "sha256" => "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256",
10
+ "sha384" => "http://www.w3.org/2001/04/xmldsig-more#rsa-sha384",
11
+ "sha512" => "http://www.w3.org/2001/04/xmldsig-more#rsa-sha512",
12
+ }
13
+ DIGEST_METHODS = {
14
+ "sha1" => "http://www.w3.org/2000/09/xmldsig#sha1",
15
+ "sha224" => "http://www.w3.org/2001/04/xmldsig-more#sha224",
16
+ "sha256" => "http://www.w3.org/2001/04/xmlenc#sha256",
17
+ "sha384" => "http://www.w3.org/2001/04/xmldsig-more#sha384",
18
+ "sha512" => "http://www.w3.org/2001/04/xmlenc#sha512",
19
+ }
20
+
21
+
5
22
  attr_accessor :reference_id
6
23
  attr_accessor :digest_value
7
24
  attr_accessor :raw_algorithm
@@ -16,13 +33,13 @@ module SamlIdp
16
33
  builder = Builder::XmlMarkup.new
17
34
  builder.tag! "ds:SignedInfo", "xmlns:ds" => "http://www.w3.org/2000/09/xmldsig#" do |signed_info|
18
35
  signed_info.tag!("ds:CanonicalizationMethod", Algorithm: "http://www.w3.org/2001/10/xml-exc-c14n#") {}
19
- signed_info.tag!("ds:SignatureMethod", Algorithm: "http://www.w3.org/2000/09/xmldsig#rsa-#{algorithm_name}") {}
36
+ signed_info.tag!("ds:SignatureMethod", Algorithm: signature_method ) {}
20
37
  signed_info.tag! "ds:Reference", URI: reference_string do |reference|
21
38
  reference.tag! "ds:Transforms" do |transforms|
22
39
  transforms.tag!("ds:Transform", Algorithm: "http://www.w3.org/2000/09/xmldsig#enveloped-signature") {}
23
40
  transforms.tag!("ds:Transform", Algorithm: "http://www.w3.org/2001/10/xml-exc-c14n#") {}
24
41
  end
25
- reference.tag!("ds:DigestMethod", Algorithm: "http://www.w3.org/2000/09/xmldsig##{algorithm_name}") {}
42
+ reference.tag!("ds:DigestMethod", Algorithm: digest_method) {}
26
43
  reference.tag! "ds:DigestValue", digest_value
27
44
  end
28
45
  end
@@ -32,6 +49,21 @@ module SamlIdp
32
49
  encoded.gsub(/\n/, "")
33
50
  end
34
51
 
52
+ def digest_method
53
+ DIGEST_METHODS.fetch(clean_algorithm_name, DIGEST_METHODS["sha1"])
54
+ end
55
+ private :digest_method
56
+
57
+ def signature_method
58
+ SIGNATURE_METHODS.fetch(clean_algorithm_name, SIGNATURE_METHODS["sha1"])
59
+ end
60
+ private :signature_method
61
+
62
+ def clean_algorithm_name
63
+ algorithm_name.to_s.downcase
64
+ end
65
+ private :clean_algorithm_name
66
+
35
67
  def secret_key
36
68
  SamlIdp.config.secret_key
37
69
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module SamlIdp
3
- VERSION = '0.0.5'
3
+ VERSION = '0.0.6'
4
4
  end
@@ -15,11 +15,11 @@ module SamlIdp
15
15
  end
16
16
 
17
17
  it "builds a legit raw XML file" do
18
- subject.raw.should == "<ds:SignedInfo xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\"><ds:CanonicalizationMethod Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\"></ds:CanonicalizationMethod><ds:SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha256\"></ds:SignatureMethod><ds:Reference URI=\"#_abc\"><ds:Transforms><ds:Transform Algorithm=\"http://www.w3.org/2000/09/xmldsig#enveloped-signature\"></ds:Transform><ds:Transform Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\"></ds:Transform></ds:Transforms><ds:DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha256\"></ds:DigestMethod><ds:DigestValue>em8csGAWynywpe8S4nN64o56/4DosXi2XWMY6RJ6YfA=</ds:DigestValue></ds:Reference></ds:SignedInfo>"
18
+ subject.raw.should == "<ds:SignedInfo xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\"><ds:CanonicalizationMethod Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\"></ds:CanonicalizationMethod><ds:SignatureMethod Algorithm=\"http://www.w3.org/2001/04/xmldsig-more#rsa-sha256\"></ds:SignatureMethod><ds:Reference URI=\"#_abc\"><ds:Transforms><ds:Transform Algorithm=\"http://www.w3.org/2000/09/xmldsig#enveloped-signature\"></ds:Transform><ds:Transform Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\"></ds:Transform></ds:Transforms><ds:DigestMethod Algorithm=\"http://www.w3.org/2001/04/xmlenc#sha256\"></ds:DigestMethod><ds:DigestValue>em8csGAWynywpe8S4nN64o56/4DosXi2XWMY6RJ6YfA=</ds:DigestValue></ds:Reference></ds:SignedInfo>"
19
19
  end
20
20
 
21
21
  it "builds a legit digest of the XML file" do
22
- subject.signed.should == "MZd0Trzk+iQiHeMf5lKI0eXkTj5RQUBQH5j81jNNR/Ndf7Q1tIxsygcAM+CeWdt/Es8/Hvxe/nHmaXkkAB0BR5p8Pfrpv90wL1D+w6zeOLDNw9/+kn9E6Syu/2NMxrFetiVM7WwZcAJRA4WHRqxk6IIHIIf/Y3pf1tqKNWe6UgY="
22
+ subject.signed.should == "hKLeWLRgatHcV6N5Fc8aKveqNp6Y/J4m2WSYp0awGFtsCTa/2nab32wI3du+3kuuIy59EDKeUhHVxEfyhoHUo6xTZuO2N7XcTpSonuZ/CB3WjozC2Q/9elss3z1rOC3154v5pW4puirLPRoG+Pwi8SmptxNRHczr6NvmfYmmGfo="
23
23
  end
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saml_idp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -344,7 +344,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
344
344
  version: '0'
345
345
  segments:
346
346
  - 0
347
- hash: -512993472113273260
347
+ hash: -3552964034721380666
348
348
  required_rubygems_version: !ruby/object:Gem::Requirement
349
349
  none: false
350
350
  requirements:
@@ -353,7 +353,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
353
353
  version: '0'
354
354
  segments:
355
355
  - 0
356
- hash: -512993472113273260
356
+ hash: -3552964034721380666
357
357
  requirements: []
358
358
  rubyforge_project:
359
359
  rubygems_version: 1.8.25