Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose raw cert info through tlsinfo (#479)
* Expose raw cert info through tlsinfo In some types of debugging, it's useful to get a more detailed view of a certificate than what `tlsinfo get-cert` currently provides. The existing fields that we parse out are the most commonly useful ones so they're good to show by default, but I'd like it to be possible to display more. My solution is to pass back the full raw certificate and allow printing it if a flag is set. We transfer the cert over the wire in binary ASN.1 DER format because it's more compact and it's easy to get from the libraries we're using, and we print it in PEM to avoid issues with unprintable characters and to keep it in a format that many CLI tools understand. I confirmed that generated PEMs were readable with `keytool -printcert -file` and `openssl x509 -in`. Example commands: ``` $ go run ./cmd/sanssh -targets localhost tlsinfo get-certs www.example.com:443 ---Server Certificate--- 0 Issuer: CN=DigiCert Global G2 TLS RSA SHA256 2020 CA1,O=DigiCert Inc,C=US Subject: CN=www.example.org,O=Internet Corporation for Assigned Names and Numbers,L=Los Angeles,ST=California,C=US NotBefore: 2024-01-29 16:00:00 -0800 PST NotAfter: 2025-03-01 15:59:59 -0800 PST DNS Names: [www.example.org example.net example.edu example.com example.org www.example.com www.example.edu www.example.net] IP Addresses: [] ---Server Certificate--- 1 Issuer: CN=DigiCert Global Root G2,OU=www.digicert.com,O=DigiCert Inc,C=US Subject: CN=DigiCert Global G2 TLS RSA SHA256 2020 CA1,O=DigiCert Inc,C=US NotBefore: 2021-03-29 17:00:00 -0700 PDT NotAfter: 2031-03-29 16:59:59 -0700 PDT DNS Names: [] IP Addresses: [] $ go run ./cmd/sanssh -targets localhost tlsinfo get-certs -pem www.example.com:443 -----BEGIN CERTIFICATE----- MIIHbjCCBlagAwIBAgIQB1vO8waJyK3fE+Ua9K/hhzANBgkqhkiG9w0BAQsFADBZ MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMTMwMQYDVQQDEypE aWdpQ2VydCBHbG9iYWwgRzIgVExTIFJTQSBTSEEyNTYgMjAyMCBDQTEwHhcNMjQw MTMwMDAwMDAwWhcNMjUwMzAxMjM1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UdIwQYMBaAFE4iVCAYlebjbuYP+vq5Eu0GF485MA4GA1UdDwEB/wQEAwIBhjAd BgNVHSUEFjAUBggrBgEFBQcDAQYIKwYBBQUHAwIwdgYIKwYBBQUHAQEEajBoMCQG CCsGAQUFBzABhhhodHRwOi8vb2NzcC5kaWdpY2VydC5jb20wQAYIKwYBBQUHMAKG NGh0dHA6Ly9jYWNlcnRzLmRpZ2ljZXJ0LmNvbS9EaWdpQ2VydEdsb2JhbFJvb3RH Mi5jcnQwQgYDVR0fBDswOTA3oDWgM4YxaHR0cDovL2NybDMuZGlnaWNlcnQuY29t L0RpZ2lDZXJ0R2xvYmFsUm9vdEcyLmNybDA9BgNVHSAENjA0MAsGCWCGSAGG/WwC ATAHBgVngQwBATAIBgZngQwBAgEwCAYGZ4EMAQICMAgGBmeBDAECAzANBgkqhkiG 9w0BAQsFAAOCAQEAkPFwyyiXaZd8dP3A+iZ7U6utzWX9upwGnIrXWkOH7U1MVl+t wcW1BSAuWdH/SvWgKtiwla3JLko716f2b4gp/DA/JIS7w7d7kwcsr4drdjPtAFVS slme5LnQ89/nD/7d+MS5EHKBCQRfz5eeLjJ1js+aWNJXMX43AYGyZm0pGrFmCW3R bpD0ufovARTFXFZkAdl9h6g4U5+LXUZtXMYnhIHUfoyMo5tS58aI7Dd8KvvwVVo4 chDYABPPTHPbqjc1qCmBaZx2vN4Ye5DUys/vZwP9BFohFrH/6j/f3IL16/RZkiMN JCqVJUzKoZHm1Lesh3Sz8W2jmdv51b2EQJ8HmA== -----END CERTIFICATE----- ``` * Update styling and add explicit error on blank cert
- Loading branch information