mirror of
https://gitlab.melroy.org/melroy/fediresolve.git
synced 2025-06-07 20:08:57 +00:00
Use public key id from the same object if attributeTo doesn't exist
This commit is contained in:
parent
02853f346d
commit
f2ffead88b
1 changed files with 23 additions and 13 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Reference in a new issue