-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
118 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package attestation | ||
|
||
import ( | ||
"encoding/json" | ||
"log" | ||
"net/http" | ||
"net/url" | ||
) | ||
|
||
const ( | ||
attestationEndpoint = "/.well-known/tinfoil-attestation" | ||
) | ||
|
||
// Fetch retrieves the attestation document from a given enclave hostname | ||
func Fetch(host string) (*Document, error) { | ||
var u url.URL | ||
u.Host = host | ||
u.Scheme = "https" | ||
u.Path = attestationEndpoint | ||
|
||
resp, err := http.Get(u.String()) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer resp.Body.Close() | ||
|
||
var doc Document | ||
if err := json.NewDecoder(resp.Body).Decode(&doc); err != nil { | ||
return nil, err | ||
} | ||
return &doc, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package github | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"regexp" | ||
) | ||
|
||
// FetchLatestRelease gets the latest release and EIF hash of a repo | ||
func FetchLatestRelease(repo string) (string, string, error) { | ||
url := "https://api.github.com/repos/" + repo + "/releases/latest" | ||
log.Printf("Fetching latest release for %s", repo) | ||
releaseResponse, err := http.Get(url) | ||
if err != nil { | ||
return "", "", err | ||
} | ||
if releaseResponse.StatusCode != 200 { | ||
return "", "", fmt.Errorf("failed to fetch latest release: %s", releaseResponse.Status) | ||
} | ||
|
||
var responseJSON struct { | ||
TagName string `json:"tag_name"` | ||
Body string `json:"body"` | ||
} | ||
if err := json.NewDecoder(releaseResponse.Body).Decode(&responseJSON); err != nil { | ||
return "", "", err | ||
} | ||
|
||
eifRegex := regexp.MustCompile(`EIF hash: ([a-fA-F0-9]{64})`) | ||
eifHash := eifRegex.FindStringSubmatch(responseJSON.Body)[1] | ||
|
||
return responseJSON.TagName, eifHash, nil | ||
} | ||
|
||
// FetchAttestationBundle fetches the sigstore bundle from a repo for a given repo and EIF hash | ||
func FetchAttestationBundle(repo, digest string) ([]byte, error) { | ||
url := "https://api.github.com/repos/" + repo + "/attestations/sha256:" + digest | ||
log.Printf("Fetching sigstore bundle from %s for EIF %s", repo, digest) | ||
bundleResponse, err := http.Get(url) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if bundleResponse.StatusCode != 200 { | ||
return nil, fmt.Errorf("failed to fetch sigstore bundle: %s", bundleResponse.Status) | ||
} | ||
|
||
var responseJSON struct { | ||
Attestations []struct { | ||
Bundle json.RawMessage `json:"bundle"` | ||
} `json:"attestations"` | ||
} | ||
if err := json.NewDecoder(bundleResponse.Body).Decode(&responseJSON); err != nil { | ||
return nil, err | ||
} | ||
|
||
return responseJSON.Attestations[0].Bundle, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters