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 +4 -4
- data/.github/workflows/push_gem.yml +25 -0
- data/AGENTS.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +6 -5
- data/lib/http_signature/version.rb +1 -1
- data/lib/http_signature.rb +25 -8
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a052e0252607d934ef7221c6aa3ea32fb21644af4f1af77985677db0cb2e2bb3
|
|
4
|
+
data.tar.gz: 843effaf6aac8b647b29d2d19f5414513be7efb76a0a1eb837b9cc2872fe3727
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
data/Gemfile.lock
CHANGED
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
|
-
|
|
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" "@
|
|
10
|
-
Signature: sig1=:
|
|
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
|
-
|
|
17
|
+
bundle add http_signature
|
|
17
18
|
```
|
|
18
19
|
|
|
19
20
|
## Usage
|
data/lib/http_signature.rb
CHANGED
|
@@ -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 @
|
|
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
|
-
|
|
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
|
-
|
|
168
|
-
|
|
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.
|
|
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
|