Skip to content

Commit 8a17891

Browse files
committed
Do not output 'signature expired' if the signature is valid in the future
1 parent 420f6ef commit 8a17891

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

internal/arduino/security/signatures.go

+20
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@ import (
2121
"errors"
2222
"io"
2323
"os"
24+
"time"
2425

2526
"github.com/ProtonMail/go-crypto/openpgp"
27+
pgperrors "github.com/ProtonMail/go-crypto/openpgp/errors"
28+
"github.com/ProtonMail/go-crypto/openpgp/packet"
2629
"github.com/arduino/arduino-cli/internal/i18n"
2730
"github.com/arduino/go-paths-helper"
31+
"github.com/sirupsen/logrus"
2832
)
2933

3034
//go:embed keys/*
@@ -81,5 +85,21 @@ func VerifySignature(targetPath *paths.Path, signaturePath *paths.Path, arduinoK
8185
return false, nil, errors.New(i18n.Tr("opening signature file: %s", err))
8286
}
8387
signer, err := openpgp.CheckDetachedSignature(keyRing, bytes.NewBuffer(target), bytes.NewBuffer(signature), nil)
88+
89+
// Some users reported spurious "expired signature" errors. After some investigation
90+
// we found that all of them had a wrong system date set on their machine, with
91+
// a date set in the past.
92+
// Even if the error says that the signature is "expired", it's actually a
93+
// signature that is not yet valid (it will be in the future).
94+
// Since we could not trust the system clock, we recheck the signature with a date set
95+
// in the future, so we may avoid to display a difficult to understand error to the user.
96+
year2100 := time.Date(2100, 0, 0, 0, 0, 0, 0, time.UTC)
97+
if errors.Is(err, pgperrors.ErrSignatureExpired) && time.Now().Before(year2100) {
98+
logrus.Warn("Ignoring expired signature")
99+
signer, err = openpgp.CheckDetachedSignature(keyRing, bytes.NewBuffer(target), bytes.NewBuffer(signature), &packet.Config{
100+
Time: func() time.Time { return year2100 },
101+
})
102+
}
103+
84104
return (signer != nil && err == nil), signer, err
85105
}

0 commit comments

Comments
 (0)