From 239f19c124ddfbcb933e290d4192a513d7b1334c Mon Sep 17 00:00:00 2001 From: Rhys Evans Date: Thu, 2 Jan 2025 07:48:17 +0000 Subject: [PATCH] shorten comment and add links to relevant sources `%x` - https://go.dev/play/p/Fylce70N2Zl Leading Zeros - https://github.com/mozilla/tls-observatory/pull/245 Signed-off-by: Rhys Evans --- prober/tls.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/prober/tls.go b/prober/tls.go index 5bb6a1ec..0589036e 100644 --- a/prober/tls.go +++ b/prober/tls.go @@ -72,9 +72,8 @@ func getLastChainExpiry(state *tls.ConnectionState) time.Time { func getSerialNumber(state *tls.ConnectionState) string { cert := state.PeerCertificates[0] - // Actual serial number = 0B:FF:BC:11:F1:90:7D:02:AF:71:9A:FC:D6:4F:B2:53 - // serialNumber := cert.SerialNumber.Text(16) // drops leading zeros outputs = BFFBC11F1907D02AF719AFCD64FB253 in lower case, telgraf follows this https://github.com/influxdata/telegraf/blob/a9c91f162ddbe453364f68a89799535c43328a3c/plugins/inputs/x509_cert/x509_cert.go#L218 - // https://github.com/atc0005/check-cert retains the leading zero with some aditional formatting + // Using `cert.SerialNumber.Text(16)` will drop the leading zeros when converting the SerialNumber to String, see https://github.com/mozilla/tls-observatory/pull/245. + // To avoid that, we format in lowercase the bytes with `%x` to base 16, with lower-case letters for a-f, see https://go.dev/play/p/Fylce70N2Zl. return fmt.Sprintf("%x", cert.SerialNumber.Bytes()) }