Add support for the bit sizes of the public keys
parent
2a2ec4ad4d
commit
f05f58c30c
|
@ -1,6 +1,9 @@
|
|||
package routes
|
||||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
"crypto/ed25519"
|
||||
"crypto/rsa"
|
||||
"crypto/sha1"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
|
@ -125,6 +128,25 @@ func GetCertificateInformationEncoded(c *gin.Context) {
|
|||
|
||||
sum := sha1.Sum(certificate.Raw)
|
||||
|
||||
var bitLength int
|
||||
|
||||
switch certificate.PublicKeyAlgorithm {
|
||||
case x509.RSA:
|
||||
if rsaKey, ok := certificate.PublicKey.(*rsa.PublicKey); ok {
|
||||
bitLength = rsaKey.N.BitLen()
|
||||
} else {
|
||||
panic("expected rsa.PublicKey for type x509.RSA")
|
||||
}
|
||||
case x509.ECDSA:
|
||||
if ecdsaKey, ok := certificate.PublicKey.(*ecdsa.PublicKey); ok {
|
||||
bitLength = ecdsaKey.Params().BitSize
|
||||
} else {
|
||||
panic("expected ecdsa.PublicKey for type x509.ECDSA")
|
||||
}
|
||||
case x509.Ed25519:
|
||||
bitLength = ed25519.PublicKeySize
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": true,
|
||||
"subject": gin.H{
|
||||
|
@ -153,6 +175,7 @@ func GetCertificateInformationEncoded(c *gin.Context) {
|
|||
"extendedKeyUsageAsText": extendedKeyUsagesText,
|
||||
"san": certificate.DNSNames,
|
||||
"fingerprint": hex.EncodeToString(sum[:]),
|
||||
"bitLength": bitLength,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -271,6 +294,23 @@ func GetCertificateInfo(c *gin.Context) {
|
|||
|
||||
sum := sha1.Sum(certificate.Raw)
|
||||
|
||||
var bitLength int
|
||||
|
||||
switch certificate.PublicKeyAlgorithm {
|
||||
case x509.RSA:
|
||||
if rsaKey, ok := certificate.PublicKey.(*rsa.PublicKey); ok {
|
||||
bitLength = rsaKey.N.BitLen()
|
||||
} else {
|
||||
panic("expected rsa.PublicKey for type x509.RSA")
|
||||
}
|
||||
case x509.ECDSA:
|
||||
if ecdsaKey, ok := certificate.PublicKey.(*ecdsa.PublicKey); ok {
|
||||
bitLength = ecdsaKey.Params().BitSize
|
||||
} else {
|
||||
panic("expected ecdsa.PublicKey for type x509.ECDSA")
|
||||
}
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": true,
|
||||
"subject": gin.H{
|
||||
|
@ -306,6 +346,7 @@ func GetCertificateInfo(c *gin.Context) {
|
|||
"extendedKeyUsageAsText": extendedKeyUsagesText,
|
||||
"san": certificate.DNSNames,
|
||||
"fingerprint": hex.EncodeToString(sum[:]),
|
||||
"bitLength": bitLength,
|
||||
"connection": gin.H{
|
||||
"tlsVersion": tlsVersion,
|
||||
"cipherSuite": cipherSuite,
|
||||
|
|
Loading…
Reference in New Issue