httpsig

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 23, 2025 License: AGPL-3.0 Imports: 17 Imported by: 0

README

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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReqHasValidSignature

func ReqHasValidSignature(ctx context.Context, req *http.Request, reqAuthorPubKeyPem string, strictMode bool) (bool, error)

ReqHasValidSignature validates the signature of POST requests by default reqAuthorPubKeyPem can optionally be specified to be the public key (RSA-SHA256 PEM format) of the actor sending the request, if it is empty, the key is fetched using http.Get strictMode=true additionally validates GET request signature as well as that the request Date is within the last 12 hours

func SignRequest

func SignRequest(ctx context.Context, req *http.Request, keyId *url.URL, privateKeyPem string) error

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL