MINA SFTP SSH Security
This page covers SSH security configuration for the MINA SFTP component, including host key verification, cipher selection, key exchange protocols, and algorithm security recommendations.
Host Key Verification
The MINA SFTP component supports comprehensive host key verification to protect against Man-in-the-Middle (MITM) attacks.
Strict Host Key Checking
When strictHostKeyChecking=yes, the server’s host key must match an entry in the known hosts source:
from("mina-sftp://user@host/path?password=secret&strictHostKeyChecking=yes")
.to("file:local"); Known Hosts Sources (Priority Order)
The component checks for known hosts in this priority order:
-
Byte array (
knownHosts): Directly configured as byte array -
URI/Classpath (
knownHostsUri): Loaded from classpath or file URI -
File path (
knownHostsFile): Loaded from filesystem -
User default (
useUserKnownHostsFile=true): Uses~/.ssh/known_hosts
// Custom known hosts file
from("mina-sftp://user@host/path?password=secret&strictHostKeyChecking=yes&knownHostsFile=/path/to/known_hosts")
.to("file:local");
// Known hosts from classpath
from("mina-sftp://user@host/path?password=secret&strictHostKeyChecking=yes&knownHostsUri=classpath:ssh/known_hosts")
.to("file:local"); Auto-Create Known Hosts File (Development Only)
For development environments, enable automatic trust-on-first-use:
from("mina-sftp://user@host/path?password=secret&autoCreateKnownHostsFile=true&knownHostsFile=/tmp/dev_known_hosts")
.to("file:local"); | Auto-create weakens security by automatically trusting new hosts. Only use for development. |
Disable Host Key Checking (Testing Only)
from("mina-sftp://user@localhost/test?password=secret&strictHostKeyChecking=no&useUserKnownHostsFile=false")
.to("mock:result"); | Disabling host key checking is insecure. Only use for testing. |
Certificate-Based Host Verification
For enterprise environments using OpenSSH host certificates, use @cert-authority entries in your known_hosts file:
# Trust this CA for all hosts in example.com domain
@cert-authority *.example.com ssh-rsa AAAAB3NzaC1yc2E... Production CA
# Trust this CA for a specific host
@cert-authority server.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5... Specific CA When both @cert-authority entries and regular host key entries are present:
-
Certificate verification takes precedence if the server presents a certificate and a matching CA exists
-
If certificate verification fails, the connection is rejected (does NOT fall back to regular entries)
-
If the server presents a plain public key, regular known hosts verification is used
Custom ServerKeyVerifier
For advanced use cases, provide a custom ServerKeyVerifier for enterprise key management integration:
ServerKeyVerifier myVerifier = (session, remoteAddress, serverKey) -> {
return verifyAgainstEnterpriseKeyStore(serverKey);
};
context.getRegistry().bind("myVerifier", myVerifier); from("mina-sftp://user@host/path?password=secret&serverKeyVerifier=#myVerifier")
.to("file:local"); When a custom verifier is provided, it is used exclusively — all other host key options are ignored.
Host Key Verification Error Messages
-
Unknown host:
Host key verification failed: server 'hostname:port' is not in the known_hosts file. -
Key mismatch:
Host key verification failed: the host key for 'hostname:port' has changed! -
Untrusted CA:
Certificate is signed by untrusted CA. -
Expired certificate:
Host certificate has expired. -
Principal mismatch:
Hostname '<hostname>' is not listed in certificate principals.
Cipher Configuration
Specify which SSH cipher algorithms to use with the ciphers option:
from("mina-sftp://user@host/path?password=secret&ciphers=aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes256-ctr")
.to("file:local"); Ciphers are offered to the server in the order specified. The first mutually supported cipher is used.
Available Ciphers
| Cipher Name | Algorithm | Mode | Notes |
|---|---|---|---|
| AES-128 | CTR | Standard, widely supported |
| AES-192 | CTR | Standard |
| AES-256 | CTR | Recommended for high security |
| AES-128 | GCM | Authenticated encryption |
| AES-256 | GCM | Recommended - authenticated encryption |
| ChaCha20 | AEAD | Modern, fast on CPUs without AES-NI |
| AES-128 | CBC | Legacy, avoid if possible |
| AES-192 | CBC | Legacy |
| AES-256 | CBC | Legacy, avoid if possible |
| Triple DES | CBC | Deprecated |
| Blowfish | CBC | Legacy |
| Unlike JSch, Apache MINA SSHD supports modern algorithms like ChaCha20-Poly1305 and AES-GCM. Invalid cipher names are validated before connecting. |
Key Exchange Protocol Configuration
Specify key exchange algorithms with the keyExchangeProtocols option:
from("mina-sftp://user@host/path?password=secret&keyExchangeProtocols=curve25519-sha256,ecdh-sha2-nistp256")
.to("file:local"); Post-Quantum Key Exchange
The hybrid post-quantum key exchanges are proposed to any server that offers them, with no configuration, so a connection is protected against harvest-now-decrypt-later attacks by default. They are implemented through Bouncy Castle, which camel-mina-sftp brings on the classpath.
sshd-core proposes sntrup761x25519-sha512 first, under its name and under its sntrup761x25519-sha512@openssh.com alias, and the ML-KEM groups after it. A server that offers both, such as OpenSSH 9.9 or later, therefore negotiates sntrup761x25519-sha512 rather than ML-KEM, and an OpenSSH server before 9.9 offers only the alias. To prefer ML-KEM, put mlkem768x25519-sha256 first in keyExchangeProtocols.
Note that keyExchangeProtocols replaces the proposal rather than adding to it: an endpoint that pins a list of classical algorithms never negotiates a post-quantum one. Check any value configured before Camel 4.24. To require the post-quantum exchange, and fail rather than fall back, pin the proposal to the hybrids alone:
from("mina-sftp://user@host/path?password=secret&keyExchangeProtocols=mlkem768x25519-sha256,sntrup761x25519-sha512,sntrup761x25519-sha512@openssh.com")
.to("file:local"); With Bouncy Castle on the classpath, Apache MINA SSHD also registers it as the security provider of all its cryptography, not only of the key exchange: key factories, key pair generation, key agreement, signatures and digests come from Bouncy Castle rather than from the JDK providers, which matters on a JVM configured for FIPS. The registration is switched off with the -Dorg.apache.sshd.security.provider.BC.enabled=false system property.
Available Key Exchange Protocols
| Protocol Name | Description | Recommended |
|---|---|---|
| Hybrid ML-KEM-768 with X25519 (post-quantum) | Yes |
| Hybrid ML-KEM-768 with NIST P-256 (post-quantum) | Yes |
| Hybrid ML-KEM-1024 with NIST P-384 (post-quantum) | Yes |
| Hybrid Streamlined NTRU Prime with X25519 (post-quantum) | Yes |
| The same exchange under the name that OpenSSH servers before 9.9 use (post-quantum) | Yes |
| Modern Curve25519 with SHA-256 | Yes |
| Curve25519 (libssh.org variant) | Yes |
| Curve448 with SHA-512 | Yes |
| ECDH with NIST P-256 | Yes |
| ECDH with NIST P-384 | Yes |
| ECDH with NIST P-521 | Yes |
| DH Group14 (2048-bit) with SHA-256 | Yes |
| DH Group16 (4096-bit) with SHA-512 | Yes |
| DH Group18 (8192-bit) with SHA-512 | Yes |
| DH Group Exchange with SHA-256 | Yes |
| DH Group14 with SHA-1 | Deprecated |
| DH Group1 (1024-bit) with SHA-1 | Deprecated |
| DH Group Exchange with SHA-1 | Deprecated |
Server Host Key Configuration
Specify accepted server host key algorithms with serverHostKeys:
from("mina-sftp://user@host/path?password=secret&serverHostKeys=ssh-ed25519,rsa-sha2-512")
.to("file:local"); Available Server Host Key Algorithms
| Algorithm Name | Description | Recommended |
|---|---|---|
| EdDSA Ed25519 (modern, fast) | Yes |
| RSA with SHA-512 | Yes |
| RSA with SHA-256 | Yes |
| ECDSA with NIST P-256 | Yes |
| ECDSA with NIST P-384 | Yes |
| ECDSA with NIST P-521 | Yes |
| RSA with SHA-1 | Deprecated |
| DSA | Deprecated |
OpenSSH certificate variants are also supported (e.g., ssh-ed25519-cert-v01@openssh.com, rsa-sha2-256-cert-v01@openssh.com).
Algorithm Security Recommendations
Recommended Secure Configuration
from("mina-sftp://user@host/path?password=secret"
+ "&keyExchangeProtocols=mlkem768x25519-sha256,curve25519-sha256,ecdh-sha2-nistp256,diffie-hellman-group16-sha512"
+ "&serverHostKeys=ssh-ed25519,rsa-sha2-512,ecdsa-sha2-nistp256"
+ "&ciphers=aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes256-ctr")
.to("file:local");