http_signature 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: 0d4b1e73dff1838a018f5e0d5bef1c6a6a14c2b8ef552dbbfd0481ac85cb03b7
4
- data.tar.gz: 1a087ded86d8f84213984d9bd56fb55462f65feb9abc876514249f12fc5166ef
3
+ metadata.gz: a052e0252607d934ef7221c6aa3ea32fb21644af4f1af77985677db0cb2e2bb3
4
+ data.tar.gz: 843effaf6aac8b647b29d2d19f5414513be7efb76a0a1eb837b9cc2872fe3727
5
5
  SHA512:
6
- metadata.gz: 7796499163d70782ea0fd809316c39a4d2a933cf01cc88f6daaa88d673607e9a138643d666fc5080063ea0bdb1068d32c48642fb487c59d6edcb7626fba7ad8e
7
- data.tar.gz: 1603d71ad33fc087e456949de3e1534f3cf08c894a3fe10a3f456f6751409ddbbda247a53511d201866cf10f629e2c676fbe2eaa7cb0e0535dae81a2cad6e2a2
6
+ metadata.gz: 5aedcedf0056a4f98414a599a51ec89484500c3447f124c4f070b11d7567ec2c8b5f682aa17e8f1e6c1dcf09f0c1e796530ada79bca633e228e3cfe98154f575
7
+ data.tar.gz: 61e44809bd68c3d072b94faee4f1ba7915aa49e2acfde2131b55c2442982a14cd199e288eff6cf34533440bebfb3b788997a395f618830da4a4c7d96407e7e01
@@ -0,0 +1,25 @@
1
+ on:
2
+ push:
3
+ tags:
4
+ - 'v*.*.*'
5
+
6
+ jobs:
7
+ push:
8
+ name: Push gem to RubyGems.org
9
+ runs-on: ubuntu-latest
10
+
11
+ permissions:
12
+ id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
13
+ contents: write # IMPORTANT: this permission is required for `rake release` to push the release tag
14
+
15
+ steps:
16
+ - uses: actions/checkout@v5
17
+ with:
18
+ persist-credentials: false
19
+ - name: Set up Ruby
20
+ uses: ruby/setup-ruby@v1
21
+ with:
22
+ bundler-cache: true
23
+ ruby-version: '3.4'
24
+
25
+ - uses: rubygems/release-gem@v1
data/AGENTS.md ADDED
@@ -0,0 +1,4 @@
1
+ ## Tests
2
+ - Run all tests: `bundle exec rake test`
3
+ - Run single test file: `bundle exec rake test TEST=test/http_signature_test.rb`
4
+ - Run single test: `bundle exec rake test TEST=test/http_signature_test.rb TESTOPTS="--name=/test_rsa_pss_sha512/"`
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- http_signature (1.0.0)
4
+ http_signature (1.0.1)
5
5
  base64
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -2,18 +2,19 @@
2
2
 
3
3
  Create and validate HTTP Message Signatures per [RFC 9421](https://www.rfc-editor.org/rfc/rfc9421) using the `Signature-Input` and `Signature` headers.
4
4
 
5
- Aims to only implement the creation and validation of signatures without any external dependencies. Adapters are provided for common HTTP libraries.
5
+ TL;DR: You specify what should be signed in `Signature-Input` with [components](https://www.rfc-editor.org/rfc/rfc9421#name-derived-components) and lowercase headers. And then the signature is in the `Signature` header
6
+
7
+ Example:
6
8
 
7
- __NOTE__: RFC 9421 signs components via two headers:
8
9
  ```
9
- Signature-Input: sig1=("@method" "@authority" "@target-uri" "date");created=...
10
- Signature: sig1=:BASE64_SIGNATURE_BYTES:
10
+ Signature-Input: sig1=("@method" "@target-uri" "date");created=1767816111;keyid="Test";alg="hmac-sha256"
11
+ Signature: sig1=:7a1ajkE2rOu+gnW3WLZ4ZEcgCm3TfExmypM/giIgdM0=:
11
12
  ```
12
13
 
13
14
  ## Installation
14
15
 
15
16
  ```shell
16
- gem install http_signature
17
+ bundle add http_signature
17
18
  ```
18
19
 
19
20
  ## Usage
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HTTPSignature
4
- VERSION = "1.0.0"
4
+ VERSION = "1.0.1"
5
5
  end
@@ -11,7 +11,8 @@ module HTTPSignature
11
11
  Config = Struct.new(:keys)
12
12
  DEFAULT_LABEL = "sig1"
13
13
  DEFAULT_ALGORITHM = "hmac-sha256"
14
- DEFAULT_COMPONENTS = %w[@method @authority @target-uri].freeze
14
+ DEFAULT_COMPONENTS = %w[@method @target-uri].freeze
15
+ DEFAULT_HEADERS = %w[content-digest content-type].freeze
15
16
 
16
17
  class SignatureError < StandardError; end
17
18
  class MissingComponent < SignatureError; end
@@ -65,10 +66,15 @@ module HTTPSignature
65
66
  normalized_headers = normalize_headers(headers)
66
67
  uri = apply_query_params(URI(url), query_string_params)
67
68
 
68
- normalized_headers = ensure_content_digest(normalized_headers, body)
69
-
70
69
  components =
71
- covered_components || default_components(normalized_headers)
70
+ covered_components || default_components(normalized_headers, body:)
71
+
72
+ normalized_headers =
73
+ if components.include?("content-digest")
74
+ ensure_content_digest(normalized_headers, body)
75
+ else
76
+ normalized_headers
77
+ end
72
78
 
73
79
  canonical_components = build_components(
74
80
  uri: uri,
@@ -124,7 +130,9 @@ module HTTPSignature
124
130
  raise SignatureError, "Key is required for verification" unless resolved_key
125
131
 
126
132
  uri = apply_query_params(URI(url), query_string_params)
127
- normalized_headers = ensure_content_digest(normalized_headers, body)
133
+ if parsed_input[:components].include?("content-digest")
134
+ normalized_headers = ensure_content_digest(normalized_headers, body)
135
+ end
128
136
 
129
137
  canonical_components = build_components(
130
138
  uri: uri,
@@ -162,10 +170,19 @@ module HTTPSignature
162
170
  new_uri
163
171
  end
164
172
 
165
- def self.default_components(headers)
173
+ def self.default_components(headers, body: nil)
166
174
  components = DEFAULT_COMPONENTS.dup
167
- components << "date" if headers["date"]
168
- components << "content-digest" if headers["content-digest"]
175
+ DEFAULT_HEADERS.each do |header|
176
+ include_header =
177
+ if header == "content-digest"
178
+ !body.to_s.empty? || headers[header]
179
+ else
180
+ headers[header]
181
+ end
182
+
183
+ components << header if include_header
184
+ end
185
+
169
186
  components
170
187
  end
171
188
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http_signature
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
  - Joel Larsson
@@ -143,9 +143,11 @@ extensions: []
143
143
  extra_rdoc_files: []
144
144
  files:
145
145
  - ".github/workflows/ci.yml"
146
+ - ".github/workflows/push_gem.yml"
146
147
  - ".github/workflows/standardrb.yml"
147
148
  - ".gitignore"
148
149
  - ".ruby-version"
150
+ - AGENTS.md
149
151
  - Gemfile
150
152
  - Gemfile.lock
151
153
  - README.md