Skip to content

Commit

Permalink
Merge pull request #6 from docker/no-devices
Browse files Browse the repository at this point in the history
Error out on no devices in dir
  • Loading branch information
jonnystoten authored May 22, 2024
2 parents 18bfd25 + 80fa7fa commit ba8ad33
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions tools/key-verification/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,30 @@ func main() {
if pathToKeys == "" {
pathToKeys = defaultKeysDir
}
devices, err := os.ReadDir(pathToKeys)
entries, err := os.ReadDir(pathToKeys)
if err != nil {
fmt.Println("Error reading directory:", err)
return
fmt.Fprintln(os.Stderr, "Error reading directory:", err)
os.Exit(1)
}
for _, device := range devices {
var devices []os.DirEntry
for _, device := range entries {
if device.IsDir() {
serial := device.Name()
path := filepath.Join(pathToKeys, serial)
err := verifyDeviceAttestation(serial, path)
if err != nil {
fmt.Println("Error verifying device attestation:", err)
continue
}
fmt.Println("Device attestation verified for:", serial)
devices = append(devices, device)
}
}
if len(devices) == 0 {
fmt.Fprintln(os.Stderr, "No devices found in the directory:", pathToKeys)
os.Exit(1)
}
for _, device := range devices {
serial := device.Name()
path := filepath.Join(pathToKeys, serial)
err := verifyDeviceAttestation(serial, path)
if err != nil {
fmt.Fprintln(os.Stderr, "Error verifying device attestation:", err)
continue
}
fmt.Println("Device attestation verified for:", serial)
}
}

Expand Down

0 comments on commit ba8ad33

Please sign in to comment.