aboutsummaryrefslogtreecommitdiff
path: root/deliver.rb
blob: b54de2dce4262619432721477c7b7cd0197d5378 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
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': 'git.exozy.me', 'Date': date, 'Signature': header })
    .post('https://git.exozy.me/api/v1/activitypub/repo/Ta180m/Hello-world/inbox', body: document)