如何使用 Java 自动执行质询-响应身份验证 [英] How to automate challenge-response authentication using Java

查看:43
本文介绍了如何使用 Java 自动执行质询-响应身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有启用了 SSH 的 Linux 手机.我需要通过质询-响应身份验证连接到它.那么如何手动查看这个过程,例如,使用 PuTTY:

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. 使用 IP 和端口连接到手机.

  1. Connect to phone using IP and port.

控制台显示登录为:"-> 输入用户名.

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

控制台显示:

登录:craft

挑战:547-04302
产品编号:7000315107

Challenge: 547-04302
Product ID: 7000315107

回复:

  • 我需要复制挑战,使用挑战从其他服务器获取响应并在控制台中输入响应.

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

    我如何使用 Java 和一些 SSH 库来做到这一点(我尝试了 JSch,但没有挑战响应的方法)?我只需要将 Challenge 写入 String,然后使用 String response 输入 Response.

    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.

    感谢您的帮助.

    推荐答案

    质询-响应身份验证也称为键盘交互身份验证.

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

    并且它得到了 JSch 库的支持.

    And it is supported by the JSch library.

    查看官方 JSch UserAuthKI 示例.

    See the official JSch UserAuthKI example.

    基本上你需要实现UIKeyboardInteractive 界面(与 UserInfo 接口) 并使用 Session.setUserInfo.

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

    要对单个质询使用程序化响应,只需从 UIKeyboardInteractive.promptKeyboardInteractive 方法 并返回带有响应的单个元素数组.

    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.

    这篇关于如何使用 Java 自动执行质询-响应身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆