@@ -21,10 +21,14 @@ import (
21
21
"errors"
22
22
"io"
23
23
"os"
24
+ "time"
24
25
25
26
"github.com/ProtonMail/go-crypto/openpgp"
27
+ pgperrors "github.com/ProtonMail/go-crypto/openpgp/errors"
28
+ "github.com/ProtonMail/go-crypto/openpgp/packet"
26
29
"github.com/arduino/arduino-cli/internal/i18n"
27
30
"github.com/arduino/go-paths-helper"
31
+ "github.com/sirupsen/logrus"
28
32
)
29
33
30
34
//go:embed keys/*
@@ -81,5 +85,21 @@ func VerifySignature(targetPath *paths.Path, signaturePath *paths.Path, arduinoK
81
85
return false , nil , errors .New (i18n .Tr ("opening signature file: %s" , err ))
82
86
}
83
87
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
+
84
104
return (signer != nil && err == nil ), signer , err
85
105
}
0 commit comments