001: package ch.ethz.ssh2;
002:
003: /**
004: * A <code>DHGexParameters</code> object can be used to specify parameters for
005: * the diffie-hellman group exchange.
006: * <p>
007: * Depending on which constructor is used, either the use of a
008: * <code>SSH_MSG_KEX_DH_GEX_REQUEST</code> or <code>SSH_MSG_KEX_DH_GEX_REQUEST_OLD</code>
009: * can be forced.
010: *
011: * @see Connection#setDHGexParameters(DHGexParameters)
012: * @author Christian Plattner, plattner@inf.ethz.ch
013: * @version $Id: DHGexParameters.java,v 1.3 2006/09/20 12:51:37 cplattne Exp $
014: */
015:
016: public class DHGexParameters {
017: private final int min_group_len;
018: private final int pref_group_len;
019: private final int max_group_len;
020:
021: private static final int MIN_ALLOWED = 1024;
022: private static final int MAX_ALLOWED = 8192;
023:
024: /**
025: * Same as calling {@link #DHGexParameters(int, int, int) DHGexParameters(1024, 1024, 4096)}.
026: * This is also the default used by the Connection class.
027: *
028: */
029: public DHGexParameters() {
030: this (1024, 1024, 4096);
031: }
032:
033: /**
034: * This constructor can be used to force the sending of a
035: * <code>SSH_MSG_KEX_DH_GEX_REQUEST_OLD</code> request.
036: * Internally, the minimum and maximum group lengths will
037: * be set to zero.
038: *
039: * @param pref_group_len has to be >= 1024 and <= 8192
040: */
041: public DHGexParameters(int pref_group_len) {
042: if ((pref_group_len < MIN_ALLOWED)
043: || (pref_group_len > MAX_ALLOWED))
044: throw new IllegalArgumentException(
045: "pref_group_len out of range!");
046:
047: this .pref_group_len = pref_group_len;
048: this .min_group_len = 0;
049: this .max_group_len = 0;
050: }
051:
052: /**
053: * This constructor can be used to force the sending of a
054: * <code>SSH_MSG_KEX_DH_GEX_REQUEST</code> request.
055: * <p>
056: * Note: older OpenSSH servers don't understand this request, in which
057: * case you should use the {@link #DHGexParameters(int)} constructor.
058: * <p>
059: * All values have to be >= 1024 and <= 8192. Furthermore,
060: * min_group_len <= pref_group_len <= max_group_len.
061: *
062: * @param min_group_len
063: * @param pref_group_len
064: * @param max_group_len
065: */
066: public DHGexParameters(int min_group_len, int pref_group_len,
067: int max_group_len) {
068: if ((min_group_len < MIN_ALLOWED)
069: || (min_group_len > MAX_ALLOWED))
070: throw new IllegalArgumentException(
071: "min_group_len out of range!");
072:
073: if ((pref_group_len < MIN_ALLOWED)
074: || (pref_group_len > MAX_ALLOWED))
075: throw new IllegalArgumentException(
076: "pref_group_len out of range!");
077:
078: if ((max_group_len < MIN_ALLOWED)
079: || (max_group_len > MAX_ALLOWED))
080: throw new IllegalArgumentException(
081: "max_group_len out of range!");
082:
083: if ((pref_group_len < min_group_len)
084: || (pref_group_len > max_group_len))
085: throw new IllegalArgumentException(
086: "pref_group_len is incompatible with min and max!");
087:
088: if (max_group_len < min_group_len)
089: throw new IllegalArgumentException(
090: "max_group_len must not be smaller than min_group_len!");
091:
092: this .min_group_len = min_group_len;
093: this .pref_group_len = pref_group_len;
094: this .max_group_len = max_group_len;
095: }
096:
097: /**
098: * Get the maximum group length.
099: *
100: * @return the maximum group length, may be <code>zero</code> if
101: * SSH_MSG_KEX_DH_GEX_REQUEST_OLD should be requested
102: */
103: public int getMax_group_len() {
104: return max_group_len;
105: }
106:
107: /**
108: * Get the minimum group length.
109: *
110: * @return minimum group length, may be <code>zero</code> if
111: * SSH_MSG_KEX_DH_GEX_REQUEST_OLD should be requested
112: */
113: public int getMin_group_len() {
114: return min_group_len;
115: }
116:
117: /**
118: * Get the preferred group length.
119: *
120: * @return the preferred group length
121: */
122: public int getPref_group_len() {
123: return pref_group_len;
124: }
125: }
|