File tree 6 files changed +29
-4
lines changed
6 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,10 @@ All notable changes to this project will be documented in this file.
4
4
The format is based on [ Keep a Changelog] ( https://keepachangelog.com/en/1.0.0/ ) ,
5
5
and this project adheres to [ Semantic Versioning] ( https://semver.org/spec/v2.0.0.html ) .
6
6
7
- ## Unreleased
7
+ ## [ 2.1.2] 2020-12-01
8
+ ### Added
9
+ - ` SetKeyGenerationOffset ` to add an offset in key generation time and prevent not-yet-valid keys.
10
+
8
11
### Changed
9
12
- Improved canonicalization performance
10
13
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ package constants
3
3
4
4
// Constants for armored data.
5
5
const (
6
- ArmorHeaderVersion = "GopenPGP 2.1.1 "
6
+ ArmorHeaderVersion = "GopenPGP 2.1.2 "
7
7
ArmorHeaderComment = "https://gopenpgp.org"
8
8
PGPMessageHeader = "PGP MESSAGE"
9
9
PGPSignatureHeader = "PGP SIGNATURE"
Original file line number Diff line number Diff line change 1
1
package constants
2
2
3
- const Version = "ddacebe0 "
3
+ const Version = "2.1.2 "
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import "time"
8
8
type GopenPGP struct {
9
9
latestServerTime int64
10
10
latestClientTime time.Time
11
+ generationOffset int64
11
12
}
12
13
13
14
var pgp = GopenPGP {}
Original file line number Diff line number Diff line change @@ -435,7 +435,7 @@ func generateKey(
435
435
cfg := & packet.Config {
436
436
Algorithm : packet .PubKeyAlgoRSA ,
437
437
RSABits : bits ,
438
- Time : getTimeGenerator (),
438
+ Time : getKeyGenerationTimeGenerator (),
439
439
DefaultHash : crypto .SHA256 ,
440
440
DefaultCipher : packet .CipherAES256 ,
441
441
}
Original file line number Diff line number Diff line change @@ -13,6 +13,11 @@ func UpdateTime(newTime int64) {
13
13
}
14
14
}
15
15
16
+ // SetKeyGenerationOffset updates the offset when generating keys.
17
+ func SetKeyGenerationOffset (offset int64 ) {
18
+ pgp .generationOffset = offset
19
+ }
20
+
16
21
// GetUnixTime gets latest cached time.
17
22
func GetUnixTime () int64 {
18
23
return getNow ().Unix ()
@@ -49,3 +54,19 @@ func getDiff() (int64, error) {
49
54
func getTimeGenerator () func () time.Time {
50
55
return getNow
51
56
}
57
+
58
+ // getNowKeyGenerationOffset returns the current time with the key generation offset.
59
+ func getNowKeyGenerationOffset () time.Time {
60
+ extrapolate , err := getDiff ()
61
+
62
+ if err != nil {
63
+ return time .Unix (time .Now ().Unix ()+ pgp .generationOffset , 0 )
64
+ }
65
+
66
+ return time .Unix (pgp .latestServerTime + extrapolate + pgp .generationOffset , 0 )
67
+ }
68
+
69
+ // getKeyGenerationTimeGenerator Returns a time generator function with the key generation offset.
70
+ func getKeyGenerationTimeGenerator () func () time.Time {
71
+ return getNowKeyGenerationOffset
72
+ }
You can’t perform that action at this time.
0 commit comments