Skip to content

Commit 8565353

Browse files
committed
Move XMLSecurity to RubySaml::XML
1 parent a3d2045 commit 8565353

33 files changed

+849
-643
lines changed

.rubocop_todo.yml

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2024-07-08 10:27:10 UTC using RuboCop version 1.64.1.
3+
# on 2024-07-09 07:40:52 UTC using RuboCop version 1.64.1.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -20,7 +20,7 @@ Layout/EmptyLineAfterGuardClause:
2020
- 'lib/ruby_saml/slo_logoutrequest.rb'
2121
- 'lib/ruby_saml/slo_logoutresponse.rb'
2222

23-
# Offense count: 9
23+
# Offense count: 6
2424
# This cop supports safe autocorrection (--autocorrect).
2525
# Configuration parameters: EnforcedStyle.
2626
# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only
@@ -32,15 +32,14 @@ Layout/EmptyLinesAroundClassBody:
3232
- 'lib/ruby_saml/logoutresponse.rb'
3333
- 'lib/ruby_saml/metadata.rb'
3434
- 'lib/ruby_saml/slo_logoutresponse.rb'
35-
- 'lib/xml_security.rb'
3635

3736
# Offense count: 1
3837
# This cop supports safe autocorrection (--autocorrect).
3938
Layout/EmptyLinesAroundMethodBody:
4039
Exclude:
4140
- 'lib/ruby_saml/slo_logoutrequest.rb'
4241

43-
# Offense count: 12
42+
# Offense count: 11
4443
# This cop supports safe autocorrection (--autocorrect).
4544
# Configuration parameters: EnforcedStyle.
4645
# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines
@@ -57,14 +56,6 @@ Layout/EmptyLinesAroundModuleBody:
5756
- 'lib/ruby_saml/slo_logoutrequest.rb'
5857
- 'lib/ruby_saml/slo_logoutresponse.rb'
5958
- 'lib/ruby_saml/utils.rb'
60-
- 'lib/xml_security.rb'
61-
62-
# Offense count: 1
63-
# Configuration parameters: EnforcedStyle.
64-
# SupportedStyles: native, lf, crlf
65-
Layout/EndOfLine:
66-
Exclude:
67-
- 'lib/ruby_saml.rb'
6859

6960
# Offense count: 3
7061
# This cop supports safe autocorrection (--autocorrect).
@@ -81,7 +72,7 @@ Layout/ExtraSpacing:
8172
Layout/FirstArgumentIndentation:
8273
Exclude:
8374
- 'lib/ruby_saml/response.rb'
84-
- 'lib/xml_security.rb'
75+
- 'lib/ruby_saml/xml/signed_document.rb'
8576

8677
# Offense count: 5
8778
# This cop supports safe autocorrection (--autocorrect).
@@ -105,7 +96,7 @@ Layout/SpaceAfterComma:
10596
Exclude:
10697
- 'lib/ruby_saml/response.rb'
10798
- 'lib/ruby_saml/settings.rb'
108-
- 'lib/xml_security.rb'
99+
- 'lib/ruby_saml/xml/signed_document.rb'
109100

110101
# Offense count: 12
111102
# This cop supports safe autocorrection (--autocorrect).
@@ -130,7 +121,8 @@ Layout/SpaceAroundOperators:
130121
Exclude:
131122
- 'lib/ruby_saml/response.rb'
132123
- 'lib/ruby_saml/utils.rb'
133-
- 'lib/xml_security.rb'
124+
- 'lib/ruby_saml/xml/document.rb'
125+
- 'lib/ruby_saml/xml/signed_document.rb'
134126

135127
# Offense count: 5
136128
# This cop supports safe autocorrection (--autocorrect).
@@ -154,15 +146,8 @@ Layout/SpaceInsideHashLiteralBraces:
154146
- 'lib/ruby_saml/response.rb'
155147
- 'lib/ruby_saml/settings.rb'
156148
- 'lib/ruby_saml/slo_logoutresponse.rb'
157-
- 'lib/xml_security.rb'
158-
159-
# Offense count: 1
160-
# This cop supports safe autocorrection (--autocorrect).
161-
# Configuration parameters: EnforcedStyle.
162-
# SupportedStyles: final_newline, final_blank_line
163-
Layout/TrailingEmptyLines:
164-
Exclude:
165-
- 'lib/ruby_saml.rb'
149+
- 'lib/ruby_saml/xml/document.rb'
150+
- 'lib/ruby_saml/xml/signed_document.rb'
166151

167152
# Offense count: 2
168153
Lint/NoReturnInBeginEndBlocks:
@@ -308,7 +293,7 @@ Performance/StringReplacement:
308293
- 'lib/ruby_saml/metadata.rb'
309294
- 'lib/ruby_saml/saml_message.rb'
310295
- 'lib/ruby_saml/utils.rb'
311-
- 'lib/xml_security.rb'
296+
- 'lib/ruby_saml/xml/document.rb'
312297

313298
# Offense count: 54
314299
# This cop supports safe autocorrection (--autocorrect).
@@ -361,7 +346,7 @@ Style/ConditionalAssignment:
361346
- 'lib/ruby_saml/logoutresponse.rb'
362347
- 'lib/ruby_saml/response.rb'
363348
- 'lib/ruby_saml/slo_logoutrequest.rb'
364-
- 'lib/xml_security.rb'
349+
- 'lib/ruby_saml/xml/signed_document.rb'
365350

366351
# Offense count: 6
367352
# Configuration parameters: AllowedConstants.
@@ -372,7 +357,9 @@ Style/Documentation:
372357
- 'lib/ruby_saml/error_handling.rb'
373358
- 'lib/ruby_saml/idp_metadata_parser.rb'
374359
- 'lib/ruby_saml/logging.rb'
375-
- 'lib/xml_security.rb'
360+
- 'lib/ruby_saml/xml/base_document.rb'
361+
- 'lib/ruby_saml/xml/document.rb'
362+
- 'lib/ruby_saml/xml/signed_document.rb'
376363

377364
# Offense count: 2
378365
# This cop supports safe autocorrection (--autocorrect).
@@ -416,7 +403,9 @@ Style/IfUnlessModifier:
416403
- 'lib/ruby_saml/slo_logoutrequest.rb'
417404
- 'lib/ruby_saml/slo_logoutresponse.rb'
418405
- 'lib/ruby_saml/utils.rb'
419-
- 'lib/xml_security.rb'
406+
- 'lib/ruby_saml/xml/base_document.rb'
407+
- 'lib/ruby_saml/xml/document.rb'
408+
- 'lib/ruby_saml/xml/signed_document.rb'
420409

421410
# Offense count: 15
422411
# Configuration parameters: AllowedMethods.
@@ -431,7 +420,7 @@ Style/OptionalBooleanParameter:
431420
- 'lib/ruby_saml/settings.rb'
432421
- 'lib/ruby_saml/slo_logoutrequest.rb'
433422
- 'lib/ruby_saml/utils.rb'
434-
- 'lib/xml_security.rb'
423+
- 'lib/ruby_saml/xml/signed_document.rb'
435424

436425
# Offense count: 1
437426
# This cop supports safe autocorrection (--autocorrect).
@@ -445,7 +434,7 @@ Style/RedundantRegexpArgument:
445434
Exclude:
446435
- 'lib/ruby_saml/saml_message.rb'
447436
- 'lib/ruby_saml/utils.rb'
448-
- 'lib/xml_security.rb'
437+
- 'lib/ruby_saml/xml/document.rb'
449438

450439
# Offense count: 3
451440
# This cop supports safe autocorrection (--autocorrect).
@@ -473,7 +462,7 @@ Style/StringConcatenation:
473462
- 'lib/ruby_saml/saml_message.rb'
474463
- 'lib/ruby_saml/slo_logoutrequest.rb'
475464

476-
# Offense count: 440
465+
# Offense count: 351
477466
# This cop supports safe autocorrection (--autocorrect).
478467
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
479468
# SupportedStyles: single_quotes, double_quotes
@@ -492,7 +481,7 @@ Style/StringLiterals:
492481
- 'lib/ruby_saml/slo_logoutrequest.rb'
493482
- 'lib/ruby_saml/slo_logoutresponse.rb'
494483
- 'lib/ruby_saml/utils.rb'
495-
- 'lib/xml_security.rb'
484+
- 'lib/ruby_saml/xml/signed_document.rb'
496485

497486
# Offense count: 3
498487
# This cop supports safe autocorrection (--autocorrect).
@@ -510,7 +499,7 @@ Style/SymbolArray:
510499
Exclude:
511500
- 'lib/ruby_saml/settings.rb'
512501

513-
# Offense count: 94
502+
# Offense count: 95
514503
# This cop supports safe autocorrection (--autocorrect).
515504
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
516505
# URISchemes: http, https

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* [#685](https://github.com/SAML-Toolkits/ruby-saml/pull/685) Create namespace alias `OneLogin = Object` for backward compatibility, to be removed in version `2.1.0`.
66
* [#685](https://github.com/SAML-Toolkits/ruby-saml/pull/685) Change directly structure from `lib/onelogin/ruby-saml` to `lib/ruby_saml`.
77
* [#685](https://github.com/SAML-Toolkits/ruby-saml/pull/685) Move schema files from `lib/onelogin/schemas` to `lib/ruby_saml/schemas`.
8+
* [#692](https://github.com/SAML-Toolkits/ruby-saml/pull/692) Remove `XMLSecurity` namespace and replace with `RubySaml::XML`.
89
* [#686](https://github.com/SAML-Toolkits/ruby-saml/pull/686) Use SHA-256 as the default hashing algorithm everywhere instead of SHA-1, including signatures, fingerprints, and digests.
910

1011
### 1.17.0

LICENSE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,3 @@ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
2121
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2222
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2323
OTHER DEALINGS IN THE SOFTWARE.
24-

README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ but it can be done as follows:
411411
* Provide the XML to the parse method if the signature was validated
412412
413413
```ruby
414-
require "xml_security"
414+
require "ruby_saml/xml"
415415
require "ruby_saml/utils"
416416
require "ruby_saml/idp_metadata_parser"
417417
@@ -431,7 +431,7 @@ get.basic_auth uri.user, uri.password if uri.user
431431
response = http.request(get)
432432
xml = response.body
433433
errors = []
434-
doc = XMLSecurity::SignedDocument.new(xml, errors)
434+
doc = RubySaml::XML::SignedDocument.new(xml, errors)
435435
cert_str = "<include_cert_here>"
436436
cert = RubySaml::Utils.format_cert("cert_str")
437437
metadata_sign_cert = OpenSSL::X509::Certificate.new(cert)
@@ -634,8 +634,8 @@ to specify different certificates for each function.
634634
You may also globally set the SP signature and digest method, to be used in SP signing (functions 1 and 2 above):
635635
636636
```ruby
637-
settings.security[:digest_method] = XMLSecurity::Document::SHA1
638-
settings.security[:signature_method] = XMLSecurity::Document::RSA_SHA1
637+
settings.security[:digest_method] = RubySaml::XML::Document::SHA1
638+
settings.security[:signature_method] = RubySaml::XML::Document::RSA_SHA1
639639
```
640640
641641
#### Signing SP Metadata
@@ -979,3 +979,14 @@ end
979979
# Output XML with custom metadata
980980
MyMetadata.new.generate(settings)
981981
```
982+
983+
## Attribution
984+
985+
Portions of the code in `RubySaml::XML` namespace is adapted from earlier work
986+
copyrighted by either Oracle and/or Todd W. Saxton. The original code was distributed
987+
under the Common Development and Distribution License (CDDL) 1.0. This code is planned to
988+
be written entirely in future versions.
989+
990+
## License
991+
992+
RubySaml is made available under the MIT License. Refer to [LICENSE](LICENSE).

UPGRADING.md

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,26 @@ Before attempting to upgrade to `2.0.0`:
88
- Upgrade your project to minimum Ruby 3.0, JRuby 9.4, or TruffleRuby 22.
99
- Upgrade RubySaml to `1.17.x`. Note that RubySaml `1.17.x` is compatible with up to Ruby 3.3.
1010

11-
### Root namespace changed to RubySaml
11+
### Root "OneLogin" namespace changed to "RubySaml"
1212

13-
RubySaml version `2.0.0` changes the root namespace from `OneLogin::RubySaml::` to just `RubySaml::`. This will require you
14-
to search your codebase for the string `OneLogin::` and remove it as appropriate. Aside from this namespace change,
13+
RubySaml version `2.0.0` changes the root namespace from `OneLogin::RubySaml::` to just `RubySaml::`.
14+
Please remove `OneLogin::` and `onelogin/` everywhere in your codebase. Aside from this namespace change,
1515
the class names themselves have intentionally been kept the same.
1616

17-
For backward compatibility, the alias `OneLogin = Object` has been set, so `OneLogin::RubySaml::` will still work.
18-
This alias will be removed in RubySaml version `2.1.0`.
17+
Note that the project folder structure has also been updated accordingly. Notably, the directory
18+
`lib/onelogin/schemas` is now `lib/ruby_saml/schemas`.
19+
20+
For backward compatibility, the alias `OneLogin = Object` has been set, so `OneLogin::RubySaml::` will still work
21+
as before. This alias will be removed in RubySaml version `2.1.0`.
22+
23+
### Root "XMLSecurity" namespace changed to "RubySaml::XML"
24+
25+
RubySaml version `2.0.0` changes the namespace `RubySaml::XML::` to `RubySaml::XML::`. Please search your
26+
codebase for `RubySaml::XML::` and replace it as appropriate. In addition, you must replace direct usage of
27+
`require 'xml_security'` with `require 'ruby_saml/xml'`.
28+
29+
For backward compatibility, the alias `XMLSecurity = RubySaml::XML` has been set, so `RubySaml::XML::` will still work
30+
as before. This alias will be removed in RubySaml version `2.1.0`.
1931

2032
### Security: Change default hashing algorithm to SHA-256 (was SHA-1)
2133

@@ -30,9 +42,9 @@ To preserve the old insecure SHA-1 behavior *(not recommended)*, you may set `Ru
3042
```ruby
3143
# Preserve RubySaml 1.x insecure SHA-1 behavior
3244
settings = RubySaml::Settings.new
33-
settings.idp_cert_fingerprint_algorithm = XMLSecurity::Document::SHA1
34-
settings.security[:digest_method] = XMLSecurity::Document::SHA1
35-
settings.security[:signature_method] = XMLSecurity::Document::RSA_SHA1
45+
settings.idp_cert_fingerprint_algorithm = RubySaml::XML::Document::SHA1
46+
settings.security[:digest_method] = RubySaml::XML::Document::SHA1
47+
settings.security[:signature_method] = RubySaml::XML::Document::RSA_SHA1
3648
```
3749

3850
## Updating from 1.12.x to 1.13.0
@@ -108,7 +120,7 @@ The new preferred way to provide _SAMLResponse_, _RelayState_, and _SigAlg_ is v
108120
# In this example `query_params` is assumed to contain decoded query parameters,
109121
# and `raw_query_params` is assumed to contain encoded query parameters as sent by the IDP.
110122
settings = {
111-
settings.security[:signature_method] = XMLSecurity::Document::RSA_SHA1
123+
settings.security[:signature_method] = RubySaml::XML::Document::RSA_SHA1
112124
settings.soft = false
113125
}
114126
options = {

lib/ruby_saml.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require 'ruby_saml/logging'
4+
require 'ruby_saml/xml'
45
require 'ruby_saml/saml_message'
56
require 'ruby_saml/authrequest'
67
require 'ruby_saml/logoutrequest'
@@ -18,5 +19,6 @@
1819
require 'ruby_saml/utils'
1920
require 'ruby_saml/version'
2021

21-
# @deprecated This alias will be removed in version 2.1.0
22+
# @deprecated These aliases add compatibility with v1.x and will be removed in v2.1.0
2223
OneLogin = Object
24+
XMLSecurity = RubySaml::XML

lib/ruby_saml/authrequest.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def create_params(settings, params={})
8484
relay_state: relay_state,
8585
sig_alg: params['SigAlg']
8686
)
87-
sign_algorithm = XMLSecurity::BaseDocument.new.algorithm(settings.security[:signature_method])
87+
sign_algorithm = RubySaml::XML::BaseDocument.new.algorithm(settings.security[:signature_method])
8888
signature = sp_signing_key.sign(sign_algorithm.new, url_string)
8989
params['Signature'] = encode(signature)
9090
end
@@ -108,7 +108,7 @@ def create_authentication_xml_doc(settings)
108108
def create_xml_document(settings)
109109
time = Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ")
110110

111-
request_doc = XMLSecurity::Document.new
111+
request_doc = RubySaml::XML::Document.new
112112
request_doc.uuid = uuid
113113

114114
root = request_doc.add_element "samlp:AuthnRequest", { "xmlns:samlp" => "urn:oasis:names:tc:SAML:2.0:protocol", "xmlns:saml" => "urn:oasis:names:tc:SAML:2.0:assertion" }

lib/ruby_saml/idp_metadata_parser.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,13 +376,13 @@ def certificates
376376

377377
# @return [String|nil] the fingerpint of the X509Certificate if it exists
378378
#
379-
def fingerprint(certificate, fingerprint_algorithm = XMLSecurity::Document::SHA256)
379+
def fingerprint(certificate, fingerprint_algorithm = RubySaml::XML::Document::SHA256)
380380
@fingerprint ||= begin
381381
return unless certificate
382382

383383
cert = OpenSSL::X509::Certificate.new(Base64.decode64(certificate))
384384

385-
fingerprint_alg = XMLSecurity::BaseDocument.new.algorithm(fingerprint_algorithm).new
385+
fingerprint_alg = RubySaml::XML::BaseDocument.new.algorithm(fingerprint_algorithm).new
386386
fingerprint_alg.hexdigest(cert.to_der).upcase.scan(/../).join(":")
387387
end
388388
end

lib/ruby_saml/logoutrequest.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def create_params(settings, params={})
8181
relay_state: relay_state,
8282
sig_alg: params['SigAlg']
8383
)
84-
sign_algorithm = XMLSecurity::BaseDocument.new.algorithm(settings.security[:signature_method])
84+
sign_algorithm = RubySaml::XML::BaseDocument.new.algorithm(settings.security[:signature_method])
8585
signature = settings.get_sp_signing_key.sign(sign_algorithm.new, url_string)
8686
params['Signature'] = encode(signature)
8787
end
@@ -105,7 +105,7 @@ def create_logout_request_xml_doc(settings)
105105
def create_xml_document(settings)
106106
time = Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ")
107107

108-
request_doc = XMLSecurity::Document.new
108+
request_doc = RubySaml::XML::Document.new
109109
request_doc.uuid = uuid
110110

111111
root = request_doc.add_element "samlp:LogoutRequest", { "xmlns:samlp" => "urn:oasis:names:tc:SAML:2.0:protocol", "xmlns:saml" => "urn:oasis:names:tc:SAML:2.0:assertion" }

lib/ruby_saml/logoutresponse.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# frozen_string_literal: true
22

3-
require "xml_security"
3+
require "ruby_saml/xml"
44
require "ruby_saml/saml_message"
5-
65
require "time"
76

87
# Only supports SAML 2.0
@@ -45,7 +44,7 @@ def initialize(response, settings = nil, options = {})
4544

4645
@options = options
4746
@response = decode_raw_saml(response, settings)
48-
@document = XMLSecurity::SignedDocument.new(@response)
47+
@document = RubySaml::XML::SignedDocument.new(@response)
4948
super()
5049
end
5150

0 commit comments

Comments
 (0)