Commit 9e69084
Changed files (4)
lib
lib/saml/kit/signatures.rb
@@ -0,0 +1,27 @@
+module Saml
+ module Kit
+ class Signatures
+ attr_reader :sign, :configuration
+
+ def initialize(configuration:, sign: true)
+ @configuration = configuration
+ @reference_ids = []
+ @sign = sign
+ end
+
+ def build(reference_id)
+ @reference_ids << reference_id
+ XmlSignature.new(reference_id, configuration: configuration, sign: sign)
+ end
+
+ def complete(raw_xml)
+ return raw_xml unless sign
+
+ @reference_ids.each do |reference_id|
+ raw_xml = Xmldsig::SignedDocument.new(raw_xml).sign(configuration.signing_private_key)
+ end
+ raw_xml
+ end
+ end
+ end
+end
lib/saml/kit/templatable.rb
@@ -1,74 +1,13 @@
module Saml
module Kit
- class XmlSignature
- SIGNATURE_METHODS = {
- SHA1: "http://www.w3.org/2000/09/xmldsig#rsa-sha1",
- SHA224: "http://www.w3.org/2001/04/xmldsig-more#rsa-sha224",
- SHA256: "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256",
- SHA384: "http://www.w3.org/2001/04/xmldsig-more#rsa-sha384",
- SHA512: "http://www.w3.org/2001/04/xmldsig-more#rsa-sha512",
- }.freeze
- DIGEST_METHODS = {
- SHA1: "http://www.w3.org/2000/09/xmldsig#SHA1",
- SHA224: "http://www.w3.org/2001/04/xmldsig-more#sha224",
- SHA256: "http://www.w3.org/2001/04/xmlenc#sha256",
- SHA384: "http://www.w3.org/2001/04/xmldsig-more#sha384",
- SHA512: "http://www.w3.org/2001/04/xmlenc#sha512",
- }.freeze
-
- attr_reader :sign, :configuration
- attr_reader :reference_id
- attr_reader :stripped_signing_certificate
-
- def initialize(reference_id, configuration:, sign: true)
- @configuration = configuration
- @reference_id = reference_id
- @sign = sign
- @stripped_signing_certificate = configuration.stripped_signing_certificate
- end
-
- def signature_method
- SIGNATURE_METHODS[configuration.signature_method]
- end
-
- def digest_method
- DIGEST_METHODS[configuration.digest_method]
- end
- end
-
- class Signatures
- attr_reader :sign, :configuration
-
- def initialize(configuration:, sign: true)
- @configuration = configuration
- @reference_ids = []
- @sign = sign
- end
-
- def build(reference_id)
- @reference_ids << reference_id
- XmlSignature.new(reference_id, configuration: configuration, sign: sign)
- end
-
- def complete(raw_xml)
- return raw_xml unless sign
-
- @reference_ids.each do |reference_id|
- raw_xml = Xmldsig::SignedDocument.new(raw_xml).sign(configuration.signing_private_key)
- end
- raw_xml
- end
- end
-
module Templatable
def to_xml(xml: ::Builder::XmlMarkup.new)
signatures.complete(Template.new(self).to_xml(xml: xml))
end
- def signature_for(reference_id: , xml:)
+ def signature_for(reference_id:, xml:)
return unless sign
- signature = signatures.build(reference_id)
- Template.new(signature).to_xml(xml: xml)
+ Template.new(signatures.build(reference_id)).to_xml(xml: xml)
end
def signatures
lib/saml/kit/xml_signature.rb
@@ -0,0 +1,39 @@
+module Saml
+ module Kit
+ class XmlSignature
+ SIGNATURE_METHODS = {
+ SHA1: "http://www.w3.org/2000/09/xmldsig#rsa-sha1",
+ SHA224: "http://www.w3.org/2001/04/xmldsig-more#rsa-sha224",
+ SHA256: "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256",
+ SHA384: "http://www.w3.org/2001/04/xmldsig-more#rsa-sha384",
+ SHA512: "http://www.w3.org/2001/04/xmldsig-more#rsa-sha512",
+ }.freeze
+ DIGEST_METHODS = {
+ SHA1: "http://www.w3.org/2000/09/xmldsig#SHA1",
+ SHA224: "http://www.w3.org/2001/04/xmldsig-more#sha224",
+ SHA256: "http://www.w3.org/2001/04/xmlenc#sha256",
+ SHA384: "http://www.w3.org/2001/04/xmldsig-more#sha384",
+ SHA512: "http://www.w3.org/2001/04/xmlenc#sha512",
+ }.freeze
+
+ attr_reader :sign, :configuration
+ attr_reader :reference_id
+ attr_reader :stripped_signing_certificate
+
+ def initialize(reference_id, configuration:, sign: true)
+ @configuration = configuration
+ @reference_id = reference_id
+ @sign = sign
+ @stripped_signing_certificate = configuration.stripped_signing_certificate
+ end
+
+ def signature_method
+ SIGNATURE_METHODS[configuration.signature_method]
+ end
+
+ def digest_method
+ DIGEST_METHODS[configuration.digest_method]
+ end
+ end
+ end
+end
lib/saml/kit.rb
@@ -44,10 +44,12 @@ require "saml/kit/invalid_document"
require "saml/kit/self_signed_certificate"
require "saml/kit/service_provider_metadata"
require "saml/kit/signature"
+require "saml/kit/signatures"
require "saml/kit/template"
require "saml/kit/xml"
require "saml/kit/xml_decryption"
require "saml/kit/xml_encryption"
+require "saml/kit/xml_signature"
I18n.load_path += Dir[File.expand_path("kit/locales/*.yml", File.dirname(__FILE__))]