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.common.ui;
27
28 import com.sshtools.common.configuration.SshToolsConnectionProfile;
29
30 import com.sshtools.j2ssh.transport.cipher.SshCipherFactory;
31 import com.sshtools.j2ssh.transport.compression.SshCompressionFactory;
32 import com.sshtools.j2ssh.transport.hmac.SshHmacFactory;
33 import com.sshtools.j2ssh.transport.kex.SshKeyExchangeFactory;
34 import com.sshtools.j2ssh.transport.publickey.SshKeyPairFactory;
35
36 import java.awt.Component;
37 import java.awt.GridBagConstraints;
38 import java.awt.GridBagLayout;
39 import java.awt.Insets;
40
41 import java.util.Iterator;
42
43 import javax.swing.BorderFactory;
44 import javax.swing.Icon;
45 import javax.swing.JComboBox;
46 import javax.swing.JLabel;
47 import javax.swing.JPanel;
48 import javax.swing.JSeparator;
49
50
51 /**
52 *
53 *
54 * @author $author$
55 * @version $Revision: 1.15 $
56 */
57 public class SshToolsConnectionProtocolTab extends JPanel
58 implements SshToolsConnectionTab {
59 final static String KEYS_ICON = "/com/sshtools/common/ui/largekeys.png";
60 final static String PROTOCOL_ICON = "/com/sshtools/common/ui/largeprotocol.png";
61 final static String DEFAULT = "<Default>";
62
63 //
64
65 /** */
66 protected JComboBox jComboCipherCS = new JComboBox();
67
68 /** */
69 protected JComboBox jComboCipherSC = new JComboBox();
70
71 /** */
72 protected JComboBox jComboMacCS = new JComboBox();
73
74 /** */
75 protected JComboBox jComboMacSC = new JComboBox();
76
77 /** */
78 protected JComboBox jComboCompCS = new JComboBox();
79
80 /** */
81 protected JComboBox jComboCompSC = new JComboBox();
82
83 /** */
84 protected JComboBox jComboKex = new JComboBox();
85
86 /** */
87 protected JComboBox jComboPK = new JComboBox();
88
89 /** */
90 protected SshToolsConnectionProfile profile;
91
92 /**
93 * Creates a new SshToolsConnectionProtocolTab object.
94 */
95 public SshToolsConnectionProtocolTab() {
96 super();
97
98 // Keys
99 JPanel keysPanel = new JPanel(new GridBagLayout());
100 GridBagConstraints gbc = new GridBagConstraints();
101 gbc.fill = GridBagConstraints.NONE;
102 gbc.anchor = GridBagConstraints.WEST;
103 gbc.insets = new Insets(2, 2, 2, 2);
104 gbc.weightx = 1.0;
105
106 // Public key
107 UIUtil.jGridBagAdd(keysPanel, new JLabel("Public key"), gbc,
108 GridBagConstraints.REMAINDER);
109 gbc.fill = GridBagConstraints.HORIZONTAL;
110 UIUtil.jGridBagAdd(keysPanel, jComboPK, gbc,
111 GridBagConstraints.REMAINDER);
112 gbc.fill = GridBagConstraints.NONE;
113
114 // Public key
115 UIUtil.jGridBagAdd(keysPanel, new JLabel("Key exchange"), gbc,
116 GridBagConstraints.REMAINDER);
117 gbc.fill = GridBagConstraints.HORIZONTAL;
118 UIUtil.jGridBagAdd(keysPanel, jComboKex, gbc,
119 GridBagConstraints.REMAINDER);
120 gbc.fill = GridBagConstraints.NONE;
121
122 //
123 IconWrapperPanel iconKeysPanel = new IconWrapperPanel(new ResourceIcon(
124 KEYS_ICON), keysPanel);
125
126 // Preferences
127 JPanel prefPanel = new JPanel(new GridBagLayout());
128 prefPanel.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0));
129 gbc = new GridBagConstraints();
130 gbc.fill = GridBagConstraints.NONE;
131 gbc.anchor = GridBagConstraints.WEST;
132 gbc.insets = new Insets(2, 2, 2, 2);
133 gbc.weightx = 1.0;
134
135 // Public key
136 gbc.fill = GridBagConstraints.HORIZONTAL;
137 UIUtil.jGridBagAdd(prefPanel, new JLabel("Client - > Server"), gbc,
138 GridBagConstraints.RELATIVE);
139 UIUtil.jGridBagAdd(prefPanel, new JLabel("Server - > Client"), gbc,
140 GridBagConstraints.REMAINDER);
141
142 // Separator
143 gbc.weightx = 2.0;
144 UIUtil.jGridBagAdd(prefPanel, new JSeparator(JSeparator.HORIZONTAL),
145 gbc, GridBagConstraints.REMAINDER);
146
147 // Cipher
148 UIUtil.jGridBagAdd(prefPanel, new JLabel("Cipher"), gbc,
149 GridBagConstraints.RELATIVE);
150 UIUtil.jGridBagAdd(prefPanel, new JLabel("Cipher"), gbc,
151 GridBagConstraints.REMAINDER);
152 UIUtil.jGridBagAdd(prefPanel, jComboCipherCS, gbc,
153 GridBagConstraints.RELATIVE);
154 UIUtil.jGridBagAdd(prefPanel, jComboCipherSC, gbc,
155 GridBagConstraints.REMAINDER);
156
157 // Mac
158 UIUtil.jGridBagAdd(prefPanel, new JLabel("Mac"), gbc,
159 GridBagConstraints.RELATIVE);
160 UIUtil.jGridBagAdd(prefPanel, new JLabel("Mac"), gbc,
161 GridBagConstraints.REMAINDER);
162 UIUtil.jGridBagAdd(prefPanel, jComboMacCS, gbc,
163 GridBagConstraints.RELATIVE);
164 UIUtil.jGridBagAdd(prefPanel, jComboMacSC, gbc,
165 GridBagConstraints.REMAINDER);
166
167 // Compression
168 UIUtil.jGridBagAdd(prefPanel, new JLabel("Compression"), gbc,
169 GridBagConstraints.RELATIVE);
170 UIUtil.jGridBagAdd(prefPanel, new JLabel("Compression"), gbc,
171 GridBagConstraints.REMAINDER);
172 UIUtil.jGridBagAdd(prefPanel, jComboCompCS, gbc,
173 GridBagConstraints.RELATIVE);
174 UIUtil.jGridBagAdd(prefPanel, jComboCompSC, gbc,
175 GridBagConstraints.REMAINDER);
176
177 //
178 IconWrapperPanel iconPrefPanel = new IconWrapperPanel(new ResourceIcon(
179 PROTOCOL_ICON), prefPanel);
180
181 // This tab
182 setLayout(new GridBagLayout());
183 setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
184 gbc = new GridBagConstraints();
185 gbc.fill = GridBagConstraints.NONE;
186 gbc.anchor = GridBagConstraints.WEST;
187 gbc.insets = new Insets(2, 2, 2, 2);
188 gbc.weightx = 1.0;
189 UIUtil.jGridBagAdd(this, iconKeysPanel, gbc,
190 GridBagConstraints.REMAINDER);
191 gbc.weighty = 1.0;
192 UIUtil.jGridBagAdd(this, iconPrefPanel, gbc,
193 GridBagConstraints.REMAINDER);
194
195 //
196 loadList(SshCipherFactory.getSupportedCiphers(), jComboCipherCS, true);
197 loadList(SshCipherFactory.getSupportedCiphers(), jComboCipherSC, true);
198 loadList(SshHmacFactory.getSupportedMacs(), jComboMacCS, true);
199 loadList(SshHmacFactory.getSupportedMacs(), jComboMacSC, true);
200 loadList(SshCompressionFactory.getSupportedCompression(), jComboCompCS,
201 true);
202 loadList(SshCompressionFactory.getSupportedCompression(), jComboCompSC,
203 true);
204 loadList(SshKeyExchangeFactory.getSupportedKeyExchanges(), jComboKex,
205 true);
206 loadList(SshKeyPairFactory.getSupportedKeys(), jComboPK, true);
207 }
208
209 /**
210 *
211 *
212 * @param profile
213 */
214 public void setConnectionProfile(SshToolsConnectionProfile profile) {
215 this.profile = profile;
216 jComboCipherCS.setSelectedItem(profile.getPrefCSEncryption());
217 jComboCipherSC.setSelectedItem(profile.getPrefSCEncryption());
218 jComboMacCS.setSelectedItem(profile.getPrefCSMac());
219 jComboMacSC.setSelectedItem(profile.getPrefSCMac());
220 jComboCompCS.setSelectedItem(profile.getPrefCSComp());
221 jComboCompSC.setSelectedItem(profile.getPrefSCComp());
222 jComboKex.setSelectedItem(profile.getPrefKex());
223 jComboPK.setSelectedItem(profile.getPrefPublicKey());
224 }
225
226 /**
227 *
228 *
229 * @return
230 */
231 public SshToolsConnectionProfile getConnectionProfile() {
232 return profile;
233 }
234
235 private void loadList(java.util.List list, JComboBox combo,
236 boolean addDefault) {
237 Iterator it = list.iterator();
238
239 if (addDefault) {
240 combo.addItem(DEFAULT);
241 }
242
243 while (it.hasNext()) {
244 combo.addItem(it.next());
245 }
246 }
247
248 /**
249 *
250 *
251 * @return
252 */
253 public String getTabContext() {
254 return "Connection";
255 }
256
257 /**
258 *
259 *
260 * @return
261 */
262 public Icon getTabIcon() {
263 return null;
264 }
265
266 /**
267 *
268 *
269 * @return
270 */
271 public String getTabTitle() {
272 return "Protocol";
273 }
274
275 /**
276 *
277 *
278 * @return
279 */
280 public String getTabToolTipText() {
281 return "Protocol related properties.";
282 }
283
284 /**
285 *
286 *
287 * @return
288 */
289 public int getTabMnemonic() {
290 return 'p';
291 }
292
293 /**
294 *
295 *
296 * @return
297 */
298 public Component getTabComponent() {
299 return this;
300 }
301
302 /**
303 *
304 *
305 * @return
306 */
307 public boolean validateTab() {
308 return true;
309 }
310
311 /**
312 *
313 */
314 public void applyTab() {
315 // Get the algorithm preferences
316 if (!jComboCipherCS.getSelectedItem().equals(DEFAULT)) {
317 profile.setPrefCSEncryption((String) jComboCipherCS.getSelectedItem());
318 }
319
320 if (!jComboCipherSC.getSelectedItem().equals(DEFAULT)) {
321 profile.setPrefSCEncryption((String) jComboCipherSC.getSelectedItem());
322 }
323
324 if (!jComboMacCS.getSelectedItem().equals(DEFAULT)) {
325 profile.setPrefCSMac((String) jComboMacCS.getSelectedItem());
326 }
327
328 if (!jComboMacSC.getSelectedItem().equals(DEFAULT)) {
329 profile.setPrefSCMac((String) jComboMacSC.getSelectedItem());
330 }
331
332 if (!jComboCompCS.getSelectedItem().equals(DEFAULT)) {
333 profile.setPrefCSComp((String) jComboCompCS.getSelectedItem());
334 }
335
336 if (!jComboCompSC.getSelectedItem().equals(DEFAULT)) {
337 profile.setPrefSCComp((String) jComboCompSC.getSelectedItem());
338 }
339
340 if (!jComboKex.getSelectedItem().equals(DEFAULT)) {
341 profile.setPrefKex((String) jComboKex.getSelectedItem());
342 }
343
344 if (!jComboPK.getSelectedItem().equals(DEFAULT)) {
345 profile.setPrefPublicKey((String) jComboPK.getSelectedItem());
346 }
347 }
348
349 /**
350 *
351 */
352 public void tabSelected() {
353 }
354 }