Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ahnlabcloudmatelabs/go-activitypub-signature-header
Signature header for the connect with ActivityPub federations
https://github.com/ahnlabcloudmatelabs/go-activitypub-signature-header
activitypub golang http-signature signature-header
Last synced: 2 months ago
JSON representation
Signature header for the connect with ActivityPub federations
- Host: GitHub
- URL: https://github.com/ahnlabcloudmatelabs/go-activitypub-signature-header
- Owner: ahnlabcloudmatelabs
- License: mit
- Created: 2023-10-23T07:37:22.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-29T14:17:04.000Z (about 1 year ago)
- Last Synced: 2024-10-13T21:23:15.193Z (3 months ago)
- Topics: activitypub, golang, http-signature, signature-header
- Language: Go
- Homepage:
- Size: 22.5 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![cloudmate logo](https://avatars.githubusercontent.com/u/69299682?s=200&v=4)
# ActivityPub Signature header
by Cloudmate
---
![Golang](https://img.shields.io/badge/Go-00ADD8?style=for-the-badge&logo=go&logoColor=white)
[![Go Test](https://github.com/cloudmatelabs/go-activitypub-signature-header/actions/workflows/gotest.yml/badge.svg)](https://github.com/cloudmatelabs/go-activitypub-signature-header/actions/workflows/gotest.yml)
## Install
```bash
go get -u github.com/cloudmatelabs/go-activitypub-signature-header
```## Introduce
This library is generate `Signature` header for the connect with ActivityPub federations.
And verify the `Signature` header.## Usage
### Sign `Signature` header
```go
import (
"crypto"
"net/url""github.com/go-resty/resty/v2"
signature_header "github.com/cloudmatelabs/go-activitypub-signature-header"
)requestURL, _ := url.Parse("https://yodangang.express/users/9iffvxhojp/inbox")
message := []byte(`{
"@context": "https://www.w3.org/ns/activitystreams",
"id": "https://snippet.social/@juunini",
"type": "Follow",
"actor": "https://snippet.social/@juunini",
"object": "https://yodangang.express/users/9iffvxhojp"
}`)headers, err := signature_header.Generate(signature_header.GenerateInput{
PrivateKeyBytes: []byte("-----BEGIN RSA PRIVATE KEY-----..."),
// Algorithm: crypto.SHA256, // optional. if not set, default is crypto.SHA256
Host: requestURL.Host,
Path: requestURL.Path,
Body: message,
KeyID: "https://snippet.social/@juunini#main-key",
})
if err != nil {
// handle error
}resty.New().R().
SetBody(message).
SetHeader("Date", headers.Date).
SetHeader("Digest", headers.Digest).
SetHeader("Host", headers.Host).
SetHeader("Signature", headers.Signature).
SetHeader("Content-Type", "application/activity+json").
Post(requestURL.String())
```### Verify `Signature` header
```go
import (
signature_header "github.com/cloudmatelabs/go-activitypub-signature-header"
)verifier := signature_header.Verifier{
Method: "POST",
URL: "https://snippet.social/@juunini/inbox",
Headers: map[string]string{
"Signature": "...",
"Host": "...",
"Date": "...",
"Digest": "...",
"Authorization": "...",
"...": "...",
},
}// Recommended
err := verifier.VerifyWithPublicKey(publicKey)
err := verifier.VerifyWithPublicKeyStr(publicKeyStr)// You can use, but not recommended
err := verifier.VerifyWithActor("https://yodangang.express/@juunini")
err := verifier.VerifyWithBody([]byte("{...}"))
```### Parse `Signature` header
```go
import (
signature_header "github.com/cloudmatelabs/go-activitypub-signature-header"
)// map[string]string
params := signature_header.ParseSignature(signature)
// or given Signature authorization header
// params := signature_header.ParseSignature(authorization)params["keyId"]
params["algorithm"]
params["headers"]
params["signature"]
```## License
[MIT](LICENSE)
But, this library use [httpsig].
[httpsig] is licensed under the [BSD 3-Clause License](https://github.com/go-fed/httpsig/blob/master/LICENSE)[httpsig]: https://github.com/go-fed/httpsig