0
|
1
|
|
2 package com.trilead.ssh2;
|
|
3
|
|
4 /**
|
|
5 * A <code>DHGexParameters</code> object can be used to specify parameters for
|
|
6 * the diffie-hellman group exchange.
|
|
7 * <p>
|
|
8 * Depending on which constructor is used, either the use of a
|
|
9 * <code>SSH_MSG_KEX_DH_GEX_REQUEST</code> or <code>SSH_MSG_KEX_DH_GEX_REQUEST_OLD</code>
|
|
10 * can be forced.
|
|
11 *
|
|
12 * @see Connection#setDHGexParameters(DHGexParameters)
|
|
13 * @author Christian Plattner, plattner@trilead.com
|
|
14 * @version $Id: DHGexParameters.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $
|
|
15 */
|
|
16
|
|
17 public class DHGexParameters {
|
|
18 private final int min_group_len;
|
|
19 private final int pref_group_len;
|
|
20 private final int max_group_len;
|
|
21
|
|
22 private static final int MIN_ALLOWED = 1024;
|
|
23 private static final int MAX_ALLOWED = 8192;
|
|
24
|
|
25 /**
|
|
26 * Same as calling {@link #DHGexParameters(int, int, int) DHGexParameters(1024, 1024, 4096)}.
|
|
27 * This is also the default used by the Connection class.
|
|
28 *
|
|
29 */
|
|
30 public DHGexParameters() {
|
|
31 this(1024, 1024, 4096);
|
|
32 }
|
|
33
|
|
34 /**
|
|
35 * This constructor can be used to force the sending of a
|
|
36 * <code>SSH_MSG_KEX_DH_GEX_REQUEST_OLD</code> request.
|
|
37 * Internally, the minimum and maximum group lengths will
|
|
38 * be set to zero.
|
|
39 *
|
|
40 * @param pref_group_len has to be >= 1024 and <= 8192
|
|
41 */
|
|
42 public DHGexParameters(int pref_group_len) {
|
|
43 if ((pref_group_len < MIN_ALLOWED) || (pref_group_len > MAX_ALLOWED))
|
|
44 throw new IllegalArgumentException("pref_group_len out of range!");
|
|
45
|
|
46 this.pref_group_len = pref_group_len;
|
|
47 this.min_group_len = 0;
|
|
48 this.max_group_len = 0;
|
|
49 }
|
|
50
|
|
51 /**
|
|
52 * This constructor can be used to force the sending of a
|
|
53 * <code>SSH_MSG_KEX_DH_GEX_REQUEST</code> request.
|
|
54 * <p>
|
|
55 * Note: older OpenSSH servers don't understand this request, in which
|
|
56 * case you should use the {@link #DHGexParameters(int)} constructor.
|
|
57 * <p>
|
|
58 * All values have to be >= 1024 and <= 8192. Furthermore,
|
|
59 * min_group_len <= pref_group_len <= max_group_len.
|
|
60 *
|
|
61 * @param min_group_len
|
|
62 * @param pref_group_len
|
|
63 * @param max_group_len
|
|
64 */
|
|
65 public DHGexParameters(int min_group_len, int pref_group_len, int max_group_len) {
|
|
66 if ((min_group_len < MIN_ALLOWED) || (min_group_len > MAX_ALLOWED))
|
|
67 throw new IllegalArgumentException("min_group_len out of range!");
|
|
68
|
|
69 if ((pref_group_len < MIN_ALLOWED) || (pref_group_len > MAX_ALLOWED))
|
|
70 throw new IllegalArgumentException("pref_group_len out of range!");
|
|
71
|
|
72 if ((max_group_len < MIN_ALLOWED) || (max_group_len > MAX_ALLOWED))
|
|
73 throw new IllegalArgumentException("max_group_len out of range!");
|
|
74
|
|
75 if ((pref_group_len < min_group_len) || (pref_group_len > max_group_len))
|
|
76 throw new IllegalArgumentException("pref_group_len is incompatible with min and max!");
|
|
77
|
|
78 if (max_group_len < min_group_len)
|
|
79 throw new IllegalArgumentException("max_group_len must not be smaller than min_group_len!");
|
|
80
|
|
81 this.min_group_len = min_group_len;
|
|
82 this.pref_group_len = pref_group_len;
|
|
83 this.max_group_len = max_group_len;
|
|
84 }
|
|
85
|
|
86 /**
|
|
87 * Get the maximum group length.
|
|
88 *
|
|
89 * @return the maximum group length, may be <code>zero</code> if
|
|
90 * SSH_MSG_KEX_DH_GEX_REQUEST_OLD should be requested
|
|
91 */
|
|
92 public int getMax_group_len() {
|
|
93 return max_group_len;
|
|
94 }
|
|
95
|
|
96 /**
|
|
97 * Get the minimum group length.
|
|
98 *
|
|
99 * @return minimum group length, may be <code>zero</code> if
|
|
100 * SSH_MSG_KEX_DH_GEX_REQUEST_OLD should be requested
|
|
101 */
|
|
102 public int getMin_group_len() {
|
|
103 return min_group_len;
|
|
104 }
|
|
105
|
|
106 /**
|
|
107 * Get the preferred group length.
|
|
108 *
|
|
109 * @return the preferred group length
|
|
110 */
|
|
111 public int getPref_group_len() {
|
|
112 return pref_group_len;
|
|
113 }
|
|
114 }
|