From 4009ab17413b54b0dac2a4fdc8e85fccce0e53de Mon Sep 17 00:00:00 2001 From: Sebastien Vincent Date: Fri, 29 Apr 2011 11:14:04 +0000 Subject: [PATCH] Store STUN password via credentials storage service. --- .../gui/main/call/OneToOneCallPeerPanel.java | 2 + .../neomedia/codec/EncodingConfiguration.java | 2 +- .../JabberAccRegWizzActivator.java | 36 +++++++++++++-- .../JabberAccountRegistration.java | 3 +- .../JabberAccountRegistrationForm.java | 45 +++++++++++++++++++ .../JabberAccountRegistrationWizard.java | 4 +- .../jabberaccregwizz.manifest.mf | 1 + .../service/protocol/AccountManager.java | 21 ++++++--- .../protocol/StunServerDescriptor.java | 6 ++- 9 files changed, 106 insertions(+), 14 deletions(-) diff --git a/src/net/java/sip/communicator/impl/gui/main/call/OneToOneCallPeerPanel.java b/src/net/java/sip/communicator/impl/gui/main/call/OneToOneCallPeerPanel.java index dab2f89ba..07db6b851 100644 --- a/src/net/java/sip/communicator/impl/gui/main/call/OneToOneCallPeerPanel.java +++ b/src/net/java/sip/communicator/impl/gui/main/call/OneToOneCallPeerPanel.java @@ -1655,6 +1655,8 @@ private class CloseButton extends Label implements MouseListener { + private static final long serialVersionUID = 0L; + Image image = ImageLoader.getImage(ImageLoader.CLOSE_VIDEO); public CloseButton() diff --git a/src/net/java/sip/communicator/impl/neomedia/codec/EncodingConfiguration.java b/src/net/java/sip/communicator/impl/neomedia/codec/EncodingConfiguration.java index a9ebe1f6e..838b822aa 100644 --- a/src/net/java/sip/communicator/impl/neomedia/codec/EncodingConfiguration.java +++ b/src/net/java/sip/communicator/impl/neomedia/codec/EncodingConfiguration.java @@ -351,7 +351,7 @@ public void setPriority(MediaFormat encoding, int priority) * by associating it with a property name/key based on encoding and * clock rate only, it does not make sense to store the MediaFormat in * encodingPreferences because MediaFormat is much more specific than - * just encoding and clock rate. + * just encoding and clock rate. */ setEncodingPreference( encodingEncoding, encoding.getClockRate(), diff --git a/src/net/java/sip/communicator/plugin/jabberaccregwizz/JabberAccRegWizzActivator.java b/src/net/java/sip/communicator/plugin/jabberaccregwizz/JabberAccRegWizzActivator.java index 43a104b98..b91e4c284 100644 --- a/src/net/java/sip/communicator/plugin/jabberaccregwizz/JabberAccRegWizzActivator.java +++ b/src/net/java/sip/communicator/plugin/jabberaccregwizz/JabberAccRegWizzActivator.java @@ -11,6 +11,7 @@ import org.osgi.framework.*; import net.java.sip.communicator.service.browserlauncher.*; +import net.java.sip.communicator.service.credentialsstorage.*; import net.java.sip.communicator.service.gui.*; import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.util.*; @@ -24,6 +25,9 @@ public class JabberAccRegWizzActivator implements BundleActivator { + /** + * The OSGi bundle context. + */ public static BundleContext bundleContext; private static final Logger logger = @@ -31,6 +35,8 @@ public class JabberAccRegWizzActivator private static BrowserLauncherService browserLauncherService; + private static CredentialsStorageService credentialsService = null; + private static WizardContainer wizardContainer; private static JabberAccountRegistrationWizard jabberWizard; @@ -103,22 +109,24 @@ public static ProtocolProviderFactory getJabberProtocolProviderFactory() /** * Returns the UIService. - * + * * @return the UIService */ public static UIService getUIService() { return uiService; } - + /** * Returns the BrowserLauncherService obtained from the bundle * context. * @return the BrowserLauncherService obtained from the bundle * context */ - public static BrowserLauncherService getBrowserLauncher() { - if (browserLauncherService == null) { + public static BrowserLauncherService getBrowserLauncher() + { + if (browserLauncherService == null) + { ServiceReference serviceReference = bundleContext .getServiceReference(BrowserLauncherService.class.getName()); @@ -128,4 +136,24 @@ public static BrowserLauncherService getBrowserLauncher() { return browserLauncherService; } + + /** + * Returns the CredentialsStorageService obtained from the bundle + * context. + * @return the CredentialsStorageService obtained from the bundle + * context + */ + public static CredentialsStorageService getCredentialsService() + { + if (credentialsService == null) + { + ServiceReference serviceReference = bundleContext + .getServiceReference(CredentialsStorageService.class.getName()); + + credentialsService = (CredentialsStorageService)bundleContext + .getService(serviceReference); + } + + return credentialsService; + } } diff --git a/src/net/java/sip/communicator/plugin/jabberaccregwizz/JabberAccountRegistration.java b/src/net/java/sip/communicator/plugin/jabberaccregwizz/JabberAccountRegistration.java index 0e294b121..0a25ab4dc 100755 --- a/src/net/java/sip/communicator/plugin/jabberaccregwizz/JabberAccountRegistration.java +++ b/src/net/java/sip/communicator/plugin/jabberaccregwizz/JabberAccountRegistration.java @@ -574,7 +574,8 @@ public void setUseUPNP(boolean isUseUPNP) /** * Is resource auto generate enabled. - * @return + * + * @return true if resource is auto generated */ public boolean isResourceAutogenerated() { diff --git a/src/net/java/sip/communicator/plugin/jabberaccregwizz/JabberAccountRegistrationForm.java b/src/net/java/sip/communicator/plugin/jabberaccregwizz/JabberAccountRegistrationForm.java index 538cfac4e..b0e4a7375 100644 --- a/src/net/java/sip/communicator/plugin/jabberaccregwizz/JabberAccountRegistrationForm.java +++ b/src/net/java/sip/communicator/plugin/jabberaccregwizz/JabberAccountRegistrationForm.java @@ -6,6 +6,7 @@ import javax.swing.*; +import net.java.sip.communicator.service.credentialsstorage.*; import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.util.swing.*; @@ -380,6 +381,14 @@ public void loadAccount(AccountID accountID) if (stunServer == null) break; + String stunPassword = loadStunPassword(accountID, + ProtocolProviderFactory.STUN_PREFIX + i); + + if(stunPassword != null) + { + stunServer.setPassword(stunPassword); + } + iceConfigPanel.addStunServer(stunServer); } @@ -536,4 +545,40 @@ protected String getHomeLinkLabel() { return wizard.getHomeLinkLabel(); } + + /** + * Load password for this STUN descriptor. + * + * @param accountID account ID + * @param namePrefix name prefix + * @return password or null if empty + */ + private static String loadStunPassword(AccountID accountID, + String namePrefix) + { + ProtocolProviderFactory providerFactory = + JabberAccRegWizzActivator.getJabberProtocolProviderFactory(); + String password = null; + String className = providerFactory.getClass().getName(); + String packageSourceName = className.substring(0, className.lastIndexOf('.')); + + String accountPrefix = ProtocolProviderFactory.findAccountPrefix( + JabberAccRegWizzActivator.bundleContext, + accountID, packageSourceName); + + CredentialsStorageService credentialsService = + JabberAccRegWizzActivator.getCredentialsService(); + + try + { + password = credentialsService. + loadPassword(accountPrefix + "." + namePrefix); + } + catch(Exception e) + { + return null; + } + + return password; + } } diff --git a/src/net/java/sip/communicator/plugin/jabberaccregwizz/JabberAccountRegistrationWizard.java b/src/net/java/sip/communicator/plugin/jabberaccregwizz/JabberAccountRegistrationWizard.java index c50653310..519c8fa7e 100644 --- a/src/net/java/sip/communicator/plugin/jabberaccregwizz/JabberAccountRegistrationWizard.java +++ b/src/net/java/sip/communicator/plugin/jabberaccregwizz/JabberAccountRegistrationWizard.java @@ -361,10 +361,10 @@ protected ProtocolProviderService installAccount( ProtocolProviderFactory.AUTO_DISCOVER_JINGLE_NODES, String.valueOf(registration.isAutoDiscoverJingleNodes())); - serverIndex = -1; - List jnRelays + List jnRelays = registration.getAdditionalJingleNodes(); + serverIndex = -1; for(JingleNodeDescriptor jnRelay : jnRelays) { serverIndex ++; diff --git a/src/net/java/sip/communicator/plugin/jabberaccregwizz/jabberaccregwizz.manifest.mf b/src/net/java/sip/communicator/plugin/jabberaccregwizz/jabberaccregwizz.manifest.mf index 31e026c14..20c617f8d 100755 --- a/src/net/java/sip/communicator/plugin/jabberaccregwizz/jabberaccregwizz.manifest.mf +++ b/src/net/java/sip/communicator/plugin/jabberaccregwizz/jabberaccregwizz.manifest.mf @@ -8,6 +8,7 @@ Export-package: net.java.sip.communicator.plugin.jabberaccregwizz Import-Package: org.osgi.framework, net.java.sip.communicator.service.browserlauncher, net.java.sip.communicator.service.configuration, + net.java.sip.communicator.service.credentialsstorage, net.java.sip.communicator.service.contactlist, net.java.sip.communicator.service.contactlist.event, net.java.sip.communicator.service.fileaccess, diff --git a/src/net/java/sip/communicator/service/protocol/AccountManager.java b/src/net/java/sip/communicator/service/protocol/AccountManager.java index 08ef08ff8..ee5f0d1ba 100644 --- a/src/net/java/sip/communicator/service/protocol/AccountManager.java +++ b/src/net/java/sip/communicator/service/protocol/AccountManager.java @@ -582,21 +582,32 @@ public void storeAccount( { String property = entry.getKey(); String value = entry.getValue(); + String secureStorePrefix = null; // If the property is a password, store it securely. if (property.equals(ProtocolProviderFactory.PASSWORD)) { - CredentialsStorageService credentialsStorage - = ServiceUtils.getService( - bundleContext, - CredentialsStorageService.class); String accountPrefix = factoryPackage + "." + accountNodeName; + secureStorePrefix = accountPrefix; + } + else if(property.endsWith("." + ProtocolProviderFactory.PASSWORD)) + { + secureStorePrefix = factoryPackage + "." + accountNodeName + + "." + property.substring(0, property.lastIndexOf(".")); + } + + if(secureStorePrefix != null) + { + CredentialsStorageService credentialsStorage + = ServiceUtils.getService( + bundleContext, + CredentialsStorageService.class); // encrypt and store if ((value != null) && (value.length() != 0) && !credentialsStorage.storePassword( - accountPrefix, + secureStorePrefix, value)) { throw diff --git a/src/net/java/sip/communicator/service/protocol/StunServerDescriptor.java b/src/net/java/sip/communicator/service/protocol/StunServerDescriptor.java index 6a43bd23e..71e948c9c 100644 --- a/src/net/java/sip/communicator/service/protocol/StunServerDescriptor.java +++ b/src/net/java/sip/communicator/service/protocol/StunServerDescriptor.java @@ -208,7 +208,11 @@ public void storeDescriptor(Map props, String namePrefix) StringUtils.getUTF8String(getUsername())); if (getPassword() != null && getPassword().length > 0) - props.put(namePrefix + STUN_PASSWORD, new String(getPassword())); + { + //props.put(namePrefix + STUN_PASSWORD, new String(getPassword())); + props.put(namePrefix + "." + STUN_PASSWORD, + new String(getPassword())); + } props.put(namePrefix + STUN_IS_TURN_SUPPORTED, Boolean.toString( isTurnSupported() ));