summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--activitypub.rb16
-rw-r--r--client.rb5
-rw-r--r--helpers.rb36
3 files changed, 36 insertions, 21 deletions
diff --git a/activitypub.rb b/activitypub.rb
index fd8583e..9b63b46 100644
--- a/activitypub.rb
+++ b/activitypub.rb
@@ -1,22 +1,7 @@
-# TODO
-# server
-# fix failed follows
-# federation
-# boost
-# thread expansion
-# include own posts in threads
-# implement remaining activities
-# test with pleroma etc
-
-# client
-# post form
-# parse hashtags in post
-# client post media
require 'uri'
require 'base64'
require 'digest/sha2'
require 'sinatra'
-require_relative 'helpers.rb'
USER = "pdp8"
WWW_DOMAIN = "pdp8.info"
@@ -32,5 +17,6 @@ set :session_secret, File.read(".secret").chomp
set :default_content_type, 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
set :port, 9292
+require_relative 'helpers.rb'
require_relative 'server.rb'
require_relative 'client.rb'
diff --git a/client.rb b/client.rb
index 2067937..512c1d3 100644
--- a/client.rb
+++ b/client.rb
@@ -1,4 +1,3 @@
-
# client-server
post "/outbox" do
protected!
@@ -62,10 +61,12 @@ post "/delete_all" do
redirect to("/")
end
-post "/follow/*/*" do
+post "/follow/*" do
protected!
mention = params['splat'][0]
actor = actor(mention)
+ p mention
+ p actor
follow = { "@context" => "https://www.w3.org/ns/activitystreams",
"id" => File.join(SOCIAL_URL, "following", mention + ".json"),
"type" => "Follow",
diff --git a/helpers.rb b/helpers.rb
index b8f65de..4533e28 100644
--- a/helpers.rb
+++ b/helpers.rb
@@ -1,4 +1,3 @@
-
helpers do
def protected!
@@ -134,7 +133,7 @@ helpers do
File.open('cache/people.tsv','a'){|f| f.puts "#{mention}\t#{actor}"}
actor
else
- actors[0][0]
+ actors[0][1]
end
end
@@ -160,8 +159,33 @@ helpers do
# https://github.com/mastodon/mastodon/blob/main/app/lib/request.rb
keypair = OpenSSL::PKey::RSA.new(File.read('private.pem'))
date = Time.now.utc.httpdate
- host = URI.parse(url).host
- inbox = fetch(url)["inbox"]
+ uri = URI.parse(url)
+
+ sha256 = OpenSSL::Digest::SHA256.new
+ body = object.to_json
+ digest = "SHA-256=" + sha256.base64digest(body)
+ p inbox(uri)
+
+ signed_string = "(request-target): post #{inbox uri}\nhost: #{uri.host}\ndate: #{date}\ndigest: #{digest}\ncontent-type: application/activity+json"
+ #signed_string = "(request-target): post #{fetch(uri)["inbox"]}\nhost: #{uri.host}\ndate: #{date}\ndigest: #{digest}\ncontent-type: application/activity+json"
+ signature = Base64.strict_encode64(keypair.sign(OpenSSL::Digest.new('SHA256'), signed_string))
+ signed_header = 'keyId="' + ACTOR + '#main-key",algorithm="rsa-sha256",headers="(request-target) host date digest content-type",signature="' + signature + '"'
+
+ puts `/run/current-system/sw/bin/curl -i -X POST -H 'Content-Type: application/activity+json' -H 'Host: #{uri.host}' -H 'Date: #{date}' -H 'Digest: #{digest}' -H 'Signature: #{signed_header}' -d '#{body}' #{fetch(url)['inbox']}`
+ end
+
+ def inbox uri
+ URI(fetch(uri)["inbox"]).request_uri
+ end
+=begin
+ def send_signed object, url
+ # https://github.com/mastodon/mastodon/blob/main/app/lib/request.rb
+ keypair = OpenSSL::PKey::RSA.new(File.read('private.pem'))
+ date = Time.now.utc.httpdate
+ uri = URI.parse(url)
+ #inbox = fetch(url)["endpoints"]["sharedInbox"]
+ #inbox = fetch(url)["inbox"]
+ #p inbox
sha256 = OpenSSL::Digest::SHA256.new
body = object.to_json
@@ -171,7 +195,11 @@ helpers do
signature = Base64.strict_encode64(keypair.sign(OpenSSL::Digest.new('SHA256'), signed_string))
signed_header = 'keyId="' + ACTOR + '#main-key",algorithm="rsa-sha256",headers="(request-target) host date digest content-type",signature="' + signature + '"'
+ #p signed_string
+ #p signed_header
+ #p body
puts `/run/current-system/sw/bin/curl -i -X POST -H 'Content-Type: application/activity+json' -H 'Host: #{host}' -H 'Date: #{date}' -H 'Digest: #{digest}' -H 'Signature: #{signed_header}' -d '#{body}' #{inbox}`
end
+=end
end