From 3ec45b8b80702da29133974103bfd405b509718e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=8E=E6=89=87=E6=BB=91=E7=BF=94=E7=BF=BC?= Date: Fri, 25 Jul 2025 08:48:03 +0000 Subject: [PATCH] Commands: Show certificate chain Length --- main/commands/all/tls/ping.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/main/commands/all/tls/ping.go b/main/commands/all/tls/ping.go index fa6409ca..031fc25a 100644 --- a/main/commands/all/tls/ping.go +++ b/main/commands/all/tls/ping.go @@ -122,13 +122,23 @@ func executePing(cmd *base.Command, args []string) { } func printCertificates(certs []*x509.Certificate) { + var leaf *x509.Certificate + var length int for _, cert := range certs { - if len(cert.DNSNames) == 0 { - continue + length += len(cert.Raw) + if len(cert.DNSNames) != 0 { + leaf = cert } - fmt.Println("Cert's signature algorithm: ", cert.SignatureAlgorithm.String()) - fmt.Println("Cert's publicKey algorithm: ", cert.PublicKeyAlgorithm.String()) - fmt.Println("Cert's allowed domains: ", cert.DNSNames) + } + if len(certs) > 1 { + fmt.Println("Certificate chain length: ", length) + } else { + fmt.Println("Certificate chain length: ", length, "(only one certificate found)") + } + if leaf != nil { + fmt.Println("Cert's signature algorithm: ", leaf.SignatureAlgorithm.String()) + fmt.Println("Cert's publicKey algorithm: ", leaf.PublicKeyAlgorithm.String()) + fmt.Println("Cert's allowed domains: ", leaf.DNSNames) } }