Skip to content

Instantly share code, notes, and snippets.

@jb55
Created August 31, 2018 04:20
Show Gist options
  • Save jb55/d81ea3f2c3666778e4be8774fa782e97 to your computer and use it in GitHub Desktop.
Save jb55/d81ea3f2c3666778e4be8774fa782e97 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
host="functional.cafe"
now="$(date -u '+%a, %d %b %Y %H:%M:%S GMT')"
published="$(date -u +'%FT%R:%SZ')"
doc=$(cat <<EOF
{
"@context": "https://www.w3.org/ns/activitystreams",
"id": "https://jb55.com/create-hello-world-2",
"type": "Create",
"actor": "https://jb55.com",
"to": [ "https://$host/users/jb55", "https://www.w3.org/ns/activitystreams#Public" ],
"object": {
"id": "https://jb55.com/hello-world-2",
"type": "Note",
"published": "$published",
"attributedTo": "https://jb55.com",
"to": [ "https://$host/users/jb55", "https://www.w3.org/ns/activitystreams#Public" ],
"content": "does this work tho"
}
}
EOF
)
echo "$doc"
#now="Tue, 28 Aug 2018 19:02:37 GMT"
sig=$(printf "(request-target): post /inbox\nhost: %s\ndate: %s" "$host" "$now" \
| openssl dgst -sha256 -sign private.pem -keyform PEM \
| base64 -w 1000
)
header="keyId=\"https://jb55.com#main-key\",headers=\"(request-target) host date\",signature=\"$sig\""
curl -v -sL -H 'Content-Type: application/json' -H "Date: $now" -H "Signature: $header" -H "Host: $host" -d "$doc" -X POST "https://$host/inbox" | nl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment