Documentation
¶
Overview ¶
Package cnsa provides configurations for Go's cryptographic libraries, aiming to adhere to NSA's Commercial National Security Algorithm Suite (CNSA) 2.0 requirements for classical baseline algorithms.
Index ¶
- func ExampleAuthorizedKeysCallback(authorizedKeysMap map[string]bool) func(ssh.ConnMetadata, ssh.PublicKey) (*ssh.Permissions, error)
- func LoadAuthorizedKeysFromFile(filePath string, validator func(key ssh.PublicKey) error) (map[string]bool, error)
- func LoadPrivateHostKeyFromFile(keyFile string) (ssh.Signer, error)
- func NewSSHClientConfig(username string, options ...sshClientOption) (*ssh.ClientConfig, error)
- func NewSSHServerConfig(options ...sshServerOption) (*ssh.ServerConfig, error)
- func NewTLSConfig(options ...tlsOption) (*tls.Config, error)
- func ValidateSSHPublicKey(key ssh.PublicKey) error
- func ValidateTLSCertificate(cert *tls.Certificate) error
- func ValidateX509Certificate(cert *x509.Certificate) error
- func WithCNSACompliantHostKeyCallback(underlyingCallback ssh.HostKeyCallback) sshClientOption
- func WithCNSAPublicKeyAuth(...) sshServerOption
- func WithHostKeyFile(keyFile string) sshServerOption
- func WithMutualTLS(clientCAPool *x509.CertPool) tlsOption
- func WithMutualTLSFromFile(clientCAFile string) tlsOption
- func WithRejectAES128() tlsOption
- func WithSessionTicketsEnabled() tlsOption
- func WithX509KeyPair(certFile, keyFile string) tlsOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExampleAuthorizedKeysCallback ¶
func ExampleAuthorizedKeysCallback(authorizedKeysMap map[string]bool) func(ssh.ConnMetadata, ssh.PublicKey) (*ssh.Permissions, error)
ExampleAuthorizedKeysCallback returns an ssh.PublicKeyCallback function suitable for use with `WithCNSAPublicKeyAuth`. It checks if the public key presented by the client exists in the `authorizedKeysMap`. This map should be pre-populated by `LoadAuthorizedKeysFromFile` using a CNSA-compliant validator.
func LoadAuthorizedKeysFromFile ¶
func LoadAuthorizedKeysFromFile(filePath string, validator func(key ssh.PublicKey) error) (map[string]bool, error)
LoadAuthorizedKeysFromFile loads public keys from a file path, parsing the content in standard authorized_keys format (one key per line, comments allowed). It validates each parsed key using the provided `validator` function (e.g., ValidateSSHPublicKey). If a non-compliant key is found, it returns an error. Returns a map where keys are the base64-encoded wire format of the authorized public keys.
func LoadPrivateHostKeyFromFile ¶
LoadPrivateHostKeyFromFile loads a private key (PEM format) from the specified file, validates its public component against CNSA 2.0 requirements using ValidateSSHPublicKey, and returns an ssh.Signer.
func NewSSHClientConfig ¶
func NewSSHClientConfig(username string, options ...sshClientOption) (*ssh.ClientConfig, error)
NewSSHClientConfig returns an ssh.ClientConfig configured with cryptographic algorithms adhering to CNSA 2.0 classical baseline requirements. Requires Go's FIPS 140-3 mode to be enabled (`GODEBUG=fips140=only`) and a non-empty username.
Defaults:
- KEX: ecdh-sha2-nistp384
- Ciphers: aes256-gcm@openssh.com
- MACs: hmac-sha2-384
- HostKeyAlgorithms (accepted host key signature types): ecdsa-sha2-nistp384, rsa-sha2-512
CRITICAL: A HostKeyCallback MUST be provided via options (e.g., using WithCNSACompliantHostKeyCallback wrapping a known_hosts implementation) to ensure server authenticity and prevent MITM attacks. CRITICAL: Authentication methods (e.g., `ssh.PublicKeys(...)`) MUST be configured by the caller by setting the `Auth` field on the returned config or via options.
func NewSSHServerConfig ¶
func NewSSHServerConfig(options ...sshServerOption) (*ssh.ServerConfig, error)
NewSSHServerConfig returns an ssh.ServerConfig configured with cryptographic algorithms adhering to CNSA 2.0 classical baseline requirements. Requires Go's FIPS 140-3 mode to be enabled (`GODEBUG=fips140=only`).
Defaults:
- KEX: ecdh-sha2-nistp384
- Ciphers: aes256-gcm@openssh.com
- MACs: hmac-sha2-384
- Password authentication: DISABLED
- Public key authentication: DISABLED (must be enabled via WithCNSAPublicKeyAuth)
CRITICAL: Host keys MUST be added via options (e.g., WithHostKeyFile). The server will fail the handshake if no host keys are configured.
func NewTLSConfig ¶
NewTLSConfig returns a TLS configuration that adheres to CNSA 2.0, keeping only TLS 1.3 with "TLS_AES_256_GCM_SHA384" as the cipher suite with a key exchange of ECDHE with P-384 or RSA with at least 3072 bits.
func ValidateSSHPublicKey ¶
ValidateSSHPublicKey checks if an ssh.PublicKey meets CNSA 2.0 requirements for key type and size/curve (ECDSA P-384 or RSA >= 3072 bits).
func ValidateTLSCertificate ¶
func ValidateTLSCertificate(cert *tls.Certificate) error
ValidateTLSCertificate verifies that the actual server certificate loaded by the TLS server meets CNSA 2.0 requirements as well. This is important because the other functions only verify the certificate chain of peer certificates, not the server certificate itself.
func ValidateX509Certificate ¶
func ValidateX509Certificate(cert *x509.Certificate) error
ValidateX509Certificate checks if an X509 certificate meets CNSA 2.0 requirements
func WithCNSACompliantHostKeyCallback ¶
func WithCNSACompliantHostKeyCallback(underlyingCallback ssh.HostKeyCallback) sshClientOption
WithCNSACompliantHostKeyCallback returns an sshClientOption that sets a HostKeyCallback. The configured callback first validates the server's host key against CNSA 2.0 requirements using ValidateSSHPublicKey. If the key is compliant, it then invokes the provided `underlyingCallback` (e.g., `knownhosts.New` callback) to verify host authenticity. An `underlyingCallback` MUST be provided to prevent TOFU attacks.
func WithCNSAPublicKeyAuth ¶
func WithCNSAPublicKeyAuth(authorizedKeysCallback func(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error)) sshServerOption
WithCNSAPublicKeyAuth returns an sshServerOption that configures the PublicKeyCallback. The callback first validates the presented public key against CNSA 2.0 requirements. If compliant, it delegates to the provided `authorizedKeysCallback` to determine if the key is authorized for the user. If `authorizedKeysCallback` is nil, this option effectively disables public key auth unless the default behavior (accepting any compliant key) is explicitly desired (NOT RECOMMENDED).
func WithHostKeyFile ¶
func WithHostKeyFile(keyFile string) sshServerOption
WithHostKeyFile returns an sshServerOption that loads a host key from the given file path and adds it to the server config using the AddHostKey method. The key is validated for CNSA 2.0 compliance before being added.
func WithMutualTLS ¶
WithMutualTLS configures the server to require and verify client certificates signed by a CA present in the provided clientCAPool. While not required or discussed in CNSA 2.0, other government standards (e.g., NIST/CMMC) do require mTLS in certain contexts. This function is provided as an optional convenience for those who need it. It is not required for CNSA 2.0 compliance.
func WithMutualTLSFromFile ¶
func WithMutualTLSFromFile(clientCAFile string) tlsOption
WithMutualTLSFromFile configures the server to require and verify client certificates signed by a CA present in the specified clientCAFile (PEM format). This is convenience wrapper around WithMutualTLS that loads the CA file into a CertPool. It is not required for CNSA 2.0 compliance.
func WithRejectAES128 ¶
func WithRejectAES128() tlsOption
WithRejectAES128 adds a VerifyConnection hook that will reject any TLS 1.3 handshake negotiating the AES-128 cipher suite, as it is not allowed by CNSA 2.0, but we have no way to disable it directly in the Go standard library. This is a workaround (or dare I say, dirty hack), and is not clean because it allows the negotiation to complete before severing the connection. I don't recommend using this in production, but offer it merely as a convenience for those who have hard requirements to reject AES-128 cipher suites.
func WithSessionTicketsEnabled ¶
func WithSessionTicketsEnabled() tlsOption
WithSessionTicketsEnabled enables session tickets in the TLS configuration. Although th is is not required or recommended by FIPS or CNSA 2.0, it isn't explicitly prohibited, and may be allowed by a specific ATO. We default to disabling session tickets to be conservative and avoid any potential security issues. This optional function can be used to re-enable session tickets.
func WithX509KeyPair ¶
func WithX509KeyPair(certFile, keyFile string) tlsOption
WithX509KeyPair loads a certificate and private key from the specified files and adds them to the TLS configuration.
Types ¶
This section is empty.