comparison src/ch/ethz/ssh2/DHGexParameters.java @ 273:91a31873c42a ganymed

start conversion from trilead to ganymed
author Carl Byington <carl@five-ten-sg.com>
date Fri, 18 Jul 2014 11:21:46 -0700
parents
children 071eccdff8ea
comparison
equal deleted inserted replaced
272:ce2f4e397703 273:91a31873c42a
1 /*
2 * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 * Please refer to the LICENSE.txt for licensing details.
4 */
5 package ch.ethz.ssh2;
6
7 /**
8 * A <code>DHGexParameters</code> object can be used to specify parameters for
9 * the diffie-hellman group exchange.
10 * <p>
11 * Depending on which constructor is used, either the use of a
12 * <code>SSH_MSG_KEX_DH_GEX_REQUEST</code> or <code>SSH_MSG_KEX_DH_GEX_REQUEST_OLD</code>
13 * can be forced.
14 *
15 * @see Connection#setDHGexParameters(DHGexParameters)
16 * @author Christian Plattner
17 * @version 2.50, 03/15/10
18 */
19
20 public class DHGexParameters
21 {
22 private final int min_group_len;
23 private final int pref_group_len;
24 private final int max_group_len;
25
26 private static final int MIN_ALLOWED = 1024;
27 private static final int MAX_ALLOWED = 8192;
28
29 /**
30 * Same as calling {@link #DHGexParameters(int, int, int) DHGexParameters(1024, 1024, 4096)}.
31 * This is also the default used by the Connection class.
32 *
33 */
34 public DHGexParameters()
35 {
36 this(1024, 1024, 4096);
37 }
38
39 /**
40 * This constructor can be used to force the sending of a
41 * <code>SSH_MSG_KEX_DH_GEX_REQUEST_OLD</code> request.
42 * Internally, the minimum and maximum group lengths will
43 * be set to zero.
44 *
45 * @param pref_group_len has to be &gt= 1024 and &lt;= 8192
46 */
47 public DHGexParameters(int pref_group_len)
48 {
49 if ((pref_group_len < MIN_ALLOWED) || (pref_group_len > MAX_ALLOWED))
50 throw new IllegalArgumentException("pref_group_len out of range!");
51
52 this.pref_group_len = pref_group_len;
53 this.min_group_len = 0;
54 this.max_group_len = 0;
55 }
56
57 /**
58 * This constructor can be used to force the sending of a
59 * <code>SSH_MSG_KEX_DH_GEX_REQUEST</code> request.
60 * <p>
61 * Note: older OpenSSH servers don't understand this request, in which
62 * case you should use the {@link #DHGexParameters(int)} constructor.
63 * <p>
64 * All values have to be &gt= 1024 and &lt;= 8192. Furthermore,
65 * min_group_len &lt;= pref_group_len &lt;= max_group_len.
66 *
67 * @param min_group_len
68 * @param pref_group_len
69 * @param max_group_len
70 */
71 public DHGexParameters(int min_group_len, int pref_group_len, int max_group_len)
72 {
73 if ((min_group_len < MIN_ALLOWED) || (min_group_len > MAX_ALLOWED))
74 throw new IllegalArgumentException("min_group_len out of range!");
75
76 if ((pref_group_len < MIN_ALLOWED) || (pref_group_len > MAX_ALLOWED))
77 throw new IllegalArgumentException("pref_group_len out of range!");
78
79 if ((max_group_len < MIN_ALLOWED) || (max_group_len > MAX_ALLOWED))
80 throw new IllegalArgumentException("max_group_len out of range!");
81
82 if ((pref_group_len < min_group_len) || (pref_group_len > max_group_len))
83 throw new IllegalArgumentException("pref_group_len is incompatible with min and max!");
84
85 if (max_group_len < min_group_len)
86 throw new IllegalArgumentException("max_group_len must not be smaller than min_group_len!");
87
88 this.min_group_len = min_group_len;
89 this.pref_group_len = pref_group_len;
90 this.max_group_len = max_group_len;
91 }
92
93 /**
94 * Get the maximum group length.
95 *
96 * @return the maximum group length, may be <code>zero</code> if
97 * SSH_MSG_KEX_DH_GEX_REQUEST_OLD should be requested
98 */
99 public int getMax_group_len()
100 {
101 return max_group_len;
102 }
103
104 /**
105 * Get the minimum group length.
106 *
107 * @return minimum group length, may be <code>zero</code> if
108 * SSH_MSG_KEX_DH_GEX_REQUEST_OLD should be requested
109 */
110 public int getMin_group_len()
111 {
112 return min_group_len;
113 }
114
115 /**
116 * Get the preferred group length.
117 *
118 * @return the preferred group length
119 */
120 public int getPref_group_len()
121 {
122 return pref_group_len;
123 }
124 }