xml-kit 0.6.0 → 0.7.0

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: 72cba660557fbb9fc55640fc292587d0bb9efc0d07d36f2dd7a57a5981f189e3
4
- data.tar.gz: da50becdadf74efbdd6ab390f2ce634870bd3e716f2beb8d843f6c1ef980ce5e
3
+ metadata.gz: 4c26430ca2a195f76646a2ff5da216ab06271749a551dc6fc2413c3a3f4422e9
4
+ data.tar.gz: 0c0e386ea21a83fb7c41ecf35abd6590883e138f024da891aa3ce3e2438e86d3
5
5
  SHA512:
6
- metadata.gz: f06dade4d5725222c16c26f2ac5063585d07e62d6f554f0428743a011d883a9a2c4fe812c56042201cd5ff11cb91b533c17d4de955d60e6aaff7539a8c6d0e6d
7
- data.tar.gz: 771f4241d74091bd09b85dfbb2bd57675d6ab9e09b2ff2e766b730c017e94f1860675e4701cc9845e945771fb1297c13daa46b9bfd91944e03146eed0d8e316d
6
+ metadata.gz: a53bce7bf2ff4d96be82abd8d17c2369de95e0ed8b6dffbb1f4a453f7b092a6d73199b601468621ecb9d486eedeb335663389cdb13a8be342c81dc3cf91106d4
7
+ data.tar.gz: 5b647418662e2a52cfdb830ed80f1679a58d949e4a00ccc4948748a5c1799eed5661e962546896eb7c71e0c7e02da1863f521b5ac65ffd68c1009cac852452cb
@@ -0,0 +1,20 @@
1
+ name: audit
2
+ on:
3
+ schedule:
4
+ - cron: '17 6 * * 1'
5
+ workflow_dispatch:
6
+ permissions: {}
7
+ jobs:
8
+ audit:
9
+ runs-on: ubuntu-latest
10
+ permissions:
11
+ contents: read
12
+ steps:
13
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
14
+ with:
15
+ persist-credentials: false
16
+ - uses: ruby/setup-ruby@be3c7df29b3349ec6bcfc6b4792f1cf9f5237d18 # v1.343.0
17
+ with:
18
+ ruby-version: '4.0'
19
+ bundler-cache: true
20
+ - run: sh bin/audit
@@ -1,41 +1,35 @@
1
1
  name: ci
2
2
  on:
3
- push:
4
- branches: [main]
5
3
  pull_request:
6
- branches: [main]
4
+ workflow_call:
5
+ permissions: {}
7
6
  jobs:
8
7
  test:
9
8
  runs-on: ubuntu-latest
9
+ permissions:
10
+ contents: read
10
11
  strategy:
11
12
  matrix:
12
- ruby-version: ['2.7', '3.0', '3.1']
13
+ ruby-version: ['3.2', '3.3', '3.4', '4.0']
13
14
  steps:
14
- - uses: actions/checkout@v2
15
- - name: Set up Ruby
16
- uses: ruby/setup-ruby@v1
15
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
16
+ with:
17
+ persist-credentials: false
18
+ - uses: ruby/setup-ruby@be3c7df29b3349ec6bcfc6b4792f1cf9f5237d18 # v1.343.0
17
19
  with:
18
20
  ruby-version: ${{ matrix.ruby-version }}
19
21
  bundler-cache: true
20
- - name: Running tests…
21
- run: sh bin/test
22
+ - run: sh bin/test
22
23
  style:
23
24
  runs-on: ubuntu-latest
25
+ permissions:
26
+ contents: read
24
27
  steps:
25
- - uses: actions/checkout@v2
26
- - uses: ruby/setup-ruby@v1
28
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
27
29
  with:
28
- ruby-version: '3.1'
29
- bundler-cache: true
30
- - name: Running style checks…
31
- run: sh bin/style
32
- audit:
33
- runs-on: ubuntu-latest
34
- steps:
35
- - uses: actions/checkout@v2
36
- - uses: ruby/setup-ruby@v1
30
+ persist-credentials: false
31
+ - uses: ruby/setup-ruby@be3c7df29b3349ec6bcfc6b4792f1cf9f5237d18 # v1.343.0
37
32
  with:
38
- ruby-version: '2.7'
33
+ ruby-version: '3.2'
39
34
  bundler-cache: true
40
- - name: Running audit…
41
- run: sh bin/audit
35
+ - run: sh bin/style
@@ -0,0 +1,52 @@
1
+ name: release
2
+ on:
3
+ push:
4
+ branches: [main]
5
+ permissions: {}
6
+ concurrency:
7
+ group: release
8
+ cancel-in-progress: false
9
+ queue: max
10
+ jobs:
11
+ test:
12
+ permissions:
13
+ contents: read
14
+ uses: ./.github/workflows/ci.yml
15
+ release-please:
16
+ needs: test
17
+ runs-on: ubuntu-latest
18
+ permissions:
19
+ contents: write
20
+ issues: write
21
+ pull-requests: write
22
+ outputs:
23
+ release_created: ${{ steps.release.outputs.release_created }}
24
+ sha: ${{ steps.release.outputs.sha }}
25
+ steps:
26
+ - id: release
27
+ uses: googleapis/release-please-action@45996ed1f6d02564a971a2fa1b5860e934307cf7 # v5.0.0
28
+ with:
29
+ config-file: release-please-config.json
30
+ manifest-file: .release-please-manifest.json
31
+ publish:
32
+ needs: release-please
33
+ if: needs.release-please.outputs.release_created == 'true'
34
+ runs-on: ubuntu-latest
35
+ environment: rubygems
36
+ permissions:
37
+ contents: write
38
+ id-token: write
39
+ steps:
40
+ - run: test "$RELEASED" = "$GITHUB_SHA"
41
+ env:
42
+ RELEASED: ${{ needs.release-please.outputs.sha }}
43
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
44
+ with:
45
+ persist-credentials: false
46
+ - uses: ruby/setup-ruby@be3c7df29b3349ec6bcfc6b4792f1cf9f5237d18 # v1.343.0
47
+ with:
48
+ ruby-version: '4.0'
49
+ bundler-cache: true
50
+ - uses: rubygems/release-gem@5c53f5308233b7c0f47411f0471b3faae6fa57b2 # v1.4.2
51
+ with:
52
+ await-release: false
@@ -0,0 +1,3 @@
1
+ {
2
+ ".": "0.7.0"
3
+ }
data/.rubocop.yml CHANGED
@@ -1,5 +1,4 @@
1
- require:
2
- - rubocop/cop/internal_affairs
1
+ plugins:
3
2
  - rubocop-rspec
4
3
 
5
4
  AllCops:
@@ -9,7 +8,9 @@ AllCops:
9
8
  - 'spec/fixtures/**/*'
10
9
  - 'tmp/**/*'
11
10
  - 'vendor/**/*'
12
- TargetRubyVersion: 2.7
11
+ NewCops: disable
12
+ SuggestExtensions: false
13
+ TargetRubyVersion: 3.2
13
14
 
14
15
  Layout/BlockAlignment:
15
16
  EnforcedStyleAlignWith: start_of_line
@@ -46,6 +47,17 @@ Lint/AmbiguousBlockAssociation:
46
47
  Exclude:
47
48
  - 'spec/**/*.rb'
48
49
 
50
+ Lint/ConstantDefinitionInBlock:
51
+ Exclude:
52
+ - 'spec/xml/kit/templatable_spec.rb'
53
+
54
+ Lint/DeprecatedOpenSSLConstant:
55
+ Enabled: false
56
+
57
+ Lint/EmptyFile:
58
+ Exclude:
59
+ - 'lib/xml/kit/templates/nil_class.builder'
60
+
49
61
  Lint/InterpolationCheck:
50
62
  Exclude:
51
63
  - 'spec/**/*.rb'
@@ -67,7 +79,7 @@ Metrics/ModuleLength:
67
79
  - 'spec/**/*.rb'
68
80
 
69
81
  Layout/LineLength:
70
- IgnoredPatterns: ['(\A|\s)#']
82
+ AllowedPatterns: ['(\A|\s)#']
71
83
  Exclude:
72
84
  - 'spec/**/*.rb'
73
85
  - 'lib/xml/kit/templates/*.builder'
@@ -76,12 +88,30 @@ Naming/FileName:
76
88
  Exclude:
77
89
  - 'lib/xml-kit.rb'
78
90
 
91
+ Style/AccessorGrouping:
92
+ Enabled: false
93
+
79
94
  Style/Documentation:
80
95
  Enabled: false
81
96
 
82
97
  Style/EachWithObject:
83
98
  Enabled: false
84
99
 
100
+ Style/GlobalStdStream:
101
+ Enabled: false
102
+
103
+ Style/KeywordParametersOrder:
104
+ Enabled: false
105
+
106
+ Style/MutableConstant:
107
+ Enabled: false
108
+
109
+ Style/RedundantFreeze:
110
+ Enabled: false
111
+
112
+ Style/SlicingWithRange:
113
+ Enabled: false
114
+
85
115
  Style/StringLiterals:
86
116
  EnforcedStyle: 'single_quotes'
87
117
 
@@ -94,10 +124,17 @@ Style/TrailingCommaInHashLiteral:
94
124
  RSpec/ExampleLength:
95
125
  Max: 80
96
126
 
127
+ RSpec/IdenticalEqualityAssertion:
128
+ Exclude:
129
+ - 'spec/xml/kit/certificate_spec.rb'
130
+
97
131
  RSpec/LeakyConstantDeclaration:
98
132
  Exclude:
99
133
  - 'spec/xml/kit/templatable_spec.rb'
100
134
 
135
+ RSpec/MatchArray:
136
+ Enabled: false
137
+
101
138
  RSpec/MultipleExpectations:
102
139
  Enabled: false
103
140
 
@@ -110,9 +147,16 @@ RSpec/NamedSubject:
110
147
  RSpec/NestedGroups:
111
148
  Max: 7
112
149
 
150
+ RSpec/SpecFilePathFormat:
151
+ Exclude:
152
+ - 'spec/xml/kit/kit_spec.rb'
153
+
113
154
  RSpec/SubjectStub:
114
155
  Enabled: false
115
156
 
116
157
  Style/DoubleNegation:
117
158
  Exclude:
118
159
  - 'lib/xml/kit/certificate.rb'
160
+
161
+ Style/YodaCondition:
162
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,12 +1,31 @@
1
- Version 0.6.0
2
-
3
1
  # Changelog
4
2
  All notable changes to this project will be documented in this file.
5
3
 
6
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
7
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
8
6
 
9
- ## [Unreleased]
7
+ ## [0.7.0](https://github.com/mokhan-ca/xml-kit/compare/v0.6.0...v0.7.0) (2026-11-25)
8
+
9
+
10
+ ### ⚠ BREAKING CHANGES
11
+
12
+ * raise for unknown decryption algorithms
13
+ * require nokogiri 1.19.1
14
+ * require strict xml and the xmlenc and xmldsig namespaces to decrypt
15
+ * require ruby 3.2
16
+
17
+ ### Features
18
+
19
+ * require ruby 3.2 ([de4163b](https://github.com/mokhan-ca/xml-kit/commit/de4163b998854521f45fd30c5d7b442591ec4cad))
20
+
21
+
22
+ ### Bug Fixes
23
+
24
+ * decrypt with each private key when openssl hides a wrong one ([b0597f0](https://github.com/mokhan-ca/xml-kit/commit/b0597f0547af3c5f76598a2555fbae866d948da7))
25
+ * link the gem to its repository and changelog ([c5549ee](https://github.com/mokhan-ca/xml-kit/commit/c5549eec7edb7d335834eddbadc8758a8b4ef8ef))
26
+ * raise for unknown decryption algorithms ([b65beac](https://github.com/mokhan-ca/xml-kit/commit/b65beac86d7a26db81ef21227c90a43ab9a127f6))
27
+ * require nokogiri 1.19.1 ([9f16831](https://github.com/mokhan-ca/xml-kit/commit/9f168319880243c62cc7f48fcd2903ac0b1e2e2e))
28
+ * require strict xml and the xmlenc and xmldsig namespaces to decrypt ([762c835](https://github.com/mokhan-ca/xml-kit/commit/762c83532d5bfd99f3f8521d86a4b0276d73f80b))
10
29
 
11
30
  ## [0.6.0] - 2022-05-23
12
31
  ### Added
data/Gemfile.lock CHANGED
@@ -1,75 +1,114 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- xml-kit (0.6.0)
4
+ xml-kit (0.7.0)
5
5
  activemodel (>= 4.2.0)
6
6
  builder (~> 3.2)
7
- nokogiri (~> 1.10)
7
+ nokogiri (~> 1.19, >= 1.19.1)
8
8
  tilt (>= 1.4.1)
9
9
  xmldsig (~> 0.6)
10
10
 
11
11
  GEM
12
12
  remote: https://rubygems.org/
13
13
  specs:
14
- activemodel (7.0.3)
15
- activesupport (= 7.0.3)
16
- activesupport (7.0.3)
17
- concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ activemodel (8.1.4.1)
15
+ activesupport (= 8.1.4.1)
16
+ activesupport (8.1.4.1)
17
+ base64
18
+ bigdecimal
19
+ concurrent-ruby (~> 1.0, >= 1.3.1)
20
+ connection_pool (>= 2.2.5)
21
+ drb
18
22
  i18n (>= 1.6, < 2)
23
+ json
24
+ logger (>= 1.4.2)
19
25
  minitest (>= 5.1)
20
- tzinfo (~> 2.0)
26
+ securerandom (>= 0.3)
27
+ tzinfo (~> 2.0, >= 2.0.5)
28
+ uri (>= 0.13.1)
21
29
  ast (2.4.2)
30
+ base64 (0.3.0)
31
+ bigdecimal (4.1.3)
22
32
  builder (3.2.4)
23
- bundler-audit (0.9.1)
24
- bundler (>= 1.2.0, < 3)
33
+ bundler-audit (0.9.3)
34
+ bundler (>= 1.2.0)
25
35
  thor (~> 1.0)
26
- concurrent-ruby (1.1.10)
36
+ concurrent-ruby (1.3.8)
37
+ connection_pool (3.0.3)
27
38
  diff-lcs (1.5.0)
28
39
  docile (1.4.0)
40
+ drb (2.2.3)
29
41
  ffaker (2.21.0)
30
- i18n (1.10.0)
42
+ i18n (1.12.0)
31
43
  concurrent-ruby (~> 1.0)
32
- mini_portile2 (2.8.0)
33
- minitest (5.15.0)
34
- nokogiri (1.13.6)
35
- mini_portile2 (~> 2.8.0)
44
+ json (3.2.0)
45
+ language_server-protocol (3.17.0.6)
46
+ lint_roller (1.1.0)
47
+ logger (1.7.0)
48
+ mini_portile2 (2.8.9)
49
+ minitest (6.1.0)
50
+ drb (~> 2.0)
51
+ prism (>= 1.5, < 3)
52
+ nokogiri (1.19.7)
53
+ mini_portile2 (~> 2.8.2)
54
+ racc (~> 1.4)
55
+ nokogiri (1.19.7-aarch64-linux-gnu)
56
+ racc (~> 1.4)
57
+ nokogiri (1.19.7-arm64-darwin)
58
+ racc (~> 1.4)
59
+ nokogiri (1.19.7-x86_64-darwin)
60
+ racc (~> 1.4)
61
+ nokogiri (1.19.7-x86_64-linux-gnu)
36
62
  racc (~> 1.4)
37
63
  parallel (1.22.1)
38
- parser (3.1.2.0)
64
+ parser (3.3.14.0)
39
65
  ast (~> 2.4.1)
66
+ racc
67
+ prism (2.1.0)
68
+ prism (2.1.0-aarch64-linux-gnu)
69
+ prism (2.1.0-arm64-darwin)
70
+ prism (2.1.0-x86_64-darwin)
71
+ prism (2.1.0-x86_64-linux-gnu)
40
72
  racc (1.6.0)
41
73
  rainbow (3.1.1)
42
- rake (13.0.6)
43
- regexp_parser (2.4.0)
44
- rexml (3.2.5)
45
- rspec (3.11.0)
46
- rspec-core (~> 3.11.0)
47
- rspec-expectations (~> 3.11.0)
48
- rspec-mocks (~> 3.11.0)
49
- rspec-core (3.11.0)
50
- rspec-support (~> 3.11.0)
51
- rspec-expectations (3.11.0)
74
+ rake (13.4.2)
75
+ regexp_parser (2.13.4)
76
+ rexml (3.4.4)
77
+ rspec (3.12.0)
78
+ rspec-core (~> 3.12.0)
79
+ rspec-expectations (~> 3.12.0)
80
+ rspec-mocks (~> 3.12.0)
81
+ rspec-core (3.12.0)
82
+ rspec-support (~> 3.12.0)
83
+ rspec-expectations (3.12.0)
52
84
  diff-lcs (>= 1.2.0, < 2.0)
53
- rspec-support (~> 3.11.0)
54
- rspec-mocks (3.11.1)
85
+ rspec-support (~> 3.12.0)
86
+ rspec-mocks (3.12.0)
55
87
  diff-lcs (>= 1.2.0, < 2.0)
56
- rspec-support (~> 3.11.0)
57
- rspec-support (3.11.0)
58
- rubocop (0.93.1)
59
- parallel (~> 1.10)
60
- parser (>= 2.7.1.5)
88
+ rspec-support (~> 3.12.0)
89
+ rspec-support (3.12.0)
90
+ rubocop (1.92.3)
91
+ json (>= 2.3)
92
+ language_server-protocol (~> 3.17.0.2)
93
+ lint_roller (~> 1.1.0)
94
+ parallel (>= 1.10)
95
+ parser (>= 3.3.0.2)
61
96
  rainbow (>= 2.2.2, < 4.0)
62
- regexp_parser (>= 1.8)
63
- rexml
64
- rubocop-ast (>= 0.6.0)
97
+ regexp_parser (>= 2.11.3, < 3.0)
98
+ rubocop-ast (>= 1.49.0, < 2.0)
65
99
  ruby-progressbar (~> 1.7)
66
- unicode-display_width (>= 1.4.0, < 2.0)
67
- rubocop-ast (1.18.0)
68
- parser (>= 3.1.1.0)
69
- rubocop-rspec (1.44.1)
70
- rubocop (~> 0.87)
71
- rubocop-ast (>= 0.7.1)
100
+ unicode-display_width (>= 2.4.0, < 4.0)
101
+ rubocop-ast (1.53.0)
102
+ ast (~> 2.4)
103
+ parser (>= 3.3.7.2)
104
+ prism (>= 1.7)
105
+ racc
106
+ rubocop-rspec (3.10.2)
107
+ lint_roller (~> 1.1)
108
+ regexp_parser (>= 2.0)
109
+ rubocop (~> 1.86, >= 1.86.2)
72
110
  ruby-progressbar (1.11.0)
111
+ securerandom (0.4.1)
73
112
  simplecov (0.21.2)
74
113
  docile (~> 1.1)
75
114
  simplecov-html (~> 0.11)
@@ -77,26 +116,33 @@ GEM
77
116
  simplecov-html (0.12.3)
78
117
  simplecov_json_formatter (0.1.4)
79
118
  thor (1.2.1)
80
- tilt (2.0.10)
81
- tzinfo (2.0.4)
119
+ tilt (2.0.11)
120
+ tzinfo (2.0.5)
82
121
  concurrent-ruby (~> 1.0)
83
- unicode-display_width (1.8.0)
84
- xmldsig (0.6.6)
122
+ unicode-display_width (3.3.0)
123
+ unicode-emoji (~> 4.3)
124
+ unicode-emoji (4.3.0)
125
+ uri (1.1.2)
126
+ xmldsig (0.7.0)
85
127
  nokogiri (>= 1.6.8, < 2.0.0)
86
128
 
87
129
  PLATFORMS
130
+ aarch64-linux
131
+ arm64-darwin
88
132
  ruby
133
+ x86_64-darwin
134
+ x86_64-linux
89
135
 
90
136
  DEPENDENCIES
91
- bundler (~> 2.0)
92
137
  bundler-audit (~> 0.6)
93
138
  ffaker (~> 2.7)
94
139
  rake (~> 13.0)
140
+ rexml (~> 3.0)
95
141
  rspec (~> 3.0)
96
- rubocop (~> 0.52)
97
- rubocop-rspec (~> 1.22)
142
+ rubocop (~> 1.0)
143
+ rubocop-rspec (~> 3.0)
98
144
  simplecov (~> 0.21.2)
99
145
  xml-kit!
100
146
 
101
147
  BUNDLED WITH
102
- 2.2.7
148
+ 4.0.17
data/LICENSE.txt CHANGED
@@ -1,6 +1,7 @@
1
1
  The MIT License (MIT)
2
2
 
3
3
  Copyright (c) 2017 mo khan
4
+ Copyright (c) 2026 2809074 Alberta Ltd.
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  of this software and associated documentation files (the "Software"), to deal
@@ -10,15 +10,15 @@ module Xml
10
10
  }.freeze
11
11
  attr_reader :algorithm, :key
12
12
 
13
+ def self.matches?(algorithm)
14
+ ALGORITHMS[algorithm]
15
+ end
16
+
13
17
  def initialize(algorithm, key)
14
18
  @algorithm = algorithm
15
19
  @key = key
16
20
  end
17
21
 
18
- def self.matches?(algorithm)
19
- ALGORITHMS[algorithm]
20
- end
21
-
22
22
  def encrypt(plain_text)
23
23
  @key.public_encrypt(plain_text, padding)
24
24
  end
@@ -7,15 +7,15 @@ module Xml
7
7
  ALGORITHM = "#{::Xml::Kit::Namespaces::XMLENC}rsa-1_5"
8
8
  attr_reader :algorithm, :key
9
9
 
10
+ def self.matches?(algorithm)
11
+ ALGORITHM == algorithm
12
+ end
13
+
10
14
  def initialize(algorithm, key)
11
15
  @algorithm = algorithm
12
16
  @key = key
13
17
  end
14
18
 
15
- def self.matches?(algorithm)
16
- ALGORITHM == algorithm
17
- end
18
-
19
19
  def encrypt(plain_text)
20
20
  @key.public_encrypt(plain_text)
21
21
  end
@@ -14,16 +14,16 @@ module Xml
14
14
 
15
15
  attr_reader :algorithm, :key, :padding
16
16
 
17
+ def self.matches?(algorithm)
18
+ ALGORITHMS[algorithm]
19
+ end
20
+
17
21
  def initialize(algorithm = DEFAULT_ALGORITHM, key = nil, padding = nil)
18
22
  @algorithm = algorithm
19
23
  @key = key || cipher.random_key
20
24
  @padding = padding
21
25
  end
22
26
 
23
- def self.matches?(algorithm)
24
- ALGORITHMS[algorithm]
25
- end
26
-
27
27
  def encrypt(plain_text)
28
28
  cipher.encrypt
29
29
  cipher.key = @key
@@ -6,17 +6,17 @@ module Xml
6
6
  class UnknownCipher
7
7
  attr_reader :algorithm, :key
8
8
 
9
+ def self.matches?(_algorithm)
10
+ true
11
+ end
12
+
9
13
  def initialize(algorithm, key)
10
14
  @algorithm = algorithm
11
15
  @key = key
12
16
  end
13
17
 
14
- def self.matches?(_algorithm)
15
- true
16
- end
17
-
18
- def decrypt(cipher_text)
19
- cipher_text
18
+ def decrypt(_cipher_text)
19
+ raise ::Xml::Kit::Error, "Unknown algorithm: #{algorithm.inspect}"
20
20
  end
21
21
  end
22
22
  end
@@ -4,6 +4,16 @@ module Xml
4
4
  module Kit
5
5
  # {include:file:spec/xml/kit/decryption_spec.rb}
6
6
  class Decryption
7
+ ELEMENTS = %w[
8
+ xenc:EncryptionMethod
9
+ ds:KeyInfo[not(parent::xenc:EncryptedKey)]
10
+ xenc:EncryptedKey
11
+ xenc:CipherData
12
+ xenc:CipherValue
13
+ ].join('|').freeze
14
+ NAMESPACES = { 'ds' => Namespaces::XMLDSIG, 'xenc' => Namespaces::XMLENC }.freeze
15
+ private_constant :ELEMENTS, :NAMESPACES
16
+
7
17
  # The list of private keys to use to attempt to decrypt the document.
8
18
  attr_reader :cipher_registry, :private_keys
9
19
 
@@ -27,7 +37,7 @@ module Xml
27
37
  #
28
38
  # @param raw_xml [String] the XML document as a string.
29
39
  def decrypt_xml(raw_xml)
30
- decrypt_hash(Hash.from_xml(raw_xml))
40
+ decrypt_element(Nokogiri::XML(raw_xml, &:strict).root)
31
41
  end
32
42
 
33
43
  # Decrypts an EncryptedData section of an XML document.
@@ -35,11 +45,9 @@ module Xml
35
45
  # @param hash [Hash] the XML document converted to a [Hash] using Hash.from_xml.
36
46
  def decrypt_hash(hash)
37
47
  data = hash['EncryptedData']
38
- to_plaintext(
39
- Base64.decode64(data['CipherData']['CipherValue']),
40
- symmetric_key_from(data['KeyInfo']['EncryptedKey']),
41
- data['EncryptionMethod']['Algorithm']
42
- )
48
+ with_each_private_key do |private_key|
49
+ to_plaintext(data, to_plaintext(data['KeyInfo']['EncryptedKey'], private_key))
50
+ end
43
51
  end
44
52
 
45
53
  # Decrypts an EncryptedData Nokogiri::XML::Element.
@@ -48,31 +56,39 @@ module Xml
48
56
  def decrypt_node(node)
49
57
  return node unless !node.nil? && node.name == 'EncryptedData'
50
58
 
51
- node.parent.replace(decrypt_xml(node.to_s))[0]
59
+ node.parent.replace(decrypt_element(node))[0]
52
60
  end
53
61
 
54
62
  private
55
63
 
56
- def symmetric_key_from(encrypted_key, attempts = private_keys.count)
57
- cipher, algorithm = cipher_and_algorithm_from(encrypted_key)
64
+ def decrypt_element(element)
65
+ decrypt_hash(element.name => hash_from(element))
66
+ end
67
+
68
+ def hash_from(element)
69
+ return element.text if element.name == 'CipherValue'
70
+
71
+ children = element.xpath(ELEMENTS, NAMESPACES)
72
+ raise Error, "#{element.name} contains repeated elements" if children.uniq(&:name).size < children.size
73
+
74
+ hash = children.to_h { |child| [child.name, hash_from(child)] }
75
+ hash.merge('Algorithm' => element['Algorithm']).compact.presence
76
+ end
77
+
78
+ def with_each_private_key(attempts = private_keys.count)
58
79
  private_keys.each do |private_key|
59
80
  attempts -= 1
60
- return to_plaintext(cipher, private_key, algorithm)
61
- rescue OpenSSL::PKey::RSAError
81
+ return yield(private_key)
82
+ rescue OpenSSL::OpenSSLError, ArgumentError
62
83
  raise if attempts.zero?
63
84
  end
64
85
  raise DecryptionError, private_keys
65
86
  end
66
87
 
67
- def to_plaintext(cipher_text, private_key, algorithm)
68
- cipher_registry.cipher_for(algorithm, private_key).decrypt(cipher_text)
69
- end
70
-
71
- def cipher_and_algorithm_from(encrypted_key)
72
- [
73
- Base64.decode64(encrypted_key['CipherData']['CipherValue']),
74
- encrypted_key['EncryptionMethod']['Algorithm']
75
- ]
88
+ def to_plaintext(element, key)
89
+ cipher_registry
90
+ .cipher_for(element['EncryptionMethod']['Algorithm'], key)
91
+ .decrypt(Base64.decode64(element['CipherData']['CipherValue']))
76
92
  end
77
93
  end
78
94
  end
@@ -7,6 +7,22 @@ module Xml
7
7
  attr_reader :private_key
8
8
  attr_reader :public_key
9
9
 
10
+ # Returns a generated self signed certificate with private key.
11
+ #
12
+ # @param use [Symbol] Can be either `:signing` or `:encryption`.
13
+ # @param passphrase [String] the passphrase to use to encrypt the private key.
14
+ # @param algorithm [String] the symmetric algorithm to use for encrypting the private key.
15
+ def self.generate(use:,
16
+ passphrase: SecureRandom.uuid,
17
+ algorithm: Crypto::SymmetricCipher::DEFAULT_ALGORITHM)
18
+ algorithm = Crypto::SymmetricCipher::ALGORITHMS[algorithm]
19
+ certificate, private_key = SelfSignedCertificate.new.create(
20
+ algorithm: algorithm,
21
+ passphrase: passphrase
22
+ )
23
+ new(certificate, private_key, passphrase, use)
24
+ end
25
+
10
26
  def initialize(certificate, private_key, passphrase, use)
11
27
  @certificate = ::Xml::Kit::Certificate.new(certificate, use: use)
12
28
  @private_key =
@@ -24,22 +40,6 @@ module Xml
24
40
  def for?(use)
25
41
  certificate.for?(use)
26
42
  end
27
-
28
- # Returns a generated self signed certificate with private key.
29
- #
30
- # @param use [Symbol] Can be either `:signing` or `:encryption`.
31
- # @param passphrase [String] the passphrase to use to encrypt the private key.
32
- # @param algorithm [String] the symmetric algorithm to use for encrypting the private key.
33
- def self.generate(use:,
34
- passphrase: SecureRandom.uuid,
35
- algorithm: Crypto::SymmetricCipher::DEFAULT_ALGORITHM)
36
- algorithm = Crypto::SymmetricCipher::ALGORITHMS[algorithm]
37
- certificate, private_key = SelfSignedCertificate.new.create(
38
- algorithm: algorithm,
39
- passphrase: passphrase
40
- )
41
- new(certificate, private_key, passphrase, use)
42
- end
43
43
  end
44
44
  end
45
45
  end
@@ -6,6 +6,20 @@ module Xml
6
6
  class Signatures # :nodoc:
7
7
  attr_reader :key_pair, :signature_method, :digest_method
8
8
 
9
+ # @!visibility private
10
+ def self.sign(xml: ::Builder::XmlMarkup.new,
11
+ key_pair:,
12
+ signature_method: :SHA256,
13
+ digest_method: :SHA256)
14
+ signatures = new(
15
+ key_pair: key_pair,
16
+ signature_method: signature_method,
17
+ digest_method: digest_method
18
+ )
19
+ yield xml, XmlSignatureTemplate.new(xml, signatures)
20
+ signatures.complete(xml.target!)
21
+ end
22
+
9
23
  # @!visibility private
10
24
  def initialize(key_pair:, signature_method:, digest_method:)
11
25
  @digest_method = digest_method
@@ -38,20 +52,6 @@ module Xml
38
52
  Xmldsig::SignedDocument.new(raw_xml).sign(private_key, false)
39
53
  end
40
54
 
41
- # @!visibility private
42
- def self.sign(xml: ::Builder::XmlMarkup.new,
43
- key_pair:,
44
- signature_method: :SHA256,
45
- digest_method: :SHA256)
46
- signatures = new(
47
- key_pair: key_pair,
48
- signature_method: signature_method,
49
- digest_method: digest_method
50
- )
51
- yield xml, XmlSignatureTemplate.new(xml, signatures)
52
- signatures.complete(xml.target!)
53
- end
54
-
55
55
  class XmlSignatureTemplate # :nodoc:
56
56
  # @!visibility private
57
57
  attr_reader :signatures, :xml
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Xml
4
4
  module Kit
5
- VERSION = '0.6.0'
5
+ VERSION = '0.7.0'
6
6
  end
7
7
  end
@@ -0,0 +1,11 @@
1
+ {
2
+ "packages": {
3
+ ".": {
4
+ "release-type": "ruby",
5
+ "package-name": "xml-kit",
6
+ "version-file": "lib/xml/kit/version.rb",
7
+ "bump-minor-pre-major": true,
8
+ "include-component-in-tag": false
9
+ }
10
+ }
11
+ }
data/xml-kit.gemspec CHANGED
@@ -12,29 +12,33 @@ Gem::Specification.new do |spec|
12
12
 
13
13
  spec.summary = 'A simple toolkit for working with XML.'
14
14
  spec.description = 'A simple toolkit for working with XML.'
15
- spec.homepage = 'https://github.com/xlgmokha/xml-kit'
15
+ spec.homepage = 'https://github.com/mokhan-ca/xml-kit'
16
16
  spec.license = 'MIT'
17
- spec.required_ruby_version = Gem::Requirement.new('>= 2.7.0')
17
+ spec.required_ruby_version = Gem::Requirement.new('>= 3.2.0')
18
18
 
19
19
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
20
  f.match(%r{^(test|spec|features)/})
21
21
  end
22
22
  spec.metadata['yard.run'] = 'yri'
23
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
24
+ spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/main/CHANGELOG.md"
25
+ spec.metadata['rubygems_mfa_required'] = 'true'
26
+ spec.metadata['source_code_uri'] = spec.homepage
23
27
  spec.bindir = 'exe'
24
28
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
29
  spec.require_paths = ['lib']
26
30
 
27
31
  spec.add_dependency 'activemodel', '>= 4.2.0'
28
32
  spec.add_dependency 'builder', '~> 3.2'
29
- spec.add_dependency 'nokogiri', '~> 1.10'
33
+ spec.add_dependency 'nokogiri', '~> 1.19', '>= 1.19.1'
30
34
  spec.add_dependency 'tilt', '>= 1.4.1'
31
35
  spec.add_dependency 'xmldsig', '~> 0.6'
32
- spec.add_development_dependency 'bundler', '~> 2.0'
33
36
  spec.add_development_dependency 'bundler-audit', '~> 0.6'
34
37
  spec.add_development_dependency 'ffaker', '~> 2.7'
35
38
  spec.add_development_dependency 'rake', '~> 13.0'
39
+ spec.add_development_dependency 'rexml', '~> 3.0'
36
40
  spec.add_development_dependency 'rspec', '~> 3.0'
37
- spec.add_development_dependency 'rubocop', '~> 0.52'
38
- spec.add_development_dependency 'rubocop-rspec', '~> 1.22'
41
+ spec.add_development_dependency 'rubocop', '~> 1.0'
42
+ spec.add_development_dependency 'rubocop-rspec', '~> 3.0'
39
43
  spec.add_development_dependency 'simplecov', '~> 0.21.2'
40
44
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xml-kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - mo khan
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2022-05-23 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activemodel
@@ -44,14 +43,20 @@ dependencies:
44
43
  requirements:
45
44
  - - "~>"
46
45
  - !ruby/object:Gem::Version
47
- version: '1.10'
46
+ version: '1.19'
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 1.19.1
48
50
  type: :runtime
49
51
  prerelease: false
50
52
  version_requirements: !ruby/object:Gem::Requirement
51
53
  requirements:
52
54
  - - "~>"
53
55
  - !ruby/object:Gem::Version
54
- version: '1.10'
56
+ version: '1.19'
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 1.19.1
55
60
  - !ruby/object:Gem::Dependency
56
61
  name: tilt
57
62
  requirement: !ruby/object:Gem::Requirement
@@ -81,61 +86,61 @@ dependencies:
81
86
  - !ruby/object:Gem::Version
82
87
  version: '0.6'
83
88
  - !ruby/object:Gem::Dependency
84
- name: bundler
89
+ name: bundler-audit
85
90
  requirement: !ruby/object:Gem::Requirement
86
91
  requirements:
87
92
  - - "~>"
88
93
  - !ruby/object:Gem::Version
89
- version: '2.0'
94
+ version: '0.6'
90
95
  type: :development
91
96
  prerelease: false
92
97
  version_requirements: !ruby/object:Gem::Requirement
93
98
  requirements:
94
99
  - - "~>"
95
100
  - !ruby/object:Gem::Version
96
- version: '2.0'
101
+ version: '0.6'
97
102
  - !ruby/object:Gem::Dependency
98
- name: bundler-audit
103
+ name: ffaker
99
104
  requirement: !ruby/object:Gem::Requirement
100
105
  requirements:
101
106
  - - "~>"
102
107
  - !ruby/object:Gem::Version
103
- version: '0.6'
108
+ version: '2.7'
104
109
  type: :development
105
110
  prerelease: false
106
111
  version_requirements: !ruby/object:Gem::Requirement
107
112
  requirements:
108
113
  - - "~>"
109
114
  - !ruby/object:Gem::Version
110
- version: '0.6'
115
+ version: '2.7'
111
116
  - !ruby/object:Gem::Dependency
112
- name: ffaker
117
+ name: rake
113
118
  requirement: !ruby/object:Gem::Requirement
114
119
  requirements:
115
120
  - - "~>"
116
121
  - !ruby/object:Gem::Version
117
- version: '2.7'
122
+ version: '13.0'
118
123
  type: :development
119
124
  prerelease: false
120
125
  version_requirements: !ruby/object:Gem::Requirement
121
126
  requirements:
122
127
  - - "~>"
123
128
  - !ruby/object:Gem::Version
124
- version: '2.7'
129
+ version: '13.0'
125
130
  - !ruby/object:Gem::Dependency
126
- name: rake
131
+ name: rexml
127
132
  requirement: !ruby/object:Gem::Requirement
128
133
  requirements:
129
134
  - - "~>"
130
135
  - !ruby/object:Gem::Version
131
- version: '13.0'
136
+ version: '3.0'
132
137
  type: :development
133
138
  prerelease: false
134
139
  version_requirements: !ruby/object:Gem::Requirement
135
140
  requirements:
136
141
  - - "~>"
137
142
  - !ruby/object:Gem::Version
138
- version: '13.0'
143
+ version: '3.0'
139
144
  - !ruby/object:Gem::Dependency
140
145
  name: rspec
141
146
  requirement: !ruby/object:Gem::Requirement
@@ -156,28 +161,28 @@ dependencies:
156
161
  requirements:
157
162
  - - "~>"
158
163
  - !ruby/object:Gem::Version
159
- version: '0.52'
164
+ version: '1.0'
160
165
  type: :development
161
166
  prerelease: false
162
167
  version_requirements: !ruby/object:Gem::Requirement
163
168
  requirements:
164
169
  - - "~>"
165
170
  - !ruby/object:Gem::Version
166
- version: '0.52'
171
+ version: '1.0'
167
172
  - !ruby/object:Gem::Dependency
168
173
  name: rubocop-rspec
169
174
  requirement: !ruby/object:Gem::Requirement
170
175
  requirements:
171
176
  - - "~>"
172
177
  - !ruby/object:Gem::Version
173
- version: '1.22'
178
+ version: '3.0'
174
179
  type: :development
175
180
  prerelease: false
176
181
  version_requirements: !ruby/object:Gem::Requirement
177
182
  requirements:
178
183
  - - "~>"
179
184
  - !ruby/object:Gem::Version
180
- version: '1.22'
185
+ version: '3.0'
181
186
  - !ruby/object:Gem::Dependency
182
187
  name: simplecov
183
188
  requirement: !ruby/object:Gem::Requirement
@@ -199,9 +204,11 @@ executables: []
199
204
  extensions: []
200
205
  extra_rdoc_files: []
201
206
  files:
202
- - ".github/dependabot.yml"
207
+ - ".github/workflows/audit.yml"
203
208
  - ".github/workflows/ci.yml"
209
+ - ".github/workflows/release.yml"
204
210
  - ".gitignore"
211
+ - ".release-please-manifest.json"
205
212
  - ".rspec"
206
213
  - ".rubocop.yml"
207
214
  - CHANGELOG.md
@@ -252,13 +259,17 @@ files:
252
259
  - lib/xml/kit/templates/rsa_key_value.builder
253
260
  - lib/xml/kit/templates/signature.builder
254
261
  - lib/xml/kit/version.rb
262
+ - release-please-config.json
255
263
  - xml-kit.gemspec
256
- homepage: https://github.com/xlgmokha/xml-kit
264
+ homepage: https://github.com/mokhan-ca/xml-kit
257
265
  licenses:
258
266
  - MIT
259
267
  metadata:
260
268
  yard.run: yri
261
- post_install_message:
269
+ allowed_push_host: https://rubygems.org
270
+ changelog_uri: https://github.com/mokhan-ca/xml-kit/blob/main/CHANGELOG.md
271
+ rubygems_mfa_required: 'true'
272
+ source_code_uri: https://github.com/mokhan-ca/xml-kit
262
273
  rdoc_options: []
263
274
  require_paths:
264
275
  - lib
@@ -266,15 +277,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
266
277
  requirements:
267
278
  - - ">="
268
279
  - !ruby/object:Gem::Version
269
- version: 2.7.0
280
+ version: 3.2.0
270
281
  required_rubygems_version: !ruby/object:Gem::Requirement
271
282
  requirements:
272
283
  - - ">="
273
284
  - !ruby/object:Gem::Version
274
285
  version: '0'
275
286
  requirements: []
276
- rubygems_version: 3.3.13
277
- signing_key:
287
+ rubygems_version: 4.0.20
278
288
  specification_version: 4
279
289
  summary: A simple toolkit for working with XML.
280
290
  test_files: []
@@ -1,9 +0,0 @@
1
- ---
2
- version: 2
3
- updates:
4
- - package-ecosystem: "bundler"
5
- directory: "/"
6
- schedule:
7
- interval: "daily"
8
- assignees:
9
- - "xlgmokha"