1515import jakarta .validation .constraints .NotNull ;
1616import lombok .*;
1717import lombok .experimental .SuperBuilder ;
18+ import lombok .extern .slf4j .Slf4j ;
1819
1920import java .io .*;
2021import java .nio .charset .StandardCharsets ;
@@ -220,6 +221,8 @@ public ScriptOutput run(RunContext runContext) throws Exception {
220221 }
221222
222223 var rPassword = runContext .render (this .password ).as (String .class );
224+ var rPrivateKeyPassphrase = runContext .render (this .privateKeyPassphrase ).as (String .class );
225+
223226 switch (renderedAuthMethod ) {
224227 case PASSWORD :
225228 session .setConfig ("PreferredAuthentications" , "password" );
@@ -228,8 +231,7 @@ public ScriptOutput run(RunContext runContext) throws Exception {
228231 case PUBLIC_KEY :
229232 session .setConfig ("PreferredAuthentications" , "publickey" );
230233 var privateKeyBytes = runContext .render (this .privateKey ).as (String .class ).orElseThrow ().getBytes ();
231- var passphrase = runContext .render (this .privateKeyPassphrase ).as (String .class );
232- jsch .addIdentity ("primary" , privateKeyBytes , null , passphrase .map (String ::getBytes ).orElse (null ));
234+ jsch .addIdentity ("primary" , privateKeyBytes , null , rPrivateKeyPassphrase .map (String ::getBytes ).orElse (null ));
233235 break ;
234236 case OPEN_SSH :
235237 var rOpenSSHConfigPath = runContext .render (openSSHConfigPath ).as (String .class );
@@ -242,6 +244,9 @@ public ScriptOutput run(RunContext runContext) throws Exception {
242244 ConfigRepository configRepository = OpenSSHConfig .parseFile (configPath );
243245 jsch .setConfigRepository (configRepository );
244246 rPassword .ifPresent (session ::setPassword );
247+ if (rPrivateKeyPassphrase .isPresent ()) {
248+ session .setUserInfo (new BasicUserInfo (rPrivateKeyPassphrase .get ()));
249+ }
245250 break ;
246251 }
247252
@@ -303,6 +308,41 @@ public ScriptOutput run(RunContext runContext) throws Exception {
303308 }
304309 }
305310
311+ // Can be extended for Password AuthMethod as well
312+ @ Slf4j
313+ private record BasicUserInfo (String passphrase ) implements UserInfo {
314+
315+ @ Override
316+ public String getPassphrase () {
317+ return passphrase ;
318+ }
319+
320+ @ Override
321+ public String getPassword () {
322+ return null ;
323+ }
324+
325+ @ Override
326+ public boolean promptPassword (String message ) {
327+ return false ;
328+ }
329+
330+ @ Override
331+ public boolean promptPassphrase (String message ) {
332+ return true ;
333+ }
334+
335+ @ Override
336+ public boolean promptYesNo (String message ) {
337+ return false ;
338+ }
339+
340+ @ Override
341+ public void showMessage (String message ) {
342+ log .debug (message );
343+ }
344+ }
345+
306346 private static class LogRunnable implements Runnable {
307347 private final InputStream inputStream ;
308348
0 commit comments