aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/trilead
diff options
context:
space:
mode:
authorKenny Root <kenny@the-b.org>2015-04-03 06:49:08 +0200
committerKenny Root <kenny@the-b.org>2015-04-03 06:50:35 +0200
commit632e4495715fbc77d129268e91da2cf513580d08 (patch)
tree0c29d13d28570a2991b0137cde70fd5b76cd3b3d /src/com/trilead
parentec8fe076919db2990888a4fdd3226abfc280407d (diff)
downloadconnectbot-632e4495715fbc77d129268e91da2cf513580d08.tar.gz
connectbot-632e4495715fbc77d129268e91da2cf513580d08.tar.bz2
connectbot-632e4495715fbc77d129268e91da2cf513580d08.zip
Check for EC support before enabling it
Fixes #69
Diffstat (limited to 'src/com/trilead')
-rw-r--r--src/com/trilead/ssh2/transport/KexManager.java30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/com/trilead/ssh2/transport/KexManager.java b/src/com/trilead/ssh2/transport/KexManager.java
index cd26530..2476b76 100644
--- a/src/com/trilead/ssh2/transport/KexManager.java
+++ b/src/com/trilead/ssh2/transport/KexManager.java
@@ -2,6 +2,8 @@
package com.trilead.ssh2.transport;
import java.io.IOException;
+import java.security.KeyFactory;
+import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.interfaces.DSAPublicKey;
import java.security.interfaces.ECPublicKey;
@@ -47,20 +49,36 @@ public class KexManager
{
private static final Logger log = Logger.getLogger(KexManager.class);
+ private static final boolean supportsEc;
+ static {
+ KeyFactory keyFact;
+ try {
+ keyFact = KeyFactory.getInstance("EC");
+ } catch (NoSuchAlgorithmException ignored) {
+ keyFact = null;
+ log.log(10, "Disabling EC support due to lack of KeyFactory");
+ }
+ supportsEc = keyFact != null;
+ }
+
private static final Set<String> HOSTKEY_ALGS = new TreeSet<String>();
static {
- HOSTKEY_ALGS.add("ecdsa-sha2-nistp256");
- HOSTKEY_ALGS.add("ecdsa-sha2-nistp384");
- HOSTKEY_ALGS.add("ecdsa-sha2-nistp521");
+ if (supportsEc) {
+ HOSTKEY_ALGS.add("ecdsa-sha2-nistp256");
+ HOSTKEY_ALGS.add("ecdsa-sha2-nistp384");
+ HOSTKEY_ALGS.add("ecdsa-sha2-nistp521");
+ }
HOSTKEY_ALGS.add("ssh-rsa");
HOSTKEY_ALGS.add("ssh-dsa");
}
private static final Set<String> KEX_ALGS = new TreeSet<String>();
static {
- KEX_ALGS.add("ecdh-sha2-nistp256");
- KEX_ALGS.add("ecdh-sha2-nistp384");
- KEX_ALGS.add("ecdh-sha2-nistp521");
+ if (supportsEc) {
+ KEX_ALGS.add("ecdh-sha2-nistp256");
+ KEX_ALGS.add("ecdh-sha2-nistp384");
+ KEX_ALGS.add("ecdh-sha2-nistp521");
+ }
KEX_ALGS.add("diffie-hellman-group-exchange-sha256");
KEX_ALGS.add("diffie-hellman-group-exchange-sha1");
KEX_ALGS.add("diffie-hellman-group14-sha1");