httpsigclient

package
v0.0.0-...-15495fc Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const MaxClockSkew = 5 * time.Minute

MaxClockSkew は許容する Date のずれ。リプレイの窓を狭めるためで、 Mastodon も同程度の値を使う。

Variables

View Source
var ErrNoSignature = errors.New("request has no http signature")

ErrNoSignature は Signature ヘッダが無いことを表す。呼び出し側が 「署名されていない」と「署名が壊れている」を区別できるようにしてある。

Functions

func CurrentTime

func CurrentTime() string

CurrentTime は HTTP の Date ヘッダ用の書式を返す。ActivityStreams の published は ISO8601 なので、こちらを流用してはならない。

func KeyIDFromRequest

func KeyIDFromRequest(r *http.Request) (string, error)

KeyIDFromRequest は Signature ヘッダから keyId を取り出す。公開鍵を どこから引くか (キャッシュか actor 取得か) は呼び出し側が決めるため、 検証本体とは分けてある。

func ParsePublicKey

func ParsePublicKey(publicKeyPEM string) (*rsa.PublicKey, error)

ParsePublicKey は actor の publicKeyPem を読む。ほとんどの実装は PKIX (BEGIN PUBLIC KEY) を出すが、PKCS#1 (BEGIN RSA PUBLIC KEY) を出すものも あるので両方受ける。

func Verify

func Verify(r *http.Request, body []byte, publicKeyPEM string) error

Verify は署名・Digest・Date をまとめて検証する。

go-fed/httpsig の Verifier は「Digest ヘッダが署名対象に含まれていた」 ことしか確認せず、Digest の値が本文のハッシュと一致するかは見ない。 そのため本文の照合はここで行う必要がある。これを省くと、正しい署名を 使い回して本文だけ差し替える改竄が通ってしまう。

Types

type Signer

type Signer struct {
	// contains filtered or unexported fields
}

func NewSigner

func NewSigner(privKey *rsa.PrivateKey, publicKey string, keyID string) (*Signer, error)

func (*Signer) GetWithSign

func (s *Signer) GetWithSign(ctx context.Context, url string) (*http.Response, error)

GetWithSign は本文の無い GET に署名して送る。authorized fetch を 有効にしているインスタンスは、署名の無い actor 取得を拒否する。

func (*Signer) KeyID

func (s *Signer) KeyID() string

KeyID は署名に使う keyId を返す。

func (*Signer) RequestWithSign

func (s *Signer) RequestWithSign(ctx context.Context, method string, url string, body []byte) (*http.Response, error)

RequestWithSign は本文付きのリクエストに署名して送る。

Jump to

Keyboard shortcuts

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