Skip to content

Commit

Permalink
shorten comment and add links to relevant sources
Browse files Browse the repository at this point in the history
`%x` - https://go.dev/play/p/Fylce70N2Zl
Leading Zeros - mozilla/tls-observatory#245

Signed-off-by: Rhys Evans <[email protected]>
  • Loading branch information
rhysxevans committed Jan 2, 2025
1 parent 32b26aa commit 239f19c
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions prober/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down

0 comments on commit 239f19c

Please sign in to comment.