まずフォローしてもらう
自分に。
他のインスタンスにアカウントがあるならば、その検索に
@aktor@ホニャララ
と入れると今作っているインスタンスの自分が表示されるのは (1) の通りである。
あとはそれをフォローしてみる。大丈夫大丈夫、あとでアンフォローしとけば何もないと思う、多分。
すると (2) でやったように 202 ディレクトリに他のインスタンスの自分からのフォローリクエストが届いているはずだ。そのボディは大体以下の様だろう。
{
"@context": "https://www.w3.org/ns/activitystreams",
"id": "https://他のインスタンス/1qaz2wsx3edc4rfv5tgb",
"type": "Follow",
"actor": "https://他のインスタンス/users/他のインスタンスの自分",
"object": "https://ホニャララ/users/aktor"
}
この json オブジェクトを
{
"@context": "https://www.w3.org/ns/activitystreams",
"id": "https://ホニャララ/users/aktor/accept/1705518720",
"type": "Accept",
"actor": "https://ホニャララ/users/aktor",
"object": {
"@context": "https://www.w3.org/ns/activitystreams",
"id": "https://他のインスタンス/1qaz2wsx3edc4rfv5tgb",
"type": "Follow",
"actor": "https://他のインスタンス/users/他のインスタンスの自分",
"object": "https://ホニャララ/users/aktor"}
}
と、Accept オブジェクトで包んで他のインスタンスの自分の inbox へ投げつけると相手(他のインスタンスの自分)は自分をフォローできる。
例によってまず json_templates ディレクトリに accept.json を作る。
{
"@context": "https://www.w3.org/ns/activitystreams",
"id": "https://{my_instance}/users/{myself}/accept/{id}",
"type": "Accept",
"actor": "https://{my_instance}/users/{myself}",
"object": {follow_request}
}
あとで自分宛に着た POST は 202 から移動させるようにする(予定)のだが、今のところは 202 へ着たフォローリクエストのファイルをそのままカレントディレクトリへコピーしてほしい。
accept.sh はそのファイルのボディの json を {follow_request} に突っ込んで送ってきたアクターの inbox へ curl で POST するだけである。
What request do you accept?:
には、フォローリクエストファイルの json の "id" タグの値(https://他のインスタンス/1qaz2wsx3edc4rfv5tgb)をコピー&ペーストなどで入力すること。
#!/bin/bash
read -p "@myself@my_instance: " MY
MY_arry=(${MY//@/ })
myself=${MY_arry[0]}
my_instance=${MY_arry[1]}
echo
read -p "@to@to_instance: " TO
TO_arry=(${TO//@/ })
to=${TO_arry[0]}
to_instance=${TO_arry[1]}
echo
read -p "What request do you accept?: " id_of_request
echo
# grep でカレントディレクトリから accept したいリクエストのファイルの json 行を取得
follow_request_json=$(grep -rh "$id_of_request" ./)
unixtime=$(date "+%s")
date_now=$(date -uR | head -c -6 | sed -e 's/$/GMT/')
sed -e "s/{id}/$unixtime/g" ./json_templates/accept.json > live
sed -i "s/{myself}/$myself/g" live
sed -i "s/{my_instance}/$my_instance/g" live
sed -i "s|{follow_request}|$follow_request_json|g" live
body=$(cat live | jq -c .)
digest_val=$(echo -n "$body" | sha256sum | xxd -r -p | base64)
URL=$(curl https://$to_instance/.well-known/webfinger?resource=acct:$to@$to_instance | jq -r '.links[] | select (.rel == "self")'.href | tr -d "\"")
INBOX=$(curl -H "Accept: application/activity+json" $URL | jq .inbox | tr -d "\"")
REQUEST_TARGET=$(echo "/"$(sed -E 's/^.*(https):\/\/([^/]+).([^/]+)/\3/g' <<< $INBOX))
signature_headers="(request-target): post ${REQUEST_TARGET}\ndate: ${date_now}\nhost: ${to_instance}\ndigest: SHA-256=${digest_val}"
echo -e "$signature_headers" > 4_sig_headers # 後に見返すためにファイルに
sig_val=$(echo -en $signature_headers | openssl dgst -binary -sign ./personal/private -sha256 | openssl enc -A -base64)
signature="Signature: keyId=\"https://${my_instance}/users/${myself}#main-key\",algorithm=\"rsa-sha256\",headers=\"(request-target) date host digest\",signature=\"$sig_val\""
curl -v -H "Date: $date_now" -H "Digest: SHA-256=$digest_val" -H "$signature" $INBOX -d "$body"
echo $body > ./post/$unixtime
echo $INBOX >> followers
bash ./script/accept.sh
で、適切に入力すれば他のインスタンスの自分の「フォロー」に Baca の自分が追加されているはずである。
また、最後に
echo $INBOX >> followers
という行を追加しているが、これは新しく他のインスタンスの自分(の inbox エンドポイント)をフォロワーとして followers ファイルに追加するものだ。