1 package com.ca.directory.jxplorer; 2 3 4 import com.ca.commons.cbutil.*; 5 import java.awt.Frame ; 6 import java.util.*; 7 import javax.swing.*; 8 import java.awt.Dimension ; 9 import javax.swing.border.TitledBorder ; 10 11 import java.security.Provider ; 12 import java.security.Security ; 13 14 25 26 public class KeystoreOptions extends CBDialog 27 { 28 29 32 33 private String caStore, clientStore; 34 35 38 39 CBFileChooserButton caChooser, clientChooser; 40 41 44 45 JTextField caKeystoreLocationText, clientKeystoreLocationText; 46 47 48 51 52 CBJComboBox caTypeCombo, clientTypeCombo; 53 54 private JTextField clientKeystore, trustedServerKeystore; 55 56 57 private boolean debug = false; 58 59 62 63 private Properties properties; 64 65 68 69 private Vector keyTypes; 70 71 77 78 KeystoreOptions(Frame owner, Properties properties) 79 { 80 super(owner, CBIntText.get("Keystore Options"), HelpIDs.SSL_CHANGE_KEYSTORE); 81 82 this.properties = properties; 83 84 keyTypes = new Vector(10); 85 86 89 90 String caType = (String ) properties.get(JXplorer.CA_TYPE_PROPERTY); 91 String clientType = (String ) properties.get(JXplorer.CLIENT_TYPE_PROPERTY); 92 caStore = (String ) properties.get(JXplorer.CA_PATH_PROPERTY); 93 clientStore = (String ) properties.get(JXplorer.CLIENT_PATH_PROPERTY); 94 95 keyTypes.add(caType); 96 if (keyTypes.contains(clientType) == false) 97 keyTypes.add(clientType); 98 99 keyTypes = setupKeyList(keyTypes); 100 101 caTypeCombo = new CBJComboBox(keyTypes); 102 caTypeCombo.setSelectedItem(caType); 103 104 clientTypeCombo = new CBJComboBox(keyTypes); 105 clientTypeCombo.setSelectedItem(clientType); 106 107 110 111 makeWide(); 112 113 115 CBPanel caPanel = new CBPanel(); 116 caPanel.setBorder(new TitledBorder (CBIntText.get("Setup the Trusted CA / Server Keystore "))); 117 118 120 caPanel.add(new JLabel(CBIntText.get("CA/Server Keystore:"))); 121 122 caKeystoreLocationText = new JTextField(caStore); 123 caPanel.addGreedyWide(caKeystoreLocationText, 2); 124 caPanel.makeLight(); 125 126 caChooser = new CBFileChooserButton(caKeystoreLocationText, this, CBIntText.get("Load"), CBIntText.get("Open the file chooser.")); 127 caChooser.setPreferredSize(new Dimension (65,21)); 128 caChooser.setStartingDirectory(caStore); 129 caPanel.addln(caChooser); 130 131 133 caPanel.add(new JLabel(CBIntText.get("Set CA/Server Keystore Type:"))); 134 caTypeCombo.setPreferredSize(new Dimension (100,21)); 135 caPanel.add(caTypeCombo); 136 caPanel.add(new JLabel(" ")); 137 caPanel.addln(new JLabel(" ")); 138 139 display.addln(new JLabel(" ")); 140 display.addln(caPanel); 141 142 144 display.addln(new JLabel(" ")); 145 CBPanel clientPanel = new CBPanel(); 146 clientPanel.setBorder(new TitledBorder (CBIntText.get("Setup the Client's Private Keystore "))); 147 148 150 clientPanel.add(new JLabel(CBIntText.get("Client Keystore:"))); 151 152 clientKeystoreLocationText = new JTextField(clientStore); 153 clientPanel.addGreedyWide(clientKeystoreLocationText, 2); 154 clientPanel.makeLight(); 155 156 clientChooser = new CBFileChooserButton(clientKeystoreLocationText, this, CBIntText.get("Load"), CBIntText.get("Open the file chooser.")); 157 clientChooser.setPreferredSize(new Dimension (65,21)); 158 clientChooser.setStartingDirectory(caStore); 159 clientPanel.addln(clientChooser); 160 161 163 clientPanel.add(new JLabel(CBIntText.get("Set Client Keystore Type: "))); 164 clientTypeCombo.setPreferredSize(new Dimension (100,21)); 165 clientPanel.add(clientTypeCombo); 166 clientPanel.add(new JLabel(" ")); 167 clientPanel.addln(new JLabel(" ")); 168 display.addln(clientPanel); 169 } 170 171 public Vector setupKeyList(Vector keyList) 172 { 173 if (debug) 174 { 175 Provider [] providers = Security.getProviders(); 176 for (int i=0; i<providers.length; i++) 177 { 178 Set keys = providers[i].keySet(); 179 Iterator iterator = keys.iterator(); 180 while (iterator.hasNext()) 181 { 182 String key = (String ) iterator.next(); 183 } 184 } 185 } 186 187 Provider [] providers = Security.getProviders(); 188 for (int i=0; i<providers.length; i++) 189 { 190 Set keys = providers[i].keySet(); 191 Iterator iterator = keys.iterator(); 192 while (iterator.hasNext()) 193 { 194 String key = (String ) iterator.next(); 195 196 if (key.startsWith("KeyStore")) 197 { 198 if (key.endsWith("ImplementedIn") == false) 199 { 200 String keyStoreName = key.substring(9); 201 202 if (keyList.contains(keyStoreName) == false) 203 keyList.add(keyStoreName); 204 } 205 } 206 } 207 } 208 209 return keyList; 210 } 211 212 217 218 public void doOK() 219 { 220 properties.setProperty(JXplorer.CA_TYPE_PROPERTY, (String )caTypeCombo.getSelectedItem()); 221 properties.setProperty(JXplorer.CLIENT_TYPE_PROPERTY, (String )clientTypeCombo.getSelectedItem()); 222 properties.setProperty(JXplorer.CA_PATH_PROPERTY, caKeystoreLocationText.getText()); 223 properties.setProperty(JXplorer.CLIENT_PATH_PROPERTY, clientKeystoreLocationText.getText()); 224 225 super.doOK(); 226 } 227 228 } | Popular Tags |