Skip to content
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

packet.Config.Time should return time with 999999999 nsec #240

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions crypto/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func verifySignature(
}
} else {
config.Time = func() time.Time {
return time.Unix(verifyTime+internal.CreationTimeOffset, 0)
return time.Unix(verifyTime+internal.CreationTimeOffset, 999999999)
}
}

Expand All @@ -258,7 +258,7 @@ func verifySignature(
// Maybe the creation time offset pushed it over the edge
// Retry with the actual verification time
config.Time = func() time.Time {
return time.Unix(verifyTime, 0)
return time.Unix(verifyTime, 999999999)
}

seeker, ok := origText.(io.ReadSeeker)
Expand Down
31 changes: 31 additions & 0 deletions crypto/signature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/ProtonMail/go-crypto/openpgp"
"github.com/ProtonMail/go-crypto/openpgp/packet"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/ProtonMail/gopenpgp/v2/constants"
)
Expand Down Expand Up @@ -663,3 +664,33 @@ func Test_verifySignaturExpire(t *testing.T) {
t.Fatal(err)
}
}

func TestKeyNotExpired(t *testing.T) {
const lifetime = uint32(time.Hour / time.Second)

cfg := &packet.Config{
Algorithm: packet.PubKeyAlgoEdDSA,
DefaultHash: crypto.SHA256,
DefaultCipher: packet.CipherAES256,
DefaultCompressionAlgo: packet.CompressionZLIB,
KeyLifetimeSecs: lifetime,
SigLifetimeSecs: lifetime,
Time: func() time.Time { return time.Unix(GetUnixTime(), 42) },
}

entity, err := openpgp.NewEntity("John Smith", "Linux", "[email protected]", cfg)
require.NoError(t, err)
key, err := NewKeyFromEntity(entity)
require.NoError(t, err)
keyRing, err := NewKeyRing(key)
require.NoError(t, err)

data := []byte("Hello, World!")
message := NewPlainMessage(data)
signature, err := keyRing.SignDetached(message)
require.NoError(t, err)

sig := NewPGPSignature(signature.GetBinary())
err = keyRing.VerifyDetached(message, sig, GetUnixTime())
require.NoError(t, err)
}
2 changes: 1 addition & 1 deletion crypto/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func getNow() time.Time {
return time.Now()
}

return time.Unix(pgp.latestServerTime, 0)
return time.Unix(pgp.latestServerTime, 999999999)
}

// getTimeGenerator Returns a time generator function.
Expand Down