additions and fixes to pgp resolver

master
Matthew 2021-07-04 19:01:09 -04:00
parent 369a1558d4
commit 50402ded76
No known key found for this signature in database
GPG Key ID: 210AF32ADE3B5C4B
1 changed files with 28 additions and 3 deletions

View File

@ -1,6 +1,8 @@
package routes package routes
import ( import (
"crypto/ecdsa"
"crypto/rsa"
"encoding/hex" "encoding/hex"
"net/http" "net/http"
"time" "time"
@ -17,7 +19,7 @@ type PGPKey struct {
CreationTime time.Time CreationTime time.Time
PublicKeyAlgorithm packet.PublicKeyAlgorithm PublicKeyAlgorithm packet.PublicKeyAlgorithm
Fingerprint [20]byte Fingerprint [20]byte
KeyID uint16 KeyID uint64
} }
func GetOpenPGPInformationEncoded(c *gin.Context) { func GetOpenPGPInformationEncoded(c *gin.Context) {
@ -57,10 +59,32 @@ func GetOpenPGPInformationEncoded(c *gin.Context) {
CreationTime: entity.PrimaryKey.CreationTime, CreationTime: entity.PrimaryKey.CreationTime,
PublicKeyAlgorithm: entity.PrimaryKey.PubKeyAlgo, PublicKeyAlgorithm: entity.PrimaryKey.PubKeyAlgo,
Fingerprint: entity.PrimaryKey.Fingerprint, Fingerprint: entity.PrimaryKey.Fingerprint,
KeyID: uint16(entity.PrimaryKey.KeyId), KeyID: entity.PrimaryKey.KeyId,
} }
break break
} }
// bitLength, _ := entity.PrimaryKey.BitLength()
var bitLength int
switch entity.PrimaryKey.PubKeyAlgo {
case packet.PubKeyAlgoECDSA:
if ecdsaKey, ok := entity.PrimaryKey.PublicKey.(*ecdsa.PublicKey); ok {
bitLength = ecdsaKey.Params().BitSize
} else {
panic("expected ecdsa.PublicKey for type packet.PubKeyAlgoECDSA")
}
case packet.PubKeyAlgoRSA:
if rsaKey, ok := entity.PrimaryKey.PublicKey.(*rsa.PublicKey); ok {
bitLength = rsaKey.N.BitLen()
} else {
panic("expected rsa.PublicKey for type packet.PubKeyAlgoRSA")
}
default:
val, _ := entity.PrimaryKey.BitLength()
bitLength = int(val)
}
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"status": true, "status": true,
"fullName": key.FullName, "fullName": key.FullName,
@ -70,6 +94,7 @@ func GetOpenPGPInformationEncoded(c *gin.Context) {
"creationTime": key.CreationTime, "creationTime": key.CreationTime,
"publicKeyAlgorithm": key.PublicKeyAlgorithm, "publicKeyAlgorithm": key.PublicKeyAlgorithm,
"fingerprint": hex.EncodeToString(key.Fingerprint[:]), "fingerprint": hex.EncodeToString(key.Fingerprint[:]),
"keyID": key.KeyID, "keyID": entity.PrimaryKey.KeyIdString(),
"bitLength": bitLength,
}) })
} }