linzer 0.8.0.beta1 → 0.8.0.beta2
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/.standard.yml +1 -0
- data/CHANGELOG.md +7 -0
- data/README.md +55 -0
- data/lib/faraday/http_signature/middleware.rb +25 -4
- data/lib/linzer/common.rb +2 -2
- data/lib/linzer/helper.rb +34 -15
- data/lib/linzer/http/signature_feature.rb +15 -4
- data/lib/linzer/http/structured_field.rb +123 -26
- data/lib/linzer/http.rb +13 -7
- data/lib/linzer/message/adapter/abstract.rb +30 -17
- data/lib/linzer/message/adapter/generic/request.rb +1 -0
- data/lib/linzer/message/field/parser.rb +5 -5
- data/lib/linzer/message/field.rb +4 -4
- data/lib/linzer/message/overlay.rb +143 -0
- data/lib/linzer/message.rb +18 -0
- data/lib/linzer/signature/context.rb +80 -0
- data/lib/linzer/signature/profile/base.rb +43 -0
- data/lib/linzer/signature/profile/example.rb +39 -0
- data/lib/linzer/signature/profile/web_bot_auth.rb +201 -0
- data/lib/linzer/signature/profile.rb +70 -0
- data/lib/linzer/signature.rb +29 -39
- data/lib/linzer/version.rb +1 -1
- data/lib/linzer.rb +5 -2
- metadata +7 -1
data/lib/linzer/signature.rb
CHANGED
|
@@ -150,11 +150,11 @@ module Linzer
|
|
|
150
150
|
def to_h
|
|
151
151
|
return @headers if @headers
|
|
152
152
|
|
|
153
|
-
items = @parsed_items || serialized_components.map { |c|
|
|
153
|
+
items = @parsed_items || serialized_components.map { |c| HTTP::StructuredField.parse_item(c) }
|
|
154
154
|
{
|
|
155
|
-
"signature" =>
|
|
156
|
-
"signature-input" =>
|
|
157
|
-
label =>
|
|
155
|
+
"signature" => HTTP::StructuredField.serialize({label => value}),
|
|
156
|
+
"signature-input" => HTTP::StructuredField.serialize({
|
|
157
|
+
label => HTTP::StructuredField::InnerList.new(items, parameters)
|
|
158
158
|
})
|
|
159
159
|
}
|
|
160
160
|
end
|
|
@@ -168,7 +168,7 @@ module Linzer
|
|
|
168
168
|
# Clone items that have parameters since the adapter's retrieve
|
|
169
169
|
# method may mutate parameters (e.g., deleting "req").
|
|
170
170
|
unless item.parameters.empty?
|
|
171
|
-
item =
|
|
171
|
+
item = HTTP::StructuredField::Item.new(item.value, item.parameters.dup)
|
|
172
172
|
end
|
|
173
173
|
Message::Field::FastIdentifier.new(serialized, item)
|
|
174
174
|
end
|
|
@@ -234,9 +234,14 @@ module Linzer
|
|
|
234
234
|
def build(headers, options = {})
|
|
235
235
|
basic_validate headers
|
|
236
236
|
headers.transform_keys!(&:downcase)
|
|
237
|
+
headers.transform_values! { |v| v.encode(Encoding::ASCII) }
|
|
237
238
|
validate headers
|
|
238
239
|
|
|
239
|
-
input =
|
|
240
|
+
input = HTTP::StructuredField.parse_dictionary(
|
|
241
|
+
headers["signature-input"],
|
|
242
|
+
field_name: "signature-input"
|
|
243
|
+
)
|
|
244
|
+
|
|
240
245
|
reject_multiple_signatures if input.size > 1 && options[:label].nil?
|
|
241
246
|
label = options[:label] || input.keys.first
|
|
242
247
|
|
|
@@ -316,51 +321,36 @@ module Linzer
|
|
|
316
321
|
end
|
|
317
322
|
|
|
318
323
|
# Label not found via fast path — fall back to Starry
|
|
319
|
-
signature =
|
|
320
|
-
value.encode(Encoding::US_ASCII),
|
|
324
|
+
signature = HTTP::StructuredField.parse_dictionary(
|
|
325
|
+
value.encode(Encoding::US_ASCII),
|
|
326
|
+
field_name: "signature"
|
|
321
327
|
)
|
|
322
328
|
fail_with_signature_not_found label unless signature.key?(label)
|
|
323
329
|
signature[label].value.force_encoding(Encoding::ASCII_8BIT)
|
|
324
330
|
rescue ArgumentError
|
|
325
331
|
# Base64 decode failed — fall back to Starry
|
|
326
|
-
signature =
|
|
327
|
-
value.encode(Encoding::US_ASCII),
|
|
328
|
-
|
|
332
|
+
signature = HTTP::StructuredField.parse_dictionary(
|
|
333
|
+
value.encode(Encoding::US_ASCII),
|
|
334
|
+
field_name: "signature")
|
|
329
335
|
fail_with_signature_not_found label unless signature.key?(label)
|
|
330
336
|
signature[label].value.force_encoding(Encoding::ASCII_8BIT)
|
|
331
337
|
end
|
|
332
338
|
|
|
333
|
-
# Serializes parsed
|
|
334
|
-
#
|
|
339
|
+
# Serializes parsed structured field items to their RFC 8941
|
|
340
|
+
# string representations.
|
|
335
341
|
#
|
|
336
|
-
#
|
|
337
|
-
#
|
|
342
|
+
# Serialization is delegated to `Starry.serialize_item` to ensure
|
|
343
|
+
# consistent RFC-compliant formatting of structured field items and
|
|
344
|
+
# parameters.
|
|
345
|
+
#
|
|
346
|
+
# @param items [Array<Starry::Item>]
|
|
347
|
+
# Parsed structured field items.
|
|
348
|
+
#
|
|
349
|
+
# @return [Array<String>]
|
|
350
|
+
# The serialized structured field item representations.
|
|
338
351
|
#
|
|
339
|
-
# @param items [Array<Starry::Item>] parsed items from signature-input
|
|
340
|
-
# @return [Array<String>] serialized component identifiers
|
|
341
352
|
def serialize_parsed_items(items)
|
|
342
|
-
items.map
|
|
343
|
-
if item.parameters.empty?
|
|
344
|
-
"\"#{item.value}\""
|
|
345
|
-
else
|
|
346
|
-
Starry.serialize_item(item)
|
|
347
|
-
end
|
|
348
|
-
end
|
|
349
|
-
end
|
|
350
|
-
|
|
351
|
-
def parse_structured_dictionary(str, field_name = nil)
|
|
352
|
-
Starry.parse_dictionary(str)
|
|
353
|
-
rescue Starry::ParseError => _
|
|
354
|
-
raise Error.new "Cannot parse \"#{field_name}\" field. Bailing out!"
|
|
355
|
-
end
|
|
356
|
-
|
|
357
|
-
# Parses a structured field value as a dictionary.
|
|
358
|
-
# @see https://datatracker.ietf.org/doc/html/rfc8941 RFC 8941
|
|
359
|
-
def parse_structured_field(hsh, field_name)
|
|
360
|
-
# Serialized Structured Field values for HTTP are ASCII strings.
|
|
361
|
-
# See: RFC 8941 (https://datatracker.ietf.org/doc/html/rfc8941)
|
|
362
|
-
value = hsh[field_name].encode(Encoding::US_ASCII)
|
|
363
|
-
parse_structured_dictionary(value, field_name)
|
|
353
|
+
items.map { |item| HTTP::StructuredField.serialize_item(item) }
|
|
364
354
|
end
|
|
365
355
|
end
|
|
366
356
|
end
|
data/lib/linzer/version.rb
CHANGED
data/lib/linzer.rb
CHANGED
|
@@ -6,12 +6,17 @@ require "uri"
|
|
|
6
6
|
require "net/http"
|
|
7
7
|
|
|
8
8
|
require_relative "linzer/version"
|
|
9
|
+
require_relative "linzer/http"
|
|
10
|
+
require_relative "linzer/http/structured_field"
|
|
9
11
|
require_relative "linzer/common"
|
|
12
|
+
require_relative "linzer/signature/context"
|
|
13
|
+
require_relative "linzer/signature/profile"
|
|
10
14
|
require_relative "linzer/helper"
|
|
11
15
|
require_relative "linzer/options"
|
|
12
16
|
require_relative "linzer/message"
|
|
13
17
|
require_relative "linzer/message/adapter"
|
|
14
18
|
require_relative "linzer/message/wrapper"
|
|
19
|
+
require_relative "linzer/message/overlay"
|
|
15
20
|
require_relative "linzer/message/field"
|
|
16
21
|
require_relative "linzer/message/field/parser"
|
|
17
22
|
require_relative "linzer/signature"
|
|
@@ -24,8 +29,6 @@ require_relative "linzer/ecdsa"
|
|
|
24
29
|
require_relative "linzer/key/helper"
|
|
25
30
|
require_relative "linzer/signer"
|
|
26
31
|
require_relative "linzer/verifier"
|
|
27
|
-
require_relative "linzer/http"
|
|
28
|
-
require_relative "linzer/http/structured_field"
|
|
29
32
|
|
|
30
33
|
# Linzer is a Ruby library for HTTP Message Signatures as defined in RFC 9421.
|
|
31
34
|
#
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: linzer
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.8.0.
|
|
4
|
+
version: 0.8.0.beta2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Miguel Landaeta
|
|
@@ -160,12 +160,18 @@ files:
|
|
|
160
160
|
- lib/linzer/message/adapter/rack/response.rb
|
|
161
161
|
- lib/linzer/message/field.rb
|
|
162
162
|
- lib/linzer/message/field/parser.rb
|
|
163
|
+
- lib/linzer/message/overlay.rb
|
|
163
164
|
- lib/linzer/message/wrapper.rb
|
|
164
165
|
- lib/linzer/options.rb
|
|
165
166
|
- lib/linzer/rack.rb
|
|
166
167
|
- lib/linzer/rsa.rb
|
|
167
168
|
- lib/linzer/rsa_pss.rb
|
|
168
169
|
- lib/linzer/signature.rb
|
|
170
|
+
- lib/linzer/signature/context.rb
|
|
171
|
+
- lib/linzer/signature/profile.rb
|
|
172
|
+
- lib/linzer/signature/profile/base.rb
|
|
173
|
+
- lib/linzer/signature/profile/example.rb
|
|
174
|
+
- lib/linzer/signature/profile/web_bot_auth.rb
|
|
169
175
|
- lib/linzer/signer.rb
|
|
170
176
|
- lib/linzer/verifier.rb
|
|
171
177
|
- lib/linzer/version.rb
|