Skip to content

Instantly share code, notes, and snippets.

@waweic
Created July 29, 2018 09:55
Show Gist options
  • Save waweic/2b2f1ad8221a738aa7df05a519d80ca3 to your computer and use it in GitHub Desktop.
Save waweic/2b2f1ad8221a738aa7df05a519d80ca3 to your computer and use it in GitHub Desktop.
I think these are all files needed to understand my problem
* Serving Flask app "simple_python_activitypub"
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [29/Jul/2018 10:58:44] "GET /users/waweic HTTP/1.0" 200 -
127.0.0.1 - - [29/Jul/2018 10:58:44] "GET /users/waweic HTTP/1.0" 200 -
127.0.0.1 - - [29/Jul/2018 10:58:44] "GET /.well-known/webfinger?resource=acct:waweic@testing1.ism.rocks HTTP/1.0" 200 -
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAutW8neaZrIGKGI5IWYGa
3aZt7Of09Op+PArt0Sl95MpUjhA44MiKbda6G6qgE2ehjK1GQ+zxLS03D5uKCCpM
3G2BHQVx9WocwJJkwDoB9EWnyJAE/bBtTbkFbMYXgRGVuEadBivbqERDkUOIEiCO
alvZCIcbDJbwLh3TtGVHndIjqYD1Flf1JyIwxhFsXgVdZNroP90fRn7lHsIxH+zK
+DciIqXlryOjpfVG8d6JUzxBMJ8JbTbdmjgqxOoM5Du7QFFPJQdTelLiAsxlIufU
CTko0eqgOIVv4RiKmDRdv4HcgywoPZ04NP2Y4445/NKlB2sW3iPIwUUmxqaYEnAv
3wIDAQAB
-----END PUBLIC KEY-----
401
Public key not found for key https://testing1.ism.rocks/users/waweic#main-key
require 'http'
require 'openssl'
document = File.read('create-hello-world.json')
date = Time.now.utc.httpdate
keypair = OpenSSL::PKey::RSA.new(File.read('private.pem'))
signed_string = "(request-target): post /inbox\nhost: mastodon.social\ndate: #{date}"
signature = Base64.strict_encode64(keypair.sign(OpenSSL::Digest::SHA256.new, signed_string))
header = 'keyId="https://testing1.ism.rocks/users/waweic#main-key",headers="(request-target) host date",signature="' + signature + '"'
http = HTTP.headers({ 'Host': 'mastodon.social', 'Date': date, 'Signature': header })
response = http.post('https://mastodon.social/inbox', body: document)
print(response.code)
print("\n")
print(response.body)
# print(response.body)
# print(signed_string)
# print("\n\n")
# print(signature)
POST /inbox HTTP/1.1
Host: mastodon.social
Date: Sun, 29 Jul 2018 08:53:30 GMT
Signature: keyId="https://testing1.ism.rocks/users/waweic#main-key",headers="(request-target) host date",signature="tgrZ/YvRzx5BuODSFz/IzvUbDvu6o3/grEAwaBnxUsYNmpYH0FNi2gxglFFlWwerSM3cM3Zv+8/wBnWe2i3/g+mtPti9nwVvRo3nTIbalCEXDIxgDpz9STZ4RGNd+jzgW+8/zR+qMgAcVcBU+nvSIXLQNTQdA/fYXrJs9ZI3LkupByzpkfiE7CjSmgfKLmsi4z8EBNJda6EnvnqDLmOroMmgTAI/5LmXfqj1S92E2i3N+bTsXx0YpMyodNMmZXzhQUfJ9zq7G0irZoYPbqBNWqUfZiUau5pSFpS/UBh1J0iurEK7/gYilkOraEewFA6BMFYGuAeA+8bWgfTgSSPMnA=="
Connection: close
User-Agent: http.rb/3.3.0
Content-Length: 582
{
"@context": "https://www.w3.org/ns/activitystreams",
"id": "https://testing1.ism.rocks/object/dsngoisgoihs/activity",
"type": "Create",
"actor": "https://testing1.ism.rocks/users/waweic",
"object": {
"id": "https://testing1.ism.rocks/object/dsngoisgoihs",
"type": "Note",
"published": "2018-07-27T20:38:11Z",
"attributedTo": "https://testing1.ism.rocks/users/waweic",
"inReplyTo": "https://mastodon.social/users/Gargron/statuses/100254678717223630",
"content": "<p>Hello world</p>",
"to": "https://www.w3.org/ns/activitystreams#Public"
}
}
{"@context": ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"], "id": "https://testing1.ism.rocks/users/waweic", "type": "Person", "inbox": "https://testing1.ism.rocks/users/waweic/inbox", "preferredUsername": "waweic", "publicKey": {"owner": "https://testing1.ism.rocks/users/waweic", "id": "https://testing1.ism.rocks/users/waweic#main-key", "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAutW8neaZrIGKGI5IWYGa\n3aZt7Of09Op+PArt0Sl95MpUjhA44MiKbda6G6qgE2ehjK1GQ+zxLS03D5uKCCpM\n3G2BHQVx9WocwJJkwDoB9EWnyJAE/bBtTbkFbMYXgRGVuEadBivbqERDkUOIEiCO\nalvZCIcbDJbwLh3TtGVHndIjqYD1Flf1JyIwxhFsXgVdZNroP90fRn7lHsIxH+zK\n+DciIqXlryOjpfVG8d6JUzxBMJ8JbTbdmjgqxOoM5Du7QFFPJQdTelLiAsxlIufU\nCTko0eqgOIVv4RiKmDRdv4HcgywoPZ04NP2Y4445/NKlB2sW3iPIwUUmxqaYEnAv\n3wIDAQAB\n-----END PUBLIC KEY-----"}}
{
"subject": "acct:waweic@testing1.ism.rocks",
"links": [
{
"rel": "self",
"type": "application/activity+json",
"href": "https://testing1.ism.rocks/users/waweic"
}
]
}
@waweic
Copy link
Author

waweic commented Jul 29, 2018

  • I execute the send.rb script.
  • The contents like in this_is_what_i_send.http are sent to mastodon.social
  • I see the entries in my flask log (at my_flask_log.log). Note that I have an nginx proxy between the internet and my server to provide an SSL connection.
  • Both the contents of waweic.json and later webfinger.json are replied to mastodon.social. (Note that I got them over curl, so this definitely works)
  • I see the contents of ruby_script.log on my screen and have no clue why I get an error code back, because verifying the signature using public.pem works.

Note, that I nearly completely copy-pasted the contents of send.rb from Gargrons blogpost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment