repo: actpub action: blob revision: path_from: ap-follow revision_from: refs/heads/master: path_to: revision_to:
blob of:
/ ap-follow
refs/heads/master:/ap-follow
#!/usr/bin/env bash
date="$(rfc7231date)"
## this is static
context="https://www.w3.org/ns/activitystreams"
## TODO: figure out if these have to mean anything
uuid="$(uuidgen -t)"
id="https://thebackupbox.net/~epoch/outbox/${uuid}"
type="Follow"
if [ ! "$1" ];then
printf "usage: ap-follow @user@host\n" >&2
printf "(leading @s are acceptable)\n" >&2
exit 1
fi
user="$1"
target_actor="$(ap-getactoruri "$user")"
if [ ! "${target_actor}" ];then
printf "unable to find actor URI for user %s\n" "$user" >&2
exit 2
fi
target_inbox="$(ap-getinboxuri "$user")"
if [ ! "$target_inbox" ];then
printf "unable to find inbox URI for user %s\n" "$user" >&2
exit 3
fi
## actor should be grabbed from a config file, or you know, static since only I'm going to use this.
actor="https://thebackupbox.net/~epoch/"
host="$(printf "%s\n" "$target_actor" | uricut -d)"
#TODO: extact the inbox to use based on the object, not just hard-coding the target's user@host here
target_inbox_path="/$(printf "%s\n" "${target_inbox}" | uricut -p)"
POST_DATA='{"@context":"'"$context"'","id":"'"$id"'","type":"'"$type"'","actor":"'"$actor"'","object":"'"$target_actor"'"}'
mkdir -p ~/.cache/ap/outbox/
cache_file=~/.cache/ap/outbox/"${uuid}"
printf "%s" "${POST_DATA}" > "${cache_file}"
ap-upload-to-outbox "${cache_file}"
HTTP_DIGEST="SHA-256=$(printf "%s" "$POST_DATA" | openssl sha256 | cut '-d ' -f2- | xxd -r -p | base64)"
printf "digest: %s\n" "${HTTP_DIGEST}"
HTTPSIG_KEYID="https://thebackupbox.net/~epoch/#main-key"
HTTPSIG_HEADERS="(request-target) host date digest content-type"
HTTPSIG_ALGO="rsa-sha256"
CONTENT_TYPE="application/activity+json"
SIGNED_STRING="(request-target): post ${target_inbox_path}
host: $host
date: $date
digest: $HTTP_DIGEST
content-type: $CONTENT_TYPE"
HTTPSIG_SIGNATURE="$(openssl dgst -sha256 -sign ~/.config/ap/private.pem <(printf "%s" "${SIGNED_STRING}") | base64 | tr -d '\n')"
HTTP_SIGNATURE='keyId="'"${HTTPSIG_KEYID}"'",algorithm="'"${HTTPSIG_ALGO}"'",headers="'"${HTTPSIG_HEADERS}"'",signature="'"${HTTPSIG_SIGNATURE}"'"'
echo -e "doing the curl:\n"
echo $target_inbox
curl -i \
--data-raw "${POST_DATA}" \
-H "Accept: application/activity+json" \
-H "Signature: $HTTP_SIGNATURE" \
-H "Date: $date" \
-H "Digest: $HTTP_DIGEST" \
-H "Content-Type: $CONTENT_TYPE" \
-g "$target_inbox"
echo 'DONE'