SSH
Since Camel 2.10
Both producer and consumer are supported
The SSH component enables access to SSH servers such that you can send an SSH command and process the response.
Maven users will need to add the following dependency to their pom.xml for this component:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-ssh</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency> Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.
For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
You can configure components using:
-
the Component DSL.
-
in a configuration file (
application.properties,*.yamlfiles, etc). -
directly in the Java code.
Configuring Endpoint Options
You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders.
Property placeholders provide a few benefits:
-
They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.
-
They allow externalizing the configuration from the code.
-
They help the code to become more flexible and reusable.
The following two sections list all the options, firstly for the component followed by the endpoint.
Component Options
The SSH component supports the following options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
The time in milliseconds that the component waits for each step of setting up the session: the connection, the authentication and the opening of the channel, unless channelOpenTimeout is set. It does not limit how long the command runs. | 30000 | long | |
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
The command that the consumer runs on the SSH server at each poll. The consumer needs it, as each poll fails without it. Some servers need the command to end with a newline, which is written %0A in an endpoint URI. | String | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
The time in milliseconds that Apache MINA SSHD allows for the authentication before it closes the session. If 0 or less, its default of 2 minutes applies. The timeout option also limits how long the component waits for the authentication. | long | ||
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean | |
The time in milliseconds that the component waits for the channel that runs the command to open. If 0 or less, the timeout option applies. | long | ||
The type of SSH channel that runs the command: exec runs it as a single command, and shell writes it to an interactive shell and reads the output up to the shellPrompt text. The endpoint fails to start with another value. Enum values:
| exec | String | |
Autowired To use a custom org.apache.sshd.client.ClientBuilder to create the SSH client, for example to set a ServerKeyVerifier. The producer and the consumer each create a client with it when they start, and the options of this endpoint that are set are applied over its settings. | ClientBuilder | ||
A comma-separated list of the compression algorithms that the client proposes, in order of preference, for example zlib,none. If not set, the client uses no compression. | String | ||
The shared configuration of the endpoints: each endpoint starts from a copy of it. | SshConfiguration | ||
The time in milliseconds that the socket connection to the server may take. If 0 or less, the default of Apache MINA SSHD, 1 minute, applies. The timeout option also limits how long the component waits for the connection. | long | ||
The interval in milliseconds at which the client sends keep-alive requests to the server while a command runs. If 0 or less, no keep-alive requests are sent. | long | ||
The number of keep-alive requests without reply after which the client closes the session, when heartbeatInterval is set. If 0 or less, the default of Apache MINA SSHD applies. | int | ||
The time in milliseconds after which Apache MINA SSHD closes a session without traffic. The session is open while a command runs. The default, 10 minutes, is the default of Apache MINA SSHD. If 0 or less, the session has no idle timeout. | 600000 | long | |
The text that the shell prompt ends with, which channelType=shell needs: the endpoint fails to start without it. The component reads the output of the shell until it ends with this text, before and after it writes the command, and the message body is the text between the first and the last line break of that output. | String | ||
The time in milliseconds between two reads of the shell output while the component waits for the shellPrompt text, with channelType=shell. | 100 | long | |
Used for enabling or disabling all consumer based health checks from this component. | true | boolean | |
Used for enabling or disabling all producer based health checks from this component. Notice: Camel has by default disabled all producer based health-checks. You can turn on producer checks globally by setting camel.health.producersEnabled=true. | true | boolean | |
Whether the producer may take the user name and the password from the CamelSshUsername and CamelSshPassword headers, in place of the username and password options. The CamelSshUsername header is then also used with public key authentication (certResource or keyPairProvider): the configured key logs in as the user that the header names. This is disabled by default, and the headers are then ignored. Enable it only when the route sets these headers itself. | false | boolean | |
The resource with the private key for public key authentication, in OpenSSH or PEM format, for example classpath:id_ed25519 or file:/home/camel/.ssh/id_ed25519. When set, it is used instead of keyPairProvider, and the password option and the CamelSshPassword header are not used. | String | ||
The passphrase of the private key in certResource, when that key is encrypted. | String | ||
A comma-separated list of the ciphers that the client proposes, in order of preference, for example aes256-ctr,aes128-ctr. It replaces the default list of Apache MINA SSHD. Names that are not known are skipped with a warning. | String | ||
Whether to reject a server whose host has no entry without a marker in knownHostsResource. When false, such a server is accepted and a warning is logged. A server whose host has such entries is always rejected when none of them lists the key it presents, and so is a key listed in a matching entry with the revoked marker. This option has no effect when knownHostsResource is not set. | false | boolean | |
A comma-separated list of the key exchange algorithms that the client proposes, in order of preference, for example mlkem768x25519-sha256,curve25519-sha256. It replaces the default list of Apache MINA SSHD, which already proposes the post-quantum hybrid algorithms. Names that are not known are skipped with a warning. | String | ||
The org.apache.sshd.common.keyprovider.KeyPairProvider that gives the key pair for public key authentication. It is not used when certResource is set, and when it is used, the password option and the CamelSshPassword header are not. | KeyPairProvider | ||
The key type of the key pair to use from certResource or keyPairProvider, for example ssh-rsa, ssh-ed25519 or ecdsa-sha2-nistp256. If not set, the first key pair is used. | String | ||
The resource of a file in the OpenSSH known_hosts format, such as file:/etc/camel/known_hosts, that the server host key is verified against. It is read at each connection, and a resource or a line that cannot be read makes every connection fail. When not set, the server host key is not verified and any server is accepted, unless clientBuilder sets a ServerKeyVerifier, which this option replaces when it is set. | String | ||
A comma-separated list of the message authentication code (MAC) algorithms that the client proposes, in order of preference, for example hmac-sha2-512,hmac-sha2-256. It replaces the default list of Apache MINA SSHD. Names that are not known are skipped with a warning. | String | ||
The password for password authentication, which is used only when neither certResource nor keyPairProvider is set. With allowUsernameAndPasswordFromHeaders=true, the CamelSshPassword header replaces it for the producer. | String | ||
A comma-separated list of the signature algorithms that the client supports, in order of preference, for example ssh-ed25519,rsa-sha2-512. It replaces the default list of Apache MINA SSHD. Names that are not known are skipped with a warning. | String | ||
The user name to log in with. With allowUsernameAndPasswordFromHeaders=true, the CamelSshUsername header replaces it for the producer. | String |
Endpoint Options
The SSH endpoint is configured using URI syntax:
ssh:host:port
With the following path and query parameters:
Query Parameters
| Name | Description | Default | Type |
|---|---|---|---|
The time in milliseconds that the component waits for each step of setting up the session: the connection, the authentication and the opening of the channel, unless channelOpenTimeout is set. It does not limit how long the command runs. | 30000 | long | |
The command that the consumer runs on the SSH server at each poll. The consumer needs it, as each poll fails without it. Some servers need the command to end with a newline, which is written %0A in an endpoint URI. | String | ||
If the polling consumer did not poll any files, you can enable this option to send an empty message (no body) instead. | false | boolean | |
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored. | ExceptionHandler | ||
Sets the exchange pattern when the consumer creates an exchange. Enum values:
| ExchangePattern | ||
A pluggable org.apache.camel.PollingConsumerPollingStrategy allowing you to provide your custom implementation to control error handling usually occurred during the poll operation before an Exchange have been created and being routed in Camel. | PollingConsumerPollStrategy | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
The time in milliseconds that Apache MINA SSHD allows for the authentication before it closes the session. If 0 or less, its default of 2 minutes applies. The timeout option also limits how long the component waits for the authentication. | long | ||
The time in milliseconds that the component waits for the channel that runs the command to open. If 0 or less, the timeout option applies. | long | ||
The type of SSH channel that runs the command: exec runs it as a single command, and shell writes it to an interactive shell and reads the output up to the shellPrompt text. The endpoint fails to start with another value. Enum values:
| exec | String | |
Autowired To use a custom org.apache.sshd.client.ClientBuilder to create the SSH client, for example to set a ServerKeyVerifier. The producer and the consumer each create a client with it when they start, and the options of this endpoint that are set are applied over its settings. | ClientBuilder | ||
A comma-separated list of the compression algorithms that the client proposes, in order of preference, for example zlib,none. If not set, the client uses no compression. | String | ||
The time in milliseconds that the socket connection to the server may take. If 0 or less, the default of Apache MINA SSHD, 1 minute, applies. The timeout option also limits how long the component waits for the connection. | long | ||
The interval in milliseconds at which the client sends keep-alive requests to the server while a command runs. If 0 or less, no keep-alive requests are sent. | long | ||
The number of keep-alive requests without reply after which the client closes the session, when heartbeatInterval is set. If 0 or less, the default of Apache MINA SSHD applies. | int | ||
The time in milliseconds after which Apache MINA SSHD closes a session without traffic. The session is open while a command runs. The default, 10 minutes, is the default of Apache MINA SSHD. If 0 or less, the session has no idle timeout. | 600000 | long | |
The text that the shell prompt ends with, which channelType=shell needs: the endpoint fails to start without it. The component reads the output of the shell until it ends with this text, before and after it writes the command, and the message body is the text between the first and the last line break of that output. | String | ||
The time in milliseconds between two reads of the shell output while the component waits for the shellPrompt text, with channelType=shell. | 100 | long | |
The number of subsequent error polls (failed due some error) that should happen before the backoffMultipler should kick-in. | int | ||
The number of subsequent idle polls that should happen before the backoffMultipler should kick-in. | int | ||
To let the scheduled polling consumer backoff if there has been a number of subsequent idles/errors in a row. The multiplier is then the number of polls that will be skipped before the next actual attempt is happening again. When this option is in use then backoffIdleThreshold and/or backoffErrorThreshold must also be configured. | int | ||
Milliseconds before the next poll. | 500 | long | |
If greedy is enabled, then the ScheduledPollConsumer will run immediately again, if the previous run polled 1 or more messages. | false | boolean | |
How long a poll may run before the health check of the consumer reports DOWN. The health check is otherwise based on the polls that are done, so it stays UP while a poll hangs, for example on a read without timeout from a connection that went silent. A poll includes routing the messages it polled, so set this above the longest poll you expect. The poll is not interrupted. The value is in millis (not affected by timeUnit). The default 0 turns this off. | 0 | long | |
Milliseconds before the first poll starts. | 1000 | long | |
Specifies a maximum limit of number of fires. So if you set it to 1, the scheduler will only fire once. If you set it to 5, it will only fire five times. A value of zero or negative means fire forever. | 0 | long | |
The consumer logs a start/complete log line when it polls. This option allows you to configure the logging level for that. Enum values:
| TRACE | LoggingLevel | |
Allows for configuring a custom/shared thread pool to use for the consumer. By default each consumer has its own single threaded thread pool. | ScheduledExecutorService | ||
To use a cron scheduler from either camel-spring or camel-quartz component. Use value spring or quartz for built in scheduler. | none | Object | |
To configure additional properties when using a custom scheduler or any of the Quartz, Spring based scheduler. This is a multi-value option with prefix: scheduler. | Map | ||
Whether the scheduler should be auto started. | true | boolean | |
Time unit for initialDelay and delay options. Enum values:
| MILLISECONDS | TimeUnit | |
Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in JDK for details. | true | boolean | |
Whether the producer may take the user name and the password from the CamelSshUsername and CamelSshPassword headers, in place of the username and password options. The CamelSshUsername header is then also used with public key authentication (certResource or keyPairProvider): the configured key logs in as the user that the header names. This is disabled by default, and the headers are then ignored. Enable it only when the route sets these headers itself. | false | boolean | |
The resource with the private key for public key authentication, in OpenSSH or PEM format, for example classpath:id_ed25519 or file:/home/camel/.ssh/id_ed25519. When set, it is used instead of keyPairProvider, and the password option and the CamelSshPassword header are not used. | String | ||
The passphrase of the private key in certResource, when that key is encrypted. | String | ||
A comma-separated list of the ciphers that the client proposes, in order of preference, for example aes256-ctr,aes128-ctr. It replaces the default list of Apache MINA SSHD. Names that are not known are skipped with a warning. | String | ||
Whether to reject a server whose host has no entry without a marker in knownHostsResource. When false, such a server is accepted and a warning is logged. A server whose host has such entries is always rejected when none of them lists the key it presents, and so is a key listed in a matching entry with the revoked marker. This option has no effect when knownHostsResource is not set. | false | boolean | |
A comma-separated list of the key exchange algorithms that the client proposes, in order of preference, for example mlkem768x25519-sha256,curve25519-sha256. It replaces the default list of Apache MINA SSHD, which already proposes the post-quantum hybrid algorithms. Names that are not known are skipped with a warning. | String | ||
The org.apache.sshd.common.keyprovider.KeyPairProvider that gives the key pair for public key authentication. It is not used when certResource is set, and when it is used, the password option and the CamelSshPassword header are not. | KeyPairProvider | ||
The key type of the key pair to use from certResource or keyPairProvider, for example ssh-rsa, ssh-ed25519 or ecdsa-sha2-nistp256. If not set, the first key pair is used. | String | ||
The resource of a file in the OpenSSH known_hosts format, such as file:/etc/camel/known_hosts, that the server host key is verified against. It is read at each connection, and a resource or a line that cannot be read makes every connection fail. When not set, the server host key is not verified and any server is accepted, unless clientBuilder sets a ServerKeyVerifier, which this option replaces when it is set. | String | ||
A comma-separated list of the message authentication code (MAC) algorithms that the client proposes, in order of preference, for example hmac-sha2-512,hmac-sha2-256. It replaces the default list of Apache MINA SSHD. Names that are not known are skipped with a warning. | String | ||
The password for password authentication, which is used only when neither certResource nor keyPairProvider is set. With allowUsernameAndPasswordFromHeaders=true, the CamelSshPassword header replaces it for the producer. | String | ||
A comma-separated list of the signature algorithms that the client supports, in order of preference, for example ssh-ed25519,rsa-sha2-512. It replaces the default list of Apache MINA SSHD. Names that are not known are skipped with a warning. | String | ||
The user name to log in with. With allowUsernameAndPasswordFromHeaders=true, the CamelSshUsername header replaces it for the producer. | String |
Message Headers
The SSH component supports the following message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
| Constant: | The user name that the producer logs in with, instead of the username option. Used only when allowUsernameAndPasswordFromHeaders=true; otherwise ignored. It applies to every kind of authentication: with certResource or keyPairProvider, the configured key logs in as this user. | String | |
| Constant: | The password that the producer uses for password authentication, instead of the password option. Used only when allowUsernameAndPasswordFromHeaders=true; otherwise ignored. It is not used when certResource or keyPairProvider is set. | String | |
| Constant: | The standard error of the command, as an InputStream. | InputStream | |
| Constant: | The exit status of the command. By convention, a value other than 0 means that the command failed, but the exchange does not fail for it. With channelType=shell it is usually null, as the shell is still running when the output is read. | Integer |
Message Body
The message body at each side of the SSH component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.
| Side | Body | Description |
|---|---|---|
Consumer |
| The standard output of the pollCommand as a stream, with the exit value and the standard error in the CamelSshExitValue and CamelSshStderr headers. |
Producer input |
| The command to run, as text: bytes, a stream or a file are read as text. A Map or a POJO is sent as its toString(): build the command as text first. No body fails. |
Producer output |
| The standard output of the command as a stream, with the exit value and the standard error in the CamelSshExitValue and CamelSshStderr headers; an exit value that is not 0 does not fail the exchange. Convert it to text to read it more than once. |
The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.
Usage
Usage as a Producer endpoint
When the SSH Component is used as a Producer (.to("ssh://…")), it will send the message body as the command to execute on the remote SSH server.
After the call, the message body is the standard output of the command as a stream, with the exit value in the CamelSshExitValue header and the standard error, as a stream as well, in the CamelSshStderr header. An exit value that is not 0 does not fail the exchange. The polling consumer gives the output of its pollCommand the same way.
Here is an example of this. Note that the command has a newline ( ).
-
Java
-
XML
-
YAML
from("direct:exampleSshProducer")
.setBody(constant("features:list\n"))
.to("ssh://user:pass@localhost:8101")
.log("${body}"); <route id="camel-example-ssh-producer">
<from uri="direct:exampleSshProducer"/>
<setBody>
<constant>features:list </constant>
</setBody>
<to uri="ssh://user:pass@localhost:8101"/>
<log message="${body}"/>
</route> - route:
id: camel-example-ssh-producer
from:
uri: direct:exampleSshProducer
steps:
- setBody:
expression:
constant:
expression: "features:list\n"
- to:
uri: ssh://user:pass@localhost:8101
- log:
message: "${body}" The timeout option covers connecting to the server, authenticating and opening the channel, not the run of the command. The producer waits until the command ends, with no time limit, so a command that does not end blocks the thread that sends the message.
With channelType=shell, the shellPrompt option is required, and the endpoint fails to start without it. The producer reads the output of the shell until it ends with the shellPrompt text, and checks the output every sleepForShellPrompt milliseconds (100 by default).
Authentication
The SSH Component can authenticate against the remote SSH server using one of two mechanisms: Public Key certificate or username/password. Configuring how the SSH Component does authentication is based on how and which options are set.
-
First, it will look to see if the
certResourceoption has been set, and if so, use it to locate the referenced Public Key certificate and use that for authentication. -
If
certResourceis not set, it will look to see if akeyPairProviderhas been set, and if so, it will use that for certificate-based authentication. -
If neither
certResourcenorkeyPairProviderare set, it will use theusernameandpasswordoptions for authentication.
In all three cases, the client logs in as the user of the username option, unless the producer takes the user from a header (see below).
The following route fragment shows an SSH polling consumer using a certificate from the classpath.
-
Java
-
XML
-
YAML
from("ssh://scott@localhost:8101?certResource=classpath:test_rsa&useFixedDelay=true&delay=5000&pollCommand=features:list%0A")
.log("${body}"); <route>
<from uri="ssh://scott@localhost:8101?certResource=classpath:test_rsa&useFixedDelay=true&delay=5000&pollCommand=features:list%0A"/>
<log message="${body}"/>
</route> - route:
from:
uri: ssh://scott@localhost:8101
parameters:
certResource: "classpath:test_rsa"
useFixedDelay: true
delay: 5000
pollCommand: "features:list%0A"
steps:
- log:
message: "${body}" An example of using Public Key authentication is provided in examples/camel-example-ssh-security.
User name and password from headers
The producer can log in with a user name and password chosen by the route, from the CamelSshUsername and CamelSshPassword headers, when the allowUsernameAndPasswordFromHeaders option is enabled. Without this option (the default), these headers are ignored, and the producer logs in with the username and password options.
With the option enabled:
-
The
CamelSshUsernameheader replaces theusernameoption for every kind of authentication. WithcertResourceorkeyPairProviderset, the configured key logs in as the user that the header names. -
The
CamelSshPasswordheader replaces thepasswordoption. It is used only for password authentication, so not whencertResourceorkeyPairProvideris set.
-
Java
-
XML
-
YAML
from("direct:status")
.setHeader("CamelSshUsername", constant("scott"))
.setHeader("CamelSshPassword", constant("{{scott.password}}"))
.to("ssh://db.example.com?allowUsernameAndPasswordFromHeaders=true"); <route>
<from uri="direct:status"/>
<setHeader name="CamelSshUsername">
<constant>scott</constant>
</setHeader>
<setHeader name="CamelSshPassword">
<constant>{{scott.password}}</constant>
</setHeader>
<to uri="ssh://db.example.com?allowUsernameAndPasswordFromHeaders=true"/>
</route> - route:
from:
uri: direct:status
steps:
- setHeader:
name: CamelSshUsername
expression:
constant:
expression: scott
- setHeader:
name: CamelSshPassword
expression:
constant:
expression: "{{scott.password}}"
- to:
uri: ssh://db.example.com
parameters:
allowUsernameAndPasswordFromHeaders: true Enable allowUsernameAndPasswordFromHeaders only when the route sets these headers itself, and remove them from messages that come from elsewhere, for example with removeHeaders("CamelSsh*") after an HTTP or JMS consumer.
Server host key verification
The SSH Component verifies the host key of the SSH server only when the knownHostsResource option is set. It refers to a file in the OpenSSH known_hosts format, such as the output of ssh-keyscan. Set failOnUnknownHost to true as well, so that a server without any entry in that file is rejected. When it is false (the default), such a server is accepted and a warning is logged.
The entries are matched as OpenSSH matches them:
-
Each host pattern of an entry is compared, ignoring case, with the host name or address the client connects to: the host configured on the endpoint, or the
HostNamethat~/.ssh/configgives for it. It is writtenhostfor port 22 and[host]:portfor another port.and?are wildcards, a pattern starting with!excludes the hosts it matches, and hashed entries are supported. Sodb.example.comonly applies to port 22,[db.example.com]:2222to port 2222, andto every host and port. The host is never resolved: an endpoint configured with an address only uses the entries for that address, and an IPv6 address such as::1is not expanded. -
The server is accepted when an entry of its host lists the key it presents. A host can be listed with several keys, one per line.
-
The server is rejected when the key it presents is listed in a matching
@revokedentry, or when its host has entries without a marker but none of them lists that key, whatever the value offailOnUnknownHost. That option only decides for a host without such an entry:@revokedand@cert-authorityentries do not list a host. -
@cert-authorityentries (OpenSSH host certificates) are not supported and are ignored. -
A
known_hostsresource that cannot be read, or that has a line that cannot be read (for example an unknown@marker, a missing key, or a key that is not valid base64), makes every connection fail.
The following route verifies the host key of a server listening on port 2222 against a known_hosts file that contains the line [db.example.com]:2222 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5….
-
Java
-
XML
-
YAML
from("direct:status")
.to("ssh://scott@db.example.com:2222?certResource=classpath:test_rsa&knownHostsResource=file:/etc/camel/known_hosts&failOnUnknownHost=true"); <route>
<from uri="direct:status"/>
<to uri="ssh://scott@db.example.com:2222?certResource=classpath:test_rsa&knownHostsResource=file:/etc/camel/known_hosts&failOnUnknownHost=true"/>
</route> - route:
from:
uri: direct:status
steps:
- to:
uri: ssh://scott@db.example.com:2222
parameters:
certResource: "classpath:test_rsa"
knownHostsResource: "file:/etc/camel/known_hosts"
failOnUnknownHost: true Post-Quantum Key Exchange
sshd-core offers the hybrid post-quantum key exchanges mlkem768x25519-sha256, mlkem768nistp256-sha256 and mlkem1024nistp384-sha384, as well as sntrup761x25519-sha512, and proposes them to a server that supports them without any configuration. They are implemented through Bouncy Castle, which camel-ssh already brings on the classpath. sntrup761x25519-sha512 is proposed first, under its name and under its sntrup761x25519-sha512@openssh.com alias, so a server that offers both, such as OpenSSH 9.9 or later, negotiates it rather than ML-KEM; an OpenSSH server before 9.9 offers only the alias. To prefer ML-KEM, put mlkem768x25519-sha256 first in kex.
The kex option replaces the proposal rather than adding to it, so 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 to a classical one, pin kex to the hybrid groups alone:
ssh://host:22?username=admin&kex=mlkem768x25519-sha256,sntrup761x25519-sha512,sntrup761x25519-sha512@openssh.com The equivalent option on the sftp component is keyExchangeProtocols.
Certificate Dependencies
You will need to add some additional runtime dependencies if you use certificate-based authentication. You may need to use later versions depending on what version of Camel you are using.
The component uses sshd-core library which is based on either bouncycastle or eddsa security providers. camel-ssh is picking explicitly bouncycastle as security provider.
<dependency>
<groupId>org.apache.sshd</groupId>
<artifactId>sshd-core</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpg-jdk18on</artifactId>
<version>1.71</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk18on</artifactId>
<version>1.71</version>
</dependency>