Mercurial > 510Connectbot
annotate app/src/main/java/ch/ethz/ssh2/DHGexParameters.java @ 520:e6fa2c27140f
add more debug code
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Fri, 31 May 2024 14:37:18 -0600 |
parents | d29cce60f393 |
children |
rev | line source |
---|---|
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
1 /* |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
2 * Copyright (c) 2006-2011 Christian Plattner. All rights reserved. |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
3 * Please refer to the LICENSE.txt for licensing details. |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
4 */ |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
5 package ch.ethz.ssh2; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
6 |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
7 /** |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
8 * A <code>DHGexParameters</code> object can be used to specify parameters for |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
9 * the diffie-hellman group exchange. |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
10 * <p> |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
11 * Depending on which constructor is used, either the use of a |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
12 * <code>SSH_MSG_KEX_DH_GEX_REQUEST</code> or <code>SSH_MSG_KEX_DH_GEX_REQUEST_OLD</code> |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
13 * can be forced. |
307 | 14 * |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
15 * @see Connection#setDHGexParameters(DHGexParameters) |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
16 * @author Christian Plattner |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
17 * @version 2.50, 03/15/10 |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
18 */ |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
19 |
307 | 20 public class DHGexParameters { |
21 private final int min_group_len; | |
22 private final int pref_group_len; | |
23 private final int max_group_len; | |
24 | |
25 private static final int MIN_ALLOWED = 1024; | |
26 private static final int MAX_ALLOWED = 8192; | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
27 |
307 | 28 /** |
29 * Same as calling {@link #DHGexParameters(int, int, int) DHGexParameters(1024, 1024, 4096)}. | |
30 * This is also the default used by the Connection class. | |
31 * | |
32 */ | |
33 public DHGexParameters() { | |
34 this(1024, 1024, 4096); | |
35 } | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
36 |
307 | 37 /** |
38 * This constructor can be used to force the sending of a | |
39 * <code>SSH_MSG_KEX_DH_GEX_REQUEST_OLD</code> request. | |
40 * Internally, the minimum and maximum group lengths will | |
41 * be set to zero. | |
42 * | |
43 * @param pref_group_len has to be >= 1024 and <= 8192 | |
44 */ | |
45 public DHGexParameters(int pref_group_len) { | |
46 if ((pref_group_len < MIN_ALLOWED) || (pref_group_len > MAX_ALLOWED)) | |
47 throw new IllegalArgumentException("pref_group_len out of range!"); | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
48 |
307 | 49 this.pref_group_len = pref_group_len; |
50 this.min_group_len = 0; | |
51 this.max_group_len = 0; | |
52 } | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
53 |
307 | 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 >= 1024 and <= 8192. Furthermore, | |
62 * min_group_len <= pref_group_len <= 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 if ((min_group_len < MIN_ALLOWED) || (min_group_len > MAX_ALLOWED)) | |
70 throw new IllegalArgumentException("min_group_len out of range!"); | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
71 |
307 | 72 if ((pref_group_len < MIN_ALLOWED) || (pref_group_len > MAX_ALLOWED)) |
73 throw new IllegalArgumentException("pref_group_len out of range!"); | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
74 |
307 | 75 if ((max_group_len < MIN_ALLOWED) || (max_group_len > MAX_ALLOWED)) |
76 throw new IllegalArgumentException("max_group_len out of range!"); | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
77 |
307 | 78 if ((pref_group_len < min_group_len) || (pref_group_len > max_group_len)) |
79 throw new IllegalArgumentException("pref_group_len is incompatible with min and max!"); | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
80 |
307 | 81 if (max_group_len < min_group_len) |
82 throw new IllegalArgumentException("max_group_len must not be smaller than min_group_len!"); | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
83 |
307 | 84 this.min_group_len = min_group_len; |
85 this.pref_group_len = pref_group_len; | |
86 this.max_group_len = max_group_len; | |
87 } | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
88 |
307 | 89 /** |
90 * Get the maximum group length. | |
91 * | |
92 * @return the maximum group length, may be <code>zero</code> if | |
93 * SSH_MSG_KEX_DH_GEX_REQUEST_OLD should be requested | |
94 */ | |
95 public int getMax_group_len() { | |
96 return max_group_len; | |
97 } | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
98 |
307 | 99 /** |
100 * Get the minimum group length. | |
101 * | |
102 * @return minimum group length, may be <code>zero</code> if | |
103 * SSH_MSG_KEX_DH_GEX_REQUEST_OLD should be requested | |
104 */ | |
105 public int getMin_group_len() { | |
106 return min_group_len; | |
107 } | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
108 |
307 | 109 /** |
110 * Get the preferred group length. | |
111 * | |
112 * @return the preferred group length | |
113 */ | |
114 public int getPref_group_len() { | |
115 return pref_group_len; | |
116 } | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
117 } |