Skip to content

Commit 38d41fe

Browse files
authored
Merge pull request #692 from johnnyshields/xml-security-to-rubysaml-xml
v2.0: Move XMLSecurity namespace to RubySaml::XML
2 parents a3d2045 + ff1cf3f commit 38d41fe

34 files changed

+881
-656
lines changed

.rubocop_todo.yml

Lines changed: 31 additions & 35 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 11:29:15 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:
@@ -185,12 +170,11 @@ Lint/UnreachableLoop:
185170
Exclude:
186171
- 'lib/ruby_saml/saml_message.rb'
187172

188-
# Offense count: 3
173+
# Offense count: 2
189174
# This cop supports unsafe autocorrection (--autocorrect-all).
190175
# Configuration parameters: AutoCorrect.
191176
Lint/UselessAssignment:
192177
Exclude:
193-
- 'lib/ruby_saml/logging.rb'
194178
- 'lib/ruby_saml/slo_logoutrequest.rb'
195179

196180
# Offense count: 42
@@ -308,7 +292,7 @@ Performance/StringReplacement:
308292
- 'lib/ruby_saml/metadata.rb'
309293
- 'lib/ruby_saml/saml_message.rb'
310294
- 'lib/ruby_saml/utils.rb'
311-
- 'lib/xml_security.rb'
295+
- 'lib/ruby_saml/xml/document.rb'
312296

313297
# Offense count: 54
314298
# This cop supports safe autocorrection (--autocorrect).
@@ -361,7 +345,7 @@ Style/ConditionalAssignment:
361345
- 'lib/ruby_saml/logoutresponse.rb'
362346
- 'lib/ruby_saml/response.rb'
363347
- 'lib/ruby_saml/slo_logoutrequest.rb'
364-
- 'lib/xml_security.rb'
348+
- 'lib/ruby_saml/xml/signed_document.rb'
365349

366350
# Offense count: 6
367351
# Configuration parameters: AllowedConstants.
@@ -372,7 +356,9 @@ Style/Documentation:
372356
- 'lib/ruby_saml/error_handling.rb'
373357
- 'lib/ruby_saml/idp_metadata_parser.rb'
374358
- 'lib/ruby_saml/logging.rb'
375-
- 'lib/xml_security.rb'
359+
- 'lib/ruby_saml/xml/base_document.rb'
360+
- 'lib/ruby_saml/xml/document.rb'
361+
- 'lib/ruby_saml/xml/signed_document.rb'
376362

377363
# Offense count: 2
378364
# This cop supports safe autocorrection (--autocorrect).
@@ -416,7 +402,17 @@ Style/IfUnlessModifier:
416402
- 'lib/ruby_saml/slo_logoutrequest.rb'
417403
- 'lib/ruby_saml/slo_logoutresponse.rb'
418404
- 'lib/ruby_saml/utils.rb'
419-
- 'lib/xml_security.rb'
405+
- 'lib/ruby_saml/xml/base_document.rb'
406+
- 'lib/ruby_saml/xml/document.rb'
407+
- 'lib/ruby_saml/xml/signed_document.rb'
408+
409+
# Offense count: 1
410+
# This cop supports unsafe autocorrection (--autocorrect-all).
411+
# Configuration parameters: EnforcedStyle, Autocorrect.
412+
# SupportedStyles: module_function, extend_self, forbidden
413+
Style/ModuleFunction:
414+
Exclude:
415+
- 'lib/ruby_saml/logging.rb'
420416

421417
# Offense count: 15
422418
# Configuration parameters: AllowedMethods.
@@ -431,7 +427,7 @@ Style/OptionalBooleanParameter:
431427
- 'lib/ruby_saml/settings.rb'
432428
- 'lib/ruby_saml/slo_logoutrequest.rb'
433429
- 'lib/ruby_saml/utils.rb'
434-
- 'lib/xml_security.rb'
430+
- 'lib/ruby_saml/xml/signed_document.rb'
435431

436432
# Offense count: 1
437433
# This cop supports safe autocorrection (--autocorrect).
@@ -445,7 +441,7 @@ Style/RedundantRegexpArgument:
445441
Exclude:
446442
- 'lib/ruby_saml/saml_message.rb'
447443
- 'lib/ruby_saml/utils.rb'
448-
- 'lib/xml_security.rb'
444+
- 'lib/ruby_saml/xml/document.rb'
449445

450446
# Offense count: 3
451447
# This cop supports safe autocorrection (--autocorrect).
@@ -473,7 +469,7 @@ Style/StringConcatenation:
473469
- 'lib/ruby_saml/saml_message.rb'
474470
- 'lib/ruby_saml/slo_logoutrequest.rb'
475471

476-
# Offense count: 440
472+
# Offense count: 351
477473
# This cop supports safe autocorrection (--autocorrect).
478474
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
479475
# SupportedStyles: single_quotes, double_quotes
@@ -492,7 +488,7 @@ Style/StringLiterals:
492488
- 'lib/ruby_saml/slo_logoutrequest.rb'
493489
- 'lib/ruby_saml/slo_logoutresponse.rb'
494490
- 'lib/ruby_saml/utils.rb'
495-
- 'lib/xml_security.rb'
491+
- 'lib/ruby_saml/xml/signed_document.rb'
496492

497493
# Offense count: 3
498494
# This cop supports safe autocorrection (--autocorrect).
@@ -510,7 +506,7 @@ Style/SymbolArray:
510506
Exclude:
511507
- 'lib/ruby_saml/settings.rb'
512508

513-
# Offense count: 94
509+
# Offense count: 95
514510
# This cop supports safe autocorrection (--autocorrect).
515511
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
516512
# 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: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,27 @@ 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. In addition, a shim file has been added so that `require 'xml_security'` continues to work.
31+
These aliases will be removed in RubySaml version `2.1.0`.
1932

2033
### Security: Change default hashing algorithm to SHA-256 (was SHA-1)
2134

@@ -30,9 +43,9 @@ To preserve the old insecure SHA-1 behavior *(not recommended)*, you may set `Ru
3043
```ruby
3144
# Preserve RubySaml 1.x insecure SHA-1 behavior
3245
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
46+
settings.idp_cert_fingerprint_algorithm = RubySaml::XML::Document::SHA1
47+
settings.security[:digest_method] = RubySaml::XML::Document::SHA1
48+
settings.security[:signature_method] = RubySaml::XML::Document::RSA_SHA1
3649
```
3750

3851
## Updating from 1.12.x to 1.13.0
@@ -108,7 +121,7 @@ The new preferred way to provide _SAMLResponse_, _RelayState_, and _SigAlg_ is v
108121
# In this example `query_params` is assumed to contain decoded query parameters,
109122
# and `raw_query_params` is assumed to contain encoded query parameters as sent by the IDP.
110123
settings = {
111-
settings.security[:signature_method] = XMLSecurity::Document::RSA_SHA1
124+
settings.security[:signature_method] = RubySaml::XML::Document::RSA_SHA1
112125
settings.soft = false
113126
}
114127
options = {

lib/ruby_saml.rb

Lines changed: 2 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,5 @@
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 This alias adds compatibility with v1.x and will be removed in v2.1.0
2223
OneLogin = Object

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

0 commit comments

Comments
 (0)