More attempt at getting this shit to work
All checks were successful
/ docker (push) Successful in 4m9s
All checks were successful
/ docker (push) Successful in 4m9s
This commit is contained in:
parent
06e6d457da
commit
59dd8d82cf
10 changed files with 158 additions and 118 deletions
56
web/shared/clientRfc9421.go
Normal file
56
web/shared/clientRfc9421.go
Normal file
|
@ -0,0 +1,56 @@
|
|||
package webshared
|
||||
|
||||
import (
|
||||
"crypto/x509"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/yaronf/httpsign"
|
||||
|
||||
"git.mstar.dev/mstar/linstrom/config"
|
||||
)
|
||||
|
||||
/*
|
||||
Links for home:
|
||||
- https://pkg.go.dev/github.com/yaronf/httpsign#Client.Do
|
||||
- https://www.ietf.org/archive/id/draft-richanna-http-message-signatures-00.html
|
||||
- https://github.com/mastodon/mastodon/issues/29905
|
||||
- https://github.com/fedify-dev/fedify/issues/208
|
||||
- https://github.com/mastodon/mastodon/issues/21429
|
||||
- https://github.com/go-ap/fedbox/blob/master/httpsig.go
|
||||
- https://swicg.github.io/activitypub-http-signature/
|
||||
- https://datatracker.ietf.org/doc/html/rfc9421
|
||||
*/
|
||||
|
||||
func RequestSigned(
|
||||
method, target string,
|
||||
body io.Reader,
|
||||
keyId string,
|
||||
privateKeyBytes []byte,
|
||||
) (*http.Response, error) {
|
||||
req, err := http.NewRequest(method, target, body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var signer *httpsign.Signer
|
||||
signerFields := httpsign.Headers("@request-target", "content-digest")
|
||||
if config.GlobalConfig.Experimental.UseEd25519Keys {
|
||||
signer, err = httpsign.NewEd25519Signer(
|
||||
privateKeyBytes,
|
||||
httpsign.NewSignConfig(),
|
||||
signerFields,
|
||||
)
|
||||
} else {
|
||||
key, err := x509.ParsePKCS1PrivateKey(privateKeyBytes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
signer, err = httpsign.NewRSASigner(*key, httpsign.NewSignConfig(), signerFields)
|
||||
}
|
||||
client := httpsign.NewClient(
|
||||
RequestClient,
|
||||
httpsign.NewClientConfig().SetSigner(signer).SetSignatureName("sig1"),
|
||||
)
|
||||
res, err := client.Do(req)
|
||||
return res, err
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue