summaryrefslogtreecommitdiffstats
path: root/models/gpg_key.go
diff options
context:
space:
mode:
authorAntoine GIRARD <sapk@users.noreply.github.com>2019-04-16 02:32:15 +0200
committertechknowlogick <matti@mdranta.net>2019-04-15 20:32:15 -0400
commite98565ddc71013bc4bc5537f15f545cf909fac3a (patch)
treede8499bfa1a607beae477111864f4e582e6d1d1d /models/gpg_key.go
parentecfa5f15944bc99f817222595ed793c526e268f8 (diff)
downloadgitea-e98565ddc71013bc4bc5537f15f545cf909fac3a.tar.gz
gitea-e98565ddc71013bc4bc5537f15f545cf909fac3a.zip
Fix wrong GPG expire date (#6643)
* fix expire of gpg relative to key creation https://tools.ietf.org/html/rfc4880#section-5.2.3.6 * add test
Diffstat (limited to 'models/gpg_key.go')
-rw-r--r--models/gpg_key.go17
1 files changed, 11 insertions, 6 deletions
diff --git a/models/gpg_key.go b/models/gpg_key.go
index 2e10fd782a..8300cdbd21 100644
--- a/models/gpg_key.go
+++ b/models/gpg_key.go
@@ -232,10 +232,9 @@ func parseSubGPGKey(ownerID int64, primaryID string, pubkey *packet.PublicKey, e
}, nil
}
-//parseGPGKey parse a PrimaryKey entity (primary key + subs keys + self-signature)
-func parseGPGKey(ownerID int64, e *openpgp.Entity) (*GPGKey, error) {
- pubkey := e.PrimaryKey
-
+//getExpiryTime extract the expire time of primary key based on sig
+func getExpiryTime(e *openpgp.Entity) time.Time {
+ expiry := time.Time{}
//Extract self-sign for expire date based on : https://github.com/golang/crypto/blob/master/openpgp/keys.go#L165
var selfSig *packet.Signature
for _, ident := range e.Identities {
@@ -246,10 +245,16 @@ func parseGPGKey(ownerID int64, e *openpgp.Entity) (*GPGKey, error) {
break
}
}
- expiry := time.Time{}
if selfSig.KeyLifetimeSecs != nil {
- expiry = selfSig.CreationTime.Add(time.Duration(*selfSig.KeyLifetimeSecs) * time.Second)
+ expiry = e.PrimaryKey.CreationTime.Add(time.Duration(*selfSig.KeyLifetimeSecs) * time.Second)
}
+ return expiry
+}
+
+//parseGPGKey parse a PrimaryKey entity (primary key + subs keys + self-signature)
+func parseGPGKey(ownerID int64, e *openpgp.Entity) (*GPGKey, error) {
+ pubkey := e.PrimaryKey
+ expiry := getExpiryTime(e)
//Parse Subkeys
subkeys := make([]*GPGKey, len(e.Subkeys))