diff --git a/resolver/helpers.go b/resolver/helpers.go index adb9b17..52de4ab 100644 --- a/resolver/helpers.go +++ b/resolver/helpers.go @@ -196,89 +196,6 @@ func (r *Resolver) fetchActivityPubObjectDirect(objectURL string) (string, error return formatter.Format(data) } -// fetchWithSignature fetches ActivityPub content using HTTP Signatures -func (r *Resolver) fetchWithSignature(objectURL string) (string, error) { - fmt.Printf("Fetching with HTTP signatures from: %s\n", objectURL) - - // First, we need to extract the actor URL from the object URL - actorURL, err := r.extractActorURLFromObjectURL(objectURL) - if err != nil { - return "", fmt.Errorf("error extracting actor URL: %v", err) - } - - // Then, we need to fetch the actor data to get the public key - actorData, err := r.fetchActorData(actorURL) - if err != nil { - return "", fmt.Errorf("error fetching actor data: %v", err) - } - - // Extract the public key ID - keyID, _, err := r.extractPublicKey(actorData) - if err != nil { - return "", fmt.Errorf("error extracting public key: %v", err) - } - - // Create a new private key for signing (in a real app, we would use a persistent key) - privateKey, err := generateRSAKey() - if err != nil { - return "", fmt.Errorf("error generating RSA key: %v", err) - } - - // Now, sign and send the request - req, err := http.NewRequest("GET", objectURL, nil) - if err != nil { - return "", fmt.Errorf("error creating signed request: %v", err) - } - - // Set headers - req.Header.Set("Accept", "application/activity+json, application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\", application/json") - req.Header.Set("User-Agent", UserAgent) - req.Header.Set("Date", time.Now().UTC().Format(http.TimeFormat)) - - // Sign the request - if err := signRequest(req, keyID, privateKey); err != nil { - return "", fmt.Errorf("error signing request: %v", err) - } - - // Send the request - fmt.Printf("Sending signed request with headers: %v\n", req.Header) - resp, err := r.client.Do(req) - if err != nil { - return "", fmt.Errorf("error sending signed request: %v", err) - } - defer resp.Body.Close() - - fmt.Printf("Received response with status: %s\n", resp.Status) - if resp.StatusCode != http.StatusOK { - // Read body for error info - body, _ := io.ReadAll(resp.Body) - return "", fmt.Errorf("signed request failed with status: %s, body: %s", resp.Status, string(body)) - } - - // Read and parse the response - body, err := io.ReadAll(resp.Body) - if err != nil { - return "", fmt.Errorf("error reading response: %v", err) - } - - // Debug output - fmt.Printf("Response content type: %s\n", resp.Header.Get("Content-Type")) - - // Check if the response is empty - if len(body) == 0 { - return "", fmt.Errorf("received empty response body") - } - - // Try to decode the JSON response - var data map[string]interface{} - if err := json.Unmarshal(body, &data); err != nil { - return "", fmt.Errorf("error decoding response: %v", err) - } - - // Format the result - return formatter.Format(data) -} - // extractActorURLFromObjectURL extracts the actor URL from an object URL func (r *Resolver) extractActorURLFromObjectURL(objectURL string) (string, error) { // This is a simplified approach - in a real app, we would parse the object URL properly diff --git a/resolver/resolver.go b/resolver/resolver.go index 005b691..65d78f7 100644 --- a/resolver/resolver.go +++ b/resolver/resolver.go @@ -6,7 +6,6 @@ import ( "io" "net/http" "net/url" - "regexp" "strings" "time" ) @@ -293,12 +292,3 @@ func (r *Resolver) fetchActivityPubObject(objectURL string) (string, error) { // Use our signature-first approach by default return r.fetchActivityPubObjectWithSignature(objectURL) } - -// isBareDomain returns true if input is a domain or domain/ (no scheme, no @, no path beyond optional trailing slash, allows port) -var bareDomainRe = regexp.MustCompile(`^[a-zA-Z0-9.-]+(:[0-9]+)?/?$`) -func isBareDomain(input string) bool { - if strings.Contains(input, "@") || strings.Contains(input, "://") { - return false - } - return bareDomainRe.MatchString(input) -}