Skip to content

Go library to sign & verify HTTP signatures, compatible with Mastodon/ActivityPub servers.

License

Notifications You must be signed in to change notification settings

MatejLach/httpsig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

httpsig

httpsig is a Go library allowing everyone to easily add Mastodon/ActivityPub-compatible HTTP signature to any HTTP request as well as verify the validity of a request's signature originating from an ActivityPub server.

Usage

Go Reference

Signing requests

package main

import (
	//...
	
	"github.com/MatejLach/httpsig"
)

func main() {
	// ...
	req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("%s/user/me", server.URL), nil)
	if err != nil {
		// error handling
	}

	reqActorPubKeyId, err := url.Parse(fmt.Sprintf("%s/user/me", server.URL))
	if err != nil {
		// error handling
	}

	err = httpsig.SignRequest(context.Background(), req, reqActorPubKeyId, privateKeyPem.String())
	if err != nil {
		// error handling
	}
}

Verifying requests

package main

import (
	//...
	
	"github.com/MatejLach/httpsig"
)

func main() {
	// ...
	validSignature, err := httpsig.ReqHasValidSignature(context.Background(), req, "", true)
	if err != nil { 
		// error handling
	}
}

See the test suite for a more complete example.

Contributing

Pull requests and bug reports are welcome.

About

Go library to sign & verify HTTP signatures, compatible with Mastodon/ActivityPub servers.

Topics

Resources

License

Stars

Watchers

Forks

Languages