Skip to content

Commit fd49a77

Browse files
author
Lee Fine
committed
1 parent 2212663 commit fd49a77

File tree

7 files changed

+90
-13
lines changed

7 files changed

+90
-13
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
v2.10.0
22
- Added support for Eliptical Curve (EC) private keys for RFPEM.
33
- For Linux hosted certificate stores, added ability to inherit file permissions and ownership when creating new stores by modifying default behavior when config.json and certificate store permissions/ownership settings are left empty.
4-
- Added new custom field to store type definitions - IncludePortInSPN - which will set this option when creating remote Powershell connections.
4+
- Added new optional custom field to store type definitions - IncludePortInSPN - which will set this option when creating remote Powershell connections.
5+
- Added new optional custom field to store type definitions - FileTransferProtocol - which will act as a store level override to the config.json setting.
56
- Fixed documentation error in Discovery section
67
- Added RemoveRootCertificate custom field to integration-manifest.json. This option was previously added in v2.8.0 but never added to the integration-manifest.json.
78

RemoteFile/InventoryBase.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,13 @@ public JobResult ProcessJob(InventoryJobConfiguration config, SubmitInventoryUpd
5555
false :
5656
Convert.ToBoolean(properties.IncludePortInSPN.Value);
5757

58-
certificateStore = new RemoteCertificateStore(config.CertificateStoreDetails.ClientMachine, userName, userPassword, config.CertificateStoreDetails.StorePath, storePassword, includePortInSPN);
58+
ApplicationSettings.FileTransferProtocolEnum fileTransferProtocol = ApplicationSettings.FileTransferProtocol;
59+
if (properties.FileTransferProtocol != null && !string.IsNullOrEmpty(properties.FileTransferProtocol.Value))
60+
{
61+
Enum.TryParse(properties.FileTransferProtocol.Value, out fileTransferProtocol);
62+
}
63+
64+
certificateStore = new RemoteCertificateStore(config.CertificateStoreDetails.ClientMachine, userName, userPassword, config.CertificateStoreDetails.StorePath, storePassword, fileTransferProtocol, includePortInSPN);
5965
certificateStore.Initialize(sudoImpersonatedUser);
6066
certificateStore.LoadCertificateStore(certificateStoreSerializer, true);
6167

RemoteFile/ManagementBase.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,13 @@ public JobResult ProcessJob(ManagementJobConfiguration config)
5757
false :
5858
Convert.ToBoolean(properties.IncludePortInSPN.Value);
5959

60-
certificateStore = new RemoteCertificateStore(config.CertificateStoreDetails.ClientMachine, userName, userPassword, config.CertificateStoreDetails.StorePath, storePassword, includePortInSPN);
60+
ApplicationSettings.FileTransferProtocolEnum fileTransferProtocol = ApplicationSettings.FileTransferProtocol;
61+
if (properties.FileTransferProtocol != null && !string.IsNullOrEmpty(properties.FileTransferProtocol.Value))
62+
{
63+
Enum.TryParse(properties.FileTransferProtocol.Value, out fileTransferProtocol);
64+
}
65+
66+
certificateStore = new RemoteCertificateStore(config.CertificateStoreDetails.ClientMachine, userName, userPassword, config.CertificateStoreDetails.StorePath, storePassword, fileTransferProtocol, includePortInSPN);
6167
certificateStore.Initialize(sudoImpersonatedUser);
6268

6369
PathFile storePathFile = RemoteCertificateStore.SplitStorePathFile(config.CertificateStoreDetails.StorePath);

RemoteFile/ReenrollmentBase.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,13 @@ public JobResult ProcessJobToDo(ReenrollmentJobConfiguration config, SubmitReenr
9393
throw new RemoteFileException($"Unsupported KeyType value {keyType}. Supported types are {keyTypes}.");
9494
}
9595

96-
certificateStore = new RemoteCertificateStore(config.CertificateStoreDetails.ClientMachine, userName, userPassword, config.CertificateStoreDetails.StorePath, storePassword, includePortInSPN);
96+
ApplicationSettings.FileTransferProtocolEnum fileTransferProtocol = ApplicationSettings.FileTransferProtocol;
97+
if (properties.FileTransferProtocol != null && !string.IsNullOrEmpty(properties.FileTransferProtocol.Value))
98+
{
99+
Enum.TryParse(properties.FileTransferProtocol.Value, out fileTransferProtocol);
100+
}
101+
102+
certificateStore = new RemoteCertificateStore(config.CertificateStoreDetails.ClientMachine, userName, userPassword, config.CertificateStoreDetails.StorePath, storePassword, fileTransferProtocol, includePortInSPN);
97103
certificateStore.Initialize(sudoImpersonatedUser);
98104

99105
PathFile storePathFile = RemoteCertificateStore.SplitStorePathFile(config.CertificateStoreDetails.StorePath);

RemoteFile/RemoteCertificateStore.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ internal enum ServerTypeEnum
5454
internal ServerTypeEnum ServerType { get; set; }
5555
internal List<string> DiscoveredStores { get; set; }
5656
internal string UploadFilePath { get; set; }
57+
internal ApplicationSettings.FileTransferProtocolEnum FileTransferProtocol { get; set; }
5758
internal bool IncludePortInSPN { get; set; }
5859

5960
private Pkcs12Store CertificateStore;
@@ -62,7 +63,7 @@ internal enum ServerTypeEnum
6263

6364
internal RemoteCertificateStore() { }
6465

65-
internal RemoteCertificateStore(string server, string serverId, string serverPassword, string storeFileAndPath, string storePassword, bool includePortInSPN)
66+
internal RemoteCertificateStore(string server, string serverId, string serverPassword, string storeFileAndPath, string storePassword, ApplicationSettings.FileTransferProtocolEnum fileTransferProtocol, bool includePortInSPN)
6667
{
6768
logger = LogHandler.GetClassLogger(this.GetType());
6869
logger.MethodEntry(LogLevel.Debug);
@@ -78,6 +79,7 @@ internal RemoteCertificateStore(string server, string serverId, string serverPas
7879
StorePassword = storePassword;
7980
ServerType = StorePath.Substring(0, 1) == "/" ? ServerTypeEnum.Linux : ServerTypeEnum.Windows;
8081
UploadFilePath = !string.IsNullOrEmpty(ApplicationSettings.SeparateUploadFilePath) && ServerType == ServerTypeEnum.Linux ? ApplicationSettings.SeparateUploadFilePath : StorePath;
82+
FileTransferProtocol = fileTransferProtocol;
8183
IncludePortInSPN = includePortInSPN;
8284
logger.LogDebug($"UploadFilePath: {UploadFilePath}");
8385

@@ -454,7 +456,7 @@ internal void Initialize(string sudoImpersonatedUser)
454456
bool treatAsLocal = Server.ToLower().EndsWith(LOCAL_MACHINE_SUFFIX);
455457

456458
if (ServerType == ServerTypeEnum.Linux || RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
457-
RemoteHandler = treatAsLocal ? new LinuxLocalHandler() as IRemoteHandler : new SSHHandler(Server, ServerId, ServerPassword, ServerType == ServerTypeEnum.Linux, sudoImpersonatedUser) as IRemoteHandler;
459+
RemoteHandler = treatAsLocal ? new LinuxLocalHandler() as IRemoteHandler : new SSHHandler(Server, ServerId, ServerPassword, ServerType == ServerTypeEnum.Linux, FileTransferProtocol, sudoImpersonatedUser) as IRemoteHandler;
458460
else
459461
RemoteHandler = new WinRMHandler(Server, ServerId, ServerPassword, treatAsLocal, IncludePortInSPN);
460462

RemoteFile/RemoteHandlers/SSHHandler.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,19 @@ class SSHHandler : BaseRemoteHandler
2828
{
2929
private ConnectionInfo Connection { get; set; }
3030
private string SudoImpersonatedUser { get; set; }
31+
private ApplicationSettings.FileTransferProtocolEnum FileTransferProtocol { get; set; }
3132
private bool IsStoreServerLinux { get; set; }
3233
private string UserId { get; set; }
3334
private string Password { get; set; }
3435
private SshClient sshClient;
3536

36-
internal SSHHandler(string server, string serverLogin, string serverPassword, bool isStoreServerLinux, string sudoImpersonatedUser)
37+
internal SSHHandler(string server, string serverLogin, string serverPassword, bool isStoreServerLinux, ApplicationSettings.FileTransferProtocolEnum fileTransferProtocol, string sudoImpersonatedUser)
3738
{
3839
_logger.MethodEntry(LogLevel.Debug);
3940

4041
Server = server;
4142
SudoImpersonatedUser = sudoImpersonatedUser;
43+
FileTransferProtocol = fileTransferProtocol;
4244
IsStoreServerLinux = isStoreServerLinux;
4345
UserId = serverLogin;
4446
Password = serverPassword;
@@ -167,7 +169,7 @@ public override void UploadCertificateFile(string path, string fileName, byte[]
167169

168170
bool scpError = false;
169171

170-
if (ApplicationSettings.FileTransferProtocol == ApplicationSettings.FileTransferProtocolEnum.Both || ApplicationSettings.FileTransferProtocol == ApplicationSettings.FileTransferProtocolEnum.SCP)
172+
if (FileTransferProtocol == ApplicationSettings.FileTransferProtocolEnum.Both || FileTransferProtocol == ApplicationSettings.FileTransferProtocolEnum.SCP)
171173
{
172174
using (ScpClient client = new ScpClient(Connection))
173175
{
@@ -186,7 +188,7 @@ public override void UploadCertificateFile(string path, string fileName, byte[]
186188
scpError = true;
187189
_logger.LogError("Exception during SCP upload...");
188190
_logger.LogError($"Upload Exception: {RemoteFileException.FlattenExceptionMessages(ex, ex.Message)}");
189-
if (ApplicationSettings.FileTransferProtocol == ApplicationSettings.FileTransferProtocolEnum.Both)
191+
if (FileTransferProtocol == ApplicationSettings.FileTransferProtocolEnum.Both)
190192
_logger.LogDebug($"SCP upload failed. Attempting with SFTP protocol...");
191193
else
192194
throw new RemoteFileException("Error attempting SCP file transfer to {Connection.Host} using login {Connection.Username} and connection method {Connection.AuthenticationMethods[0].Name}. Please contact your company's system administrator to verify connection and permission settings.", ex);
@@ -198,7 +200,7 @@ public override void UploadCertificateFile(string path, string fileName, byte[]
198200
}
199201
}
200202

201-
if ((ApplicationSettings.FileTransferProtocol == ApplicationSettings.FileTransferProtocolEnum.Both && scpError) || ApplicationSettings.FileTransferProtocol == ApplicationSettings.FileTransferProtocolEnum.SFTP)
203+
if ((FileTransferProtocol == ApplicationSettings.FileTransferProtocolEnum.Both && scpError) || FileTransferProtocol == ApplicationSettings.FileTransferProtocolEnum.SFTP)
202204
{
203205
using (SftpClient client = new SftpClient(Connection))
204206
{
@@ -256,7 +258,7 @@ public override byte[] DownloadCertificateFile(string path)
256258

257259
bool scpError = false;
258260

259-
if (ApplicationSettings.FileTransferProtocol == ApplicationSettings.FileTransferProtocolEnum.Both || ApplicationSettings.FileTransferProtocol == ApplicationSettings.FileTransferProtocolEnum.SCP)
261+
if (FileTransferProtocol == ApplicationSettings.FileTransferProtocolEnum.Both || FileTransferProtocol == ApplicationSettings.FileTransferProtocolEnum.SCP)
260262
{
261263
using (ScpClient client = new ScpClient(Connection))
262264
{
@@ -276,7 +278,7 @@ public override byte[] DownloadCertificateFile(string path)
276278
scpError = true;
277279
_logger.LogError("Exception during SCP download...");
278280
_logger.LogError($"Upload Exception: {RemoteFileException.FlattenExceptionMessages(ex, ex.Message)}");
279-
if (ApplicationSettings.FileTransferProtocol == ApplicationSettings.FileTransferProtocolEnum.Both)
281+
if (FileTransferProtocol == ApplicationSettings.FileTransferProtocolEnum.Both)
280282
_logger.LogDebug($"SCP download failed. Attempting with SFTP protocol...");
281283
else
282284
throw new RemoteFileException($"Error attempting SCP file transfer from {Connection.Host} using login {Connection.Username} and connection method {Connection.AuthenticationMethods[0].Name}. Please contact your company's system administrator to verify connection and permission settings.", ex);
@@ -288,7 +290,7 @@ public override byte[] DownloadCertificateFile(string path)
288290
}
289291
}
290292

291-
if ((ApplicationSettings.FileTransferProtocol == ApplicationSettings.FileTransferProtocolEnum.Both && scpError) || ApplicationSettings.FileTransferProtocol == ApplicationSettings.FileTransferProtocolEnum.SFTP)
293+
if ((FileTransferProtocol == ApplicationSettings.FileTransferProtocolEnum.Both && scpError) || FileTransferProtocol == ApplicationSettings.FileTransferProtocolEnum.SFTP)
292294
{
293295
using (SftpClient client = new SftpClient(Connection))
294296
{

integration-manifest.json

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,15 @@
105105
"Type": "Bool",
106106
"DefaultValue": "False",
107107
"Description": "Internally set the -IncludePortInSPN option when creating the remote PowerShell connection. Needed for some Kerberos configurations."
108+
},
109+
{
110+
"Name": "FileTransferProtocol",
111+
"DisplayName": "File Transfer Protocol to Use",
112+
"Required": false,
113+
"DependsOn": "",
114+
"Type": "MultipleChoice",
115+
"DefaultValue": "SCP,SFTP,Both",
116+
"Description": "Which protocol should be used when uploading/downloading files - SCP, SFTP, or Both (try one, and then if necessary, the other)."
108117
}
109118
],
110119
"EntryParameters": [],
@@ -237,6 +246,15 @@
237246
"Type": "Bool",
238247
"DefaultValue": "False",
239248
"Description": "Internally set the -IncludePortInSPN option when creating the remote PowerShell connection. Needed for some Kerberos configurations."
249+
},
250+
{
251+
"Name": "FileTransferProtocol",
252+
"DisplayName": "File Transfer Protocol to Use",
253+
"Required": false,
254+
"DependsOn": "",
255+
"Type": "MultipleChoice",
256+
"DefaultValue": "SCP,SFTP,Both",
257+
"Description": "Which protocol should be used when uploading/downloading files - SCP, SFTP, or Both (try one, and then if necessary, the other)."
240258
}
241259
],
242260
"EntryParameters": [],
@@ -333,6 +351,15 @@
333351
"Type": "Bool",
334352
"DefaultValue": "False",
335353
"Description": "Internally set the -IncludePortInSPN option when creating the remote PowerShell connection. Needed for some Kerberos configurations."
354+
},
355+
{
356+
"Name": "FileTransferProtocol",
357+
"DisplayName": "File Transfer Protocol to Use",
358+
"Required": false,
359+
"DependsOn": "",
360+
"Type": "MultipleChoice",
361+
"DefaultValue": "SCP,SFTP,Both",
362+
"Description": "Which protocol should be used when uploading/downloading files - SCP, SFTP, or Both (try one, and then if necessary, the other)."
336363
}
337364
],
338365
"EntryParameters": [],
@@ -438,6 +465,15 @@
438465
"Type": "Bool",
439466
"DefaultValue": "False",
440467
"Description": "Internally set the -IncludePortInSPN option when creating the remote PowerShell connection. Needed for some Kerberos configurations."
468+
},
469+
{
470+
"Name": "FileTransferProtocol",
471+
"DisplayName": "File Transfer Protocol to Use",
472+
"Required": false,
473+
"DependsOn": "",
474+
"Type": "MultipleChoice",
475+
"DefaultValue": "SCP,SFTP,Both",
476+
"Description": "Which protocol should be used when uploading/downloading files - SCP, SFTP, or Both (try one, and then if necessary, the other)."
441477
}
442478
],
443479
"EntryParameters": [],
@@ -534,6 +570,15 @@
534570
"Type": "Bool",
535571
"DefaultValue": "False",
536572
"Description": "Internally set the -IncludePortInSPN option when creating the remote PowerShell connection. Needed for some Kerberos configurations."
573+
},
574+
{
575+
"Name": "FileTransferProtocol",
576+
"DisplayName": "File Transfer Protocol to Use",
577+
"Required": false,
578+
"DependsOn": "",
579+
"Type": "MultipleChoice",
580+
"DefaultValue": "SCP,SFTP,Both",
581+
"Description": "Which protocol should be used when uploading/downloading files - SCP, SFTP, or Both (try one, and then if necessary, the other)."
537582
}
538583
],
539584
"EntryParameters": [],
@@ -639,6 +684,15 @@
639684
"Type": "Bool",
640685
"DefaultValue": "False",
641686
"Description": "Internally set the -IncludePortInSPN option when creating the remote PowerShell connection. Needed for some Kerberos configurations."
687+
},
688+
{
689+
"Name": "FileTransferProtocol",
690+
"DisplayName": "File Transfer Protocol to Use",
691+
"Required": false,
692+
"DependsOn": "",
693+
"Type": "MultipleChoice",
694+
"DefaultValue": "SCP,SFTP,Both",
695+
"Description": "Which protocol should be used when uploading/downloading files - SCP, SFTP, or Both (try one, and then if necessary, the other)."
642696
}
643697
],
644698
"EntryParameters": [],

0 commit comments

Comments
 (0)