Repository: mina-sshd Updated Branches: refs/heads/master f3cac42ae -> ba4772a23
[SSHD-319] Handling error scenarios if Prime cannot be found Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/ba4772a2 Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/ba4772a2 Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/ba4772a2 Branch: refs/heads/master Commit: ba4772a23573998a1c801e28130ccfb1a9b77121 Parents: f3cac42 Author: Guillaume Nodet <[email protected]> Authored: Mon Jun 16 11:05:34 2014 +0200 Committer: Guillaume Nodet <[email protected]> Committed: Mon Jun 16 11:05:34 2014 +0200 ---------------------------------------------------------------------- .../java/org/apache/sshd/server/kex/DHGEX.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/ba4772a2/sshd-core/src/main/java/org/apache/sshd/server/kex/DHGEX.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/kex/DHGEX.java b/sshd-core/src/main/java/org/apache/sshd/server/kex/DHGEX.java index b988ef9..04b8a13 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/kex/DHGEX.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/kex/DHGEX.java @@ -18,6 +18,7 @@ */ package org.apache.sshd.server.kex; +import java.io.IOException; import java.math.BigInteger; import java.net.URL; import java.security.KeyPair; @@ -34,6 +35,7 @@ import org.apache.sshd.common.SshConstants; import org.apache.sshd.common.SshException; import org.apache.sshd.common.digest.SHA1; import org.apache.sshd.common.kex.DH; +import org.apache.sshd.common.kex.DHGroupData; import org.apache.sshd.common.session.AbstractSession; import org.apache.sshd.common.util.Buffer; import org.apache.sshd.common.util.BufferUtils; @@ -219,14 +221,21 @@ public class DHGEX implements KeyExchange { } private DH chooseDH(int min, int prf, int max) throws Exception { + List<Moduli.DhGroup> groups = null; URL moduli; String moduliStr = session.getFactoryManager().getProperties().get(ServerFactoryManager.MODULI_URL); if (moduliStr != null) { - moduli = new URL(moduliStr); - } else { + try { + moduli = new URL(moduliStr); + groups = Moduli.parseModuli(moduli); + } catch (IOException e) { + log.warn("Error loading external moduli", e); + } + } + if (groups == null) { moduli = getClass().getResource("/org/apache/sshd/moduli"); + groups = Moduli.parseModuli(moduli); } - List<Moduli.DhGroup> groups = Moduli.parseModuli(moduli); min = Math.max(min, 1024); prf = Math.max(prf, 1024); @@ -249,7 +258,8 @@ public class DHGEX implements KeyExchange { } } if (selected.isEmpty()) { - throw new IllegalArgumentException("No suitable primes"); + log.warn("No suitable primes found, defaulting to DHG1"); + return getDH(new BigInteger(DHGroupData.getG()), new BigInteger(DHGroupData.getP1())); } Random random = session.getFactoryManager().getRandomFactory().create(); int which = random.random(selected.size());
