diff --git a/resources/languages/resources.properties b/resources/languages/resources.properties index ca2fd007d..8320e7f47 100644 --- a/resources/languages/resources.properties +++ b/resources/languages/resources.properties @@ -1564,6 +1564,11 @@ plugin.globalproxy.PROTOCOL_SUPPORT= \ \ \
XMPP++++
ICQ/AIM++++
+#plugin.globalproxy.PROTOCOL_SUPPORT +plugin.globalproxy.FWD_DNS=Also proxy DNS +plugin.globalproxy.FWD_DNS_NOTE=Useful with Tor. Helps avoiding DNS leaks by forwarding all DNS traffic to the Tor proxy. Requires restart. +plugin.globalproxy.FWD_DNS_ADDR=DNS Proxy Address +plugin.globalproxy.FWD_DNS_PORT=DNS Proxy port # plugin reconnect plugin.reconnectplugin.CONNECTION_FAILED_MSG=Connection failed for the following account:\nUser name: {0}, Server name: {1}.\nPlease check your settings or contact your network administrator for more information. diff --git a/src/net/java/sip/communicator/impl/dns/DnsUtilActivator.java b/src/net/java/sip/communicator/impl/dns/DnsUtilActivator.java index fff3b119c..d31f6a041 100644 --- a/src/net/java/sip/communicator/impl/dns/DnsUtilActivator.java +++ b/src/net/java/sip/communicator/impl/dns/DnsUtilActivator.java @@ -10,14 +10,19 @@ import net.java.sip.communicator.service.netaddr.*; import net.java.sip.communicator.service.netaddr.event.*; import net.java.sip.communicator.service.notification.*; +import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.util.*; +import net.java.sip.communicator.util.Logger; import org.jitsi.service.configuration.*; import org.jitsi.service.resources.*; +import org.jitsi.util.*; import org.osgi.framework.*; import org.xbill.DNS.*; +import java.net.*; + /** * The DNS Util activator registers the DNSSEC resolver if enabled. * @@ -103,6 +108,15 @@ public void start(BundleContext context) bundleContext = context; context.addServiceListener(this); + if(Logger.getLogger("org.xbill").isTraceEnabled()) + Options.set("verbose", "1"); + + if(loadDNSProxyForward()) + { + // dns is forced to go through a proxy so skip any further settings + return; + } + if(UtilActivator.getConfigurationService().getBoolean( DnsUtilActivator.PNAME_BACKUP_RESOLVER_ENABLED, DnsUtilActivator.PDEFAULT_BACKUP_RESOLVER_ENABLED) @@ -131,6 +145,59 @@ public void start(BundleContext context) logger.info("DNS service ... [STARTED]"); } + /** + * Checks settings and if needed load forwarding of dns to the server + * that is specified. + * @return whether loading was successfull or false if it is not or + * was not enabled. + */ + private static boolean loadDNSProxyForward() + { + if(getConfigurationService().getBoolean( + ProxyInfo.CONNECTION_PROXY_FORWARD_DNS_PROPERTY_NAME, false)) + { + try + { + // enabled forward of dns + String serverAddress = + (String)getConfigurationService().getProperty( + ProxyInfo + .CONNECTION_PROXY_FORWARD_DNS_ADDRESS_PROPERTY_NAME); + if(StringUtils.isNullOrEmpty(serverAddress, true)) + return false; + + int port = SimpleResolver.DEFAULT_PORT; + + try + { + port = getConfigurationService() + .getInt(ProxyInfo + .CONNECTION_PROXY_FORWARD_DNS_PORT_PROPERTY_NAME, + SimpleResolver.DEFAULT_PORT); + } + catch(NumberFormatException ne) + { + logger.error("Wrong port value", ne); + } + + // initially created with localhost setting + SimpleResolver sResolver = new SimpleResolver("0"); + // then set the desired address and port + sResolver.setAddress( + new InetSocketAddress(serverAddress, port)); + Lookup.setDefaultResolver(sResolver); + + return true; + } + catch(Throwable t) + { + logger.error("Creating simple forwarding resolver", t); + } + } + + return false; + } + /** * Listens when network is going from down to up and * resets dns configuration. @@ -189,7 +256,8 @@ public static void reloadDnsResolverConfig() else { // or the default otherwise - Lookup.refreshDefault(); + if(!loadDNSProxyForward()) + Lookup.refreshDefault(); } } diff --git a/src/net/java/sip/communicator/plugin/globalproxyconfig/GlobalProxyConfigForm.java b/src/net/java/sip/communicator/plugin/globalproxyconfig/GlobalProxyConfigForm.java index 56a9a6d02..ba1160eb9 100644 --- a/src/net/java/sip/communicator/plugin/globalproxyconfig/GlobalProxyConfigForm.java +++ b/src/net/java/sip/communicator/plugin/globalproxyconfig/GlobalProxyConfigForm.java @@ -55,6 +55,26 @@ public class GlobalProxyConfigForm */ private JPasswordField passwordField = new JPasswordField(); + /** + * The dns forward global checkbox, hides/shows the panel with values. + */ + private JCheckBox dnsForwardCheck = new JCheckBox(); + + /** + * Dns server address initially filled with the value of the proxy. + */ + private JTextField dnsForwardServerAddressField = new JTextField(); + + /** + * Dns server port, initially filled with the value of the proxy. + */ + private JTextField dnsForwardPortField = new JTextField(); + + /** + * Tha panel containing address and port for dns forwarding. + */ + private TransparentPanel dnsAddressPane; + /** * Creates the form. */ @@ -63,7 +83,6 @@ public GlobalProxyConfigForm() super(new BorderLayout()); init(); - loadValues(); } /** @@ -71,11 +90,6 @@ public GlobalProxyConfigForm() */ private void init() { - serverAddressField.addKeyListener(this); - portField.addKeyListener(this); - usernameField.addKeyListener(this); - passwordField.addKeyListener(this); - TransparentPanel centerPanel = new TransparentPanel(new GridBagLayout()); GridBagConstraints constraints = new GridBagConstraints(); @@ -108,7 +122,6 @@ private void init() constraints.gridy = 0; constraints.gridwidth = 3; typeCombo = new JComboBox(ProxyInfo.ProxyType.values()); - typeCombo.addActionListener(this); typeCombo.setEditable(false); centerPanel.add(typeCombo, constraints); @@ -136,7 +149,7 @@ private void init() constraints.gridy = 4; constraints.gridwidth = 4; constraints.gridheight = 2; - constraints.insets = new Insets(20,15,20,15); + constraints.insets = new Insets(15,15,0,15); JTextPane pane = new JTextPane(); pane.setEditable(false); pane.setOpaque(false); @@ -167,7 +180,60 @@ private void init() table, constraints); + constraints.weightx = 0; + constraints.gridx = 0; + constraints.gridy = 9; + constraints.gridwidth = 4; + constraints.gridheight = 1; + constraints.insets = new Insets(5,10,0,0); + dnsForwardCheck.setText(Resources.getResources() + .getI18NString("plugin.globalproxy.FWD_DNS")); + centerPanel.add(dnsForwardCheck, constraints); + + constraints.gridy = 10; + constraints.insets = new Insets(0, 38, 0, 0); + String dnsForwardLabelText = Resources.getResources() + .getI18NString("plugin.globalproxy.FWD_DNS_NOTE"); + JTextPane dnspane = new JTextPane(); + dnspane.setEditable(false); + dnspane.setOpaque(false); + dnspane.setText(dnsForwardLabelText); + dnspane.setForeground(Color.GRAY); + dnspane.setFont(dnspane.getFont().deriveFont(8)); + centerPanel.add(dnspane, constraints); + + constraints.gridy = 11; + constraints.gridwidth = 4; + constraints.gridheight = 2; + dnsAddressPane = + new TransparentPanel(new GridLayout(2, 2)); + dnsAddressPane.add(new JLabel(Resources.getResources() + .getI18NString("plugin.globalproxy.FWD_DNS_ADDR"))); + dnsAddressPane.add(dnsForwardServerAddressField); + dnsAddressPane.add(new JLabel(Resources.getResources() + .getI18NString("plugin.globalproxy.FWD_DNS_PORT"))); + dnsAddressPane.add(dnsForwardPortField); + + dnsAddressPane.setVisible(false); + centerPanel.add(dnsAddressPane, constraints); + add(centerPanel, BorderLayout.NORTH); + + loadValues(); + + // now after loading has finished we can add all the listeners + // so we can get further changes + serverAddressField.addKeyListener(this); + portField.addKeyListener(this); + usernameField.addKeyListener(this); + passwordField.addKeyListener(this); + + typeCombo.addActionListener(this); + + dnsForwardServerAddressField.addKeyListener(this); + dnsForwardPortField.addKeyListener(this); + + dnsForwardCheck.addActionListener(this); } /** @@ -219,6 +285,23 @@ private void loadValues() usernameField.setEnabled(false); passwordField.setEnabled(false); } + + // load dns forward values + if(configService.getBoolean( + ProxyInfo.CONNECTION_PROXY_FORWARD_DNS_PROPERTY_NAME, + false)) + { + dnsForwardCheck.setSelected(true); + + dnsForwardServerAddressField.setText( + (String)configService.getProperty( + ProxyInfo.CONNECTION_PROXY_FORWARD_DNS_ADDRESS_PROPERTY_NAME)); + dnsForwardPortField.setText( + (String)configService.getProperty( + ProxyInfo.CONNECTION_PROXY_FORWARD_DNS_PORT_PROPERTY_NAME)); + + dnsAddressPane.setVisible(true); + } } /** @@ -244,47 +327,72 @@ private void saveValues() ProxyInfo.CONNECTION_PROXY_USERNAME_PROPERTY_NAME); configService.removeProperty( ProxyInfo.CONNECTION_PROXY_PASSWORD_PROPERTY_NAME); - - return; - } - - configService.setProperty( - ProxyInfo.CONNECTION_PROXY_TYPE_PROPERTY_NAME, - ((ProxyInfo.ProxyType)typeCombo.getSelectedItem()).name()); - - String serverAddress = serverAddressField.getText(); - if(serverAddress != null && serverAddress.length() > 0) - configService.setProperty( - ProxyInfo.CONNECTION_PROXY_ADDRESS_PROPERTY_NAME, serverAddress); - - String port = portField.getText(); - if(port != null && port.length() > 0) - configService.setProperty( - ProxyInfo.CONNECTION_PROXY_PORT_PROPERTY_NAME, port); - - String username = usernameField.getText(); - if(username != null && username.length() > 0) - { - configService.setProperty( - ProxyInfo.CONNECTION_PROXY_USERNAME_PROPERTY_NAME, username); } else { - configService.removeProperty( - ProxyInfo.CONNECTION_PROXY_USERNAME_PROPERTY_NAME); + configService.setProperty( + ProxyInfo.CONNECTION_PROXY_TYPE_PROPERTY_NAME, + ((ProxyInfo.ProxyType)typeCombo.getSelectedItem()).name()); + + String serverAddress = serverAddressField.getText(); + if(serverAddress != null && serverAddress.length() > 0) + configService.setProperty( + ProxyInfo.CONNECTION_PROXY_ADDRESS_PROPERTY_NAME, + serverAddress); + + String port = portField.getText(); + if(port != null && port.length() > 0) + configService.setProperty( + ProxyInfo.CONNECTION_PROXY_PORT_PROPERTY_NAME, port); + + String username = usernameField.getText(); + if(username != null && username.length() > 0) + { + configService.setProperty( + ProxyInfo.CONNECTION_PROXY_USERNAME_PROPERTY_NAME, + username); + } + else + { + configService.removeProperty( + ProxyInfo.CONNECTION_PROXY_USERNAME_PROPERTY_NAME); + } + + char[] password = passwordField.getPassword(); + if(password.length > 0) + { + configService.setProperty( + ProxyInfo.CONNECTION_PROXY_PASSWORD_PROPERTY_NAME, + new String(password)); + } + else + { + configService.removeProperty( + ProxyInfo.CONNECTION_PROXY_PASSWORD_PROPERTY_NAME); + } } - char[] password = passwordField.getPassword(); - if(password.length > 0) + // save dns forward values + if(dnsForwardCheck.isSelected()) { configService.setProperty( - ProxyInfo.CONNECTION_PROXY_PASSWORD_PROPERTY_NAME, - new String(password)); + ProxyInfo.CONNECTION_PROXY_FORWARD_DNS_PROPERTY_NAME, + Boolean.TRUE); + configService.setProperty( + ProxyInfo.CONNECTION_PROXY_FORWARD_DNS_ADDRESS_PROPERTY_NAME, + dnsForwardServerAddressField.getText().trim()); + configService.setProperty( + ProxyInfo.CONNECTION_PROXY_FORWARD_DNS_PORT_PROPERTY_NAME, + dnsForwardPortField.getText().trim()); } else { configService.removeProperty( - ProxyInfo.CONNECTION_PROXY_PASSWORD_PROPERTY_NAME); + ProxyInfo.CONNECTION_PROXY_FORWARD_DNS_PROPERTY_NAME); + configService.removeProperty( + ProxyInfo.CONNECTION_PROXY_FORWARD_DNS_ADDRESS_PROPERTY_NAME); + configService.removeProperty( + ProxyInfo.CONNECTION_PROXY_FORWARD_DNS_PORT_PROPERTY_NAME); } GlobalProxyPluginActivator.initProperties(); @@ -296,6 +404,32 @@ private void saveValues() */ public void actionPerformed(ActionEvent e) { + if(e.getSource().equals(dnsForwardCheck)) + { + // lets show or hide the fields + dnsAddressPane.setVisible(dnsForwardCheck.isSelected()); + + if(dnsForwardCheck.isSelected()) + { + if(dnsForwardServerAddressField.getText().length() == 0) + dnsForwardServerAddressField.setText( + serverAddressField.getText()); + + if(dnsForwardPortField.getText().length() == 0) + dnsForwardPortField.setText("53"); + } + + revalidate(); + repaint(); + + // and save initial values + saveValues(); + + return; + } + + // else this is the typeCombo action + if(typeCombo.getSelectedItem().equals(ProxyInfo.ProxyType.NONE)) { serverAddressField.setEnabled(false); diff --git a/src/net/java/sip/communicator/plugin/globalproxyconfig/GlobalProxyPluginActivator.java b/src/net/java/sip/communicator/plugin/globalproxyconfig/GlobalProxyPluginActivator.java index 6823a3a17..63fc26e1e 100644 --- a/src/net/java/sip/communicator/plugin/globalproxyconfig/GlobalProxyPluginActivator.java +++ b/src/net/java/sip/communicator/plugin/globalproxyconfig/GlobalProxyPluginActivator.java @@ -122,6 +122,12 @@ static void initProperties() String globalProxyAddress = getConfigurationService().getString( ProxyInfo.CONNECTION_PROXY_ADDRESS_PROPERTY_NAME); + if(globalProxyAddress == null || + globalProxyAddress.length() <= 0) + { + // no address + return; + } String globalProxyPortStr = getConfigurationService().getString( ProxyInfo.CONNECTION_PROXY_PORT_PROPERTY_NAME); @@ -141,12 +147,6 @@ static void initProperties() String globalProxyPassword = getConfigurationService().getString( ProxyInfo.CONNECTION_PROXY_PASSWORD_PROPERTY_NAME); - if(globalProxyAddress == null || - globalProxyAddress.length() <= 0) - { - // no address - return; - } String type = null; if(globalProxyType.equals( diff --git a/src/net/java/sip/communicator/service/protocol/ProxyInfo.java b/src/net/java/sip/communicator/service/protocol/ProxyInfo.java index bd1103398..8b983fdd6 100644 --- a/src/net/java/sip/communicator/service/protocol/ProxyInfo.java +++ b/src/net/java/sip/communicator/service/protocol/ProxyInfo.java @@ -66,4 +66,22 @@ public static enum ProxyType */ public final static String CONNECTION_PROXY_PASSWORD_PROPERTY_NAME = "net.java.sip.communicator.service.connectionProxyPassword"; + + /** + * Stores in the configuration the connection dns forwarding is it enabled. + */ + public final static String CONNECTION_PROXY_FORWARD_DNS_PROPERTY_NAME = + "net.java.sip.communicator.service.connectionProxyForwardDNS"; + + /** + * Stores in the configuration the connection dns forwarding address. + */ + public final static String CONNECTION_PROXY_FORWARD_DNS_ADDRESS_PROPERTY_NAME + = "net.java.sip.communicator.service.connectionProxyForwardDNSAddress"; + + /** + * Stores in the configuration the connection dns forwarding port. + */ + public final static String CONNECTION_PROXY_FORWARD_DNS_PORT_PROPERTY_NAME + = "net.java.sip.communicator.service.connectionProxyForwardDNSPort"; }