SIP: Show checkboxes for configurable SSL/TLS protocol versions

cusax-fix
Ingo Bauersachs 14 years ago
parent 3d6b4e5b11
commit c15618c987

@ -801,7 +801,6 @@ plugin.generalconfig.DEFAULT_LANGUAGE_RESTART_WARN=Your changes will take effect
plugin.generalconfig.SIP_CLIENT_PORT=SIP client port
plugin.generalconfig.SIP_CLIENT_SECURE_PORT=SIP client secure port
plugin.generalconfig.SIP_SSL_PROTOCOLS=Enabled SSL/TLS protocols
plugin.generalconfig.SIP_SSL_PROTOCOLS_EXAMPLE=Example: "{0}", leave empty for default
plugin.generalconfig.ERROR_PORT_NUMBER=Wrong port number
plugin.generalconfig.CHECK_FOR_UPDATES=Check for updates on startup
plugin.generalconfig.STARTUP_CONFIG=Startup

@ -6,8 +6,11 @@
*/
package net.java.sip.communicator.plugin.generalconfig;
import java.io.*;
import java.util.*;
import javax.net.ssl.*;
import net.java.sip.communicator.service.configuration.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.resources.*;
@ -15,6 +18,9 @@
public class ConfigurationManager
{
private static final Logger logger
= Logger.getLogger(ConfigurationManager.class);
public static final String ENTER_COMMAND = "Enter";
public static final String CTRL_ENTER_COMMAND = "Ctrl-Enter";
@ -614,20 +620,55 @@ public static int getClientSecurePort()
5061);
}
public static String getSSLProtocols()
public static String[] getAvailableSslProtocols()
{
return configService
.getString("gov.nist.javax.sip.TLS_CLIENT_PROTOCOLS", "");
SSLSocket temp;
try
{
temp = (SSLSocket) SSLSocketFactory
.getDefault().createSocket();
return temp.getSupportedProtocols();
}
catch (IOException e)
{
logger.error(e);
return new String[]{};
}
}
public static void setSSLProtocols(String enabledProtocols)
public static String[] getEnabledSslProtocols()
{
if(StringUtils.isNullOrEmpty(enabledProtocols, true))
String enabledSslProtocols = configService
.getString("gov.nist.javax.sip.TLS_CLIENT_PROTOCOLS");
if(StringUtils.isNullOrEmpty(enabledSslProtocols, true))
{
SSLSocket temp;
try
{
temp = (SSLSocket) SSLSocketFactory
.getDefault().createSocket();
return temp.getEnabledProtocols();
}
catch (IOException e)
{
logger.error(e);
return getAvailableSslProtocols();
}
}
return enabledSslProtocols.split("(,)|(,\\s)");
}
public static void setEnabledSslProtocols(String[] enabledProtocols)
{
if(enabledProtocols == null || enabledProtocols.length == 0)
configService.removeProperty(
"gov.nist.javax.sip.TLS_CLIENT_PROTOCOLS");
else
{
String protocols = Arrays.toString(enabledProtocols);
configService.setProperty(
"gov.nist.javax.sip.TLS_CLIENT_PROTOCOLS",
enabledProtocols);
protocols.substring(1, protocols.length() - 1));
}
}
}

@ -7,6 +7,8 @@
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.List;
import javax.swing.*;
@ -20,19 +22,24 @@
*/
public class SIPConfigForm
extends TransparentPanel
implements ActionListener
{
private Box pnlSslProtocols;
/**
* Creates the form.
*/
public SIPConfigForm()
{
super(new BorderLayout());
Box box = Box.createVerticalBox();
add(box, BorderLayout.NORTH);
TransparentPanel sipClientPortConfigPanel = new TransparentPanel();
sipClientPortConfigPanel.setLayout(new BorderLayout(10, 10));
sipClientPortConfigPanel.setPreferredSize(new Dimension(250, 100));
sipClientPortConfigPanel.setPreferredSize(new Dimension(250, 50));
add(sipClientPortConfigPanel, BorderLayout.NORTH);
box.add(sipClientPortConfigPanel);
TransparentPanel labelPanel
= new TransparentPanel(new GridLayout(0, 1, 2, 2));
@ -43,10 +50,6 @@ public SIPConfigForm()
BorderLayout.WEST);
sipClientPortConfigPanel.add(valuePanel,
BorderLayout.CENTER);
sipClientPortConfigPanel.add(new JLabel(
Resources.getString(
"plugin.generalconfig.DEFAULT_LANGUAGE_RESTART_WARN")),
BorderLayout.SOUTH);
labelPanel.add(new JLabel(
Resources.getString(
@ -54,9 +57,6 @@ public SIPConfigForm()
labelPanel.add(new JLabel(
Resources.getString(
"plugin.generalconfig.SIP_CLIENT_SECURE_PORT")));
labelPanel.add(new JLabel(
Resources.getString(
"plugin.generalconfig.SIP_SSL_PROTOCOLS")));
final JTextField clientPortField = new JTextField(6);
clientPortField.setText(
@ -142,22 +142,39 @@ public void focusGained(FocusEvent e)
}
});
final JTextField sslProtocols = new SIPCommTextField(
Resources.getString(
"plugin.generalconfig.SIP_SSL_PROTOCOLS_EXAMPLE",
new String[]{"SSLv3, TLSv1"}));
sslProtocols.setText(
String.valueOf(ConfigurationManager.getSSLProtocols()));
valuePanel.add(sslProtocols);
sslProtocols.addFocusListener(new FocusListener()
String configuredProtocols = Arrays.toString(
ConfigurationManager.getEnabledSslProtocols());
pnlSslProtocols = Box.createVerticalBox();
pnlSslProtocols.setBorder(BorderFactory.createTitledBorder(Resources
.getString("plugin.generalconfig.SIP_SSL_PROTOCOLS")));
pnlSslProtocols.setAlignmentX(Component.LEFT_ALIGNMENT);
for(String protocol : ConfigurationManager.getAvailableSslProtocols())
{
public void focusLost(FocusEvent e)
{
ConfigurationManager.setSSLProtocols(sslProtocols.getText());
}
JCheckBox chkProtocol = new SIPCommCheckBox(protocol);
chkProtocol.addActionListener(this);
chkProtocol.setSelected(configuredProtocols.contains(protocol));
pnlSslProtocols.add(chkProtocol);
}
pnlSslProtocols.add(new JLabel(
Resources.getString(
"plugin.generalconfig.DEFAULT_LANGUAGE_RESTART_WARN")));
JPanel sslWrapper = new TransparentPanel(new BorderLayout());
sslWrapper.add(pnlSslProtocols, BorderLayout.CENTER);
box.add(sslWrapper);
}
public void focusGained(FocusEvent e)
{}
});
public void actionPerformed(ActionEvent e)
{
List<String> enabledSslProtocols = new ArrayList<String>(
pnlSslProtocols.getComponentCount());
for(Component child : pnlSslProtocols.getComponents())
{
if(child instanceof JCheckBox)
if(((JCheckBox) child).isSelected())
enabledSslProtocols.add(((JCheckBox) child).getText());
}
ConfigurationManager.setEnabledSslProtocols(
enabledSslProtocols.toArray(new String[]{}));
}
}

@ -21,6 +21,8 @@ Import-Package: org.osgi.framework,
com.sun.jna,
com.sun.jna.ptr,
com.sun.jna.platform.win32,
javax.net,
javax.net.ssl,
javax.swing,
javax.swing.event,
javax.swing.table,

Loading…
Cancel
Save