lyrebird 1.0.0 → 1.0.1

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
  SHA256:
3
- metadata.gz: 61005075359475ff6b492db62c80f7fea1724bb059c03f19a3f9d04c1f37871f
4
- data.tar.gz: 0e44c46fe69c8701c7b5441f7a23b6bbf752ad957ae044e5f19d398c01a8db91
3
+ metadata.gz: a2c22dc89d09728d25d5563a9db0c136b144865ddea516ea71bd1806a4bf0ce2
4
+ data.tar.gz: 002da134ef786dd04b2f61a3b2f01a2fe43ec4e772081b9d76dd4b4f5788e839
5
5
  SHA512:
6
- metadata.gz: 1ccd8ff5e0c7a4f441dc275a6231924f8969993c7b670b83a60d01f16e4ebf8fff33ccedffaad21a45dc6bca056d1450c5b6566699f9fd733f71fc9342818bec
7
- data.tar.gz: c0ebff2c3cc4134b84fb52327ee41c7d34bd9b2ab3d89ac7a50a3485bc912ca6936ad64388b04253001106a961f7f2caad313b88a2915e86c7bbd4c516eae673
6
+ metadata.gz: dc069741583e5940e825df140b405fe9c5710632c38927d2fb0baa80c52a4dafcb06170ac72a82259b9708f651e83e2ca11ee1d758d0031c1502f2d068faba57
7
+ data.tar.gz: 78a80065561c35f30b81a588a9584c173b044064a9b73266385a6708109f0b02952e0acbcbc1d6768d1750ea47ebdcbf346f42dbc7b9e151e0731a43316c995a
data/README.md CHANGED
@@ -15,6 +15,10 @@ gem "lyrebird", group: :test
15
15
  ```ruby
16
16
  # test/integration/saml_test.rb
17
17
  class SAMLTest < ActionDispatch::IntegrationTest
18
+ setup do
19
+ @idp_cert = Lyrebird::Certificate.build
20
+ end
21
+
18
22
  test "consume creates a session" do
19
23
  user = users(:alice)
20
24
 
@@ -24,6 +28,7 @@ class SAMLTest < ActionDispatch::IntegrationTest
24
28
  r.recipient = saml_consume_url
25
29
  r.audience = root_url
26
30
  r.name_id = user.email
31
+ r.sign_with = @idp_cert
27
32
 
28
33
  r.attributes do |a|
29
34
  a.email = user.email
@@ -168,7 +173,6 @@ cert.key # OpenSSL::PKey::RSA private key
168
173
  cert.x509 # OpenSSL::X509::Certificate object
169
174
  cert.key_pem # PEM-encoded private key
170
175
  cert.x509_pem # PEM-encoded certificate
171
- cert.sign(data) # Sign data with RSA-SHA256
172
176
  cert.base64 # Base64-encoded certificate (for SAML metadata)
173
177
  cert.fingerprint # SHA256 fingerprint
174
178
  ```
@@ -28,7 +28,7 @@ module Lyrebird
28
28
  end
29
29
 
30
30
  def document
31
- Nokogiri::XML::Document.new.tap do |doc|
31
+ @document ||= Nokogiri::XML::Document.new.tap do |doc|
32
32
  doc.root = root(doc)
33
33
  end
34
34
  end
@@ -49,10 +49,6 @@ module Lyrebird
49
49
  Base64.strict_encode64(@x509.to_der)
50
50
  end
51
51
 
52
- def sign(data)
53
- @key.sign("SHA256", data)
54
- end
55
-
56
52
  private
57
53
 
58
54
  def build_x509
@@ -39,7 +39,7 @@ module Lyrebird
39
39
  end
40
40
 
41
41
  def document
42
- Nokogiri::XML::Document.new.tap do |doc|
42
+ @document ||= Nokogiri::XML::Document.new.tap do |doc|
43
43
  doc.root = build_response(doc)
44
44
  sign_assertion(doc) if @sign_with && !@encrypt_with
45
45
  sign_response(doc) if @sign_with
@@ -13,6 +13,7 @@ module Lyrebird
13
13
  def sign!
14
14
  issuer = @element.at_xpath("saml:Issuer", "saml" => SAML_ASSERTION_NS)
15
15
  issuer.add_next_sibling(build_signature)
16
+ populate_signature_value
16
17
  self
17
18
  end
18
19
 
@@ -52,16 +53,14 @@ module Lyrebird
52
53
  def build_signature_value
53
54
  @doc.create_element("SignatureValue").tap do |sv|
54
55
  sv.namespace = @ds
55
- canonical = canonicalize_signed_info
56
- sig = @certificate.sign(canonical)
57
- sv.content = Base64.strict_encode64(sig)
56
+ @signature_value = sv
58
57
  end
59
58
  end
60
59
 
61
- def canonicalize_signed_info
62
- xml = @signed_info.to_xml(save_with: Nokogiri::XML::Node::SaveOptions::AS_XML)
63
- xml = xml.sub("<ds:SignedInfo>", "<ds:SignedInfo xmlns:ds=\"#{XMLDSIG_NS}\">")
64
- Nokogiri::XML(xml).root.canonicalize(C14N_EXCLUSIVE)
60
+ def populate_signature_value
61
+ canonical = @signed_info.canonicalize(C14N_EXCLUSIVE)
62
+ sig = @certificate.key.sign("SHA256", canonical)
63
+ @signature_value.content = Base64.strict_encode64(sig)
65
64
  end
66
65
 
67
66
  def build_key_info
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lyrebird
4
- VERSION = "1.0.0"
4
+ VERSION = "1.0.1"
5
5
  end
data/lib/lyrebird.rb CHANGED
@@ -18,8 +18,6 @@ require_relative "lyrebird/signature"
18
18
  require_relative "lyrebird/version"
19
19
 
20
20
  module Lyrebird
21
- class Error < StandardError; end
22
-
23
21
  rails_env = ENV["RAILS_ENV"]&.downcase
24
22
  rack_env = ENV["RACK_ENV"]&.downcase
25
23
 
@@ -33,6 +33,11 @@ module Lyrebird
33
33
  assert_equal "saml", @root.namespace.prefix
34
34
  end
35
35
 
36
+ def test_document_is_memoized
37
+ assertion = Assertion.new
38
+ assert_same assertion.document, assertion.document
39
+ end
40
+
36
41
  def test_root_namespace
37
42
  assert_equal SAML_ASSERTION_NS, @root.namespace.href
38
43
  end
@@ -53,13 +53,6 @@ module Lyrebird
53
53
  assert @certificate.x509.verify(@certificate.key)
54
54
  end
55
55
 
56
- def test_sign
57
- data = "test"
58
- signature = @certificate.sign(data)
59
- public_key = @certificate.x509.public_key
60
- assert public_key.verify("SHA256", signature, data)
61
- end
62
-
63
56
  def test_x509_with_custom_subject
64
57
  certificate = Certificate.build(cn: "Test", o: "Acme")
65
58
  subject = certificate.x509.subject.to_s
@@ -100,6 +100,14 @@ module Lyrebird
100
100
  assert decoded.include?("<saml:Assertion")
101
101
  end
102
102
 
103
+ def test_document_is_memoized
104
+ assert_same @response.document, @response.document
105
+ end
106
+
107
+ def test_mimic_is_stable
108
+ assert_equal @response.mimic, @response.mimic
109
+ end
110
+
103
111
  def test_root_name
104
112
  assert_equal "Response", @root.name
105
113
  assert_equal "samlp", @root.namespace.prefix
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lyrebird
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-02-02 00:00:00.000000000 Z
11
+ date: 2026-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64