@@ -166,8 +166,6 @@ public void Initialize()
166166 // Skipped in JEA sessions: [System.Environment] and [System.Net.Dns] are blocked
167167 // by ConstrainedLanguage and this script runs as untrusted inline code, not as a
168168 // trusted module function.
169- // TODO: Create Get-KeyfactorHostInfo in Keyfactor.WinCert.Common so JEA sessions
170- // can also log host details at startup.
171169 if ( ! useJea )
172170 {
173171 string psInfo = @"
@@ -267,35 +265,43 @@ private void InitializeRemoteSession()
267265
268266 if ( protocol == "ssh" )
269267 {
270- _logger . LogTrace ( "Initializing SSH connection" ) ;
271-
272268 try
273269 {
274- _logger . LogInformation ( "Attempting to create a temporary key file" ) ;
275- tempKeyFilePath = createPrivateKeyFile ( ) ;
270+ _logger . LogTrace ( "Initializing SSH connection" ) ;
271+
272+ try
273+ {
274+ _logger . LogInformation ( "Attempting to create a temporary key file" ) ;
275+ tempKeyFilePath = createPrivateKeyFile ( ) ;
276+ }
277+ catch ( Exception ex )
278+ {
279+ _logger . LogError ( $ "Error while creating temporary KeyFilePath: { ex . Message } ") ;
280+ throw new Exception ( "Error while creating temporary KeyFilePath." ) ;
281+ }
282+
283+ Hashtable options = new Hashtable
284+ {
285+ { "StrictHostKeyChecking" , "No" } ,
286+ { "UserKnownHostsFile" , "/dev/null" } ,
287+ } ;
288+
289+ _logger . LogInformation ( $ "Temporary KeyFilePath created at: { tempKeyFilePath } ") ;
290+ _logger . LogInformation ( $ "HostName: { ClientMachineName } ") ;
291+ _logger . LogInformation ( $ "Username: { serverUserName } ") ;
292+
293+ PS . AddCommand ( "New-PSSession" )
294+ . AddParameter ( "HostName" , ClientMachineName )
295+ . AddParameter ( "UserName" , serverUserName )
296+ . AddParameter ( "KeyFilePath" , tempKeyFilePath )
297+ . AddParameter ( "ConnectingTimeout" , 10000 )
298+ . AddParameter ( "Options" , options ) ;
276299 }
277300 catch ( Exception ex )
278301 {
279- _logger . LogError ( $ "Error while creating temporary KeyFilePath: { ex . Message } ") ;
280- throw new Exception ( "Error while creating temporary KeyFilePath. " ) ;
302+ _logger . LogError ( $ "An error occurred while attempting to establish an SSH connection. \n { ex . Message } ") ;
303+ throw new Exception ( "Problems establishing SSH connection. Please check the User name and KeyFilePath for the Certificate Store " ) ;
281304 }
282-
283- Hashtable options = new Hashtable
284- {
285- { "StrictHostKeyChecking" , "No" } ,
286- { "UserKnownHostsFile" , "/dev/null" } ,
287- } ;
288-
289- _logger . LogTrace ( $ "Temporary KeyFilePath created at: { tempKeyFilePath } ") ;
290- _logger . LogTrace ( $ "HostName: { ClientMachineName } ") ;
291- _logger . LogTrace ( $ "Username: { serverUserName } ") ;
292-
293- PS . AddCommand ( "New-PSSession" )
294- . AddParameter ( "HostName" , ClientMachineName )
295- . AddParameter ( "UserName" , serverUserName )
296- . AddParameter ( "KeyFilePath" , tempKeyFilePath )
297- . AddParameter ( "ConnectingTimeout" , 10000 )
298- . AddParameter ( "Options" , options ) ;
299305 }
300306 else
301307 {
@@ -341,7 +347,7 @@ private void InitializeRemoteSession()
341347
342348 }
343349
344- _logger . LogTrace ( "Attempting to invoke PS-Session command on remote machine." ) ;
350+ _logger . LogInformation ( "Attempting to invoke PS-Session command on remote machine." ) ;
345351
346352 var asyncResult = PS . BeginInvoke ( ) ;
347353 if ( ! asyncResult . AsyncWaitHandle . WaitOne ( TimeSpan . FromSeconds ( timeoutSeconds ) ) )
0 commit comments