-
Notifications
You must be signed in to change notification settings - Fork 3
/
pcrs.go
78 lines (65 loc) · 1.91 KB
/
pcrs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package cmd
import (
"fmt"
"io"
"net/http"
"path"
"strings"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/capeprivacy/cli/pcrs"
)
// runCmd represents the get-prcs command
var getPCRsCmd = &cobra.Command{
Use: "get-pcrs",
Short: "Retrieve the PCRs of a given runtime version",
Long: `Retrieve the PCRs of a given runtime version.
The PCRs are measurements of the executable version of the cape
runtime that processes requests. These PCRs can be supplied to
other commands to validate that Cape is running a version of the
code that you've verified. This command takes a while to run as it
requires downloading of the latest runtime version.`,
RunE: getPCRs,
}
func init() {
rootCmd.AddCommand(getPCRsCmd)
getPCRsCmd.PersistentFlags().String("version", "", "the version of the runtime EIF to get PCRs for")
getPCRsCmd.PersistentFlags().StringP("bucket", "b", "user-eif-release-bucket", "the artifact source bucket in S3")
}
func getPCRs(cmd *cobra.Command, args []string) error {
version, err := cmd.Flags().GetString("version")
if err != nil {
return fmt.Errorf("error retrieving version flag %s", err)
}
// Get the latest stable version
if version == "" {
resp, err := http.Get("https://user-eif-release-bucket.s3.amazonaws.com/stable.txt")
if err != nil {
return fmt.Errorf("error retrieving latest version %s", err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
version = string(body[:len(body)-1])
}
bucket, err := cmd.Flags().GetString("bucket")
if err != nil {
return fmt.Errorf("error retrieving bucket flag %s", err)
}
p, err := pcrs.DownloadEIF(bucket, version)
if err != nil {
return err
}
info, err := pcrs.GetEIFInfo(path.Base(p))
if err != nil {
return err
}
for key, item := range info.Measurements {
if strings.HasPrefix(key, "PCR") {
log.Infof("%s:\t%s", key, item)
}
}
return nil
}