KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ch > ethz > ssh2 > DHGexParameters


1
2 package ch.ethz.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@inf.ethz.ch
14  * @version $Id: DHGexParameters.java,v 1.3 2006/09/20 12:51:37 cplattne Exp $
15  */

16
17 public class DHGexParameters
18 {
19     private final int min_group_len;
20     private final int pref_group_len;
21     private final int max_group_len;
22
23     private static final int MIN_ALLOWED = 1024;
24     private static final int MAX_ALLOWED = 8192;
25
26     /**
27      * Same as calling {@link #DHGexParameters(int, int, int) DHGexParameters(1024, 1024, 4096)}.
28      * This is also the default used by the Connection class.
29      *
30      */

31     public DHGexParameters()
32     {
33         this(1024, 1024, 4096);
34     }
35
36     /**
37      * This constructor can be used to force the sending of a
38      * <code>SSH_MSG_KEX_DH_GEX_REQUEST_OLD</code> request.
39      * Internally, the minimum and maximum group lengths will
40      * be set to zero.
41      *
42      * @param pref_group_len has to be &gt= 1024 and &lt;= 8192
43      */

44     public DHGexParameters(int pref_group_len)
45     {
46         if ((pref_group_len < MIN_ALLOWED) || (pref_group_len > MAX_ALLOWED))
47             throw new IllegalArgumentException JavaDoc("pref_group_len out of range!");
48
49         this.pref_group_len = pref_group_len;
50         this.min_group_len = 0;
51         this.max_group_len = 0;
52     }
53
54     /**
55      * This constructor can be used to force the sending of a
56      * <code>SSH_MSG_KEX_DH_GEX_REQUEST</code> request.
57      * <p>
58      * Note: older OpenSSH servers don't understand this request, in which
59      * case you should use the {@link #DHGexParameters(int)} constructor.
60      * <p>
61      * All values have to be &gt= 1024 and &lt;= 8192. Furthermore,
62      * min_group_len &lt;= pref_group_len &lt;= max_group_len.
63      *
64      * @param min_group_len
65      * @param pref_group_len
66      * @param max_group_len
67      */

68     public DHGexParameters(int min_group_len, int pref_group_len, int max_group_len)
69     {
70         if ((min_group_len < MIN_ALLOWED) || (min_group_len > MAX_ALLOWED))
71             throw new IllegalArgumentException JavaDoc("min_group_len out of range!");
72
73         if ((pref_group_len < MIN_ALLOWED) || (pref_group_len > MAX_ALLOWED))
74             throw new IllegalArgumentException JavaDoc("pref_group_len out of range!");
75
76         if ((max_group_len < MIN_ALLOWED) || (max_group_len > MAX_ALLOWED))
77             throw new IllegalArgumentException JavaDoc("max_group_len out of range!");
78
79         if ((pref_group_len < min_group_len) || (pref_group_len > max_group_len))
80             throw new IllegalArgumentException JavaDoc("pref_group_len is incompatible with min and max!");
81
82         if (max_group_len < min_group_len)
83             throw new IllegalArgumentException JavaDoc("max_group_len must not be smaller than min_group_len!");
84
85         this.min_group_len = min_group_len;
86         this.pref_group_len = pref_group_len;
87         this.max_group_len = max_group_len;
88     }
89
90     /**
91      * Get the maximum group length.
92      *
93      * @return the maximum group length, may be <code>zero</code> if
94      * SSH_MSG_KEX_DH_GEX_REQUEST_OLD should be requested
95      */

96     public int getMax_group_len()
97     {
98         return max_group_len;
99     }
100
101     /**
102      * Get the minimum group length.
103      *
104      * @return minimum group length, may be <code>zero</code> if
105      * SSH_MSG_KEX_DH_GEX_REQUEST_OLD should be requested
106      */

107     public int getMin_group_len()
108     {
109         return min_group_len;
110     }
111
112     /**
113      * Get the preferred group length.
114      *
115      * @return the preferred group length
116      */

117     public int getPref_group_len()
118     {
119         return pref_group_len;
120     }
121 }
122
Popular Tags