Skip to content

Avoid signature expired error on index update, if the clock time is not set correctly. #2744

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

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Do not output 'signature expired' if the signature is valid in the fu…
…ture
  • Loading branch information
cmaglie committed Nov 7, 2024
commit 8a17891b996b92991bd562031fe3a25abc50457b
20 changes: 20 additions & 0 deletions internal/arduino/security/signatures.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ import (
"errors"
"io"
"os"
"time"

"github.com/ProtonMail/go-crypto/openpgp"
pgperrors "github.com/ProtonMail/go-crypto/openpgp/errors"
"github.com/ProtonMail/go-crypto/openpgp/packet"
"github.com/arduino/arduino-cli/internal/i18n"
"github.com/arduino/go-paths-helper"
"github.com/sirupsen/logrus"
)

//go:embed keys/*
Expand Down Expand Up @@ -81,5 +85,21 @@ func VerifySignature(targetPath *paths.Path, signaturePath *paths.Path, arduinoK
return false, nil, errors.New(i18n.Tr("opening signature file: %s", err))
}
signer, err := openpgp.CheckDetachedSignature(keyRing, bytes.NewBuffer(target), bytes.NewBuffer(signature), nil)

// Some users reported spurious "expired signature" errors. After some investigation
// we found that all of them had a wrong system date set on their machine, with
// a date set in the past.
// Even if the error says that the signature is "expired", it's actually a
// signature that is not yet valid (it will be in the future).
// Since we could not trust the system clock, we recheck the signature with a date set
// in the future, so we may avoid to display a difficult to understand error to the user.
year2100 := time.Date(2100, 0, 0, 0, 0, 0, 0, time.UTC)
if errors.Is(err, pgperrors.ErrSignatureExpired) && time.Now().Before(year2100) {
logrus.Warn("Ignoring expired signature")
signer, err = openpgp.CheckDetachedSignature(keyRing, bytes.NewBuffer(target), bytes.NewBuffer(signature), &packet.Config{
Time: func() time.Time { return year2100 },
})
}

return (signer != nil && err == nil), signer, err
}
Loading