strings.ToUpper() for x509 and pgp fingerprints
parent
50402ded76
commit
8c27393d8f
|
@ -5,6 +5,7 @@ import (
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/crypto/openpgp"
|
"golang.org/x/crypto/openpgp"
|
||||||
|
@ -69,20 +70,20 @@ func GetOpenPGPInformationEncoded(c *gin.Context) {
|
||||||
|
|
||||||
switch entity.PrimaryKey.PubKeyAlgo {
|
switch entity.PrimaryKey.PubKeyAlgo {
|
||||||
case packet.PubKeyAlgoECDSA:
|
case packet.PubKeyAlgoECDSA:
|
||||||
if ecdsaKey, ok := entity.PrimaryKey.PublicKey.(*ecdsa.PublicKey); ok {
|
if ecdsaKey, ok := entity.PrimaryKey.PublicKey.(*ecdsa.PublicKey); ok {
|
||||||
bitLength = ecdsaKey.Params().BitSize
|
bitLength = ecdsaKey.Params().BitSize
|
||||||
} else {
|
} else {
|
||||||
panic("expected ecdsa.PublicKey for type packet.PubKeyAlgoECDSA")
|
panic("expected ecdsa.PublicKey for type packet.PubKeyAlgoECDSA")
|
||||||
}
|
}
|
||||||
case packet.PubKeyAlgoRSA:
|
case packet.PubKeyAlgoRSA:
|
||||||
if rsaKey, ok := entity.PrimaryKey.PublicKey.(*rsa.PublicKey); ok {
|
if rsaKey, ok := entity.PrimaryKey.PublicKey.(*rsa.PublicKey); ok {
|
||||||
bitLength = rsaKey.N.BitLen()
|
bitLength = rsaKey.N.BitLen()
|
||||||
} else {
|
} else {
|
||||||
panic("expected rsa.PublicKey for type packet.PubKeyAlgoRSA")
|
panic("expected rsa.PublicKey for type packet.PubKeyAlgoRSA")
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
val, _ := entity.PrimaryKey.BitLength()
|
val, _ := entity.PrimaryKey.BitLength()
|
||||||
bitLength = int(val)
|
bitLength = int(val)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
@ -93,8 +94,8 @@ func GetOpenPGPInformationEncoded(c *gin.Context) {
|
||||||
"email": key.Email,
|
"email": key.Email,
|
||||||
"creationTime": key.CreationTime,
|
"creationTime": key.CreationTime,
|
||||||
"publicKeyAlgorithm": key.PublicKeyAlgorithm,
|
"publicKeyAlgorithm": key.PublicKeyAlgorithm,
|
||||||
"fingerprint": hex.EncodeToString(key.Fingerprint[:]),
|
"fingerprint": strings.ToUpper(hex.EncodeToString(key.Fingerprint[:])),
|
||||||
"keyID": entity.PrimaryKey.KeyIdString(),
|
"keyID": entity.PrimaryKey.KeyIdString(),
|
||||||
"bitLength": bitLength,
|
"bitLength": bitLength,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
@ -179,7 +180,7 @@ func GetCertificateInformationEncoded(c *gin.Context) {
|
||||||
"extendedKeyUsageAsText": extendedKeyUsagesText,
|
"extendedKeyUsageAsText": extendedKeyUsagesText,
|
||||||
"san": certificate.DNSNames,
|
"san": certificate.DNSNames,
|
||||||
"emailAddresses": certificate.EmailAddresses,
|
"emailAddresses": certificate.EmailAddresses,
|
||||||
"fingerprint": hex.EncodeToString(sum[:]),
|
"fingerprint": strings.ToUpper(hex.EncodeToString(sum[:])),
|
||||||
"bitLength": bitLength,
|
"bitLength": bitLength,
|
||||||
"pem": string(pem.EncodeToMemory(block)),
|
"pem": string(pem.EncodeToMemory(block)),
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue