Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
fix public key parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Cole Kennedy committed May 31, 2023
1 parent 724d123 commit a9926c8
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,31 +356,32 @@ func parseKeyFromFile(filePath string) (policy.PublicKey, error) {
}

// Read the file
certPEM, err := ioutil.ReadFile(filePath)
pubPEM, err := ioutil.ReadFile(filePath)
if err != nil {
return pk, err
}

// Decode the PEM block
block, _ := pem.Decode(certPEM)
block, _ := pem.Decode(pubPEM)
if block == nil {
return pk, errors.New("failed to decode PEM block containing the public key")
}

// Parse the X.509 certificate
_, err = x509.ParseCertificate(block.Bytes)
// Parse the public key
_, err = x509.ParsePKIXPublicKey(block.Bytes)
if err != nil {
return pk, err
}

//keyid is the sha256 hash of the cert.raw
h := sha256.Sum256(certPEM)
// keyid is the sha256 hash of the PEM
h := sha256.Sum256(pubPEM)
hexEncoded := hex.EncodeToString(h[:])
pk.KeyID = hexEncoded
pk.Key = certPEM
pk.Key = pubPEM

return pk, nil
}

func parseAttestationsFromFlags(flags []string) []policy.Attestation {
var attestations []policy.Attestation
var currentAttestation *policy.Attestation
Expand Down

0 comments on commit a9926c8

Please sign in to comment.