saml-kit 0.2.13 → 0.2.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 70dbb0e0364cd23b3f1afd8b02fb38cbe7b0b6fd
4
- data.tar.gz: 6f3644f902897ca75eb959b621cd42db9dc9436d
3
+ metadata.gz: 8c247888ce2d9b7ca65605a7169e275f60094185
4
+ data.tar.gz: 666425c5224ece36334d9fee1c0b8c249fabc7e1
5
5
  SHA512:
6
- metadata.gz: fecaa317d931cf2e07c0b32e34b1787cd85b7b0b8f8b65322abab157f5886b712b0122832e36ce529fc3adfc803c84dd90dc380d02d3d204985eecc71f0d2b79
7
- data.tar.gz: 07b68fcbcfd29c2777565c63ac66ad3d9a4fa3cac3e4d007986ea6b79fa197f8fc829680345b949aaf9182f05f2019f1c74d4fb540ee3412a757baea6c98f6ef
6
+ metadata.gz: 6dffef3e1532ceef9178bace64ffae38caf0a4580e0926ea5a1524d15242efc29148b47164aadaabcc14808ef2e62c7ae618c4dfd42954346a556081750161d6
7
+ data.tar.gz: db069d1133acf615608f846d86d46d9ba38cddc4670ea5c45899266a25a465247e0a809f6308c98f011896de3a8f1753485ac83a801f88359ef6c7ab492201d5
@@ -41,9 +41,10 @@ module Saml
41
41
  # Generate a Response for a specific user.
42
42
  # @param user [Object] this is a custom user object that can be used for generating a nameid and assertion attributes.
43
43
  # @param binding [Symbol] the SAML binding to use `:http_post` or `:http_redirect`.
44
- def response_for(user, binding:, relay_state: nil)
44
+ # @param configuration [Saml::Kit::Configuration] the configuration to use to build the response.
45
+ def response_for(user, binding:, relay_state: nil, configuration: Saml::Kit.configuration)
45
46
  response_binding = provider.assertion_consumer_service_for(binding: binding)
46
- builder = Saml::Kit::Response.builder(user, self) do |x|
47
+ builder = Saml::Kit::Response.builder(user, self, configuration: configuration) do |x|
47
48
  x.embed_signature = provider.want_assertions_signed
48
49
  yield x if block_given?
49
50
  end
@@ -14,7 +14,7 @@ xml.Signature "xmlns" => Saml::Kit::Namespaces::XMLDSIG do
14
14
  xml.SignatureValue ""
15
15
  xml.KeyInfo do
16
16
  xml.X509Data do
17
- xml.X509Certificate x509_certificate
17
+ xml.X509Certificate certificate.stripped
18
18
  end
19
19
  end
20
20
  end
@@ -19,12 +19,12 @@ module Saml
19
19
 
20
20
  attr_reader :embed_signature, :configuration
21
21
  attr_reader :reference_id
22
- attr_reader :x509_certificate
22
+ attr_reader :certificate
23
23
 
24
- def initialize(reference_id, configuration:)
24
+ def initialize(reference_id, configuration:, certificate: )
25
25
  @configuration = configuration
26
26
  @reference_id = reference_id
27
- @x509_certificate = configuration.certificates(use: :signing).last.stripped
27
+ @certificate = certificate
28
28
  end
29
29
 
30
30
  def signature_method
@@ -35,7 +35,7 @@ module Saml
35
35
  end
36
36
 
37
37
  def ==(other)
38
- self.to_s == other.to_s
38
+ self.fingerprint == other.fingerprint
39
39
  end
40
40
 
41
41
  def eql?(other)
@@ -51,7 +51,7 @@ module Saml
51
51
  end
52
52
 
53
53
  def to_h
54
- { use: @use, x509: @value }
54
+ { use: @use, fingerprint: fingerprint.to_s }
55
55
  end
56
56
 
57
57
  def inspect
@@ -3,15 +3,20 @@ module Saml
3
3
  class KeyPair # :nodoc:
4
4
  attr_reader :certificate, :private_key, :use
5
5
 
6
- def initialize(certificate, private_key, password, use)
6
+ def initialize(certificate, private_key, passphrase, use)
7
7
  @use = use
8
8
  @certificate = Saml::Kit::Certificate.new(certificate, use: use)
9
- @private_key = OpenSSL::PKey::RSA.new(private_key, password)
9
+ @private_key = OpenSSL::PKey::RSA.new(private_key, passphrase)
10
10
  end
11
11
 
12
12
  def for?(use)
13
13
  @use == use
14
14
  end
15
+
16
+ def self.generate(use:, passphrase: SecureRandom.uuid)
17
+ certificate, private_key = SelfSignedCertificate.new(passphrase).create
18
+ new(certificate, private_key, passphrase, use)
19
+ end
15
20
  end
16
21
  end
17
22
  end
@@ -3,8 +3,8 @@ module Saml
3
3
  class SelfSignedCertificate
4
4
  SUBJECT="/C=CA/ST=Alberta/L=Calgary/O=SamlKit/OU=SamlKit/CN=SamlKit"
5
5
 
6
- def initialize(password)
7
- @password = password
6
+ def initialize(passphrase)
7
+ @passphrase = passphrase
8
8
  end
9
9
 
10
10
  def create
@@ -20,7 +20,7 @@ module Saml
20
20
  certificate.sign(rsa_key, OpenSSL::Digest::SHA256.new)
21
21
  [
22
22
  certificate.to_pem,
23
- rsa_key.to_pem(OpenSSL::Cipher.new('AES-256-CBC'), @password)
23
+ rsa_key.to_pem(OpenSSL::Cipher.new('AES-256-CBC'), @passphrase)
24
24
  ]
25
25
  end
26
26
  end
@@ -7,18 +7,24 @@ module Saml
7
7
  # @!visibility private
8
8
  def initialize(configuration:)
9
9
  @configuration = configuration
10
+ @key_pair = configuration.key_pairs(use: :signing).last
11
+ end
12
+
13
+ def sign_with(key_pair)
14
+ @key_pair = key_pair
10
15
  end
11
16
 
12
17
  # @!visibility private
13
18
  def build(reference_id)
14
19
  return nil unless configuration.sign?
15
- Saml::Kit::Builders::XmlSignature.new(reference_id, configuration: configuration)
20
+ certificate = @key_pair.certificate
21
+ Saml::Kit::Builders::XmlSignature.new(reference_id, configuration: configuration, certificate: certificate)
16
22
  end
17
23
 
18
24
  # @!visibility private
19
25
  def complete(raw_xml)
20
26
  return raw_xml unless configuration.sign?
21
- private_key = configuration.private_keys(use: :signing).last
27
+ private_key = @key_pair.private_key
22
28
  Xmldsig::SignedDocument.new(raw_xml).sign(private_key)
23
29
  end
24
30
 
@@ -17,6 +17,10 @@ module Saml
17
17
  render(signatures.build(reference_id), xml: xml)
18
18
  end
19
19
 
20
+ def sign_with(key_pair)
21
+ signatures.sign_with(key_pair)
22
+ end
23
+
20
24
  def sign?
21
25
  embed_signature.nil? ? configuration.sign? : embed_signature && configuration.sign?
22
26
  end
@@ -1,5 +1,5 @@
1
1
  module Saml
2
2
  module Kit
3
- VERSION = "0.2.13"
3
+ VERSION = "0.2.14"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saml-kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.13
4
+ version: 0.2.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - mo khan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-12-19 00:00:00.000000000 Z
11
+ date: 2017-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel