Skip to content

Commit

Permalink
feat: support SEV
Browse files Browse the repository at this point in the history
  • Loading branch information
natesales committed Jan 31, 2025
1 parent 813dec9 commit ccfebeb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
20 changes: 0 additions & 20 deletions gen/main.go

This file was deleted.

25 changes: 22 additions & 3 deletions github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package github
import (
"encoding/json"
"fmt"
"io"
"net/http"
"regexp"
"strings"
)

// FetchLatestRelease gets the latest release and EIF hash of a repo
// FetchLatestRelease gets the latest release and attestation digest of a repo
func FetchLatestRelease(repo string) (string, string, error) {
url := "https://api.github.com/repos/" + repo + "/releases/latest"
releaseResponse, err := http.Get(url)
Expand All @@ -26,10 +28,27 @@ func FetchLatestRelease(repo string) (string, string, error) {
return "", "", err
}

// Backwards compatibility for old EIF releases
eifRegex := regexp.MustCompile(`EIF hash: ([a-fA-F0-9]{64})`)
eifHash := eifRegex.FindStringSubmatch(responseJSON.Body)[1]
matches := eifRegex.FindStringSubmatch(responseJSON.Body)
if len(matches) > 1 {
return responseJSON.TagName, matches[1], nil
}

url = fmt.Sprintf(`https://github.com/tinfoilanalytics/provably-private-deepseek-r1/releases/download/%s/tinfoil.hash`, responseJSON.TagName)
digestResp, err := http.Get(url)
if err != nil {
return "", "", err
}
if digestResp.StatusCode != 200 {
return "", "", fmt.Errorf("failed to fetch attestation digest: %s", digestResp.Status)
}
digest, err := io.ReadAll(digestResp.Body)
if err != nil {
return "", "", err
}

return responseJSON.TagName, eifHash, nil
return responseJSON.TagName, strings.TrimSpace(string(digest)), nil
}

// FetchAttestationBundle fetches the sigstore bundle from a repo for a given repo and EIF hash
Expand Down
7 changes: 6 additions & 1 deletion sigstore/sigstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func VerifyAttestation(
"",
"",
// TODO: Can we pin this to latest without fetching the latest release?
"^https://github.com/"+repo+"/.github/workflows/release.yml@refs/tags/*",
"^https://github.com/"+repo+"/.github/workflows/.*@refs/tags/*",
)
if err != nil {
return nil, fmt.Errorf("creating certificate identity: %w", err)
Expand Down Expand Up @@ -96,6 +96,11 @@ func VerifyAttestation(
predicateFields["PCR2"].GetStringValue(),
},
}, nil
case attestation.SevGuestV1:
return &attestation.Measurement{
Type: measurementType,
Registers: []string{predicateFields["measurement"].GetStringValue()},
}, nil
default:
return nil, fmt.Errorf("unsupported predicate type: %s", result.Statement.PredicateType)
}
Expand Down

0 comments on commit ccfebeb

Please sign in to comment.