Chore: Adding debug logging to signature checks (#86915)

Adding debug logging to signature checks
This commit is contained in:
Timur Olzhabayev 2024-04-25 12:53:10 +02:00 committed by GitHub
parent 18c4bee18e
commit ed89354eaa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -169,6 +169,7 @@ func (s *Signature) Calculate(ctx context.Context, src plugins.PluginSource, plu
// Make sure the versions all match
if manifest.Plugin != plugin.JSONData.ID || manifest.Version != plugin.JSONData.Info.Version {
s.log.Debug("Plugin signature invalid because ID or Version mismatch", "pluginId", plugin.JSONData.ID, "manifestPluginId", manifest.Plugin, "pluginVersion", plugin.JSONData.Info.Version, "manifestPluginVersion", manifest.Version)
return plugins.Signature{
Status: plugins.SignatureStatusModified,
}, nil
@ -194,6 +195,7 @@ func (s *Signature) Calculate(ctx context.Context, src plugins.PluginSource, plu
for p, hash := range manifest.Files {
err = verifyHash(s.log, plugin, p, hash)
if err != nil {
s.log.Debug("Plugin signature invalid", "pluginId", plugin.JSONData.ID, "error", err)
return plugins.Signature{
Status: plugins.SignatureStatusModified,
}, nil
@ -259,7 +261,7 @@ func verifyHash(mlog log.Logger, plugin plugins.FoundPlugin, path, hash string)
h := sha256.New()
if _, err := io.Copy(h, f); err != nil {
return errors.New("could not calculate plugin file checksum")
return fmt.Errorf("could not calculate plugin file checksum. Path: %s. Error: %w", path, err)
}
sum := hex.EncodeToString(h.Sum(nil))
if sum != hash {