Andrea Cosentino created CAMEL-27932:
----------------------------------------
Summary: camel-smb - verify SMB 3 encryption is active when
encryptData=true
Key: CAMEL-27932
URL: https://issues.apache.org/jira/browse/CAMEL-27932
Project: Camel
Issue Type: Improvement
Components: camel-smb
Reporter: Andrea Cosentino
Assignee: Andrea Cosentino
Fix For: 4.25.0
h3. Background
The {{encryptData}} option of the camel-smb component (introduced in 4.24.0)
requests SMB 3 encryption for the session. Camel passes it to the underlying
smbj library as {{SmbConfig.withEncryptData(true)}}. In smbj this flag only
advertises the client's encryption capability during the negotiation; it does
not by itself guarantee that the established session is encrypted.
h3. Current behaviour
With {{encryptData=true}}, when the server negotiates SMB 3 with encryption
support for a non-guest session, smbj derives an encryption key and the traffic
(including file content) is encrypted. When the server negotiates SMB 2, or an
SMB 3 dialect without encryption support, or the login is a guest login, smbj
derives no encryption key and sends the messages unencrypted, without raising
any error. The component documentation already states this in the "Encryption
and timeouts" section ("the messages are sent unencrypted, without an error").
Camel never checks, after the session is established, whether encryption is
actually in effect, so a route configured with {{encryptData=true}} can
transfer file content over an unencrypted session even though encryption was
requested.
A share that _requires_ encryption (for Samba, {{smb encrypt = required}})
already refuses an unencrypted session with {{STATUS_ACCESS_DENIED}}, so only
shares that allow but do not require encryption are affected.
h3. Proposed behaviour
After the session is established, when {{encryptData=true}} was requested but
the session was not actually encrypted, Camel should fail the connection with a
clear message instead of continuing over an unencrypted session (at a minimum,
log a WARN). The reliable signal that encryption is in effect is a non-null
session encryption key, which mirrors smbj's own internal check.
h3. Classes involved
* {{org.apache.camel.component.smb.SmbConfiguration}} - holds the
{{encryptData}} option and builds the smbj {{SmbConfig}} in
{{createSmbConfig()}} via {{withEncryptData(encryptData)}}. Encryption can also
be requested through a user-supplied {{smbConfig}} bean built with
{{withEncryptData(true)}}.
* {{org.apache.camel.component.smb.SmbOperations}} - {{connectIfNecessary()}}
opens the connection, authenticates and connects the share, but performs no
check that encryption was negotiated.
h3. Code-level change
* In {{SmbOperations.connectIfNecessary()}}, after {{session =
connection.authenticate(ac)}} and before the session is marked as logged in,
determine whether encryption was requested ({{configuration.isEncryptData()}},
or a {{smbConfig}} bean built with encryption) and, if so, check that the
session negotiated an encryption key
({{session.getSessionContext().getEncryptionKey() != null}}). When encryption
was requested but not negotiated, fail with a
{{GenericFileOperationFailedException}} (or at least log a WARN).
* Update {{components/camel-smb/src/main/docs/smb-component.adoc}} ("Encryption
and timeouts") to describe the new fail/warn behaviour instead of "sent
unencrypted, without an error", and regenerate the mirrored catalog doc under
{{catalog/camel-catalog}}.
h3. Tests
* A unit test (beside {{SmbConfigurationSmbConfigTest}}) that, with
{{encryptData=true}} and a session whose {{SessionContext.getEncryptionKey()}}
returns null (mocked smbj {{Session}} / {{SessionContext}}), asserts the
connect fails.
* An integration test extending {{SmbServerTestSupport}}: a share that allows
but does not require encryption, reached with a guest login and
{{encryptData=true}}, must now fail instead of transferring over an unencrypted
session (the test infra already supports guest logins, cf. {{SmbNoPasswordIT}}).
* The existing {{SmbEncryptDataIT}} (the required-encryption share case) must
stay green.
New tests follow the module's existing JUnit 5 assertion style (the camel-smb
tests use JUnit assertions, not AssertJ) and are package-private, per the
project's test conventions.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)