@@ -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