Skip to content

Commit

Permalink
Rework the cert extraction
Browse files Browse the repository at this point in the history
Signed-off-by: Itxaka <[email protected]>
  • Loading branch information
Itxaka committed Apr 18, 2024
1 parent 21cf40e commit 2131a29
Showing 1 changed file with 11 additions and 28 deletions.
39 changes: 11 additions & 28 deletions signatures/signatures.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,46 +44,29 @@ func GetAllFullCerts() (types.CertListFull, error) {
return certList, err
}

for _, k := range *pk {
if isValidSignature(k.SignatureType) {
for _, k1 := range k.Signatures {
// Note the S at the end of the function, we are parsing multiple certs, not just one
certificates, err := x509.ParseCertificates(k1.Data)
if err != nil {
continue
}
certList.PK = append(certList.PK, certificates...)
}
}
}
certList.PK = ExtractCertsFromSignatureDatabase(pk)
certList.KEK = ExtractCertsFromSignatureDatabase(kek)
certList.DB = ExtractCertsFromSignatureDatabase(db)

for _, k := range *kek {
if isValidSignature(k.SignatureType) {
for _, k1 := range k.Signatures {
// Note the S at the end of the function, we are parsing multiple certs, not just one
certificates, err := x509.ParseCertificates(k1.Data)
if err != nil {
continue
}
certList.KEK = append(certList.KEK, certificates...)
}
}
}
return certList, nil
}

for _, k := range *db {
// ExtractCertsFromSignatureDatabase returns a []*x509.Certificate from a *signature.SignatureDatabase
func ExtractCertsFromSignatureDatabase(database *signature.SignatureDatabase) []*x509.Certificate {
var result []*x509.Certificate
for _, k := range *database {
if isValidSignature(k.SignatureType) {
for _, k1 := range k.Signatures {
// Note the S at the end of the function, we are parsing multiple certs, not just one
certificates, err := x509.ParseCertificates(k1.Data)
if err != nil {
continue
}
certList.DB = append(certList.DB, certificates...)
result = append(result, certificates...)
}
}
}

return certList, nil
return result
}

// GetAllCerts returns a list of certs in the system
Expand Down

0 comments on commit 2131a29

Please sign in to comment.