- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我目前有一个 Android 应用程序使用密码通过 ssh 连接到我的路由器。我正在寻求改进这一点,以便我可以使用 key ,但我遇到了实际问题。据我了解,android 中包含的 bouncycaSTLe 版本是一个残缺版本,因此 ssh key 不适用于 jsch。我看过 spongycaSTLe,它声称是一个更完整的实现。下面是与使用 bouncycaSTLe 基本相同的结果,Auth Fail。
10-26 18:18:23.528: INFO/System.out(10642): Log(jsch,1): Connecting to 192.168.88.1 port 22
10-26 18:18:23.538: INFO/System.out(10642): Log(jsch,1): Connection established
10-26 18:18:23.548: INFO/System.out(10642): Log(jsch,1): Remote version string: SSH-2.0-ROSSSH
10-26 18:18:23.548: INFO/System.out(10642): Log(jsch,1): Local version string: SSH-2.0-JSCH-0.1.44
10-26 18:18:23.548: INFO/System.out(10642): Log(jsch,1): CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256
10-26 18:18:23.618: INFO/System.out(10642): Log(jsch,1): SSH_MSG_KEXINIT sent
10-26 18:18:23.618: INFO/System.out(10642): Log(jsch,1): SSH_MSG_KEXINIT received
10-26 18:18:23.628: INFO/System.out(10642): Log(jsch,1): kex: server->client aes128-cbc hmac-md5 none
10-26 18:18:23.628: INFO/System.out(10642): Log(jsch,1): kex: client->server aes128-cbc hmac-md5 none
10-26 18:18:23.688: INFO/System.out(10642): Log(jsch,1): SSH_MSG_KEXDH_INIT sent
10-26 18:18:23.688: INFO/System.out(10642): Log(jsch,1): expecting SSH_MSG_KEXDH_REPLY
10-26 18:18:24.058: INFO/System.out(10642): Log(jsch,1): ssh_dss_verify: signature true
10-26 18:18:24.058: INFO/System.out(10642): Log(jsch,2): Permanently added '192.168.88.1' (DSA) to the list of known hosts.
10-26 18:18:24.058: INFO/System.out(10642): Log(jsch,1): SSH_MSG_NEWKEYS sent
10-26 18:18:24.058: INFO/System.out(10642): Log(jsch,1): SSH_MSG_NEWKEYS received
10-26 18:18:24.078: INFO/System.out(10642): Log(jsch,1): SSH_MSG_SERVICE_REQUEST sent
10-26 18:18:24.088: INFO/System.out(10642): Log(jsch,1): SSH_MSG_SERVICE_ACCEPT received
10-26 18:18:24.108: INFO/System.out(10642): Log(jsch,1): Authentications that can continue: publickey,keyboard-interactive,password
10-26 18:18:24.108: INFO/System.out(10642): Log(jsch,1): Next authentication method: publickey
10-26 18:18:24.108: INFO/System.out(10642): Log(jsch,1): Authentications that can continue: password
10-26 18:18:24.118: INFO/System.out(10642): Log(jsch,1): Next authentication method: password
10-26 18:18:24.128: INFO/System.out(10642): Log(jsch,1): Disconnecting from 192.168.88.1 port 22
10-26 18:18:24.138: WARN/System.err(10642): com.jcraft.jsch.JSchException: Auth fail
jsch 没有大量的日志信息来帮助我找出问题所在。
我想我为此使用了非常标准的代码:
static {
Security.addProvider(new org.spongycastle.jce.provider.BouncyCastleProvider());
}
在 OnCreate 中,我将删除原始的 bouncycaSTLe 提供程序
Security.removeProvider("BC");
然后我在尝试连接之前添加身份
jsch.addIdentity(key_filename);
Properties sshProp = new Properties();
sshProp.put("StrictHostKeyChecking", "no");
session.setConfig(sshProp);
session.connect();
有人成功过吗?我是不是忘记了什么?
编辑点附加信息:
正如我在评论中所说,我现在怀疑当我切换 key 并在 sshd 版本 OpenSSH_5.3p1 Debian-3ubuntu7 上进行测试时甚至没有尝试 key
debug2: mac_setup: found hmac-md5
debug1: kex: client->server aes128-ctr hmac-md5 none
debug2: mac_setup: found hmac-md5
debug1: kex: server->client aes128-ctr hmac-md5 none
debug2: dh_gen_key: priv key bits set: 122/256
debug2: bits set: 519/1024
debug1: expecting SSH2_MSG_KEXDH_INIT
debug2: bits set: 537/1024
debug2: kex_derive_keys
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug2: monitor_read: 5 used once, disabling now
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: KEX done
debug1: userauth-request for user root service ssh-connection method none
debug1: attempt 0 failures 0
debug2: parse_server_config: config reprocess config len 638
debug2: input_userauth_request: setting up authctxt for root
debug2: input_userauth_request: try method none
debug2: monitor_read: 7 used once, disabling now
debug1: PAM: initializing for "root"
debug1: PAM: setting PAM_RHOST to "nexus"
debug1: PAM: setting PAM_TTY to "ssh"
debug2: monitor_read: 50 used once, disabling now
debug2: monitor_read: 3 used once, disabling now
Failed none for root from 192.168.88.31 port 37807 ssh2
debug1: userauth-request for user root service ssh-connection method password
debug1: attempt 1 failures 0
debug2: input_userauth_request: try method password
debug1: PAM: password authentication failed for root: Authentication failure
Failed password for root from 192.168.88.31 port 37807 ssh2
Received disconnect from 192.168.88.31: 3: com.jcraft.jsch.JSchException: Auth fail
debug1: do_cleanup
debug1: do_cleanup
debug1: PAM: cleanup
我看不到有人尝试使用 key ,而从电脑上看
debug1: userauth-request for user root service ssh-connection method publickey
debug1: attempt 1 failures 0
debug2: input_userauth_request: try method publickey
debug1: test whether pkalg/pkblob are acceptable
debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
debug1: temporarily_use_uid: 0/0 (e=0/0)
debug1: trying public key file /root/.ssh/authorized_keys
debug1: restore_uid: 0/0
debug1: temporarily_use_uid: 0/0 (e=0/0)
debug1: trying public key file /root/.ssh/authorized_keys2
debug1: fd 4 clearing O_NONBLOCK
debug1: matching key found: file /root/.ssh/authorized_keys2, line 2
我可以看到正在使用的关键方法。下面是我用于测试的代码,虽然不漂亮但很实用。我知道这很可怕,但密码确实包含文件名和 key 路径,当 authtype == AUTHENTICATION_METHOD_KEY
public static String testSSHCommand ( String username, String password, String hostname, int port, String command, int authtype) throws Exception {
JSch jsch = new JSch();
JSch.setLogger(new Logger() {
public boolean isEnabled(int i) {
return true;
}
public void log(int i, String s) {
System.out.println("Log(jsch," + i + "): " + s);
}
});
if (authtype != AUTHENTICATION_METHOD_PASSWORD) {
Log.v("AUTHMETHOD","authmethod was "+authtype+" with key filename of "+password);
jsch.addIdentity(password);
}
Session session = jsch.getSession(username, hostname, 22);
if (authtype != AUTHENTICATION_METHOD_KEY) {
session.setPassword(password);
}
Properties prop = new Properties();
prop.put("StrictHostKeyChecking", "no");
session.setConfig(prop);
session.connect();
if (session.isConnected() ) {
ChannelExec channelssh = (ChannelExec)
session.openChannel("exec");
ByteArrayOutputStream os = new ByteArrayOutputStream();
channelssh.setOutputStream(os);
channelssh.setCommand(command);
channelssh.connect();
channelssh.disconnect();
return os.toString();
} else {
return "";
}
}
最佳答案
我通过将它包装到 class with main method 中来测试你的方法,因此,它可以在普通的 Java 6 JRE(没有 BouncyCaSTLe)中工作,带有 JSch-0.1.45(具有更多日志输出的修改版本)和“OpenSSH_5.8p1 Debian-1ubuntu3”sshd。
不过,我添加了一个 session.disconnect()
和一些休眠代码。
我这里没有 Android,看看这是否会有任何不同。
这是我的本地输出:
authmethod was 2 with key filename of /home/paulo/.ssh/id_rsa
Log(jsch,1): Connecting to localhost port 22
Log(jsch,1): Connection established
Log(jsch,1): Remote version string: SSH-2.0-OpenSSH_5.8p1 Debian-1ubuntu3
Log(jsch,1): Local version string: SSH-2.0-JSCH-0.1.45
Log(jsch,1): CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256
Log(jsch,1): aes256-ctr is not available.
Log(jsch,1): aes192-ctr is not available.
Log(jsch,1): aes256-cbc is not available.
Log(jsch,1): aes192-cbc is not available.
Log(jsch,1): arcfour256 is not available.
Log(jsch,1): CheckKexes: diffie-hellman-group14-sha1
Log(jsch,1): diffie-hellman-group14-sha1 is not available.
Log(jsch,1): SSH_MSG_KEXINIT sent
Log(jsch,1): SSH_MSG_KEXINIT received
Log(jsch,1): kex: server->client aes128-ctr hmac-md5 none
Log(jsch,1): kex: client->server aes128-ctr hmac-md5 none
Log(jsch,1): SSH_MSG_KEXDH_INIT sent
Log(jsch,1): expecting SSH_MSG_KEXDH_REPLY
Log(jsch,1): ssh_rsa_verify: signature true
Log(jsch,2): Permanently added 'localhost' (RSA) to the list of known hosts.
Log(jsch,1): SSH_MSG_NEWKEYS sent
Log(jsch,1): SSH_MSG_NEWKEYS received
Log(jsch,1): SSH_MSG_SERVICE_REQUEST sent
Log(jsch,1): SSH_MSG_SERVICE_ACCEPT received
Log(jsch,1): Authentications that can continue: publickey,keyboard-interactive,password
Log(jsch,1): Next authentication method: publickey
Log(jsch,1): Authentication succeeded (publickey).
Log(jsch,0): packet received, type: 91
Log(jsch,1): SSH_MSG_CHANNEL_OPEN_CONFIRMATION received, channel: 0
Log(jsch,0): packet received, type: 94
Log(jsch,1): SSH_MSG_CHANNEL_DATA received, channel: 0, len: 13
Log(jsch,0): packet received, type: 96
Log(jsch,1): SSH_MSG_CHANNEL_EOF received, channel: 0
Log(jsch,0): packet received, type: 98
Log(jsch,1): SSH_MSG_CHANNEL_REQUEST received, channel: 0, type: [B@1ad086a, want reply: false
Log(jsch,0): packet received, type: 97
Log(jsch,1): SSH_MSG_CHANNEL_CLOSE received, channel: 0
Log(jsch,1): Disconnecting from localhost port 22
Log(jsch,1): Caught an exception, leaving main loop due to Socket closed
Output: »Hallo, Welt!
«
(我用参数调用程序 paulo -key/home/paulo/.ssh/id_rsa localhost 22 hello
,所以它在目标机器上执行默认的 Hello World 程序,在德语中,因为这是我配置的语言环境。)
关于android - 在 Android 上使用 spongycaSTLe 而不是 bouncycaSTLe 的 Jsch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7906818/
我最近在/ drawable中添加了一些.gifs,以便可以将它们与按钮一起使用。这个工作正常(没有错误)。现在,当我重建/运行我的应用程序时,出现以下错误: Error: Gradle: Execu
Android 中有返回内部存储数据路径的方法吗? 我有 2 部 Android 智能手机(Samsung s2 和 s7 edge),我在其中安装了一个应用程序。我想使用位于这条路径中的 sqlit
这个问题在这里已经有了答案: What's the difference between "?android:" and "@android:" in an android layout xml f
我只想知道 android 开发手机、android 普通手机和 android root 手机之间的实际区别。 我们不能从实体店或除 android marketplace 以外的其他地方购买开发手
自Gradle更新以来,我正在努力使这个项目达到标准。这是一个团队项目,它使用的是android-apt插件。我已经进行了必要的语法更改(编译->实现和apt->注释处理器),但是编译器仍在告诉我存在
我是android和kotlin的新手,所以请原谅要解决的一个非常简单的问题! 我已经使用导航体系结构组件创建了一个基本应用程序,使用了底部的导航栏和三个导航选项。每个导航选项都指向一个专用片段,该片
我目前正在使用 Facebook official SDK for Android . 我现在正在使用高级示例应用程序,但我不知道如何让它获取应用程序墙/流/状态而不是登录的用户。 这可能吗?在那种情
我在下载文件时遇到问题, 我可以在模拟器中下载文件,但无法在手机上使用。我已经定义了上网和写入 SD 卡的权限。 我在服务器上有一个 doc 文件,如果用户单击下载。它下载文件。这在模拟器中工作正常但
这个问题在这里已经有了答案: What is the difference between gravity and layout_gravity in Android? (22 个答案) 关闭 9
任何人都可以告诉我什么是 android 缓存和应用程序缓存,因为当我们谈论缓存清理应用程序时,它的作用是,缓存清理概念是清理应用程序缓存还是像内存管理一样主存储、RAM、缓存是不同的并且据我所知,缓
假设应用程序 Foo 和 Eggs 在同一台 Android 设备上。任一应用程序都可以获取设备上所有应用程序的列表。一个应用程序是否有可能知道另一个应用程序是否已经运行以及运行了多长时间? 最佳答案
我有点困惑,我只看到了从 android 到 pc 或者从 android 到 pc 的例子。我需要制作一个从两部手机 (android) 连接的 android 应用程序进行视频聊天。我在想,我知道
用于使用 Android 以编程方式锁定屏幕。我从 Stackoverflow 之前关于此的问题中得到了一些好主意,并且我做得很好,但是当我运行该代码时,没有异常和错误。而且,屏幕没有锁定。请在这段代
文档说: android:layout_alignParentStart If true, makes the start edge of this view match the start edge
我不知道这两个属性和高度之间的区别。 以一个TextView为例,如果我将它的layout_width设置为wrap_content,并将它的width设置为50 dip,会发生什么情况? 最佳答案
这两个属性有什么关系?如果我有 android:noHistory="true",那么有 android:finishOnTaskLaunch="true" 有什么意义吗? 最佳答案 假设您的应用中有
我是新手,正在尝试理解以下 XML 代码: 查看 developer.android.com 上的文档,它说“starStyle”是 R.attr 中的常量, public static final
在下面的代码中,为什么当我设置时单选按钮的外观会发生变化 android:layout_width="fill_parent" 和 android:width="fill_parent" 我说的是
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 9
假设我有一个函数 fun myFunction(name:String, email:String){},当我调用这个函数时 myFunction('Ali', 'ali@test.com ') 如何
我是一名优秀的程序员,十分优秀!