This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-kamelets.git
The following commit(s) were added to refs/heads/main by this push:
new 431a95f58 chore: the FTPS Kamelets can set the newest TLS version
(securityProtocol) (#3319)
431a95f58 is described below
commit 431a95f58a4d06b62167abba949729d0e7c49c64
Author: Claus Ibsen <[email protected]>
AuthorDate: Sat Nov 21 13:58:06 2026 +0100
chore: the FTPS Kamelets can set the newest TLS version (securityProtocol)
(#3319)
ftps-source and ftps-sink get the securityProtocol option of the ftps
component: the newest TLS version the connection offers. With TLSv1.2
the connection never uses TLS 1.3, for a server whose TLS 1.3
connections fail or hang. When it is not set, TLSv1.3, as before.
The new ftps-protocol-route test runs an FTPS server that speaks only
TLS 1.3: the source without the option reads the file, the sink with
TLSv1.3 uploads it, and the sink and the source with TLSv1.2 are refused
with protocol_version.
Claude-Session: https://claude.ai/code/session_016Y4dDmBDsSWV117kccuNf9
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
kamelets/ftps-sink.kamelet.yaml | 8 +-
kamelets/ftps-source.kamelet.yaml | 8 +-
.../main/resources/META-INF/kamelets-index.json | 4 +-
.../main/resources/kamelets/ftps-sink.kamelet.yaml | 8 +-
.../resources/kamelets/ftps-source.kamelet.yaml | 8 +-
.../ftp/ftps-protocol-route.citrus.it.yaml | 83 ++++++++++++++++++
.../test/resources/ftp/ftps-protocol-route.yaml | 98 ++++++++++++++++++++++
.../test/resources/ftp/ftpsServerProtocols.groovy | 92 ++++++++++++++++++++
8 files changed, 303 insertions(+), 6 deletions(-)
diff --git a/kamelets/ftps-sink.kamelet.yaml b/kamelets/ftps-sink.kamelet.yaml
index d98253452..ae0516e4c 100644
--- a/kamelets/ftps-sink.kamelet.yaml
+++ b/kamelets/ftps-sink.kamelet.yaml
@@ -40,7 +40,7 @@ spec:
Output: the message is unchanged. The `CamelFileNameProduced` header is
set to the path of the file on the server.
- Good to know: a file with the same name is replaced, unless `fileExist`
says otherwise. A file is uploaded under its real name from the start, so a
reader that polls the directory can pick it up half-written. To prevent that,
set `tempPrefix` to upload it under a temporary name and rename it once it is
complete, or `doneFileName` to write an empty done file next to it once it is
complete. By default it uses explicit TLS: it connects to the normal FTP port,
usually 21, and then swit [...]
+ Good to know: a file with the same name is replaced, unless `fileExist`
says otherwise. A file is uploaded under its real name from the start, so a
reader that polls the directory can pick it up half-written. To prevent that,
set `tempPrefix` to upload it under a temporary name and rename it once it is
complete, or `doneFileName` to write an empty done file next to it once it is
complete. By default it uses explicit TLS: it connects to the normal FTP port,
usually 21, and then swit [...]
required:
- connectionHost
- connectionPort
@@ -112,6 +112,11 @@ spec:
title: Implicit TLS
description: 'If true, the connection uses implicit TLS: it is
encrypted from the start, usually on port 990. If false, it uses explicit TLS:
it connects to the normal FTP port, usually 21, and then switches to TLS. Use
the mode the server expects; the other one fails to connect. When it is not
set, false.'
type: boolean
+ securityProtocol:
+ title: TLS Version
+ description: The newest TLS version that the connection offers, such
as `TLSv1.3` or `TLSv1.2`. With `TLSv1.3`, a server that speaks only TLS 1.2 is
reached too. With `TLSv1.2`, the connection never uses TLS 1.3. Set it for a
server whose TLS 1.3 connections fail or hang. A server that speaks only TLS
1.3 then refuses the connection, with `protocol_version` in the error. When it
is not set, `TLSv1.3`.
+ type: string
+ example: TLSv1.2
trustStoreFile:
title: Trust Store File
description: The path of a trust store file that holds the certificate
of the FTPS server, or of the certificate authority (CA) that signed it, such
as a PKCS12 or JKS file made with `keytool`. Set it for a server with a
self-signed certificate, or one signed by a private CA. Set
`trustStorePassword` with it, or every message fails. Only the certificates in
this file are trusted for the server, not those that Java trusts, and only for
this connection, so the rest of the integrati [...]
@@ -209,4 +214,5 @@ spec:
implicit: "{{?implicit}}"
passiveMode: "{{passiveMode}}"
password: "RAW({{password}})"
+ securityProtocol: "{{?securityProtocol}}"
tempPrefix: "RAW({{?tempPrefix}})"
diff --git a/kamelets/ftps-source.kamelet.yaml
b/kamelets/ftps-source.kamelet.yaml
index acf152a50..424cdfb1c 100644
--- a/kamelets/ftps-source.kamelet.yaml
+++ b/kamelets/ftps-source.kamelet.yaml
@@ -38,7 +38,7 @@ spec:
Output: the body is the content of the file, as a stream. `Content-Type`
is `application/octet-stream`. The `file` and `ce-file` headers hold the name
of the file, with its path below `directoryName` when `recursive` is true, such
as `2026/orders.csv`. `CamelFileName` holds the same name, and
`CamelFileLength` the size of the file in bytes.
- Good to know: files are not deleted or moved after they are read, unless
`delete` is true or `move` is set. A file is read only once while the
integration runs (`idempotent`), but the files left on the server are all read
again after a restart; to read each file only once, also across restarts, set
`move` to a directory such as `.done`, set `delete` to true, or keep the list
of the files read in a file with `idempotentRepository`. To read only some of
the files, set `include`, `exc [...]
+ Good to know: files are not deleted or moved after they are read, unless
`delete` is true or `move` is set. A file is read only once while the
integration runs (`idempotent`), but the files left on the server are all read
again after a restart; to read each file only once, also across restarts, set
`move` to a directory such as `.done`, set `delete` to true, or keep the list
of the files read in a file with `idempotentRepository`. To read only some of
the files, set `include`, `exc [...]
required:
- connectionHost
- connectionPort
@@ -193,6 +193,11 @@ spec:
title: Implicit TLS
description: 'If true, the connection uses implicit TLS: it is
encrypted from the start, usually on port 990. If false, it uses explicit TLS:
it connects to the normal FTP port, usually 21, and then switches to TLS. Use
the mode the server expects; the other one fails to connect. When it is not
set, false.'
type: boolean
+ securityProtocol:
+ title: TLS Version
+ description: The newest TLS version that the connection offers, such
as `TLSv1.3` or `TLSv1.2`. With `TLSv1.3`, a server that speaks only TLS 1.2 is
reached too. With `TLSv1.2`, the connection never uses TLS 1.3. Set it for a
server whose TLS 1.3 connections fail or hang. A server that speaks only TLS
1.3 then refuses the connection, with `protocol_version` in the error. When it
is not set, `TLSv1.3`.
+ type: string
+ example: TLSv1.2
trustStoreFile:
title: Trust Store File
description: The path of a trust store file that holds the certificate
of the FTPS server, or of the certificate authority (CA) that signed it, such
as a PKCS12 or JKS file made with `keytool`. Set it for a server with a
self-signed certificate, or one signed by a private CA. Set
`trustStorePassword` with it, or the integration fails to start. Only the
certificates in this file are trusted for the server, not those that Java
trusts, and only for this connection, so the rest of th [...]
@@ -268,6 +273,7 @@ spec:
readLock: "{{?readLock}}"
readLockMinAge: "{{?readLockMinAge}}"
recursive: "{{recursive}}"
+ securityProtocol: "{{?securityProtocol}}"
sortBy: "RAW({{?sortBy}})"
soTimeout: "{{?socketTimeout}}"
stepwise: "{{?stepwise}}"
diff --git
a/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
b/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
index 0ca257d8d..36eabb9fd 100644
--- a/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
+++ b/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
@@ -805,7 +805,7 @@
"supportLevel" : "Stable",
"title" : "FTPS Sink",
"summary" : "Uploads each message as a file to a directory on an FTPS
server, which is FTP with TLS encryption.",
- "description" : "Uploads each message as a file to a directory on an FTPS
server, which is FTP with TLS encryption.\n\nUse it to deliver exports, reports
or data files to a partner or a legacy system that receives files over FTPS.
For a server without TLS use `ftp-sink`, and for a server you reach with SSH
use `sftp-sink`.\n\nInput: the body is the content of the file, as text, bytes
or a stream. The name of the file comes from the `file` header, or from
`ce-file` when `file` is not [...]
+ "description" : "Uploads each message as a file to a directory on an FTPS
server, which is FTP with TLS encryption.\n\nUse it to deliver exports, reports
or data files to a partner or a legacy system that receives files over FTPS.
For a server without TLS use `ftp-sink`, and for a server you reach with SSH
use `sftp-sink`.\n\nInput: the body is the content of the file, as text, bytes
or a stream. The name of the file comes from the `file` header, or from
`ce-file` when `file` is not [...]
"group" : "FTP",
"namespace" : "File",
"provider" : "Apache Software Foundation"
@@ -815,7 +815,7 @@
"supportLevel" : "Stable",
"title" : "FTPS Source",
"summary" : "Reads the files in a directory on an FTPS server (FTP with
TLS encryption), one message per file, and by default leaves them on the
server.",
- "description" : "Reads the files in a directory on an FTPS server (FTP
with TLS encryption), one message per file, and by default leaves them on the
server.\n\nUse it to collect the files that a partner or a legacy system drops
on an FTPS server, such as orders, invoices or exports. For a server without
TLS use `ftp-source`, and for a server you reach with SSH use
`sftp-source`.\n\nOutput: the body is the content of the file, as a stream.
`Content-Type` is `application/octet-stream`. [...]
+ "description" : "Reads the files in a directory on an FTPS server (FTP
with TLS encryption), one message per file, and by default leaves them on the
server.\n\nUse it to collect the files that a partner or a legacy system drops
on an FTPS server, such as orders, invoices or exports. For a server without
TLS use `ftp-source`, and for a server you reach with SSH use
`sftp-source`.\n\nOutput: the body is the content of the file, as a stream.
`Content-Type` is `application/octet-stream`. [...]
"group" : "FTP",
"namespace" : "File",
"provider" : "Apache Software Foundation"
diff --git
a/library/camel-kamelets/src/main/resources/kamelets/ftps-sink.kamelet.yaml
b/library/camel-kamelets/src/main/resources/kamelets/ftps-sink.kamelet.yaml
index d98253452..ae0516e4c 100644
--- a/library/camel-kamelets/src/main/resources/kamelets/ftps-sink.kamelet.yaml
+++ b/library/camel-kamelets/src/main/resources/kamelets/ftps-sink.kamelet.yaml
@@ -40,7 +40,7 @@ spec:
Output: the message is unchanged. The `CamelFileNameProduced` header is
set to the path of the file on the server.
- Good to know: a file with the same name is replaced, unless `fileExist`
says otherwise. A file is uploaded under its real name from the start, so a
reader that polls the directory can pick it up half-written. To prevent that,
set `tempPrefix` to upload it under a temporary name and rename it once it is
complete, or `doneFileName` to write an empty done file next to it once it is
complete. By default it uses explicit TLS: it connects to the normal FTP port,
usually 21, and then swit [...]
+ Good to know: a file with the same name is replaced, unless `fileExist`
says otherwise. A file is uploaded under its real name from the start, so a
reader that polls the directory can pick it up half-written. To prevent that,
set `tempPrefix` to upload it under a temporary name and rename it once it is
complete, or `doneFileName` to write an empty done file next to it once it is
complete. By default it uses explicit TLS: it connects to the normal FTP port,
usually 21, and then swit [...]
required:
- connectionHost
- connectionPort
@@ -112,6 +112,11 @@ spec:
title: Implicit TLS
description: 'If true, the connection uses implicit TLS: it is
encrypted from the start, usually on port 990. If false, it uses explicit TLS:
it connects to the normal FTP port, usually 21, and then switches to TLS. Use
the mode the server expects; the other one fails to connect. When it is not
set, false.'
type: boolean
+ securityProtocol:
+ title: TLS Version
+ description: The newest TLS version that the connection offers, such
as `TLSv1.3` or `TLSv1.2`. With `TLSv1.3`, a server that speaks only TLS 1.2 is
reached too. With `TLSv1.2`, the connection never uses TLS 1.3. Set it for a
server whose TLS 1.3 connections fail or hang. A server that speaks only TLS
1.3 then refuses the connection, with `protocol_version` in the error. When it
is not set, `TLSv1.3`.
+ type: string
+ example: TLSv1.2
trustStoreFile:
title: Trust Store File
description: The path of a trust store file that holds the certificate
of the FTPS server, or of the certificate authority (CA) that signed it, such
as a PKCS12 or JKS file made with `keytool`. Set it for a server with a
self-signed certificate, or one signed by a private CA. Set
`trustStorePassword` with it, or every message fails. Only the certificates in
this file are trusted for the server, not those that Java trusts, and only for
this connection, so the rest of the integrati [...]
@@ -209,4 +214,5 @@ spec:
implicit: "{{?implicit}}"
passiveMode: "{{passiveMode}}"
password: "RAW({{password}})"
+ securityProtocol: "{{?securityProtocol}}"
tempPrefix: "RAW({{?tempPrefix}})"
diff --git
a/library/camel-kamelets/src/main/resources/kamelets/ftps-source.kamelet.yaml
b/library/camel-kamelets/src/main/resources/kamelets/ftps-source.kamelet.yaml
index acf152a50..424cdfb1c 100644
---
a/library/camel-kamelets/src/main/resources/kamelets/ftps-source.kamelet.yaml
+++
b/library/camel-kamelets/src/main/resources/kamelets/ftps-source.kamelet.yaml
@@ -38,7 +38,7 @@ spec:
Output: the body is the content of the file, as a stream. `Content-Type`
is `application/octet-stream`. The `file` and `ce-file` headers hold the name
of the file, with its path below `directoryName` when `recursive` is true, such
as `2026/orders.csv`. `CamelFileName` holds the same name, and
`CamelFileLength` the size of the file in bytes.
- Good to know: files are not deleted or moved after they are read, unless
`delete` is true or `move` is set. A file is read only once while the
integration runs (`idempotent`), but the files left on the server are all read
again after a restart; to read each file only once, also across restarts, set
`move` to a directory such as `.done`, set `delete` to true, or keep the list
of the files read in a file with `idempotentRepository`. To read only some of
the files, set `include`, `exc [...]
+ Good to know: files are not deleted or moved after they are read, unless
`delete` is true or `move` is set. A file is read only once while the
integration runs (`idempotent`), but the files left on the server are all read
again after a restart; to read each file only once, also across restarts, set
`move` to a directory such as `.done`, set `delete` to true, or keep the list
of the files read in a file with `idempotentRepository`. To read only some of
the files, set `include`, `exc [...]
required:
- connectionHost
- connectionPort
@@ -193,6 +193,11 @@ spec:
title: Implicit TLS
description: 'If true, the connection uses implicit TLS: it is
encrypted from the start, usually on port 990. If false, it uses explicit TLS:
it connects to the normal FTP port, usually 21, and then switches to TLS. Use
the mode the server expects; the other one fails to connect. When it is not
set, false.'
type: boolean
+ securityProtocol:
+ title: TLS Version
+ description: The newest TLS version that the connection offers, such
as `TLSv1.3` or `TLSv1.2`. With `TLSv1.3`, a server that speaks only TLS 1.2 is
reached too. With `TLSv1.2`, the connection never uses TLS 1.3. Set it for a
server whose TLS 1.3 connections fail or hang. A server that speaks only TLS
1.3 then refuses the connection, with `protocol_version` in the error. When it
is not set, `TLSv1.3`.
+ type: string
+ example: TLSv1.2
trustStoreFile:
title: Trust Store File
description: The path of a trust store file that holds the certificate
of the FTPS server, or of the certificate authority (CA) that signed it, such
as a PKCS12 or JKS file made with `keytool`. Set it for a server with a
self-signed certificate, or one signed by a private CA. Set
`trustStorePassword` with it, or the integration fails to start. Only the
certificates in this file are trusted for the server, not those that Java
trusts, and only for this connection, so the rest of th [...]
@@ -268,6 +273,7 @@ spec:
readLock: "{{?readLock}}"
readLockMinAge: "{{?readLockMinAge}}"
recursive: "{{recursive}}"
+ securityProtocol: "{{?securityProtocol}}"
sortBy: "RAW({{?sortBy}})"
soTimeout: "{{?socketTimeout}}"
stepwise: "{{?stepwise}}"
diff --git
a/tests/camel-kamelets-itest/src/test/resources/ftp/ftps-protocol-route.citrus.it.yaml
b/tests/camel-kamelets-itest/src/test/resources/ftp/ftps-protocol-route.citrus.it.yaml
new file mode 100644
index 000000000..8b196f249
--- /dev/null
+++
b/tests/camel-kamelets-itest/src/test/resources/ftp/ftps-protocol-route.citrus.it.yaml
@@ -0,0 +1,83 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ---------------------------------------------------------------------------
+
+name: ftps-protocol-route-test
+description: 'securityProtocol of ftps-source and ftps-sink is the newest TLS
version the connection offers: against a server that speaks only TLS 1.3, the
default and TLSv1.3 connect, TLSv1.2 does not'
+variables:
+ - name: "ftp.tls.protocols"
+ value: "TLSv1.3"
+actions:
+ # Start an FTPS server that speaks only TLS 1.3, with a file for the source
to read
+ - groovy:
+ script:
+ file: "ftp/ftpsServerProtocols.groovy"
+ - groovy:
+ script:
+ file: "ftp/putFile.groovy"
+
+ - camel:
+ cli:
+ run:
+ waitForRunningState: false
+ integration:
+ file: "ftp/ftps-protocol-route.yaml"
+ systemProperties:
+ properties:
+ - name: "http.sink.url"
+ value: "http://localhost:${file.http.server.port}"
+ - name: "ftp.port"
+ value: "${ftp.server.port}"
+ - name: "ftp.truststore"
+ value: "${ftp.truststore}"
+
+ # The source without securityProtocol read the file, the sink with TLSv1.3
uploaded it, and the sink
+ # with TLSv1.2 failed the message
+ - http:
+ server: "fileHttpServer"
+ receiveRequest:
+ POST:
+ path: "/result"
+ type: "plaintext"
+ headers:
+ - name: "X-File-Name-Produced"
+ value: 'upload/order 1.csv'
+ - name: "X-Error"
+ value: '@contains(''Received fatal alert: protocol_version'')@'
+ body:
+ data: |
+ id,item
+ 1,book
+ - http:
+ server: "fileHttpServer"
+ sendResponse:
+ response:
+ status: 200
+ reasonPhrase: "OK"
+ version: "HTTP/1.1"
+
+ # The source with TLSv1.2 cannot connect: the server refuses the TLS
handshake, and the source logs it
+ - camel:
+ cli:
+ verify:
+ integration: "ftps-protocol-route"
+ logMessage: "protocol_version"
+ maxAttempts: 30
+
+finally:
+ - groovy:
+ script:
+ file: "ftp/ftpServerStop.groovy"
diff --git
a/tests/camel-kamelets-itest/src/test/resources/ftp/ftps-protocol-route.yaml
b/tests/camel-kamelets-itest/src/test/resources/ftp/ftps-protocol-route.yaml
new file mode 100644
index 000000000..8496e4e11
--- /dev/null
+++ b/tests/camel-kamelets-itest/src/test/resources/ftp/ftps-protocol-route.yaml
@@ -0,0 +1,98 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ---------------------------------------------------------------------------
+
+# The FTPS server of this test speaks only TLS 1.3.
+
+# Without securityProtocol, ftps-source offers TLS 1.3, and reads the file.
Then ftps-sink with
+# securityProtocol TLSv1.3 uploads it, and ftps-sink with TLSv1.2 fails the
message.
+- route:
+ from:
+ uri: "kamelet:ftps-source"
+ parameters:
+ connectionHost: 'localhost'
+ connectionPort: '{{ftp.port}}'
+ username: 'citrus'
+ password: 's3cr&t+pw'
+ directoryName: 'orders'
+ trustStoreFile: '{{ftp.truststore}}'
+ trustStorePassword: 'changeit'
+ steps:
+ - log:
+ message: "ftps-source read ${header.CamelFileName}"
+ - convertBodyTo:
+ type: "java.lang.String"
+ - removeHeader:
+ name: Content-Type
+ - to:
+ uri: "kamelet:ftps-sink"
+ parameters:
+ connectionHost: 'localhost'
+ connectionPort: '{{ftp.port}}'
+ username: 'citrus'
+ password: 's3cr&t+pw'
+ directoryName: 'upload'
+ trustStoreFile: '{{ftp.truststore}}'
+ trustStorePassword: 'changeit'
+ passiveMode: true
+ securityProtocol: 'TLSv1.3'
+ - setHeader:
+ name: X-File-Name-Produced
+ simple: "${header.CamelFileNameProduced}"
+ - doTry:
+ steps:
+ - to:
+ uri: "kamelet:ftps-sink"
+ parameters:
+ connectionHost: 'localhost'
+ connectionPort: '{{ftp.port}}'
+ username: 'citrus'
+ password: 's3cr&t+pw'
+ directoryName: 'upload12'
+ trustStoreFile: '{{ftp.truststore}}'
+ trustStorePassword: 'changeit'
+ passiveMode: true
+ securityProtocol: 'TLSv1.2'
+ - setHeader:
+ name: X-Error
+ constant: 'none'
+ doCatch:
+ - exception:
+ - "java.lang.Exception"
+ steps:
+ - setHeader:
+ name: X-Error
+ simple: "${exception.class.name}: ${exception.message}"
+ - to:
+ uri: "{{http.sink.url}}/result"
+
+# With securityProtocol TLSv1.2, ftps-source never offers TLS 1.3, so it
cannot connect
+- route:
+ from:
+ uri: "kamelet:ftps-source"
+ parameters:
+ connectionHost: 'localhost'
+ connectionPort: '{{ftp.port}}'
+ username: 'citrus'
+ password: 's3cr&t+pw'
+ directoryName: 'orders'
+ trustStoreFile: '{{ftp.truststore}}'
+ trustStorePassword: 'changeit'
+ securityProtocol: 'TLSv1.2'
+ delay: 1000
+ steps:
+ - log:
+ message: "ftps-source with TLSv1.2 read ${header.CamelFileName}"
diff --git
a/tests/camel-kamelets-itest/src/test/resources/ftp/ftpsServerProtocols.groovy
b/tests/camel-kamelets-itest/src/test/resources/ftp/ftpsServerProtocols.groovy
new file mode 100644
index 000000000..ac124c467
--- /dev/null
+++
b/tests/camel-kamelets-itest/src/test/resources/ftp/ftpsServerProtocols.groovy
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Starts an Apache FtpServer that speaks FTPS (explicit TLS, on the control
and the data connections) with
+// only the TLS versions in the variable ftp.tls.protocols, such as TLSv1.3,
on port ftp.server.port of this
+// machine. Otherwise it is the server of ftpServer.groovy: the user citrus, a
new temporary home directory
+// (variable ftp.home), a certificate for localhost made for the test, and
ftp.truststore, a trust store with
+// only this certificate. Apache FtpServer speaks only TLSv1.2 unless it is
told otherwise.
+
+import java.nio.file.Files
+import java.security.KeyStore
+
+import org.apache.ftpserver.DataConnectionConfigurationFactory
+import org.apache.ftpserver.FtpServerFactory
+import org.apache.ftpserver.listener.ListenerFactory
+import org.apache.ftpserver.ssl.SslConfigurationFactory
+import org.apache.ftpserver.usermanager.impl.BaseUser
+import org.apache.ftpserver.usermanager.impl.WritePermission
+
+def home = Files.createTempDirectory('kamelets-ftp-').toRealPath()
+context.setVariable('ftp.home', home.toString())
+
+def listener = new ListenerFactory()
+listener.setServerAddress('localhost')
+listener.setPort(Integer.parseInt(context.getVariable('ftp.server.port')))
+
+if (context.getVariable('ftp.tls.protocols')) {
+ def keyStore = home.resolveSibling(home.getFileName().toString() +
'-keystore.p12')
+ def trustStore = home.resolveSibling(home.getFileName().toString() +
'-truststore.p12')
+ def keytool = new File(System.getProperty('java.home'),
'bin/keytool').getAbsolutePath()
+ def process = [keytool, '-genkeypair', '-alias', 'ftps', '-keyalg', 'RSA',
'-keysize', '2048',
+ '-dname', 'CN=localhost', '-ext',
'SAN=dns:localhost,ip:127.0.0.1', '-validity', '2',
+ '-storetype', 'PKCS12', '-keystore', keyStore.toString(),
+ '-storepass', 'changeit', '-keypass', 'changeit'].execute()
+ process.waitForProcessOutput(System.out, System.err)
+ if (process.exitValue() != 0) {
+ throw new IllegalStateException('keytool failed with exit code ' +
process.exitValue())
+ }
+
+ // the trust store holds only the certificate of the server: the Kamelet
uses it for its FTPS connection
+ // alone (trustStoreFile), so the rest of the integration, such as the
downloads of camel run, keeps the
+ // trust store of the JVM; with the JVM-wide javax.net.ssl.trustStore
instead, those downloads would fail
+ // with "PKIX path building failed"
+ def keys = KeyStore.getInstance('PKCS12')
+ keyStore.toFile().withInputStream { keys.load(it,
'changeit'.toCharArray()) }
+ def trusted = KeyStore.getInstance('PKCS12')
+ trusted.load(null, null)
+ trusted.setCertificateEntry('ftps', keys.getCertificate('ftps'))
+ trustStore.toFile().withOutputStream { trusted.store(it,
'changeit'.toCharArray()) }
+ context.setVariable('ftp.truststore', trustStore.toString())
+
+ def ssl = new SslConfigurationFactory()
+ ssl.setKeystoreFile(keyStore.toFile())
+ ssl.setKeystoreType('PKCS12')
+ ssl.setKeystorePassword('changeit')
+ ssl.setKeyPassword('changeit')
+ ssl.setSslProtocol(context.getVariable('ftp.tls.protocols').split(',') as
String[])
+ def sslConfiguration = ssl.createSslConfiguration()
+ listener.setSslConfiguration(sslConfiguration)
+ listener.setImplicitSsl(false)
+ def dataConnection = new DataConnectionConfigurationFactory()
+ dataConnection.setSslConfiguration(sslConfiguration)
+
listener.setDataConnectionConfiguration(dataConnection.createDataConnectionConfiguration())
+}
+
+def user = new BaseUser()
+user.setName('citrus')
+user.setPassword('s3cr&t+pw')
+user.setHomeDirectory(home.toString())
+user.setAuthorities([new WritePermission()])
+
+def serverFactory = new FtpServerFactory()
+serverFactory.addListener('default', listener.createListener())
+serverFactory.getUserManager().save(user)
+
+def server = serverFactory.createServer()
+server.start()
+context.getReferenceResolver().bind('ftpServer', server)