Add Ruby script for delivering AS payload

This commit is contained in:
Anthony Wang 2022-07-11 15:12:46 -05:00
parent 964d4ff5a0
commit 41223c10be
Signed by: a
GPG Key ID: BC96B00AEC5F2D76
3 changed files with 55 additions and 0 deletions

14
deliver.rb Normal file
View File

@ -0,0 +1,14 @@
# https://blog.joinmastodon.org/2018/06/how-to-implement-a-basic-activitypub-server/
require 'http'
require 'openssl'
document = File.read('message')
date = Time.now.utc.httpdate
keypair = OpenSSL::PKey::RSA.new(File.read('private.pem'))
signed_string = "(request-target): post /inbox\nhost: git.exozy.me\ndate: #{date}"
signature = Base64.strict_encode64(keypair.sign(OpenSSL::Digest::SHA256.new, signed_string))
header = 'keyId="https://test.exozy.me/api/v1/activitypub/user/test#main-key",headers="(request-target) host date",signature="' + signature + '"'
HTTP.headers({ 'Host': 'mastodon.social', 'Date': date, 'Signature': header })
.post('https://git.exozy.me/api/v1/activitypub/user/Ta180m/inbox', body: document)

14
message Normal file
View File

@ -0,0 +1,14 @@
{
"@context": "https://www.w3.org/ns/activitystreams",
"type": "Note",
"attributedTo": "https://test.exozy.me/api/v1/activitypub/user/test",
"context": "https://git.exozy.me/Ta180m/Hello-world/issues/2",
"inReplyTo": "https://git.exozy.me/Ta180m/Hello-world/issues/2",
"mediaType": "text/html",
"content": "<p>Hello from test.exozy.me!</p>",
"source": {
"mediaType": "text/markdown; variant=Commonmark",
"content": "Hello from test.exozy.me!"
},
"published": "2019-11-06T20:49:05.604488Z"
}

27
private.pem Normal file
View File

@ -0,0 +1,27 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAsPQH/jssyJryAX9I065SZE69e5OIBW3q2nFjMBDlC+WStN2P
uJqFznsEcEMq9Ge3pTQ3Rqj2SumyqngwYhN63SpFjeplgvL20ygNfd5c4sVwZicn
aLAsjwcWS/7hF6ENW9Vhwk5yBYel7efxPaNY98XhPLVDYeX8ZfB8PKExC6V4h8d1
iQqMnSw+/twy1/W69x3A4sZlsIisqmiY18haxyR4Bbl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