Use public key id from the same object if attributeTo doesn't exist

This commit is contained in:
Melroy van den Berg 2025-04-24 23:54:12 +02:00
parent 02853f346d
commit f2ffead88b
No known key found for this signature in database
GPG key ID: 71D11FF23454B9D7

View file

@ -33,22 +33,32 @@ func (r *Resolver) fetchActivityPubObjectWithSignature(objectURL string) ([]byte
return nil, nil, err
}
var keyID string
actorURL, ok := data["attributedTo"].(string)
if !ok || actorURL == "" {
return nil, nil, fmt.Errorf("could not find attributedTo in object")
fmt.Printf("Could not find attributedTo in object\n")
// Try to find key in the object itself
// Try to catch an error
if _, ok := data["publicKey"].(map[string]interface{}); !ok {
return nil, nil, fmt.Errorf("could not find public key in object")
}
if _, ok := data["publicKey"].(map[string]interface{})["id"]; !ok {
return nil, nil, fmt.Errorf("could not find public key ID in object")
}
keyID = data["publicKey"].(map[string]interface{})["id"].(string)
} else {
// Fetch actor data
_, actorData, err := r.fetchActorData(actorURL)
if err != nil {
return nil, nil, fmt.Errorf("could not fetch actor data: %v", err)
}
// Extract the public key ID
keyID, _, err := r.extractPublicKey(actorData)
key, _, err := r.extractPublicKey(actorData)
if err != nil {
return nil, nil, fmt.Errorf("could not extract public key: %v", err)
}
keyID = key
}
// Create a new private key for signing (in a real app, we would use a persistent key)
privateKey, err := generateRSAKey()