webhookd/pkg/middleware/signature/http-signature.go
Nicolas Carlier f2054d2dc4 feat(signature): signature refactoring
- add ed5519 HTTP signature support
- refactor truststore package
- add P12 trust store support

close #72
2022-12-29 17:14:28 +00:00

29 lines
602 B
Go

package signature
import (
"fmt"
"net/http"
"github.com/go-fed/httpsig"
"github.com/ncarlier/webhookd/pkg/truststore"
)
// HTTPSignatureHandler validate request HTTP signature
func HTTPSignatureHandler(r *http.Request, ts truststore.TrustStore) error {
verifier, err := httpsig.NewVerifier(r)
if err != nil {
return err
}
pubkeyID := verifier.KeyId()
pubkey := ts.GetPublicKey(pubkeyID)
if pubkey == nil {
return fmt.Errorf("public key not found: %s", pubkeyID)
}
// TODO dynamic algo
err = verifier.Verify(pubkey, httpsig.RSA_SHA256)
if err != nil {
return err
}
return nil
}