mirror of https://github.com/jlelse/GoBlog
Small activitypub changes
This commit is contained in:
parent
58586fb9a7
commit
04f5cdc122
|
@ -68,10 +68,13 @@ func initActivityPub() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
prefs := []httpsig.Algorithm{httpsig.RSA_SHA256}
|
apPostSigner, _, err = httpsig.NewSigner(
|
||||||
digestAlgorithm := httpsig.DigestSha256
|
[]httpsig.Algorithm{httpsig.RSA_SHA256},
|
||||||
headersToSign := []string{httpsig.RequestTarget, "date", "host", "digest"}
|
httpsig.DigestSha256,
|
||||||
apPostSigner, _, err = httpsig.NewSigner(prefs, digestAlgorithm, headersToSign, httpsig.Signature, 0)
|
[]string{httpsig.RequestTarget, "date", "host", "digest"},
|
||||||
|
httpsig.Signature,
|
||||||
|
0,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,14 +96,13 @@ func apQueueSendSigned(blogIri, to string, activity interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func apSendSigned(blogIri, to string, activity []byte) error {
|
func apSendSigned(blogIri, to string, activity []byte) error {
|
||||||
// Copy activity to sign it
|
|
||||||
activityCopy := make([]byte, len(activity))
|
|
||||||
copy(activityCopy, activity)
|
|
||||||
// Create request context with timeout
|
// Create request context with timeout
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
// Create request
|
// Create request
|
||||||
r, err := http.NewRequestWithContext(ctx, http.MethodPost, to, bytes.NewBuffer(activity))
|
var requestBuffer bytes.Buffer
|
||||||
|
requestBuffer.Write(activity)
|
||||||
|
r, err := http.NewRequestWithContext(ctx, http.MethodPost, to, &requestBuffer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -119,7 +118,7 @@ func apSendSigned(blogIri, to string, activity []byte) error {
|
||||||
r.Header.Set("Host", iri.Host)
|
r.Header.Set("Host", iri.Host)
|
||||||
// Sign request
|
// Sign request
|
||||||
apPostSignMutex.Lock()
|
apPostSignMutex.Lock()
|
||||||
err = apPostSigner.SignRequest(apPrivateKey, blogIri+"#main-key", r, activityCopy)
|
err = apPostSigner.SignRequest(apPrivateKey, blogIri+"#main-key", r, activity)
|
||||||
apPostSignMutex.Unlock()
|
apPostSignMutex.Unlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue