Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be more verbose in case of signature check failures #361

Merged
merged 4 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 14 additions & 18 deletions cmd/csaf_checker/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type processor struct {
pmdURL string
pmd256 []byte
pmd any
keys []*crypto.KeyRing
keys *crypto.KeyRing

invalidAdvisories topicMessages
badFilenames topicMessages
Expand Down Expand Up @@ -458,7 +458,7 @@ func (p *processor) integrity(
// Check if we are in checking time interval.
if p.ageAccept != nil && !p.ageAccept(
time.Date(
year, 12, 31, // Assume last day og year.
year, 12, 31, // Assume last day of year.
23, 59, 59, 0, // 23:59:59
time.UTC)) {
continue
Expand Down Expand Up @@ -621,18 +621,11 @@ func (p *processor) integrity(
continue
}

if len(p.keys) > 0 {
if p.keys != nil {
pm := crypto.NewPlainMessage(data.Bytes())
t := crypto.GetUnixTime()
var verified bool
for _, key := range p.keys {
if err := key.VerifyDetached(pm, sig, t); err == nil {
verified = true
break
}
}
if !verified {
p.badSignatures.error("Signature of %s could not be verified.", u)
if err := p.keys.VerifyDetached(pm, sig, t); err != nil {
p.badSignatures.error("Signature of %s could not be verified: %v.", u, err)
}
}
}
Expand Down Expand Up @@ -1369,15 +1362,18 @@ func (p *processor) checkPGPKeys(_ string) error {
p.badPGPs.error("Fingerprint of public OpenPGP key %s does not match remotely loaded.", u)
continue
}
keyring, err := crypto.NewKeyRing(ckey)
if err != nil {
p.badPGPs.error("Creating store for public OpenPGP key %s failed: %v.", u, err)
continue
if p.keys == nil {
if keyring, err := crypto.NewKeyRing(ckey); err != nil {
p.badPGPs.error("Creating store for public OpenPGP key %s failed: %v.", u, err)
} else {
p.keys = keyring
}
} else {
p.keys.AddKey(ckey)
}
p.keys = append(p.keys, keyring)
}

if len(p.keys) == 0 {
if p.keys == nil {
p.badPGPs.info("No OpenPGP keys loaded.")
}
return nil
Expand Down
5 changes: 3 additions & 2 deletions cmd/csaf_checker/reporters.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ func (r *publicPGPKeyReporter) report(p *processor, domain *Domain) {
return
}
req.Messages = p.badPGPs
if len(p.keys) > 0 {
req.message(InfoType, fmt.Sprintf("%d public OpenPGP key(s) loaded.", len(p.keys)))
if p.keys != nil {
req.message(InfoType, fmt.Sprintf("%d public OpenPGP key(s) loaded.",
p.keys.CountEntities()))
}
}