I am trying to write an activity pub server with Go.
I am following this tutorial and ap spec. I can find my account, it seems that webfinger is ok, when I try to post to pleroma I get “ok”. But in mastodon there is a verification problem: “Verification failed for […] using rsa-sha256 (RSASSA-PKCS1-v1_5 with SHA-256)”
I have tried to sign my request both with httpsig(go-fed) library and
write it manually. In both cases, I have the same problem.
Here is my code:
prefs := []httpsig.Algorithm{httpsig.RSA_SHA512, httpsig.RSA_SHA256}
digestAlgorithm := httpsig.DigestSha256
headersToSign := []string{httpsig.RequestTarget, "host", "date", "digest", "content-type"}
postSigner, _, err := httpsig.NewSigner(prefs, digestAlgorithm, headersToSign, httpsig.Signature, 60)
req, _ := http.NewRequest("POST", to, buf)
date := fmt.Sprintf("%s GMT", x.UTC().Format("Mon, 02 Jan 2006 15:04:05"))
pub := "example.org/actor#main-key"
req.Header.Add("Accept", "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"")
req.Header.Add("User-Agent", "example")
req.Header.Add("Host", iri.Host) // mstdn.social in this case
req.Header.Add("Date", time.Now().UTC().Format("Mon, 02 Jan 2006 15:04:05")+" GMT")
req.Header.Add("Content-Type", "application/activity+json; charset=utf-8")
err = postSigner.SignRequest(get_private(), pub, req, b)
I have tried to test it with httpsig.NewVerifier and the error is nil.
Here is my actor:
{
"@context": [
"https://www.w3.org/ns/activitystreams",
"https://w3id.org/security/v1"
],
"id": "https://example.org/actor",
"type": "Person",
"preferredUsername": "actor",
"inbox": "https://example.org/actor/inbox",
"outbox": "https://example.org/actor/outbox",
"publicKey": {
"id": "https://example.org/actor#main-key",
"owner": "https://example.org/actor",
"publicKeyPem": "-----BEGIN PUBLIC KEY-----\n[long]\n-----END PUBLIC KEY-----\n"
}
}
and my note:
{
"@context": "https://www.w3.org/ns/activitystreams",
"id": "https://example.org/id",
"type": "Create",
"actor": "https://example.org/actor",
"published": "2012-07-29T102:035:07Z",
"object": {
"id": "https://example.org/actor/hello",
"type": "Note",
"attributedTo": "https://example.org/actor",
"content": "<p>Hello world</p>",
"to": "https://www.w3.org/ns/activitystreams#Public"
}
}