serge 0.1.0 → 0.2.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: 7d123b881b2747c9be15783a3acc8f79af45aacf0e9823708c504bdd83877c04
4
- data.tar.gz: aef408116087ad1eb5427f777766c4ac44880dece234772416455784641ffdc6
3
+ metadata.gz: dd9ed2d4820a6121a5f0b4539ade121e54d55af302a42144879f91c15bff1375
4
+ data.tar.gz: 251d4173c7836cdf85f5d0dfe56585dc93937f26018a5c08d88c2b9faf8776db
5
5
  SHA512:
6
- metadata.gz: 22b4f55ebbb5b38a9eef5fe699ff17421e9bfa56eb208a6dfc0a9f698364c2f17e48a1a68619f11168cdc1c0a7d27ab2bf1fd32da003898b94e62b6a92c7c625
7
- data.tar.gz: 5a497cf2a756d26ac3d1165d77eaeab1c6385e323daa5751446f909626706c2e48bf41fbb6415f94162f15f9de72d8128a581031cea9ecbefc7729666c0b6c92
6
+ metadata.gz: a25124728926af3ddf194e6b1d869f7b1e8a8aec009db2cd667c0ff848b6b2cadd99b091ad1cfd3eaf7aabd852cebe41846e2eb06e561de79bc32e328c38eea7
7
+ data.tar.gz: 99b41d570a88802bc638da8df1529baa9f0ff999eee33ed2c57c45dbbf6b3f62478aeea3e882974f0fda25aa7ce122123e5ae9d14674214c87a1b0b765e5ebba
data/README.md CHANGED
@@ -1,28 +1,49 @@
1
1
  # Serge
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
4
-
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/serge`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ A Ruby library to handle HTTP signatures for inbox deliveries on the Fediverse.
6
4
 
7
5
  ## Installation
8
6
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
-
11
7
  Install the gem and add to the application's Gemfile by executing:
12
8
 
13
9
  ```bash
14
- bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
10
+ bundle add serge
15
11
  ```
16
12
 
17
13
  If bundler is not being used to manage dependencies, install the gem by executing:
18
14
 
19
15
  ```bash
20
- gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
16
+ gem install serge
21
17
  ```
22
18
 
23
19
  ## Usage
24
20
 
25
- TODO: Write usage instructions here
21
+ There are 2 HTTP signature formats (draft-cavage and [RFC 9421](https://www.rfc-editor.org/info/rfc9421/)) in use on the Fediverse. `InboxDelivery` handles both formats with one interface.
22
+
23
+ For incoming messages, inside of a Rails controller method:
24
+
25
+ ```ruby
26
+ begin
27
+ inbox_delivery = Serge::InboxDelivery.new(request)
28
+ key_id = inbox_delivery.key_id
29
+ # public_key = YOUR_CODE_TO_RETRIEVE_PUBLIC_KEY_FROM_KEY_ID
30
+
31
+ # verify the signature using the PEM-encoded RSA public key
32
+ if inbox_delivery.verified?(public_key)
33
+ # signature is valid
34
+ else
35
+ # signature is not valid
36
+ end
37
+ rescue Serge::SignatureVerificationError => e
38
+ # YOUR_CODE_TO_HANDLE_EXCEPTION
39
+ end
40
+ ```
41
+
42
+ You can also set the logger in a Rails initializer like `config/initializers/serge.rb`:
43
+
44
+ ```ruby
45
+ Serge::InboxDelivery.logger = Rails.logger
46
+ ```
26
47
 
27
48
  ## Development
28
49
 
@@ -32,8 +53,8 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
53
 
33
54
  ## Contributing
34
55
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/serge. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/serge/blob/main/CODE_OF_CONDUCT.md).
56
+ Bug reports and pull requests are welcome on GitHub at https://github.com/herestomwiththeweather/serge. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/herestomwiththeweather/serge/blob/main/CODE_OF_CONDUCT.md).
36
57
 
37
58
  ## Code of Conduct
38
59
 
39
- Everyone interacting in the Serge project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/serge/blob/main/CODE_OF_CONDUCT.md).
60
+ Everyone interacting in the Serge project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/herestomwiththeweather/serge/blob/main/CODE_OF_CONDUCT.md).
@@ -0,0 +1,22 @@
1
+ module Serge
2
+ class MessageSignature
3
+ def self.headers(method:, url:, body:, public_key_id:, private_key:)
4
+ components = %w[@method @target-uri]
5
+
6
+ signature_headers = {}
7
+ if body.present?
8
+ signature_headers['Content-Digest'] = "sha-256=:#{Digest::SHA256.base64digest(body)}:"
9
+ components << 'content-digest'
10
+ end
11
+
12
+ temp_request = Net::HTTP.const_get(method.capitalize).new(URI(url), signature_headers)
13
+ key = Linzer.new_rsa_v1_5_sha256_key(private_key, public_key_id)
14
+ Linzer.sign!(temp_request, key: key, components: components)
15
+
16
+ signature_headers.merge({
17
+ 'Signature-Input' => temp_request['signature-input'],
18
+ 'Signature' => temp_request['signature']
19
+ })
20
+ end
21
+ end
22
+ end
data/lib/serge/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Serge
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/serge.rb CHANGED
@@ -16,4 +16,5 @@ end
16
16
  require 'serge/error.rb'
17
17
  require 'serge/signature_verification_error.rb'
18
18
  require 'serge/fedi_signature.rb'
19
+ require 'serge/message_signature.rb'
19
20
  require 'serge/inbox_delivery.rb'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Brown
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-09-28 00:00:00.000000000 Z
11
+ date: 2026-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -78,6 +78,7 @@ files:
78
78
  - lib/serge/inbox_delivery.rb
79
79
  - lib/serge/inbox_delivery/http_legacy_signature.rb
80
80
  - lib/serge/inbox_delivery/http_message_signature.rb
81
+ - lib/serge/message_signature.rb
81
82
  - lib/serge/signature_verification_error.rb
82
83
  - lib/serge/version.rb
83
84
  homepage: https://github.com/herestomwiththeweather/serge