Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,10 @@ The SMB 2.x and CIFS protocol implementation of Overthere defines a number of ad
<th align="left" valign="top"><a name="smb_smbRequireSigning"></a>smbRequireSigning</th>
<td>Whether to require the server to sign the responses. The default value is <code>false</code>.</td>
</tr>
<tr>
<th align="left" valign="top"><a name="smb_smbEncryptData"></a>smbEncryptData</th>
<td>Whether to encrypt the SMB transport data. Set to <code>true</code> or <code>false</code> for SMB 3.x servers. Must be <code>false</code> for SMB 2.x servers, as SMB 2.x does not support encryption and the connection will fail otherwise. The default value is <code>false</code>.</td>
</tr>
</table>

<a name="cifs_connection_options"></a>
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/xebialabs/overthere/smb/SmbConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,15 @@ protected SmbConnection(String protocol, ConnectionOptions options, AddressPortM
if (!realSmbHost.equals(hostname)) {
transportLayerFactory = new TunnelTransportFactory<>(transportLayerFactory, hostname, smbPort);
}
boolean encryptData = options.getBoolean(SMB_ENCRYPT_DATA, SMB_ENCRYPT_DATA_DEFAULT);

username = options.get(USERNAME);
password = options.get(PASSWORD);
SmbConfig config = SmbConfig.builder()
.withSigningRequired(requireSigning)
.withTransportLayerFactory(transportLayerFactory)
.withSecurityProvider(new BCSecurityProvider())
.withEncryptData(encryptData)
.build();
client = new SMBClient(config);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ public class SmbConnectionBuilder extends BaseCifsConnectionBuilder implements O
*/
public static final String SMB_REQUIRE_SIGNING = "smbRequireSigning";

/**
* Whether SMB Connections require the server to encrypt the data.
*/
public static final boolean SMB_ENCRYPT_DATA_DEFAULT = false;
public static final String SMB_ENCRYPT_DATA = "smbEncryptData";

private final SmbConnection connection;

public SmbConnectionBuilder(String type, ConnectionOptions options, AddressPortMapper mapper) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,27 @@
new SmbProcessConnection(SMB_PROTOCOL, options, INSTANCE);
}

@Test
@SuppressWarnings("resource")
public void shouldSupportEncryptDataEnabled() {
options.set(USERNAME, "user");
options.set(SMB_ENCRYPT_DATA, true);
new SmbProcessConnection(SMB_PROTOCOL, options, INSTANCE);
}

@Test
@SuppressWarnings("resource")
public void shouldSupportEncryptDataDisabled() {
options.set(USERNAME, "user");
options.set(SMB_ENCRYPT_DATA, false);
new SmbProcessConnection(SMB_PROTOCOL, options, INSTANCE);
}

@Test
@SuppressWarnings("resource")
public void shouldDefaultEncryptDataToFalse() {

Check warning on line 95 in src/test/java/com/xebialabs/overthere/smb/winrm/SmbWinRmConnectionTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Update this method so that its implementation is not identical to "shouldSupportDomainlessAccount" on line 72.

See more on https://sonarcloud.io/project/issues?id=xebialabs_overthere&issues=AZzgaKH6X4y0O1PSadVd&open=AZzgaKH6X4y0O1PSadVd&pullRequest=338
options.set(USERNAME, "user");
new SmbProcessConnection(SMB_PROTOCOL, options, INSTANCE);
}

}