3

I have Linux phone with enabled SSH. I need to connect to it via challenge-response authentication. So how looks this process manually, for example, using PuTTY:

  1. Connect to phone using IP and port.

  2. Console shows "login as:" -> Enter user name.

  3. Console shows:

    login as: craft

    Challenge: 547-04302
    Product ID: 7000315107

    Response:

  4. I need to copy Challenge, get Response from other server using Challenge and enter the Response in console.

How I can do this using Java and some libraries for SSH (I tried JSch, but there are no methods for challenge-response)? I need only to write Challenge into String, and after that enter the Response using String response.

Thanks for help.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992

1 Answers1

1

The challenge-response authentication is also known as a keyboard-interactive authentication.

And it is supported by the JSch library.

See the official JSch UserAuthKI example.

Basically you need to implement the UIKeyboardInteractive interface (together with the UserInfo interface) and associate the implementation with the session using the Session.setUserInfo.

To use a programmatic response to a single challenge, just collect the challenge from the prompt[0] parameter of the UIKeyboardInteractive.promptKeyboardInteractive method and return a single element array with the response.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • 1
    I rewrited UserAuthKeyboardInteractive class according to my example (added code to parse `String[] response=new String[prompt.length];` from `promptKeyboardInteractive` method and methods for getting response using Challenge via Selenium) , all works. Your comment was helpful for me, Thanks – Svyat Pastukhov Dec 17 '15 at 13:19