Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
leefine02 authored and leefine02 committed Jul 19, 2024
1 parent c83503a commit 22671e5
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 37 deletions.
2 changes: 0 additions & 2 deletions RemoteFile/RemoteCertificateStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,6 @@ internal void Initialize(string sudoImpersonatedUser)
else
RemoteHandler = new WinRMHandler(Server, ServerId, ServerPassword, treatAsLocal);

RemoteHandler.Initialize();

logger.MethodExit(LogLevel.Debug);
}

Expand Down
2 changes: 0 additions & 2 deletions RemoteFile/RemoteHandlers/BaseRemoteHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ public static void AreLinuxPermissionsValid(string permissions)
throw new RemoteFileException($"Invalid format for Linux file permissions. This value must be exactly 3 digits long with each digit between 0-7 but found {permissions} instead.");
}

public abstract void Initialize();

public abstract void Terminate();

public abstract string RunCommand(string commandText, object[] arguments, bool withSudo, string[] passwordsToMaskInLog);
Expand Down
2 changes: 0 additions & 2 deletions RemoteFile/RemoteHandlers/IRemoteHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ namespace Keyfactor.Extensions.Orchestrator.RemoteFile.RemoteHandlers
/// </summary>
interface IRemoteHandler
{
void Initialize();

void Terminate();

string RunCommand(string commandText, object[] arguments, bool withSudo, string[] passwordsToMaskInLog);
Expand Down
6 changes: 0 additions & 6 deletions RemoteFile/RemoteHandlers/LinuxLocalHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ class LinuxLocalHandler : BaseRemoteHandler
private Command BaseCommand { get; set; }

internal LinuxLocalHandler()
{
_logger.MethodEntry(LogLevel.Debug);
_logger.MethodExit(LogLevel.Debug);
}

public override void Initialize()
{
_logger.MethodEntry(LogLevel.Debug);

Expand Down
34 changes: 18 additions & 16 deletions RemoteFile/RemoteHandlers/SSHHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Keyfactor.PKI.PEM;
using static Microsoft.ApplicationInsights.MetricDimensionNames.TelemetryContext;
using Renci.SshNet.Common;
using Org.BouncyCastle.Bcpg;

namespace Keyfactor.Extensions.Orchestrator.RemoteFile.RemoteHandlers
{
Expand All @@ -28,6 +29,7 @@ class SSHHandler : BaseRemoteHandler
private ConnectionInfo Connection { get; set; }
private string SudoImpersonatedUser { get; set; }
private bool IsStoreServerLinux { get; set; }
private string UserId { get; set; }
private string Password { get; set; }
private SshClient sshClient;

Expand All @@ -38,16 +40,25 @@ internal SSHHandler(string server, string serverLogin, string serverPassword, bo
Server = server;
SudoImpersonatedUser = sudoImpersonatedUser;
IsStoreServerLinux = isStoreServerLinux;
UserId = serverLogin;
Password = serverPassword;

List<AuthenticationMethod> authenticationMethods = new List<AuthenticationMethod>();
if (serverPassword.Length < PASSWORD_LENGTH_MAX)
{
authenticationMethods.Add(new PasswordAuthenticationMethod(serverLogin, serverPassword));

KeyboardInteractiveAuthenticationMethod keyboardAuthentication = new KeyboardInteractiveAuthenticationMethod(UserId);
keyboardAuthentication.AuthenticationPrompt += KeyboardAuthentication_AuthenticationPrompt;
authenticationMethods.Add(keyboardAuthentication);
try
{
Connection = new ConnectionInfo(server, serverLogin, new PasswordAuthenticationMethod(serverLogin, serverPassword));
SshClient tempSshClient = new SshClient(Connection);
tempSshClient.Connect();
tempSshClient.Disconnect();
tempSshClient.Dispose();
}
catch (Exception ex)

Check warning on line 56 in RemoteFile/RemoteHandlers/SSHHandler.cs

View workflow job for this annotation

GitHub Actions / call-starter-workflow / call-dotnet-build-and-release-workflow / dotnet-build-and-release

The variable 'ex' is declared but never used
{
KeyboardInteractiveAuthenticationMethod keyboardAuthentication = new KeyboardInteractiveAuthenticationMethod(UserId);
keyboardAuthentication.AuthenticationPrompt += KeyboardAuthentication_AuthenticationPrompt;
Connection = new ConnectionInfo(server, serverLogin, keyboardAuthentication);
}
}
else
{
Expand All @@ -68,18 +79,9 @@ internal SSHHandler(string server, string serverLogin, string serverPassword, bo
}
}

authenticationMethods.Add(new PrivateKeyAuthenticationMethod(serverLogin, privateKeyFile));
Connection = new ConnectionInfo(server, serverLogin, new PrivateKeyAuthenticationMethod(serverLogin, privateKeyFile));
}

Connection = new ConnectionInfo(server, serverLogin, authenticationMethods.ToArray());

_logger.MethodExit(LogLevel.Debug);
}

public override void Initialize()
{
_logger.MethodEntry(LogLevel.Debug);

try
{
sshClient = new SshClient(Connection);
Expand Down
11 changes: 2 additions & 9 deletions RemoteFile/RemoteHandlers/WinRMHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ internal WinRMHandler(string server, string serverLogin, string serverPassword,
}
}

_logger.MethodExit(LogLevel.Debug);
}

public override void Initialize()
{
_logger.MethodEntry(LogLevel.Debug);

try
{
if (RunLocal)
Expand All @@ -69,8 +62,8 @@ public override void Initialize()

catch (Exception ex)
{
_logger.LogError($"Exception during Initialize...{RemoteFileException.FlattenExceptionMessages(ex, ex.Message)}");
throw ex;
_logger.LogError($"Exception attempting to connect to server...{RemoteFileException.FlattenExceptionMessages(ex, ex.Message)}");
throw;
}

_logger.MethodExit(LogLevel.Debug);
Expand Down

0 comments on commit 22671e5

Please sign in to comment.