Documentation
¶
Index ¶
- Constants
- Variables
- func CertsToTables(w io.Writer, certs []*x509.Certificate, filter ...[]map[int][]string)
- func GetCertsFromBundle(certBundlePath string, fileReader Reader) ([]*x509.Certificate, error)
- func GetKeyFromFile(keyFilePath string, keyPwEnvVar string, inputReader Reader) (crypto.PrivateKey, error)
- func GetRootCertsFromFile(caBundlePath string, fileReader Reader) (*x509.CertPool, error)
- func GetRootCertsFromString(caBundleString string) (*x509.CertPool, error)
- func IsPrivateKeyEncrypted(key []byte) (bool, error)
- func ParsePrivateKey(keyPEM []byte, pwEnvKey string, pwReader Reader) (crypto.PrivateKey, error)
- func PrintCertInfo(cert *x509.Certificate, depth int, w io.Writer)
- type Config
- func (c *Config) GetRemoteCerts(ctx context.Context) error
- func (c *Config) PrintData(ctx context.Context, w io.Writer) error
- func (c *Config) ProbeTLSInfo(ctx context.Context) error
- func (c *Config) SetCaPoolFromFile(filePath string, fileReader Reader) error
- func (c *Config) SetCertsFromFile(filePath string, fileReader Reader) error
- func (c *Config) SetPrivateKeyFromFile(filePath string, keyPwEnvVar string, fileReader Reader) error
- func (c *Config) SetTLSEndpoint(ctx context.Context, hostport string) error
- func (c *Config) SetTLSInfoRequested(requested bool) *Config
- func (c *Config) SetTLSInsecure(skipVerify bool) *Config
- func (c *Config) SetTLSServerName(serverName string) *Config
- type InputReader
- type NoPasswordPromptReader
- type ProbedCipher
- type Reader
Constants ¶
const ( // TLSTimeout is the maximum time to wait for a TLS handshake. TLSTimeout = 3 * time.Second // CertExpWarnDays is the number of days before expiration to start showing warnings. CertExpWarnDays = 40 )
Variables ¶
var ( // TLSServerName is the default ServerName to use for SNI. TLSServerName string // TLSInsecure indicates if certificate verification should be skipped globally. TLSInsecure bool )
Functions ¶
func CertsToTables ¶
CertsToTables formats and prints a list of x509 certificates as tables to the provided writer. An optional filter slice of maps can be provided to filter printed output by certificate index and field names.
func GetCertsFromBundle ¶
func GetCertsFromBundle(certBundlePath string, fileReader Reader) ([]*x509.Certificate, error)
GetCertsFromBundle reads a PEM bundle from a file and returns a slice of x509 Certificates.
func GetKeyFromFile ¶
func GetKeyFromFile( keyFilePath string, keyPwEnvVar string, inputReader Reader, ) (crypto.PrivateKey, error)
GetKeyFromFile reads a private key from a file and parses it using ParsePrivateKey.
func GetRootCertsFromFile ¶
GetRootCertsFromFile reads a PEM bundle from a file and returns an x509 CertPool.
func GetRootCertsFromString ¶
GetRootCertsFromString parses a PEM bundle from a string and returns an x509 CertPool.
func IsPrivateKeyEncrypted ¶
IsPrivateKeyEncrypted checks if the given PEM key is encrypted. It returns true if encrypted, false otherwise, and an error if decoding fails.
func ParsePrivateKey ¶
ParsePrivateKey parses a PEM-encoded private key and returns it as a crypto.PrivateKey.
Supported formats:
- PKCS#8 ("BEGIN PRIVATE KEY" / "BEGIN ENCRYPTED PRIVATE KEY") — decrypted with github.com/youmark/pkcs8
- PKCS#1 RSA ("BEGIN RSA PRIVATE KEY") — cleartext or PEM-encrypted (x509.DecryptPEMBlock)
- EC private keys ("BEGIN EC PRIVATE KEY") — cleartext or certain PKCS#8-encrypted ECDSA keys
If the PEM is encrypted the function will try to read the passphrase from the environment variable named by pwEnvKey; if that is empty it will prompt the user interactively.
The function returns a descriptive error if the PEM cannot be decoded, decryption/parsing fails, or the key format is unsupported.
func PrintCertInfo ¶
func PrintCertInfo(cert *x509.Certificate, depth int, w io.Writer)
PrintCertInfo prints basic information about an x509 certificate to the provided writer with a specified indentation depth.
Types ¶
type Config ¶
type Config struct {
// CACertsPool is the pool of root CA certificates used for verification.
CACertsPool *x509.CertPool
// CACertsFilePath is the path to the CA certificate bundle file.
CACertsFilePath string
// CertsBundle is a slice of certificates loaded from a local bundle.
CertsBundle []*x509.Certificate
// CertsBundleFilePath is the path to the certificate bundle file.
CertsBundleFilePath string
// CertsBundleFromKey indicates if the certificate was derived from a private key.
CertsBundleFromKey bool
// PrivKey is the loaded private key.
PrivKey crypto.PrivateKey
// PrivKeyFilePath is the path to the private key file.
PrivKeyFilePath string
// TLSEndpoint is the host:port string of the remote TLS endpoint.
TLSEndpoint string
// TLSEndpointHost is the hostname part of the TLS endpoint.
TLSEndpointHost string
// TLSEndpointPort is the port part of the TLS endpoint.
TLSEndpointPort string
// TLSEndpointCerts is the slice of certificates retrieved from the remote endpoint.
TLSEndpointCerts []*x509.Certificate
// TLSEndpointCertsFromKey indicates if the endpoint certificates were matched with a private key.
TLSEndpointCertsFromKey bool
// TLSServerName is the ServerName used for SNI.
TLSServerName string
// TLSInsecure indicates if certificate verification should be skipped.
TLSInsecure bool
// TLSInfoRequested indicates if negotiated TLS info and supported protocol/cipher scan was requested.
TLSInfoRequested bool
// NegotiatedProtocol is the TLS protocol version negotiated in the primary connection.
NegotiatedProtocol string
// NegotiatedCipher is the TLS cipher suite negotiated in the primary connection.
NegotiatedCipher string
// ProbedProtocols maps a TLS protocol name to whether the remote endpoint supports it.
ProbedProtocols map[string]bool
// ProbedCiphers is a slice of ciphers that were probed against the endpoint.
ProbedCiphers []ProbedCipher
}
Config holds the configuration and results for certificate and key information retrieval.
func (*Config) GetRemoteCerts ¶
GetRemoteCerts establishes a TLS connection to the configured endpoint and retrieves the peer certificate chain. It also performs certificate verification unless TLSInsecure is true.
func (*Config) PrintData ¶
PrintData prints all collected certificate and key information (local files and remote endpoints) to the provided writer in a human-readable format.
func (*Config) ProbeTLSInfo ¶
ProbeTLSInfo concurrently scans the endpoint for supported TLS versions and cipher suites.
func (*Config) SetCaPoolFromFile ¶
SetCaPoolFromFile loads a CA certificate pool from the specified PEM bundle file. Note that x509.SystemCertPool is not used in this case. All certificates from the system certificate pool are excluded.
func (*Config) SetCertsFromFile ¶
SetCertsFromFile loads a certificate bundle from the specified PEM file.
func (*Config) SetPrivateKeyFromFile ¶
func (c *Config) SetPrivateKeyFromFile( filePath string, keyPwEnvVar string, fileReader Reader, ) error
SetPrivateKeyFromFile loads a private key from the specified PEM file. If the key is encrypted, it will attempt to retrieve the passphrase from the environment variable passed as argument or from the interactive prompt.
func (*Config) SetTLSEndpoint ¶
SetTLSEndpoint parses a host:port string and fetches the remote certificates from that endpoint.
func (*Config) SetTLSInfoRequested ¶
SetTLSInfoRequested sets whether to probe and print remote TLS protocol/cipher information.
func (*Config) SetTLSInsecure ¶
SetTLSInsecure sets whether TLS certificate verification should be skipped for the remote endpoint.
func (*Config) SetTLSServerName ¶
SetTLSServerName sets the ServerName to use for SNI when connecting to a remote TLS endpoint.
type InputReader ¶
type InputReader struct{}
InputReader implements the Reader interface using standard OS calls.
func (InputReader) ReadFile ¶
func (InputReader) ReadFile(name string) ([]byte, error)
ReadFile reads the content of a file from the filesystem.
func (InputReader) ReadPassword ¶
func (InputReader) ReadPassword(fd int) ([]byte, error)
ReadPassword reads a password from the terminal without echoing it.
type NoPasswordPromptReader ¶
type NoPasswordPromptReader interface {
NoPasswordPrompt() bool
}
NoPasswordPromptReader is implemented by readers that must not use an interactive terminal prompt (for example MCP or automated tests).
type ProbedCipher ¶
ProbedCipher holds the result of a single cipher suite probe.