1 /*
2 * SSHTools - Java SSH2 API
3 *
4 * Copyright (C) 2002-2003 Lee David Painter and Contributors.
5 *
6 * Contributions made by:
7 *
8 * Brett Smith
9 * Richard Pernavas
10 * Erwin Bolwidt
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 */
26 package com.sshtools.j2ssh.configuration;
27
28 import com.sshtools.j2ssh.forwarding.ForwardingConfiguration;
29 import com.sshtools.j2ssh.transport.cipher.SshCipherFactory;
30 import com.sshtools.j2ssh.transport.compression.SshCompressionFactory;
31 import com.sshtools.j2ssh.transport.hmac.SshHmacFactory;
32 import com.sshtools.j2ssh.transport.kex.SshKeyExchangeFactory;
33 import com.sshtools.j2ssh.transport.publickey.SshKeyPairFactory;
34
35 import org.apache.commons.logging.Log;
36 import org.apache.commons.logging.LogFactory;
37
38 import java.util.HashMap;
39 import java.util.Map;
40
41
42 /**
43 *
44 *
45 * @author $author$
46 * @version $Revision: 1.27 $
47 */
48 public class SshConnectionProperties {
49 private static Log log = LogFactory.getLog(SshConnectionProperties.class);
50
51 /** */
52 public static final int USE_STANDARD_SOCKET = 1;
53
54 /** */
55 public static final int USE_HTTP_PROXY = 2;
56
57 /** */
58 public static final int USE_SOCKS4_PROXY = 3;
59
60 /** */
61 public static final int USE_SOCKS5_PROXY = 4;
62
63 /** */
64 protected int transportProvider = USE_STANDARD_SOCKET;
65
66 /** */
67 protected String proxyHostname;
68
69 /** */
70 protected int proxyPort;
71
72 /** */
73 protected String proxyUsername;
74
75 /** */
76 protected String proxyPassword;
77
78 /** */
79 protected String host;
80
81 /** */
82 protected String prefDecryption = SshCipherFactory.getDefaultCipher();
83
84 /** */
85 protected String prefEncryption = SshCipherFactory.getDefaultCipher();
86
87 /** */
88 protected String prefKex = SshKeyExchangeFactory.getDefaultKeyExchange();
89
90 /** */
91 protected String prefPK = SshKeyPairFactory.getDefaultPublicKey();
92
93 /** */
94 protected String prefRecvComp = SshCompressionFactory.getDefaultCompression();
95
96 /** */
97 protected String prefRecvMac = SshHmacFactory.getDefaultHmac();
98
99 /** */
100 protected String prefSendComp = SshCompressionFactory.getDefaultCompression();
101
102 /** */
103 protected String prefSendMac = SshHmacFactory.getDefaultHmac();
104
105 /** */
106 protected String username;
107
108 /** */
109 protected int port = 22;
110 protected Map localForwardings = new HashMap();
111 protected Map remoteForwardings = new HashMap();
112 protected boolean forwardingAutoStart = false;
113
114 /**
115 * Creates a new SshConnectionProperties object.
116 */
117 public SshConnectionProperties() {
118 }
119
120 /**
121 *
122 *
123 * @param host
124 */
125 public void setHost(String host) {
126 this.host = host;
127 }
128
129 /**
130 *
131 *
132 * @return
133 */
134 public String getHost() {
135 return host;
136 }
137
138 /**
139 *
140 *
141 * @param port
142 */
143 public void setPort(int port) {
144 this.port = port;
145 }
146
147 /**
148 *
149 *
150 * @return
151 */
152 public int getPort() {
153 return port;
154 }
155
156 /**
157 *
158 *
159 * @return
160 */
161 public int getTransportProvider() {
162 return transportProvider;
163 }
164
165 /**
166 *
167 *
168 * @param name
169 */
170 public void setTransportProviderString(String name) {
171 if (name != null) {
172 if (name.equalsIgnoreCase("http")) {
173 transportProvider = USE_HTTP_PROXY;
174 } else if (name.equalsIgnoreCase("socks4")) {
175 transportProvider = USE_SOCKS4_PROXY;
176 } else if (name.equalsIgnoreCase("socks5")) {
177 transportProvider = USE_SOCKS5_PROXY;
178 } else {
179 transportProvider = USE_STANDARD_SOCKET;
180 }
181 } else {
182 transportProvider = USE_STANDARD_SOCKET;
183 }
184 }
185
186 /**
187 *
188 *
189 * @return
190 */
191 public String getTransportProviderString() {
192 if (transportProvider == USE_HTTP_PROXY) {
193 return "http";
194 } else if (transportProvider == USE_SOCKS4_PROXY) {
195 return "socks4";
196 } else if (transportProvider == USE_SOCKS5_PROXY) {
197 return "socks5";
198 } else {
199 return "socket";
200 }
201 }
202
203 /**
204 *
205 *
206 * @return
207 */
208 public String getProxyHost() {
209 return proxyHostname;
210 }
211
212 public void removeAllForwardings() {
213 localForwardings.clear();
214 remoteForwardings.clear();
215 }
216
217 /**
218 *
219 *
220 * @return
221 */
222 public int getProxyPort() {
223 return proxyPort;
224 }
225
226 /**
227 *
228 *
229 * @return
230 */
231 public String getProxyUsername() {
232 return proxyUsername;
233 }
234
235 /**
236 *
237 *
238 * @return
239 */
240 public String getProxyPassword() {
241 return proxyPassword;
242 }
243
244 /**
245 *
246 *
247 * @param transportProvider
248 */
249 public void setTransportProvider(int transportProvider) {
250 this.transportProvider = transportProvider;
251 }
252
253 /**
254 *
255 *
256 * @param proxyHostname
257 */
258 public void setProxyHost(String proxyHostname) {
259 this.proxyHostname = proxyHostname;
260 }
261
262 /**
263 *
264 *
265 * @param proxyPort
266 */
267 public void setProxyPort(int proxyPort) {
268 this.proxyPort = proxyPort;
269 }
270
271 /**
272 *
273 *
274 * @param proxyUsername
275 */
276 public void setProxyUsername(String proxyUsername) {
277 this.proxyUsername = proxyUsername;
278 }
279
280 /**
281 *
282 *
283 * @param proxyPassword
284 */
285 public void setProxyPassword(String proxyPassword) {
286 this.proxyPassword = proxyPassword;
287 }
288
289 /**
290 *
291 *
292 * @param pref
293 */
294 public void setPrefCSComp(String pref) {
295 prefSendComp = pref;
296 }
297
298 /**
299 *
300 *
301 * @return
302 */
303 public String getPrefCSComp() {
304 return prefSendComp;
305 }
306
307 /**
308 *
309 *
310 * @param pref
311 */
312 public void setPrefCSEncryption(String pref) {
313 prefEncryption = pref;
314 }
315
316 /**
317 *
318 *
319 * @return
320 */
321 public String getPrefCSEncryption() {
322 return prefEncryption;
323 }
324
325 /**
326 *
327 *
328 * @param pref
329 */
330 public void setPrefCSMac(String pref) {
331 prefSendMac = pref;
332 }
333
334 /**
335 *
336 *
337 * @return
338 */
339 public String getPrefCSMac() {
340 return prefSendMac;
341 }
342
343 /**
344 *
345 *
346 * @param pref
347 */
348 public void setPrefKex(String pref) {
349 prefKex = pref;
350 }
351
352 /**
353 *
354 *
355 * @return
356 */
357 public String getPrefKex() {
358 return prefKex;
359 }
360
361 /**
362 *
363 *
364 * @param pref
365 */
366 public void setPrefPublicKey(String pref) {
367 prefPK = pref;
368 }
369
370 /**
371 *
372 *
373 * @return
374 */
375 public String getPrefPublicKey() {
376 return prefPK;
377 }
378
379 /**
380 *
381 *
382 * @param pref
383 */
384 public void setPrefSCComp(String pref) {
385 prefRecvComp = pref;
386 }
387
388 /**
389 *
390 *
391 * @return
392 */
393 public String getPrefSCComp() {
394 return prefRecvComp;
395 }
396
397 /**
398 *
399 *
400 * @param pref
401 */
402 public void setPrefSCEncryption(String pref) {
403 prefDecryption = pref;
404 }
405
406 /**
407 *
408 *
409 * @return
410 */
411 public String getPrefSCEncryption() {
412 return prefDecryption;
413 }
414
415 public Map getLocalForwardings() {
416 return localForwardings;
417 }
418
419 public Map getRemoteForwardings() {
420 return remoteForwardings;
421 }
422
423 public void addLocalForwarding(ForwardingConfiguration cf) {
424 localForwardings.put(cf.getName(), cf);
425 }
426
427 public void addRemoteForwarding(ForwardingConfiguration cf) {
428 remoteForwardings.put(cf.getName(), cf);
429 }
430
431 public boolean getForwardingAutoStartMode() {
432 return forwardingAutoStart;
433 }
434
435 public void setForwardingAutoStartMode(boolean forwardingAutoStart) {
436 this.forwardingAutoStart = forwardingAutoStart;
437 }
438
439 /**
440 *
441 *
442 * @param pref
443 */
444 public void setPrefSCMac(String pref) {
445 prefRecvMac = pref;
446 }
447
448 /**
449 *
450 *
451 * @return
452 */
453 public String getPrefSCMac() {
454 return prefRecvMac;
455 }
456
457 /**
458 *
459 *
460 * @param username
461 */
462 public void setUsername(String username) {
463 this.username = username;
464 }
465
466 /**
467 *
468 *
469 * @return
470 */
471 public String getUsername() {
472 return username;
473 }
474 }