From 8c27393d8f3bbd0ef6f01eddbc2829bd4034afc3 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sun, 4 Jul 2021 19:13:24 -0400 Subject: [PATCH] strings.ToUpper() for x509 and pgp fingerprints --- routes/pgp.go | 33 +++++++++++++++++---------------- routes/x509.go | 3 ++- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/routes/pgp.go b/routes/pgp.go index 2f99ed6..72d146f 100644 --- a/routes/pgp.go +++ b/routes/pgp.go @@ -5,6 +5,7 @@ import ( "crypto/rsa" "encoding/hex" "net/http" + "strings" "time" "golang.org/x/crypto/openpgp" @@ -69,20 +70,20 @@ func GetOpenPGPInformationEncoded(c *gin.Context) { 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) + 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{ @@ -93,8 +94,8 @@ func GetOpenPGPInformationEncoded(c *gin.Context) { "email": key.Email, "creationTime": key.CreationTime, "publicKeyAlgorithm": key.PublicKeyAlgorithm, - "fingerprint": hex.EncodeToString(key.Fingerprint[:]), + "fingerprint": strings.ToUpper(hex.EncodeToString(key.Fingerprint[:])), "keyID": entity.PrimaryKey.KeyIdString(), - "bitLength": bitLength, + "bitLength": bitLength, }) } diff --git a/routes/x509.go b/routes/x509.go index 2f36df5..e1e423c 100644 --- a/routes/x509.go +++ b/routes/x509.go @@ -11,6 +11,7 @@ import ( "encoding/pem" "io/ioutil" "net/http" + "strings" "github.com/gin-gonic/gin" ) @@ -179,7 +180,7 @@ func GetCertificateInformationEncoded(c *gin.Context) { "extendedKeyUsageAsText": extendedKeyUsagesText, "san": certificate.DNSNames, "emailAddresses": certificate.EmailAddresses, - "fingerprint": hex.EncodeToString(sum[:]), + "fingerprint": strings.ToUpper(hex.EncodeToString(sum[:])), "bitLength": bitLength, "pem": string(pem.EncodeToMemory(block)), })