diff --git a/lib/installer-exclude/otr4j.jar b/lib/installer-exclude/otr4j.jar index 06dc4a7b1..fc229151d 100644 Binary files a/lib/installer-exclude/otr4j.jar and b/lib/installer-exclude/otr4j.jar differ diff --git a/src/net/java/sip/communicator/plugin/otr/OtrActivator.java b/src/net/java/sip/communicator/plugin/otr/OtrActivator.java index d4745249f..ae56e3907 100644 --- a/src/net/java/sip/communicator/plugin/otr/OtrActivator.java +++ b/src/net/java/sip/communicator/plugin/otr/OtrActivator.java @@ -8,15 +8,13 @@ import java.util.*; -import net.java.sip.communicator.plugin.otr.authdialog.*; import net.java.sip.communicator.service.contactlist.*; import net.java.sip.communicator.service.gui.*; -import net.java.sip.communicator.service.msghistory.*; 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 net.java.sip.communicator.util.Logger; import org.jitsi.service.configuration.*; import org.jitsi.service.resources.*; import org.jitsi.util.*; @@ -30,6 +28,12 @@ public class OtrActivator extends AbstractServiceDependentActivator implements ServiceListener { + /** + * A property specifying whether private messaging should be automatically + * initiated. + */ + public static final String AUTO_INIT_OTR_PROP = + "net.java.sip.communicator.plugin.otr.AUTO_INIT_PRIVATE_MESSAGING"; /** * The {@link BundleContext} of the {@link OtrActivator}. @@ -96,11 +100,6 @@ public class OtrActivator * The MetaContactListService reference. */ private static MetaContactListService metaCListService; - - /** - * The message history service. - */ - private static MessageHistoryService messageHistoryService; /** * Gets an {@link AccountID} by its UID. @@ -308,7 +307,6 @@ public void start(Object dependentService) // Register Transformation Layer bundleContext.addServiceListener(this); bundleContext.addServiceListener((ServiceListener) scOtrEngine); - bundleContext.addServiceListener(new OtrContactManager()); ServiceReference[] protocolProviderRefs = ServiceUtils.getServiceReferences( @@ -372,20 +370,6 @@ public void start(Object dependentService) bundleContext.registerService( OtrActionHandler.class.getName(), new SwingOtrActionHandler(), null); - - containerFilter.put(Container.CONTAINER_ID, - Container.CONTAINER_CHAT_WRITE_PANEL.getID()); - bundleContext.registerService( - PluginComponentFactory.class.getName(), - new PluginComponentFactory( Container.CONTAINER_CHAT_WRITE_PANEL) - { - protected PluginComponent getPluginInstance() - { - return new OTRv3OutgoingSessionSwitcher( - getContainer(), this); - } - }, - containerFilter); } // If the general configuration form is disabled don't register it. @@ -400,8 +384,7 @@ protected PluginComponent getPluginInstance() // Register the configuration form. bundleContext.registerService(ConfigurationForm.class.getName(), new LazyConfigurationForm( - "net.java.sip.communicator.plugin.otr.authdialog." + - "OtrConfigurationPanel", + "net.java.sip.communicator.plugin.otr.OtrConfigurationPanel", getClass().getClassLoader(), "plugin.otr.configform.ICON", "service.gui.CHAT", 1), @@ -465,19 +448,6 @@ public static MetaContactListService getContactListService() return metaCListService; } - /** - * Gets the service giving access to message history. - * - * @return the service giving access to message history. - */ - public static MessageHistoryService getMessageHistoryService() - { - if (messageHistoryService == null) - messageHistoryService = ServiceUtils.getService(bundleContext, - MessageHistoryService.class); - return messageHistoryService; - } - /** * The factory that will be registered in OSGi and will create * otr menu instances. diff --git a/src/net/java/sip/communicator/plugin/otr/OtrConfigurator.java b/src/net/java/sip/communicator/plugin/otr/OtrConfigurator.java index a4c47e4cf..8a1bf58f7 100755 --- a/src/net/java/sip/communicator/plugin/otr/OtrConfigurator.java +++ b/src/net/java/sip/communicator/plugin/otr/OtrConfigurator.java @@ -144,31 +144,4 @@ public int getPropertyInt(String id, int defaultValue) { return OtrActivator.configService.getInt(getID(id), defaultValue); } - - /** - * Appends value to the old value of the property with the - * specified name. The two values will be comma separated. - * - * @param id the name of the property to append to - * @param value the value to append - */ - public void appendProperty(String id, Object value) - { - Object oldValue = OtrActivator.configService.getProperty(getID(id)); - - String newValue = - oldValue == null ? value.toString() : oldValue + "," + value; - - setProperty(id, newValue); - } - - public List getAppendedProperties(String id) - { - String listProperties = - (String) OtrActivator.configService.getProperty(getID(id)); - - if (listProperties == null) return new ArrayList(); - - return Arrays.asList(listProperties.split(",")); - } } diff --git a/src/net/java/sip/communicator/plugin/otr/OtrContactManager.java b/src/net/java/sip/communicator/plugin/otr/OtrContactManager.java deleted file mode 100644 index 789c8df86..000000000 --- a/src/net/java/sip/communicator/plugin/otr/OtrContactManager.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.plugin.otr; - -import java.util.*; -import java.util.concurrent.*; - -import net.java.sip.communicator.service.protocol.*; -import net.java.sip.communicator.util.*; - -import org.osgi.framework.*; - -/** - * The OtrContactManager is used for accessing OtrContacts in a static - * way. - * - * The OtrContact class is just a wrapper of [Contact, ContactResource] - * pairs. Its purpose is for the otr plugin to be able to create different - * Sessions for every ContactResource that a Contact has. - * - * Currently, only the Jabber protocol supports ContactResources. - * - * @author Marin Dzhigarov - * - */ -public class OtrContactManager implements ServiceListener -{ - - /** - * The logger - */ - private final Logger logger = Logger.getLogger(OtrContactManager.class); - - /** - * A map that caches OtrContacts to minimize memory usage. - */ - private static final Map> contactsMap = - new ConcurrentHashMap>(); - - /** - * The OtrContact class is just a wrapper of - * [Contact, ContactResource] pairs. Its purpose is for the otr plugin to be - * able to create different Sessions for every ContactResource that - * a Contact has. - * - * @author Marin Dzhigarov - * - */ - public static class OtrContact - { - public final Contact contact; - - public final ContactResource resource; - - private OtrContact(Contact contact, ContactResource resource) - { - this.contact = contact; - this.resource = resource; - } - - public boolean equals(Object obj) - { - if (this == obj) - return true; - - if (!(obj instanceof OtrContact)) - return false; - - OtrContact other = (OtrContact) obj; - - if (this.contact != null && this.contact.equals(other.contact)) - { - if (this.resource != null && resource.equals(other.resource)) - return true; - if (this.resource == null && other.resource == null) - return true; - return false; - } - return false; - } - - public int hashCode() - { - int result = 17; - - result = 31 * result + (contact == null ? 0 : contact.hashCode()); - result = 31 * result + (resource == null ? 0 : resource.hashCode()); - - return result; - } - } - - /** - * Gets the OtrContact that represents this - * [Contact, ContactResource] pair from the cache. If such pair does not - * still exist it is then created and cached for further usage. - * - * @param contact the Contact that the returned OtrContact - * represents. - * @param resource the ContactResource that the returned OtrContact - * represents. - * @return The OtrContact that represents this - * [Contact, ContactResource] pair. - */ - public static OtrContact getOtrContact( - Contact contact, ContactResource resource) - { - if (contact == null) - return null; - - List otrContactsList = contactsMap.get(contact); - if (otrContactsList != null) - { - for (OtrContact otrContact : otrContactsList) - { - if (resource != null && resource.equals(otrContact.resource)) - return otrContact; - } - OtrContact otrContact = new OtrContact(contact, resource); - synchronized (otrContactsList) - { - while (!otrContactsList.contains(otrContact)) - otrContactsList.add(otrContact); - } - return otrContact; - } - else - { - synchronized (contactsMap) - { - while (!contactsMap.containsKey(contact)) - { - otrContactsList = new ArrayList(); - contactsMap.put(contact, otrContactsList); - } - } - return getOtrContact(contact, resource); - } - } - - /** - * Cleans up unused cached up Contacts. - */ - public void serviceChanged(ServiceEvent event) - { - Object service - = OtrActivator.bundleContext.getService(event.getServiceReference()); - - if (!(service instanceof ProtocolProviderService)) - return; - - if (event.getType() == ServiceEvent.UNREGISTERING) - { - if (logger.isDebugEnabled()) - { - logger.debug( - "Unregistering a ProtocolProviderService, cleaning" - + " OTR's Contact to OtrContact map"); - } - - ProtocolProviderService provider - = (ProtocolProviderService) service; - - synchronized(contactsMap) - { - Iterator i = contactsMap.keySet().iterator(); - - while (i.hasNext()) - { - if (provider.equals(i.next().getProtocolProvider())) - i.remove(); - } - } - } - } -} diff --git a/src/net/java/sip/communicator/plugin/otr/OtrContactMenu.java b/src/net/java/sip/communicator/plugin/otr/OtrContactMenu.java index 4332c4e73..040f93215 100644 --- a/src/net/java/sip/communicator/plugin/otr/OtrContactMenu.java +++ b/src/net/java/sip/communicator/plugin/otr/OtrContactMenu.java @@ -7,15 +7,12 @@ package net.java.sip.communicator.plugin.otr; import java.awt.event.*; -import java.security.*; import javax.swing.*; import net.java.otr4j.*; import net.java.sip.communicator.plugin.desktoputil.*; -import net.java.sip.communicator.plugin.otr.OtrContactManager.OtrContact; import net.java.sip.communicator.service.protocol.*; -import net.java.sip.communicator.util.*; /** * A special {@link JMenu} that holds the menu items for controlling the @@ -23,15 +20,12 @@ * * @author George Politis * @author Lyubomir Marinov - * @author Marin Dzhigarov */ class OtrContactMenu implements ActionListener, ScOtrEngineListener, ScOtrKeyManagerListener { - private final Logger logger = Logger.getLogger(OtrContactMenu.class); - private static final String ACTION_COMMAND_AUTHENTICATE_BUDDY = "AUTHENTICATE_BUDDY"; @@ -51,7 +45,7 @@ class OtrContactMenu private static final String ACTION_COMMAND_START_OTR = "START_OTR"; - private final OtrContact contact; + private final Contact contact; /** * The indicator which determines whether this JMenu is displayed @@ -75,27 +69,23 @@ class OtrContactMenu /** * The OtrContactMenu constructor. * - * @param otrContact the OtrContact this menu refers to. + * @param contact the Contact this menu refers to. * @param inMacOSXScreenMenuBar true if the new menu is to be * displayed in the Mac OS X screen menu bar; false, otherwise * @param menu the parent menu */ - public OtrContactMenu( OtrContact otrContact, + public OtrContactMenu( Contact contact, boolean inMacOSXScreenMenuBar, JMenu menu, boolean isSeparateMenu) { - this.contact = otrContact; + this.contact = contact; this.inMacOSXScreenMenuBar = inMacOSXScreenMenuBar; this.parentMenu = menu; - String resourceName = - otrContact.resource != null - ? "/" + otrContact.resource.getResourceName() - : ""; + separateMenu = isSeparateMenu - ? new SIPCommMenu(otrContact.contact.getDisplayName() - + resourceName) + ? new SIPCommMenu(contact.getDisplayName()) : null; /* @@ -113,10 +103,8 @@ public OtrContactMenu( OtrContact otrContact, this, OtrActivator.scOtrEngine, OtrActivator.scOtrKeyManager); - setSessionStatus( - OtrActivator.scOtrEngine.getSessionStatus(this.contact)); - setOtrPolicy( - OtrActivator.scOtrEngine.getContactPolicy(otrContact.contact)); + setSessionStatus(OtrActivator.scOtrEngine.getSessionStatus(contact)); + setOtrPolicy(OtrActivator.scOtrEngine.getContactPolicy(contact)); buildMenu(); } @@ -129,28 +117,12 @@ public void actionPerformed(ActionEvent e) String actionCommand = e.getActionCommand(); if (ACTION_COMMAND_END_OTR.equals(actionCommand)) - { - OtrPolicy policy = - OtrActivator.scOtrEngine.getContactPolicy(contact.contact); - policy.setSendWhitespaceTag(false); - OtrActivator.scOtrEngine.setContactPolicy(contact.contact, policy); - // End session. OtrActivator.scOtrEngine.endSession(contact); - } else if (ACTION_COMMAND_START_OTR.equals(actionCommand)) - { - OtrPolicy policy = - OtrActivator.scOtrEngine.getContactPolicy(contact.contact); - OtrPolicy globalPolicy = - OtrActivator.scOtrEngine.getGlobalPolicy(); - policy.setSendWhitespaceTag(globalPolicy.getSendWhitespaceTag()); - OtrActivator.scOtrEngine.setContactPolicy(contact.contact, policy); - // Start session. OtrActivator.scOtrEngine.startSession(contact); - } else if (ACTION_COMMAND_REFRESH_OTR.equals(actionCommand)) // Refresh session. @@ -163,22 +135,22 @@ else if (ACTION_COMMAND_AUTHENTICATE_BUDDY.equals(actionCommand)) else if (ACTION_COMMAND_CB_ENABLE.equals(actionCommand)) { OtrPolicy policy = - OtrActivator.scOtrEngine.getContactPolicy(contact.contact); + OtrActivator.scOtrEngine.getContactPolicy(contact); boolean state = ((JCheckBoxMenuItem) e.getSource()).isSelected(); policy.setEnableManual(state); - OtrActivator.scOtrEngine.setContactPolicy(contact.contact, policy); + OtrActivator.scOtrEngine.setContactPolicy(contact, policy); } else if (ACTION_COMMAND_CB_AUTO.equals(actionCommand)) { OtrPolicy policy = - OtrActivator.scOtrEngine.getContactPolicy(contact.contact); + OtrActivator.scOtrEngine.getContactPolicy(contact); boolean state = ((JCheckBoxMenuItem) e.getSource()).isSelected(); - policy.setSendWhitespaceTag(state); + policy.setEnableAlways(state); - OtrActivator.scOtrEngine.setContactPolicy(contact.contact, policy); + OtrActivator.scOtrEngine.setContactPolicy(contact, policy); } else if (ACTION_COMMAND_CB_AUTO_ALL.equals(actionCommand)) @@ -187,7 +159,10 @@ else if (ACTION_COMMAND_CB_AUTO_ALL.equals(actionCommand)) OtrActivator.scOtrEngine.getGlobalPolicy(); boolean state = ((JCheckBoxMenuItem) e.getSource()).isSelected(); - globalPolicy.setSendWhitespaceTag(state); + globalPolicy.setEnableAlways(state); + OtrActivator.configService.setProperty( + OtrActivator.AUTO_INIT_OTR_PROP, + Boolean.toString(state)); OtrActivator.scOtrEngine.setGlobalPolicy(globalPolicy); } @@ -195,17 +170,17 @@ else if (ACTION_COMMAND_CB_AUTO_ALL.equals(actionCommand)) else if (ACTION_COMMAND_CB_REQUIRE.equals(actionCommand)) { OtrPolicy policy = - OtrActivator.scOtrEngine.getContactPolicy(contact.contact); + OtrActivator.scOtrEngine.getContactPolicy(contact); boolean state = ((JCheckBoxMenuItem) e.getSource()).isSelected(); policy.setRequireEncryption(state); OtrActivator.configService.setProperty( OtrActivator.OTR_MANDATORY_PROP, Boolean.toString(state)); - OtrActivator.scOtrEngine.setContactPolicy(contact.contact, policy); + OtrActivator.scOtrEngine.setContactPolicy(contact, policy); } else if (ACTION_COMMAND_CB_RESET.equals(actionCommand)) - OtrActivator.scOtrEngine.setContactPolicy(contact.contact, null); + OtrActivator.scOtrEngine.setContactPolicy(contact, null); } /* @@ -214,8 +189,7 @@ else if (ACTION_COMMAND_CB_RESET.equals(actionCommand)) public void contactPolicyChanged(Contact contact) { // Update the corresponding to the contact menu. - if (OtrContactMenu.this.contact != null && - contact.equals(OtrContactMenu.this.contact.contact)) + if (contact.equals(OtrContactMenu.this.contact)) setOtrPolicy(OtrActivator.scOtrEngine.getContactPolicy(contact)); } @@ -223,11 +197,10 @@ public void contactPolicyChanged(Contact contact) * Implements ScOtrKeyManagerListener#contactVerificationStatusChanged( * Contact). */ - public void contactVerificationStatusChanged(OtrContact otrContact) + public void contactVerificationStatusChanged(Contact contact) { - if (otrContact.equals(OtrContactMenu.this.contact)) - setSessionStatus( - OtrActivator.scOtrEngine.getSessionStatus(otrContact)); + if (contact.equals(OtrContactMenu.this.contact)) + setSessionStatus(OtrActivator.scOtrEngine.getSessionStatus(contact)); } /** @@ -247,7 +220,7 @@ void dispose() */ public void globalPolicyChanged() { - setOtrPolicy(OtrActivator.scOtrEngine.getContactPolicy(contact.contact)); + setOtrPolicy(OtrActivator.scOtrEngine.getContactPolicy(contact)); } /** @@ -259,8 +232,7 @@ private void buildMenu() if(separateMenu != null) separateMenu.removeAll(); - OtrPolicy policy = - OtrActivator.scOtrEngine.getContactPolicy(contact.contact); + OtrPolicy policy = OtrActivator.scOtrEngine.getContactPolicy(contact); JMenuItem endOtr = new JMenuItem(); endOtr.setText(OtrActivator.resourceService @@ -354,8 +326,7 @@ private void buildMenu() OtrActivator.resourceService .getI18NString( "plugin.otr.menu.CB_AUTO", - new String[] - {contact.contact.getDisplayName()}))); + new String[] {contact.getDisplayName()}))); cbAlways.setEnabled(policy.getEnableManual()); cbAlways.setSelected(policy.getEnableAlways()); @@ -368,9 +339,13 @@ private void buildMenu() .getI18NString("plugin.otr.menu.CB_AUTO_ALL")); cbAlwaysAll.setEnabled(policy.getEnableManual()); + String autoInitPropValue + = OtrActivator.configService.getString( + OtrActivator.AUTO_INIT_OTR_PROP); boolean isAutoInit = OtrActivator.scOtrEngine.getGlobalPolicy().getEnableAlways(); - + if (autoInitPropValue != null) + isAutoInit = Boolean.parseBoolean(autoInitPropValue); cbAlwaysAll.setSelected(isAutoInit); cbAlwaysAll.setActionCommand(ACTION_COMMAND_CB_AUTO_ALL); @@ -432,11 +407,10 @@ else if (!isMandatory && defaultOtrPropValue != null) /* * Implements ScOtrEngineListener#sessionStatusChanged(Contact). */ - public void sessionStatusChanged(OtrContact otrContact) + public void sessionStatusChanged(Contact contact) { - if (otrContact.equals(OtrContactMenu.this.contact)) - setSessionStatus( - OtrActivator.scOtrEngine.getSessionStatus(otrContact)); + if (contact.equals(OtrContactMenu.this.contact)) + setSessionStatus(OtrActivator.scOtrEngine.getSessionStatus(contact)); } /** @@ -450,9 +424,6 @@ private void setSessionStatus(ScSessionStatus sessionStatus) { if (sessionStatus != this.sessionStatus) { - logger.debug( - "Setting session status of contact " + contact.contact + - " to " + sessionStatus + ". Was " + this.sessionStatus); this.sessionStatus = sessionStatus; if (separateMenu != null) @@ -499,14 +470,8 @@ private void updateIcon() switch (sessionStatus) { case ENCRYPTED: - PublicKey pubKey = - OtrActivator.scOtrEngine.getRemotePublicKey(contact); - String fingerprint = - OtrActivator.scOtrKeyManager. - getFingerprintFromPublicKey(pubKey); imageID - = OtrActivator.scOtrKeyManager.isVerified( - contact.contact, fingerprint) + = OtrActivator.scOtrKeyManager.isVerified(contact) ? "plugin.otr.ENCRYPTED_ICON_16x16" : "plugin.otr.ENCRYPTED_UNVERIFIED_ICON_16x16"; break; @@ -525,15 +490,4 @@ private void updateIcon() separateMenu.setIcon(OtrActivator.resourceService.getImage(imageID)); } - - @Override - public void multipleInstancesDetected(OtrContact contact) {} - - @Override - public void outgoingSessionChanged(OtrContact otrContact) - { - if (otrContact.equals(OtrContactMenu.this.contact)) - setSessionStatus( - OtrActivator.scOtrEngine.getSessionStatus(otrContact)); - } } diff --git a/src/net/java/sip/communicator/plugin/otr/OtrMetaContactButton.java b/src/net/java/sip/communicator/plugin/otr/OtrMetaContactButton.java index a6d4b2538..2984fb75f 100644 --- a/src/net/java/sip/communicator/plugin/otr/OtrMetaContactButton.java +++ b/src/net/java/sip/communicator/plugin/otr/OtrMetaContactButton.java @@ -9,14 +9,12 @@ import java.awt.*; import java.awt.event.*; import java.io.*; -import java.security.*; import javax.imageio.*; import net.java.otr4j.*; import net.java.otr4j.session.*; import net.java.sip.communicator.plugin.desktoputil.*; -import net.java.sip.communicator.plugin.otr.OtrContactManager.OtrContact; import net.java.sip.communicator.service.contactlist.*; import net.java.sip.communicator.service.gui.*; import net.java.sip.communicator.service.gui.Container; @@ -28,7 +26,6 @@ * the main chat toolbar. * * @author George Politis - * @author Marin Dzhigarov */ public class OtrMetaContactButton extends AbstractPluginComponent @@ -42,7 +39,7 @@ public class OtrMetaContactButton private SIPCommButton button; - private OtrContact otrContact; + private Contact contact; private AnimatedImage animatedPadlockImage; @@ -56,21 +53,25 @@ public class OtrMetaContactButton private Image timedoutPadlockImage; - public void sessionStatusChanged(OtrContact otrContact) + /** + * The timer task that changes the padlock icon to "loading" and + * then to "broken" if the specified timeout passed + */ + public void sessionStatusChanged(Contact contact) { // OtrMetaContactButton.this.contact can be null. - if (otrContact.equals(OtrMetaContactButton.this.otrContact)) + if (contact.equals(OtrMetaContactButton.this.contact)) { + setStatus( - OtrActivator.scOtrEngine.getSessionStatus(otrContact)); + OtrActivator.scOtrEngine.getSessionStatus(contact)); } } public void contactPolicyChanged(Contact contact) { // OtrMetaContactButton.this.contact can be null. - if (OtrMetaContactButton.this.otrContact != null && - contact.equals(OtrMetaContactButton.this.otrContact.contact)) + if (contact.equals(OtrMetaContactButton.this.contact)) { setPolicy( OtrActivator.scOtrEngine.getContactPolicy(contact)); @@ -79,18 +80,18 @@ public void contactPolicyChanged(Contact contact) public void globalPolicyChanged() { - if (OtrMetaContactButton.this.otrContact != null) + if (OtrMetaContactButton.this.contact != null) setPolicy( - OtrActivator.scOtrEngine.getContactPolicy(otrContact.contact)); + OtrActivator.scOtrEngine.getContactPolicy(contact)); } - public void contactVerificationStatusChanged(OtrContact otrContact) + public void contactVerificationStatusChanged(Contact contact) { // OtrMetaContactButton.this.contact can be null. - if (otrContact.equals(OtrMetaContactButton.this.otrContact)) + if (contact.equals(OtrMetaContactButton.this.contact)) { setStatus( - OtrActivator.scOtrEngine.getSessionStatus(otrContact)); + OtrActivator.scOtrEngine.getSessionStatus(contact)); } } @@ -171,38 +172,23 @@ private SIPCommButton getButton() { public void actionPerformed(ActionEvent e) { - if (otrContact == null) + if (contact == null) return; - switch (OtrActivator.scOtrEngine.getSessionStatus(otrContact)) + switch (OtrActivator.scOtrEngine.getSessionStatus(contact)) { case ENCRYPTED: - OtrPolicy policy = - OtrActivator.scOtrEngine.getContactPolicy( - otrContact.contact); - policy.setSendWhitespaceTag(false); - OtrActivator.scOtrEngine.setContactPolicy( - otrContact.contact, policy); case FINISHED: case LOADING: // Default action for finished, encrypted and loading // sessions is end session. - OtrActivator.scOtrEngine.endSession(otrContact); + OtrActivator.scOtrEngine.endSession(contact); break; case TIMED_OUT: case PLAINTEXT: - policy = - OtrActivator.scOtrEngine.getContactPolicy( - otrContact.contact); - OtrPolicy globalPolicy = - OtrActivator.scOtrEngine.getGlobalPolicy(); - policy.setSendWhitespaceTag( - globalPolicy.getSendWhitespaceTag()); - OtrActivator.scOtrEngine.setContactPolicy( - otrContact.contact, policy); // Default action for timed_out and plaintext sessions // is start session. - OtrActivator.scOtrEngine.startSession(otrContact); + OtrActivator.scOtrEngine.startSession(contact); break; } } @@ -235,49 +221,20 @@ public String getName() @Override public void setCurrentContact(Contact contact) { - setCurrentContact(contact, null); - } - - public void setCurrentContact(Contact contact, String resourceName) - { - if (contact == null) - { - this.otrContact = null; - this.setPolicy(null); - this.setStatus(ScSessionStatus.PLAINTEXT); + if (this.contact == contact) return; - } - if (resourceName == null) + this.contact = contact; + if (contact != null) { - OtrContact otrContact = - OtrContactManager.getOtrContact(contact, null); - if (this.otrContact == otrContact) - return; - this.otrContact = otrContact; - this.setStatus( - OtrActivator.scOtrEngine.getSessionStatus(otrContact)); - this.setPolicy( - OtrActivator.scOtrEngine.getContactPolicy(contact)); - return; + this.setStatus(OtrActivator.scOtrEngine.getSessionStatus(contact)); + this.setPolicy(OtrActivator.scOtrEngine.getContactPolicy(contact)); } - for (ContactResource resource : contact.getResources()) + else { - if (resource.getResourceName().equals(resourceName)) - { - OtrContact otrContact = - OtrContactManager.getOtrContact(contact, resource); - if (this.otrContact == otrContact) - return; - this.otrContact = otrContact; - this.setStatus( - OtrActivator.scOtrEngine.getSessionStatus(otrContact)); - this.setPolicy( - OtrActivator.scOtrEngine.getContactPolicy(contact)); - return; - } + this.setStatus(ScSessionStatus.PLAINTEXT); + this.setPolicy(null); } - logger.debug("Could not find resource for contact " + contact); } /* @@ -315,19 +272,12 @@ private void setStatus(ScSessionStatus status) switch (status) { case ENCRYPTED: - PublicKey pubKey = - OtrActivator.scOtrEngine.getRemotePublicKey(otrContact); - String fingerprint = - OtrActivator.scOtrKeyManager. - getFingerprintFromPublicKey(pubKey); image - = OtrActivator.scOtrKeyManager.isVerified( - otrContact.contact, fingerprint) + = OtrActivator.scOtrKeyManager.isVerified(contact) ? verifiedLockedPadlockImage : unverifiedLockedPadlockImage; tipKey = - OtrActivator.scOtrKeyManager.isVerified( - otrContact.contact, fingerprint) + OtrActivator.scOtrKeyManager.isVerified(contact) ? "plugin.otr.menu.VERIFIED" : "plugin.otr.menu.UNVERIFIED"; break; @@ -358,19 +308,4 @@ private void setStatus(ScSessionStatus status) .getI18NString(tipKey)); button.repaint(); } - - @Override - public void multipleInstancesDetected(OtrContact contact) - {} - - @Override - public void outgoingSessionChanged(OtrContact otrContact) - { - // OtrMetaContactButton.this.contact can be null. - if (otrContact.equals(OtrMetaContactButton.this.otrContact)) - { - setStatus( - OtrActivator.scOtrEngine.getSessionStatus(otrContact)); - } - } } diff --git a/src/net/java/sip/communicator/plugin/otr/OtrMetaContactMenu.java b/src/net/java/sip/communicator/plugin/otr/OtrMetaContactMenu.java index 024ec5649..1602cf8f4 100644 --- a/src/net/java/sip/communicator/plugin/otr/OtrMetaContactMenu.java +++ b/src/net/java/sip/communicator/plugin/otr/OtrMetaContactMenu.java @@ -13,11 +13,11 @@ import javax.swing.*; import javax.swing.event.*; -import net.java.sip.communicator.plugin.desktoputil.*; import net.java.sip.communicator.service.contactlist.*; import net.java.sip.communicator.service.gui.*; import net.java.sip.communicator.service.gui.Container; import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.plugin.desktoputil.*; /** * @author George Politis @@ -95,54 +95,14 @@ private void createOtrContactMenus(MetaContact metaContact) if (metaContact.getContactCount() == 1) { - Contact contact = contacts.next(); - Collection resources = contact.getResources(); - if (contact.supportResources() && - resources != null && - resources.size() > 0) - { - for (ContactResource resource : resources) - { - new OtrContactMenu( - OtrContactManager.getOtrContact(contact, resource), - inMacOSXScreenMenuBar, - menu, - true); - } - } - else - new OtrContactMenu( - OtrContactManager.getOtrContact(contact, null), - inMacOSXScreenMenuBar, - menu, - false); + new OtrContactMenu( + contacts.next(), inMacOSXScreenMenuBar, menu, false); } else while (contacts.hasNext()) { - Contact contact = contacts.next(); - Collection resources = - contact.getResources(); - if (contact.supportResources() && - resources != null && - resources.size() > 0) - { - for (ContactResource resource : resources) - { - new OtrContactMenu( - OtrContactManager.getOtrContact( - contact, resource), - inMacOSXScreenMenuBar, - menu, - true); - } - } - else - new OtrContactMenu( - OtrContactManager.getOtrContact(contact, null), - inMacOSXScreenMenuBar, - menu, - true); + new OtrContactMenu( + contacts.next(), inMacOSXScreenMenuBar, menu, true); } } } diff --git a/src/net/java/sip/communicator/plugin/otr/OtrTransformLayer.java b/src/net/java/sip/communicator/plugin/otr/OtrTransformLayer.java index f447de029..44e0f0e25 100644 --- a/src/net/java/sip/communicator/plugin/otr/OtrTransformLayer.java +++ b/src/net/java/sip/communicator/plugin/otr/OtrTransformLayer.java @@ -7,8 +7,6 @@ package net.java.sip.communicator.plugin.otr; import net.java.otr4j.*; -import net.java.otr4j.io.*; -import net.java.sip.communicator.plugin.otr.OtrContactManager.OtrContact; import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.service.protocol.event.*; @@ -26,12 +24,10 @@ public class OtrTransformLayer public MessageDeliveredEvent messageDelivered(MessageDeliveredEvent evt) { Contact contact = evt.getDestinationContact(); - OtrContact otrContact = - OtrContactManager.getOtrContact(contact, evt.getContactResource()); OtrPolicy policy = OtrActivator.scOtrEngine.getContactPolicy(contact); ScSessionStatus sessionStatus = - OtrActivator.scOtrEngine.getSessionStatus(otrContact); + OtrActivator.scOtrEngine.getSessionStatus(contact); // If OTR is disabled and we are not over an encrypted session, don't // process anything. if (!policy.getEnableManual() @@ -65,12 +61,10 @@ public MessageDeliveredEvent messageDeliveryPending( MessageDeliveredEvent evt) { Contact contact = evt.getDestinationContact(); - OtrContact otrContact = - OtrContactManager.getOtrContact(contact, evt.getContactResource()); OtrPolicy policy = OtrActivator.scOtrEngine.getContactPolicy(contact); ScSessionStatus sessionStatus = - OtrActivator.scOtrEngine.getSessionStatus(otrContact); + OtrActivator.scOtrEngine.getSessionStatus(contact); // If OTR is disabled and we are not over an encrypted session, don't // process anything. if (!policy.getEnableManual() @@ -86,7 +80,7 @@ public MessageDeliveredEvent messageDeliveryPending( // Process the outgoing message. String msgContent = evt.getSourceMessage().getContent(); String processedMessageContent = - OtrActivator.scOtrEngine.transformSending(otrContact, msgContent); + OtrActivator.scOtrEngine.transformSending(contact, msgContent); if (processedMessageContent == null || processedMessageContent.length() < 1) @@ -100,22 +94,13 @@ public MessageDeliveredEvent messageDeliveryPending( contact.getProtocolProvider().getOperationSet( OperationSetBasicInstantMessaging.class); Message processedMessage = - imOpSet.createMessage( - processedMessageContent, - evt.getSourceMessage().getContentType(), - evt.getSourceMessage().getEncoding(), - evt.getSourceMessage().getSubject()); + imOpSet.createMessage(processedMessageContent); // Create a new event and return. MessageDeliveredEvent processedEvent = new MessageDeliveredEvent(processedMessage, contact, evt .getTimestamp()); - if(processedMessage.getContent().contains(SerializationConstants.HEAD)) - { - processedEvent.setMessageEncrypted(true); - } - return processedEvent; } @@ -125,12 +110,10 @@ public MessageDeliveredEvent messageDeliveryPending( public MessageReceivedEvent messageReceived(MessageReceivedEvent evt) { Contact contact = evt.getSourceContact(); - OtrContact otrContact = - OtrContactManager.getOtrContact(contact, evt.getContactResource()); OtrPolicy policy = OtrActivator.scOtrEngine.getContactPolicy(contact); ScSessionStatus sessionStatus = - OtrActivator.scOtrEngine.getSessionStatus(otrContact); + OtrActivator.scOtrEngine.getSessionStatus(contact); // If OTR is disabled and we are not over an encrypted session, don't // process anything. if (!policy.getEnableManual() @@ -142,7 +125,7 @@ public MessageReceivedEvent messageReceived(MessageReceivedEvent evt) String msgContent = evt.getSourceMessage().getContent(); String processedMessageContent = - OtrActivator.scOtrEngine.transformReceiving(otrContact, msgContent); + OtrActivator.scOtrEngine.transformReceiving(contact, msgContent); if (processedMessageContent == null || processedMessageContent.length() < 1) @@ -157,9 +140,7 @@ public MessageReceivedEvent messageReceived(MessageReceivedEvent evt) OperationSetBasicInstantMessaging.class); Message processedMessage = imOpSet.createMessageWithUID( - processedMessageContent, - evt.getSourceMessage().getContentType(), - evt.getSourceMessage().getMessageUID()); + processedMessageContent, evt.getSourceMessage().getMessageUID()); // Create a new event and return. MessageReceivedEvent processedEvent = diff --git a/src/net/java/sip/communicator/plugin/otr/OtrWeakListener.java b/src/net/java/sip/communicator/plugin/otr/OtrWeakListener.java index 4c55f248d..423cf23f2 100644 --- a/src/net/java/sip/communicator/plugin/otr/OtrWeakListener.java +++ b/src/net/java/sip/communicator/plugin/otr/OtrWeakListener.java @@ -8,7 +8,6 @@ import java.lang.ref.*; -import net.java.sip.communicator.plugin.otr.OtrContactManager.OtrContact; import net.java.sip.communicator.service.protocol.*; /** @@ -94,7 +93,7 @@ public void contactPolicyChanged(Contact contact) * Forwards the event/notification to the associated * T if it is still needed by the application. */ - public void contactVerificationStatusChanged(OtrContact contact) + public void contactVerificationStatusChanged(Contact contact) { ScOtrKeyManagerListener l = getListener(); @@ -146,35 +145,11 @@ public void globalPolicyChanged() * Forwards the event/notification to the associated * T if it is still needed by the application. */ - public void sessionStatusChanged(OtrContact contact) + public void sessionStatusChanged(Contact contact) { ScOtrEngineListener l = getListener(); if (l != null) l.sessionStatusChanged(contact); } - - /** - * Forwards the event/notification to the associated - * T if it is still needed by the application. - */ - public void multipleInstancesDetected(OtrContact contact) - { - ScOtrEngineListener l = getListener(); - - if (l != null) - l.multipleInstancesDetected(contact); - } - - /** - * Forwards the event/notification to the associated - * T if it is still needed by the application. - */ - public void outgoingSessionChanged(OtrContact contact) - { - ScOtrEngineListener l = getListener(); - - if (l != null) - l.outgoingSessionChanged(contact); - } } diff --git a/src/net/java/sip/communicator/plugin/otr/ScOtrEngine.java b/src/net/java/sip/communicator/plugin/otr/ScOtrEngine.java index f9ee9098b..853c5fc5b 100644 --- a/src/net/java/sip/communicator/plugin/otr/ScOtrEngine.java +++ b/src/net/java/sip/communicator/plugin/otr/ScOtrEngine.java @@ -6,12 +6,7 @@ */ package net.java.sip.communicator.plugin.otr; -import java.security.*; -import java.util.*; - import net.java.otr4j.*; -import net.java.otr4j.session.*; -import net.java.sip.communicator.plugin.otr.OtrContactManager.OtrContact; import net.java.sip.communicator.service.protocol.*; /** @@ -34,7 +29,7 @@ public interface ScOtrEngine * @param secret The secret answer for the question. */ public abstract void initSmp( - OtrContact contact, String question, String secret); + Contact contact, String question, String secret); /** * Responds to a question that is asked during the Smp negotiation process. @@ -42,16 +37,12 @@ public abstract void initSmp( * >http://en.wikipedia.org/wiki/Socialist_Millionaire_Problem * * @param contact The contact for whom we want to respond to a question - * during the Smp negotiation process. - * @param receiverTag The instance tag of the intended receiver of the SMP - * response + * during the Smp negotiation process. * @param question The question that is asked during the Smp negotiation. * @param secret The secret answer for the question. */ - public abstract void respondSmp(OtrContact contact, - InstanceTag receiverTag, - String question, - String secret); + public abstract void respondSmp( + Contact contact, String question, String secret); /** * Aborts the Smp negotiation process. @@ -61,111 +52,61 @@ public abstract void respondSmp(OtrContact contact, * @param contact The contact with whom we want to abort the * Smp negotiation process. */ - public abstract void abortSmp(OtrContact contact); + public abstract void abortSmp(Contact contact); /** * Transforms an outgoing message. * - * @param contact the destination {@link OtrContact}. + * @param contact the destination {@link Contact}. * @param content the original message content. * @return the transformed message content. */ - public abstract String transformSending(OtrContact contact, String content); + public abstract String transformSending(Contact contact, String content); /** * Transforms an incoming message. * - * @param contact the source {@link OtrContact}. + * @param contact the source {@link Contact}. * @param content the original message content. * @return the transformed message content. */ - public abstract String transformReceiving(OtrContact contact, String content); + public abstract String transformReceiving(Contact contact, String content); /** - * Starts the Off-the-Record session for the given {@link OtrContact}, if it's + * Starts the Off-the-Record session for the given {@link Contact}, if it's * not already started. * - * @param contact the {@link OtrContact} with whom we want to start an OTR + * @param contact the {@link Contact} with whom we want to start an OTR * session. */ - public abstract void startSession(OtrContact contact); + public abstract void startSession(Contact contact); /** - * Ends the Off-the-Record session for the given {@link OtrContact}, if it is + * Ends the Off-the-Record session for the given {@link Contact}, if it is * not already started. * - * @param contact the {@link OtrContact} with whom we want to end the OTR + * @param contact the {@link Contact} with whom we want to end the OTR * session. */ - public abstract void endSession(OtrContact contact); + public abstract void endSession(Contact contact); /** - * Refreshes the Off-the-Record session for the given {@link OtrContact}. If + * Refreshes the Off-the-Record session for the given {@link Contact}. If * the session does not exist, a new session is established. * - * @param contact the {@link OtrContact} with whom we want to refresh the OTR + * @param contact the {@link Contact} with whom we want to refresh the OTR * session. */ - public abstract void refreshSession(OtrContact contact); + public abstract void refreshSession(Contact contact); /** - * Get the outgoing OTRv3 Session. This could be the 'master' - * session as well as a 'slave' session. - * This method could also be safely used for OTRv2 sessions. In the case of - * version 2 the master session itself will always be returned. - * - * @param contact the {@link OtrContact} for whom we want to get the - * outgoing OTR session. + * Gets the {@link ScSessionStatus} for the given {@link Contact}. * - * @return the Session that is currently transforming outgoing all - * messages. - */ - public abstract Session getOutgoingSession(OtrContact contact); - - /** - * Some IM networks always relay all messages to all sessions of a client - * who is logged in multiple times. OTR version 3 deals with this problem - * with introducing instance tags. - * - * https://otr.cypherpunks.ca/Protocol-v3-4.0.0.html - *

- * Returns a list containing all instances of a session. The 'master' - * session is always first in the list. - * - * @param contact the {@link OtrContact} for whom we want to get the instances - * - * @return A list of all instances of the session for the specified contact. - */ - public abstract List getSessionInstances(OtrContact contact); - - /** - * Some IM networks always relay all messages to all sessions of a client - * who is logged in multiple times. OTR version 3 deals with this problem - * with introducing instance tags. - * - * https://otr.cypherpunks.ca/Protocol-v3-4.0.0.html - *

- * When the client wishes to start sending OTRv3 encrypted messages to a - * specific session of his buddy who is logged in multiple times, he can set - * the outgoing instance of his buddy by specifying his InstanceTag. - * - * @param contact the {@link OtrContact} to whom we want to set the outgoing - * instance tag. - * @param tag the outgoing {@link InstanceTag} - * - * @return true if an outgoing session with such {@link InstanceTag} exists - * . Otherwise false - */ - public abstract boolean setOutgoingSession(OtrContact contact, InstanceTag tag); - - /** - * Gets the {@link ScSessionStatus} for the given {@link OtrContact}. - * - * @param contact the {@link OtrContact} whose {@link ScSessionStatus} we are + * @param contact the {@link Contact} whose {@link ScSessionStatus} we are * interested in. * @return the {@link ScSessionStatus}. */ - public abstract ScSessionStatus getSessionStatus(OtrContact contact); + public abstract ScSessionStatus getSessionStatus(Contact contact); // New Methods (Misc) @@ -194,8 +135,6 @@ public abstract void respondSmp(OtrContact contact, */ public abstract void removeListener(ScOtrEngineListener listener); - public abstract PublicKey getRemotePublicKey(OtrContact otrContact); - // New Methods (Policy management) /** * Gets the global {@link OtrPolicy}. diff --git a/src/net/java/sip/communicator/plugin/otr/ScOtrEngineImpl.java b/src/net/java/sip/communicator/plugin/otr/ScOtrEngineImpl.java index 171fc7810..09be3990f 100644 --- a/src/net/java/sip/communicator/plugin/otr/ScOtrEngineImpl.java +++ b/src/net/java/sip/communicator/plugin/otr/ScOtrEngineImpl.java @@ -12,9 +12,7 @@ import java.util.concurrent.*; import net.java.otr4j.*; -import net.java.otr4j.crypto.*; import net.java.otr4j.session.*; -import net.java.sip.communicator.plugin.otr.OtrContactManager.OtrContact; import net.java.sip.communicator.plugin.otr.authdialog.*; import net.java.sip.communicator.service.browserlauncher.*; import net.java.sip.communicator.service.contactlist.*; @@ -53,60 +51,21 @@ public KeyPair getLocalKeyPair(SessionID sessionID) public OtrPolicy getSessionPolicy(SessionID sessionID) { - return getContactPolicy(getOtrContact(sessionID).contact); + return getContactPolicy(getContact(sessionID)); } public void injectMessage(SessionID sessionID, String messageText) { - OtrContact otrContact = getOtrContact(sessionID); - Contact contact = otrContact.contact; - ContactResource resource = null; - - if (contact.supportResources()) - { - Collection resources = contact.getResources(); - if (resources != null) - { - for (ContactResource r : resources) - { - if (r.equals(otrContact.resource)) - { - resource = r; - break; - } - } - } - } - + Contact contact = getContact(sessionID); OperationSetBasicInstantMessaging imOpSet = contact .getProtocolProvider() .getOperationSet( OperationSetBasicInstantMessaging.class); - - // This is a dirty way of detecting whether the injected message - // contains HTML markup. If this is the case then we should create - // the message with the appropriate content type so that the remote - // party can properly display the HTML. - // When otr4j injects QueryMessages it calls - // OtrEngineHost.getFallbackMessage() which is currently the only - // host method that uses HTML so we can simply check if the injected - // message contains the string that getFallbackMessage() returns. - String otrHtmlFallbackMessage - = ""; - String contentType - = messageText.contains(otrHtmlFallbackMessage) - ? OperationSetBasicInstantMessaging.HTML_MIME_TYPE - : OperationSetBasicInstantMessaging.DEFAULT_MIME_TYPE; - Message message - = imOpSet.createMessage( - messageText, - contentType, - OperationSetBasicInstantMessaging.DEFAULT_MIME_ENCODING, - null); + Message message = imOpSet.createMessage(messageText); injectedMessageUIDs.add(message.getMessageUID()); - imOpSet.sendInstantMessage(contact, resource, message); + imOpSet.sendInstantMessage(contact, message); } public void showError(SessionID sessionID, String err) @@ -116,11 +75,10 @@ public void showError(SessionID sessionID, String err) public void showWarning(SessionID sessionID, String warn) { - OtrContact otrContact = getOtrContact(sessionID); - if (otrContact == null) + Contact contact = getContact(sessionID); + if (contact == null) return; - Contact contact = otrContact.contact; OtrActivator.uiService.getChat(contact).addMessage( contact.getDisplayName(), new Date(), Chat.SYSTEM_MESSAGE, warn, @@ -131,16 +89,14 @@ public void showWarning(SessionID sessionID, String warn) public void unreadableMessageReceived(SessionID sessionID) throws OtrException { - OtrContact otrContact = getOtrContact(sessionID); - String resourceName = otrContact.resource != null ? - "/" + otrContact.resource.getResourceName() : ""; + Contact contact = getContact(sessionID); + if (contact == null) + return; - Contact contact = otrContact.contact; String error = OtrActivator.resourceService.getI18NString( "plugin.otr.activator.unreadablemsgreceived", - new String[] - {contact.getDisplayName() + resourceName}); + new String[] {contact.getDisplayName()}); OtrActivator.uiService.getChat(contact).addMessage( contact.getDisplayName(), new Date(), Chat.ERROR_MESSAGE, error, @@ -151,11 +107,10 @@ public void unreadableMessageReceived(SessionID sessionID) public void unencryptedMessageReceived(SessionID sessionID, String msg) throws OtrException { - OtrContact otrContact = getOtrContact(sessionID); - if (otrContact == null) + Contact contact = getContact(sessionID); + if (contact == null) return; - Contact contact = otrContact.contact; String warn = OtrActivator.resourceService.getI18NString( "plugin.otr.activator.unencryptedmsgreceived"); @@ -169,11 +124,10 @@ public void unencryptedMessageReceived(SessionID sessionID, String msg) public void smpError(SessionID sessionID, int tlvType, boolean cheated) throws OtrException { - OtrContact otrContact = getOtrContact(sessionID); - if (otrContact == null) + Contact contact = getContact(sessionID); + if (contact == null) return; - Contact contact = otrContact.contact; logger.debug("SMP error occurred" + ". Contact: " + contact.getDisplayName() + ". TLV type: " + tlvType @@ -187,11 +141,11 @@ public void smpError(SessionID sessionID, int tlvType, boolean cheated) Chat.ERROR_MESSAGE, error, OperationSetBasicInstantMessaging.DEFAULT_MIME_TYPE); - SmpProgressDialog progressDialog = progressDialogMap.get(otrContact); + SmpProgressDialog progressDialog = progressDialogMap.get(contact); if (progressDialog == null) { progressDialog = new SmpProgressDialog(contact); - progressDialogMap.put(otrContact, progressDialog); + progressDialogMap.put(contact, progressDialog); } progressDialog.setProgressFail(); @@ -201,11 +155,10 @@ public void smpError(SessionID sessionID, int tlvType, boolean cheated) @Override public void smpAborted(SessionID sessionID) throws OtrException { - OtrContact otrContact = getOtrContact(sessionID); - if (otrContact == null) + Contact contact = getContact(sessionID); + if (contact == null) return; - Contact contact = otrContact.contact; Session session = otrEngine.getSession(sessionID); if (session.isSmpInProgress()) { @@ -218,12 +171,11 @@ public void smpAborted(SessionID sessionID) throws OtrException Chat.SYSTEM_MESSAGE, warn, OperationSetBasicInstantMessaging.DEFAULT_MIME_TYPE); - SmpProgressDialog progressDialog = - progressDialogMap.get(otrContact); + SmpProgressDialog progressDialog = progressDialogMap.get(contact); if (progressDialog == null) { progressDialog = new SmpProgressDialog(contact); - progressDialogMap.put(otrContact, progressDialog); + progressDialogMap.put(contact, progressDialog); } progressDialog.setProgressFail(); @@ -232,21 +184,17 @@ public void smpAborted(SessionID sessionID) throws OtrException } @Override - public void finishedSessionMessage(SessionID sessionID, String msgText) + public void finishedSessionMessage(SessionID sessionID) throws OtrException { - OtrContact otrContact = getOtrContact(sessionID); - if (otrContact == null) + Contact contact = getContact(sessionID); + if (contact == null) return; - String resourceName = otrContact.resource != null ? - "/" + otrContact.resource.getResourceName() : ""; - Contact contact = otrContact.contact; String error = OtrActivator.resourceService.getI18NString( "plugin.otr.activator.sessionfinishederror", - new String[] - {msgText, contact.getDisplayName() + resourceName}); + new String[] {contact.getDisplayName()}); OtrActivator.uiService.getChat(contact).addMessage( contact.getDisplayName(), new Date(), Chat.ERROR_MESSAGE, error, @@ -257,16 +205,14 @@ public void finishedSessionMessage(SessionID sessionID, String msgText) public void requireEncryptedMessage(SessionID sessionID, String msgText) throws OtrException { - OtrContact otrContact = getOtrContact(sessionID); - if (otrContact == null) + Contact contact = getContact(sessionID); + if (contact == null) return; - Contact contact = otrContact.contact; String error = OtrActivator.resourceService.getI18NString( "plugin.otr.activator.requireencryption", - new String[] - {msgText}); + new String[] {contact.getDisplayName()}); OtrActivator.uiService.getChat(contact).addMessage( contact.getDisplayName(), new Date(), Chat.ERROR_MESSAGE, error, @@ -283,24 +229,21 @@ public byte[] getLocalFingerprintRaw(SessionID sessionID) } @Override - public void askForSecret( - SessionID sessionID, InstanceTag receiverTag, String question) + public void askForSecret(SessionID sessionID, String question) { - OtrContact otrContact = getOtrContact(sessionID); - if (otrContact == null) + Contact contact = getContact(sessionID); + if (contact == null) return; - Contact contact = otrContact.contact; SmpAuthenticateBuddyDialog dialog = - new SmpAuthenticateBuddyDialog( - otrContact, receiverTag, question); + new SmpAuthenticateBuddyDialog(contact, question); dialog.setVisible(true); - SmpProgressDialog progressDialog = progressDialogMap.get(otrContact); + SmpProgressDialog progressDialog = progressDialogMap.get(contact); if (progressDialog == null) { progressDialog = new SmpProgressDialog(contact); - progressDialogMap.put(otrContact, progressDialog); + progressDialogMap.put(contact, progressDialog); } progressDialog.init(); @@ -308,21 +251,19 @@ public void askForSecret( } @Override - public void verify( - SessionID sessionID, String fingerprint, boolean approved) + public void verify(SessionID sessionID, boolean approved) { - OtrContact otrContact = getOtrContact(sessionID); - if (otrContact == null) + Contact contact = getContact(sessionID); + if (contact == null) return; - Contact contact = otrContact.contact; - OtrActivator.scOtrKeyManager.verify(otrContact, fingerprint); + OtrActivator.scOtrKeyManager.verify(contact); - SmpProgressDialog progressDialog = progressDialogMap.get(otrContact); + SmpProgressDialog progressDialog = progressDialogMap.get(contact); if (progressDialog == null) { progressDialog = new SmpProgressDialog(contact); - progressDialogMap.put(otrContact, progressDialog); + progressDialogMap.put(contact, progressDialog); } progressDialog.setProgressSuccess(); @@ -330,20 +271,19 @@ public void verify( } @Override - public void unverify(SessionID sessionID, String fingerprint) + public void unverify(SessionID sessionID) { - OtrContact otrContact = getOtrContact(sessionID); - if (otrContact == null) + Contact contact = getContact(sessionID); + if (contact == null) return; - Contact contact = otrContact.contact; - OtrActivator.scOtrKeyManager.unverify(otrContact, fingerprint); + OtrActivator.scOtrKeyManager.unverify(contact); - SmpProgressDialog progressDialog = progressDialogMap.get(otrContact); + SmpProgressDialog progressDialog = progressDialogMap.get(contact); if (progressDialog == null) { progressDialog = new SmpProgressDialog(contact); - progressDialogMap.put(otrContact, progressDialog); + progressDialogMap.put(contact, progressDialog); } progressDialog.setProgressFail(); @@ -372,50 +312,6 @@ public String getFallbackMessage(SessionID sessionID) "plugin.otr.activator.fallbackmessage", new String[] {accountID.getDisplayName()}); } - - @Override - public void multipleInstancesDetected(SessionID sessionID) - { - OtrContact otrContact = getOtrContact(sessionID); - if (otrContact == null) - return; - - String resourceName = otrContact.resource != null ? - "/" + otrContact.resource.getResourceName() : ""; - Contact contact = otrContact.contact; - String message = - OtrActivator.resourceService.getI18NString( - "plugin.otr.activator.multipleinstancesdetected", - new String[] - {contact.getDisplayName() + resourceName}); - OtrActivator.uiService.getChat(contact).addMessage( - contact.getDisplayName(), - new Date(), Chat.SYSTEM_MESSAGE, - message, - OperationSetBasicInstantMessaging.HTML_MIME_TYPE); - } - - @Override - public void messageFromAnotherInstanceReceived(SessionID sessionID) - { - OtrContact otrContact = getOtrContact(sessionID); - if (otrContact == null) - return; - - String resourceName = otrContact.resource != null ? - "/" + otrContact.resource.getResourceName() : ""; - Contact contact = otrContact.contact; - String message = - OtrActivator.resourceService.getI18NString( - "plugin.otr.activator.msgfromanotherinstance", - new String[] - {contact.getDisplayName() + resourceName}); - OtrActivator.uiService.getChat(contact).addMessage( - contact.getDisplayName(), - new Date(), Chat.SYSTEM_MESSAGE, - message, - OperationSetBasicInstantMessaging.HTML_MIME_TYPE); - } } /** @@ -439,13 +335,13 @@ public void messageFromAnotherInstanceReceived(SessionID sessionID) private Map scSessionStatusMap = new ConcurrentHashMap(); - private static final Map contactsMap = - new Hashtable(); + private static final Map contactsMap = + new Hashtable(); - private static final Map progressDialogMap = - new ConcurrentHashMap(); + private static final Map progressDialogMap = + new ConcurrentHashMap(); - public static OtrContact getOtrContact(SessionID sessionID) + public static Contact getContact(SessionID sessionID) { return contactsMap.get(new ScSessionID(sessionID)); } @@ -468,15 +364,13 @@ public static ScSessionID getScSessionForGuid(UUID guid) return null; } - public static SessionID getSessionID(OtrContact otrContact) + public static SessionID getSessionID(Contact contact) { - ProtocolProviderService pps = otrContact.contact.getProtocolProvider(); - String resourceName = otrContact.resource != null ? - "/" + otrContact.resource.getResourceName() : ""; + ProtocolProviderService pps = contact.getProtocolProvider(); SessionID sessionID = new SessionID( pps.getAccountID().getAccountUniqueID(), - otrContact.contact.getAddress() + resourceName, + contact.getAddress(), pps.getProtocolName()); synchronized (contactsMap) @@ -486,7 +380,7 @@ public static SessionID getSessionID(OtrContact otrContact) ScSessionID scSessionID = new ScSessionID(sessionID); - contactsMap.put(scSessionID, otrContact); + contactsMap.put(scSessionID, contact); } return sessionID; @@ -521,18 +415,15 @@ public ScOtrEngineImpl() { public void sessionStatusChanged(SessionID sessionID) { - OtrContact otrContact = getOtrContact(sessionID); - if (otrContact == null) + Contact contact = getContact(sessionID); + if (contact == null) return; - String resourceName = otrContact.resource != null ? - "/" + otrContact.resource.getResourceName() : ""; - Contact contact = otrContact.contact; // Cancels any scheduled tasks that will change the // ScSessionStatus for this Contact - scheduler.cancel(otrContact); + scheduler.cancel(contact); - ScSessionStatus scSessionStatus = getSessionStatus(otrContact); + ScSessionStatus scSessionStatus = getSessionStatus(contact); String message = ""; switch (otrEngine.getSessionStatus(sessionID)) { @@ -542,38 +433,15 @@ public void sessionStatusChanged(SessionID sessionID) PublicKey remotePubKey = otrEngine.getRemotePublicKey(sessionID); - String remoteFingerprint = null; - try - { - remoteFingerprint = - new OtrCryptoEngineImpl(). - getFingerprint(remotePubKey); - } - catch (OtrCryptoException e) - { - logger.debug( - "Could not get the fingerprint from the " - + "public key of contact: " + contact); - } + PublicKey storedPubKey = + OtrActivator.scOtrKeyManager.loadPublicKey(contact); - List allFingerprintsOfContact = - OtrActivator.scOtrKeyManager. - getAllRemoteFingerprints(contact); - if (allFingerprintsOfContact != null) - { - if (!allFingerprintsOfContact.contains( - remoteFingerprint)) - { - OtrActivator.scOtrKeyManager.saveFingerprint( - contact, remoteFingerprint); - } - } + if (!remotePubKey.equals(storedPubKey)) + OtrActivator.scOtrKeyManager.savePublicKey(contact, + remotePubKey); - if (!OtrActivator.scOtrKeyManager.isVerified( - contact, remoteFingerprint)) + if (!OtrActivator.scOtrKeyManager.isVerified(contact)) { - OtrActivator.scOtrKeyManager.unverify( - otrContact, remoteFingerprint); UUID sessionGuid = null; for(ScSessionID scSessionID : contactsMap.keySet()) { @@ -593,7 +461,7 @@ public void sessionStatusChanged(SessionID sessionID) + ".unverifiedsessionwarning", new String[] { - contact.getDisplayName() + resourceName, + contact.getDisplayName(), this.getClass().getName(), "AUTHENTIFICATION", sessionGuid.toString() @@ -608,9 +476,8 @@ public void sessionStatusChanged(SessionID sessionID) // show info whether history is on or off String otrAndHistoryMessage; - if(!OtrActivator.getMessageHistoryService() - .isHistoryLoggingEnabled() || - !isHistoryLoggingEnabled(contact)) + if(!ConfigurationUtils.isHistoryLoggingEnabled() + || !isHistoryLoggingEnabled(contact)) { otrAndHistoryMessage = OtrActivator.resourceService.getI18NString( @@ -642,30 +509,13 @@ public void sessionStatusChanged(SessionID sessionID) otrAndHistoryMessage, OperationSetBasicInstantMessaging.HTML_MIME_TYPE); - message = - OtrActivator.resourceService.getI18NString( - "plugin.otr.activator.multipleinstancesdetected", - new String[] - {contact.getDisplayName()}); - - if (contact.supportResources() - && contact.getResources() != null - && contact.getResources().size() > 1) - OtrActivator.uiService.getChat(contact).addMessage( - contact.getDisplayName(), - new Date(), Chat.SYSTEM_MESSAGE, - message, - OperationSetBasicInstantMessaging.DEFAULT_MIME_TYPE); - message = OtrActivator.resourceService.getI18NString( - OtrActivator.scOtrKeyManager.isVerified( - contact, remoteFingerprint) + OtrActivator.scOtrKeyManager.isVerified(contact) ? "plugin.otr.activator.sessionstared" : "plugin.otr.activator" + ".unverifiedsessionstared", - new String[] - {contact.getDisplayName() + resourceName}); + new String[] { contact.getDisplayName() }); break; case FINISHED: @@ -675,7 +525,7 @@ public void sessionStatusChanged(SessionID sessionID) OtrActivator.resourceService.getI18NString( "plugin.otr.activator.sessionfinished", new String[] - {contact.getDisplayName() + resourceName}); + { contact.getDisplayName() }); break; case PLAINTEXT: scSessionStatus = ScSessionStatus.PLAINTEXT; @@ -683,7 +533,7 @@ public void sessionStatusChanged(SessionID sessionID) message = OtrActivator.resourceService.getI18NString( "plugin.otr.activator.sessionlost", new String[] - {contact.getDisplayName() + resourceName}); + { contact.getDisplayName() }); break; } @@ -693,27 +543,7 @@ public void sessionStatusChanged(SessionID sessionID) OperationSetBasicInstantMessaging.HTML_MIME_TYPE); for (ScOtrEngineListener l : getListeners()) - l.sessionStatusChanged(otrContact); - } - - public void multipleInstancesDetected(SessionID sessionID) - { - OtrContact otrContact = getOtrContact(sessionID); - if (otrContact == null) - return; - - for (ScOtrEngineListener l : getListeners()) - l.multipleInstancesDetected(otrContact); - } - - public void outgoingSessionChanged(SessionID sessionID) - { - OtrContact otrContact = getOtrContact(sessionID); - if (otrContact == null) - return; - - for (ScOtrEngineListener l : getListeners()) - l.outgoingSessionChanged(otrContact); + l.sessionStatusChanged(contact); } }); } @@ -730,8 +560,8 @@ private boolean isHistoryLoggingEnabled(Contact contact) MetaContact metaContact = OtrActivator .getContactListService().findMetaContactByContact(contact); if(metaContact != null) - return OtrActivator.getMessageHistoryService() - .isHistoryLoggingEnabled(metaContact.getMetaUID()); + return ConfigurationUtils.isHistoryLoggingEnabled( + metaContact.getMetaUID()); else return true; } @@ -773,12 +603,12 @@ public void chatLinkClicked(URI url) } } - public void endSession(OtrContact otrContact) + public void endSession(Contact contact) { - SessionID sessionID = getSessionID(otrContact); + SessionID sessionID = getSessionID(contact); try { - setSessionStatus(otrContact, ScSessionStatus.PLAINTEXT); + setSessionStatus(contact, ScSessionStatus.PLAINTEXT); otrEngine.endSession(sessionID); } @@ -790,14 +620,8 @@ public void endSession(OtrContact otrContact) public OtrPolicy getContactPolicy(Contact contact) { - ProtocolProviderService pps = contact.getProtocolProvider(); - SessionID sessionID - = new SessionID( - pps.getAccountID().getAccountUniqueID(), - contact.getAddress(), - pps.getProtocolName()); int policy = - this.configurator.getPropertyInt(sessionID + "contact_policy", + this.configurator.getPropertyInt(getSessionID(contact) + "policy", -1); if (policy < 0) return getGlobalPolicy(); @@ -807,13 +631,8 @@ public OtrPolicy getContactPolicy(Contact contact) public OtrPolicy getGlobalPolicy() { - /* - * SEND_WHITESPACE_TAG bit will be lowered until we stabilize the OTR. - */ - int defaultScOtrPolicy = - OtrPolicy.OTRL_POLICY_DEFAULT & ~OtrPolicy.SEND_WHITESPACE_TAG; - return new OtrPolicyImpl(this.configurator.getPropertyInt( - "GLOBAL_POLICY", defaultScOtrPolicy)); + return new OtrPolicyImpl(this.configurator.getPropertyInt("POLICY", + OtrPolicy.OTRL_POLICY_MANUAL)); } /** @@ -843,31 +662,31 @@ private class ScSessionStatusScheduler { private final Timer timer = new Timer(); - private final Map tasks = - new ConcurrentHashMap(); + private final Map tasks = + new ConcurrentHashMap(); public void scheduleScSessionStatusChange( - final OtrContact otrContact, final ScSessionStatus status) + final Contact contact, final ScSessionStatus status) { - cancel(otrContact); + cancel(contact); TimerTask task = new TimerTask() { @Override public void run() { - setSessionStatus(otrContact, status); + setSessionStatus(contact, status); } }; timer.schedule(task, SESSION_TIMEOUT); - tasks.put(otrContact, task); + tasks.put(contact, task); } - public void cancel(final OtrContact otrContact) + public void cancel(final Contact contact) { - TimerTask task = tasks.get(otrContact); + TimerTask task = tasks.get(contact); if (task != null) task.cancel(); - tasks.remove(otrContact); + tasks.remove(contact); } public void serviceChanged(ServiceEvent ev) @@ -884,15 +703,13 @@ public void serviceChanged(ServiceEvent ev) ProtocolProviderService provider = (ProtocolProviderService) service; - Iterator i = tasks.keySet().iterator(); + Iterator i = tasks.keySet().iterator(); while (i.hasNext()) { - OtrContact otrContact = i.next(); - if (provider.equals( - otrContact.contact.getProtocolProvider())) - { - cancel(otrContact); + Contact contact = i.next(); + if (provider.equals(contact.getProtocolProvider())) { + cancel(contact); i.remove(); } } @@ -900,15 +717,14 @@ public void serviceChanged(ServiceEvent ev) } } - private void setSessionStatus(OtrContact contact, ScSessionStatus status) + private void setSessionStatus(Contact contact, ScSessionStatus status) { scSessionStatusMap.put(getSessionID(contact), status); - scheduler.cancel(contact); for (ScOtrEngineListener l : getListeners()) l.sessionStatusChanged(contact); } - public ScSessionStatus getSessionStatus(OtrContact contact) + public ScSessionStatus getSessionStatus(Contact contact) { SessionID sessionID = getSessionID(contact); SessionStatus sessionStatus = otrEngine.getSessionStatus(sessionID); @@ -953,9 +769,9 @@ public void launchHelp() .getI18NString("plugin.otr.authbuddydialog.HELP_URI")); } - public void refreshSession(OtrContact otrContact) + public void refreshSession(Contact contact) { - SessionID sessionID = getSessionID(otrContact); + SessionID sessionID = getSessionID(contact); try { otrEngine.refreshSession(sessionID); @@ -1004,25 +820,24 @@ public void serviceChanged(ServiceEvent ev) synchronized(contactsMap) { - Iterator i = contactsMap.values().iterator(); + Iterator i = contactsMap.values().iterator(); while (i.hasNext()) - { - OtrContact otrContact = i.next(); - if (provider.equals( - otrContact.contact.getProtocolProvider())) + { + Contact contact = i.next(); + if (provider.equals(contact.getProtocolProvider())) { - scSessionStatusMap.remove(getSessionID(otrContact)); + scSessionStatusMap.remove(getSessionID(contact)); i.remove(); } } } - Iterator i = progressDialogMap.keySet().iterator(); + Iterator i = progressDialogMap.keySet().iterator(); while (i.hasNext()) { - if (provider.equals(i.next().contact.getProtocolProvider())) + if (provider.equals(i.next().getProtocolProvider())) i.remove(); } scheduler.serviceChanged(ev); @@ -1031,14 +846,7 @@ public void serviceChanged(ServiceEvent ev) public void setContactPolicy(Contact contact, OtrPolicy policy) { - ProtocolProviderService pps = contact.getProtocolProvider(); - SessionID sessionID - = new SessionID( - pps.getAccountID().getAccountUniqueID(), - contact.getAddress(), - pps.getProtocolName()); - - String propertyID = sessionID + "contact_policy"; + String propertyID = getSessionID(contact) + "policy"; if (policy == null) this.configurator.removeProperty(propertyID); else @@ -1051,9 +859,9 @@ public void setContactPolicy(Contact contact, OtrPolicy policy) public void setGlobalPolicy(OtrPolicy policy) { if (policy == null) - this.configurator.removeProperty("GLOBAL_POLICY"); + this.configurator.removeProperty("POLICY"); else - this.configurator.setProperty("GLOBAL_POLICY", policy.getPolicy()); + this.configurator.setProperty("POLICY", policy.getPolicy()); for (ScOtrEngineListener l : getListeners()) l.globalPolicyChanged(); @@ -1061,32 +869,30 @@ public void setGlobalPolicy(OtrPolicy policy) public void showError(SessionID sessionID, String err) { - OtrContact otrContact = getOtrContact(sessionID); - if (otrContact == null) + Contact contact = getContact(sessionID); + if (contact == null) return; - Contact contact = otrContact.contact; OtrActivator.uiService.getChat(contact).addMessage( contact.getDisplayName(), new Date(), Chat.ERROR_MESSAGE, err, OperationSetBasicInstantMessaging.DEFAULT_MIME_TYPE); } - public void startSession(OtrContact otrContact) + public void startSession(Contact contact) { - SessionID sessionID = getSessionID(otrContact); + SessionID sessionID = getSessionID(contact); - ScSessionStatus scSessionStatus = getSessionStatus(otrContact); + ScSessionStatus scSessionStatus = getSessionStatus(contact); scSessionStatus = ScSessionStatus.LOADING; scSessionStatusMap.put(sessionID, scSessionStatus); for (ScOtrEngineListener l : getListeners()) { - l.sessionStatusChanged(otrContact); + l.sessionStatusChanged(contact); + scheduler.scheduleScSessionStatusChange( + contact, ScSessionStatus.TIMED_OUT); } - scheduler.scheduleScSessionStatusChange( - otrContact, ScSessionStatus.TIMED_OUT); - try { otrEngine.startSession(sessionID); @@ -1098,9 +904,9 @@ public void startSession(OtrContact otrContact) } } - public String transformReceiving(OtrContact otrContact, String msgText) + public String transformReceiving(Contact contact, String msgText) { - SessionID sessionID = getSessionID(otrContact); + SessionID sessionID = getSessionID(contact); try { return otrEngine.transformReceiving(sessionID, msgText); @@ -1113,9 +919,9 @@ public String transformReceiving(OtrContact otrContact, String msgText) } } - public String transformSending(OtrContact otrContact, String msgText) + public String transformSending(Contact contact, String msgText) { - SessionID sessionID = getSessionID(otrContact); + SessionID sessionID = getSessionID(contact); try { return otrEngine.transformSending(sessionID, msgText); @@ -1128,25 +934,25 @@ public String transformSending(OtrContact otrContact, String msgText) } } - private Session getSession(OtrContact contact) + private Session getSession(Contact contact) { SessionID sessionID = getSessionID(contact); return otrEngine.getSession(sessionID); } @Override - public void initSmp(OtrContact otrContact, String question, String secret) + public void initSmp(Contact contact, String question, String secret) { - Session session = getSession(otrContact); + Session session = getSession(contact); try { session.initSmp(question, secret); - SmpProgressDialog progressDialog = progressDialogMap.get(otrContact); + SmpProgressDialog progressDialog = progressDialogMap.get(contact); if (progressDialog == null) { - progressDialog = new SmpProgressDialog(otrContact.contact); - progressDialogMap.put(otrContact, progressDialog); + progressDialog = new SmpProgressDialog(contact); + progressDialogMap.put(contact, progressDialog); } progressDialog.init(); @@ -1155,27 +961,24 @@ public void initSmp(OtrContact otrContact, String question, String secret) catch (OtrException e) { logger.error("Error initializing SMP session with contact " - + otrContact.contact.getDisplayName(), e); + + contact.getDisplayName(), e); showError(session.getSessionID(), e.getMessage()); } } @Override - public void respondSmp( OtrContact otrContact, - InstanceTag receiverTag, - String question, - String secret) + public void respondSmp(Contact contact, String question, String secret) { - Session session = getSession(otrContact); + Session session = getSession(contact); try { - session.respondSmp(receiverTag, question, secret); + session.respondSmp(question, secret); - SmpProgressDialog progressDialog = progressDialogMap.get(otrContact); + SmpProgressDialog progressDialog = progressDialogMap.get(contact); if (progressDialog == null) { - progressDialog = new SmpProgressDialog(otrContact.contact); - progressDialogMap.put(otrContact, progressDialog); + progressDialog = new SmpProgressDialog(contact); + progressDialogMap.put(contact, progressDialog); } progressDialog.incrementProgress(); @@ -1185,24 +988,24 @@ public void respondSmp( OtrContact otrContact, { logger.error( "Error occured when sending SMP response to contact " - + otrContact.contact.getDisplayName(), e); + + contact.getDisplayName(), e); showError(session.getSessionID(), e.getMessage()); } } @Override - public void abortSmp(OtrContact otrContact) + public void abortSmp(Contact contact) { - Session session = getSession(otrContact); + Session session = getSession(contact); try { session.abortSmp(); - SmpProgressDialog progressDialog = progressDialogMap.get(otrContact); + SmpProgressDialog progressDialog = progressDialogMap.get(contact); if (progressDialog == null) { - progressDialog = new SmpProgressDialog(otrContact.contact); - progressDialogMap.put(otrContact, progressDialog); + progressDialog = new SmpProgressDialog(contact); + progressDialogMap.put(contact, progressDialog); } progressDialog.dispose(); @@ -1210,47 +1013,9 @@ public void abortSmp(OtrContact otrContact) catch (OtrException e) { logger.error("Error aborting SMP session with contact " - + otrContact.contact.getDisplayName(), e); + + contact.getDisplayName(), e); showError(session.getSessionID(), e.getMessage()); } - } - - public PublicKey getRemotePublicKey(OtrContact otrContact) - { - if (otrContact == null) - return null; - - Session session = getSession(otrContact); - - return session.getRemotePublicKey(); - } - - public List getSessionInstances(OtrContact otrContact) - { - if (otrContact == null) - return null; - - return getSession(otrContact).getInstances(); - } - - public boolean setOutgoingSession(OtrContact contact, InstanceTag tag) - { - if (contact == null) - return false; - - Session session = getSession(contact); - - scSessionStatusMap.remove(session.getSessionID()); - return session.setOutgoingInstance(tag); - } - - public Session getOutgoingSession(OtrContact contact) - { - if (contact == null) - return null; - - SessionID sessionID = getSessionID(contact); - return otrEngine.getOutgoingSession(sessionID); } } diff --git a/src/net/java/sip/communicator/plugin/otr/ScOtrEngineListener.java b/src/net/java/sip/communicator/plugin/otr/ScOtrEngineListener.java index ffd211ae2..790fc160a 100644 --- a/src/net/java/sip/communicator/plugin/otr/ScOtrEngineListener.java +++ b/src/net/java/sip/communicator/plugin/otr/ScOtrEngineListener.java @@ -6,7 +6,6 @@ */ package net.java.sip.communicator.plugin.otr; -import net.java.sip.communicator.plugin.otr.OtrContactManager.OtrContact; import net.java.sip.communicator.service.protocol.*; /** @@ -19,9 +18,5 @@ public interface ScOtrEngineListener public void globalPolicyChanged(); - public void sessionStatusChanged(OtrContact contact); - - public void multipleInstancesDetected(OtrContact contact); - - public void outgoingSessionChanged(OtrContact contact); + public void sessionStatusChanged(Contact contact); } diff --git a/src/net/java/sip/communicator/plugin/otr/ScOtrKeyManager.java b/src/net/java/sip/communicator/plugin/otr/ScOtrKeyManager.java index 5b36f5855..56ffff002 100755 --- a/src/net/java/sip/communicator/plugin/otr/ScOtrKeyManager.java +++ b/src/net/java/sip/communicator/plugin/otr/ScOtrKeyManager.java @@ -7,9 +7,7 @@ package net.java.sip.communicator.plugin.otr; import java.security.*; -import java.util.*; -import net.java.sip.communicator.plugin.otr.OtrContactManager.OtrContact; import net.java.sip.communicator.service.protocol.*; /** @@ -24,24 +22,24 @@ public interface ScOtrKeyManager public abstract void removeListener(ScOtrKeyManagerListener l); - public abstract void verify(OtrContact contact, String fingerprint); + public abstract void verify(Contact contact); - public abstract void unverify(OtrContact contact, String fingerprint); + public abstract void unverify(Contact contact); - public abstract boolean isVerified(Contact contact, String fingerprint); + public abstract boolean isVerified(Contact contact); - public abstract String getFingerprintFromPublicKey(PublicKey pubKey); - - public abstract List getAllRemoteFingerprints(Contact contact); + public abstract String getRemoteFingerprint(Contact contact); public abstract String getLocalFingerprint(AccountID account); public abstract byte[] getLocalFingerprintRaw(AccountID account); - public abstract void saveFingerprint(Contact contact, String fingerprint); + public abstract void savePublicKey(Contact contact, PublicKey pubKey); + + public abstract PublicKey loadPublicKey(Contact contact); public abstract KeyPair loadKeyPair(AccountID accountID); public abstract void generateKeyPair(AccountID accountID); -} +} diff --git a/src/net/java/sip/communicator/plugin/otr/ScOtrKeyManagerImpl.java b/src/net/java/sip/communicator/plugin/otr/ScOtrKeyManagerImpl.java index eb6d07be3..37adc6325 100755 --- a/src/net/java/sip/communicator/plugin/otr/ScOtrKeyManagerImpl.java +++ b/src/net/java/sip/communicator/plugin/otr/ScOtrKeyManagerImpl.java @@ -11,7 +11,6 @@ import java.util.*; import net.java.otr4j.crypto.*; -import net.java.sip.communicator.plugin.otr.OtrContactManager.OtrContact; import net.java.sip.communicator.service.protocol.*; /** @@ -63,113 +62,47 @@ public void removeListener(ScOtrKeyManagerListener l) } } - public void verify(OtrContact otrContact, String fingerprint) + public void verify(Contact contact) { - if ((fingerprint == null) || otrContact == null) + if ((contact == null) || isVerified(contact)) return; - this.configurator.setProperty(otrContact.contact.getAddress() + fingerprint - + ".fingerprint.verified", true); + this.configurator.setProperty(contact.getAddress() + + ".publicKey.verified", true); for (ScOtrKeyManagerListener l : getListeners()) - l.contactVerificationStatusChanged(otrContact); + l.contactVerificationStatusChanged(contact); } - public void unverify(OtrContact otrContact, String fingerprint) + public void unverify(Contact contact) { - if ((fingerprint == null) || otrContact == null) + if ((contact == null) || !isVerified(contact)) return; - this.configurator.setProperty(otrContact.contact.getAddress() + fingerprint - + ".fingerprint.verified", false); + this.configurator.removeProperty(contact.getAddress() + + ".publicKey.verified"); for (ScOtrKeyManagerListener l : getListeners()) - l.contactVerificationStatusChanged(otrContact); + l.contactVerificationStatusChanged(contact); } - public boolean isVerified(Contact contact, String fingerprint) + public boolean isVerified(Contact contact) { - if (fingerprint == null || contact == null) + if (contact == null) return false; - return this.configurator.getPropertyBoolean( - contact.getAddress() + fingerprint - + ".fingerprint.verified", false); + return this.configurator.getPropertyBoolean(contact.getAddress() + + ".publicKey.verified", false); } - public List getAllRemoteFingerprints(Contact contact) + public String getRemoteFingerprint(Contact contact) { - if (contact == null) + PublicKey remotePublicKey = loadPublicKey(contact); + if (remotePublicKey == null) return null; - - /* - * The following lines are needed for backward compatibility with old - * versions of the otr plugin. Instead of lists of fingerprints the otr - * plugin used to store one public key for every contact in the form of - * "userID.publicKey=..." and one boolean property in the form of - * "userID.publicKey.verified=...". In order not to loose these old - * properties we have to convert them to match the new format. - */ - String userID = contact.getAddress(); - - byte[] b64PubKey = - this.configurator.getPropertyBytes(userID + ".publicKey"); - if (b64PubKey != null) - { - // We delete the old format property because we are going to convert - // it in the new format - this.configurator.removeProperty(userID + ".publicKey"); - - X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(b64PubKey); - - KeyFactory keyFactory; - try - { - keyFactory = KeyFactory.getInstance("DSA"); - PublicKey pubKey = keyFactory.generatePublic(publicKeySpec); - - boolean isVerified = - this.configurator.getPropertyBoolean(userID - + ".publicKey.verified", false); - - // We also make sure to delete this old format property if it - // exists. - this.configurator.removeProperty(userID + ".publicKey.verified"); - - String fingerprint = getFingerprintFromPublicKey(pubKey); - - // Now we can store the old properties in the new format. - if (isVerified) - verify(OtrContactManager.getOtrContact(contact, null), fingerprint); - else - unverify(OtrContactManager.getOtrContact(contact, null), fingerprint); - - // Finally we append the new fingerprint to out stored list of - // fingerprints. - this.configurator.appendProperty( - userID + ".fingerprints", fingerprint); - } - catch (NoSuchAlgorithmException e) - { - e.printStackTrace(); - } - catch (InvalidKeySpecException e) - { - e.printStackTrace(); - } - } - - // Now we can safely return our list of fingerprints for this contact - // without worrying that we missed an old format property. - return this.configurator.getAppendedProperties( - contact.getAddress() + ".fingerprints"); - } - - public String getFingerprintFromPublicKey(PublicKey pubKey) - { try { - return new OtrCryptoEngineImpl().getFingerprint(pubKey); + return new OtrCryptoEngineImpl().getFingerprint(remotePublicKey); } catch (OtrCryptoException e) { @@ -218,16 +151,52 @@ public byte[] getLocalFingerprintRaw(AccountID account) } } - public void saveFingerprint(Contact contact, String fingerprint) + public void savePublicKey(Contact contact, PublicKey pubKey) { if (contact == null) return; - this.configurator.appendProperty(contact.getAddress() + ".fingerprints", - fingerprint); + X509EncodedKeySpec x509EncodedKeySpec = + new X509EncodedKeySpec(pubKey.getEncoded()); + + this.configurator.setProperty(contact.getAddress() + ".publicKey", + x509EncodedKeySpec.getEncoded()); + + this.configurator.removeProperty(contact.getAddress() + + ".publicKey.verified"); + } + + public PublicKey loadPublicKey(Contact contact) + { + if (contact == null) + return null; - this.configurator.setProperty(contact.getAddress() + fingerprint - + ".fingerprint.verified", false); + String userID = contact.getAddress(); + + byte[] b64PubKey = + this.configurator.getPropertyBytes(userID + ".publicKey"); + if (b64PubKey == null) + return null; + + X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(b64PubKey); + + // Generate KeyPair. + KeyFactory keyFactory; + try + { + keyFactory = KeyFactory.getInstance("DSA"); + return keyFactory.generatePublic(publicKeySpec); + } + catch (NoSuchAlgorithmException e) + { + e.printStackTrace(); + return null; + } + catch (InvalidKeySpecException e) + { + e.printStackTrace(); + return null; + } } public KeyPair loadKeyPair(AccountID account) diff --git a/src/net/java/sip/communicator/plugin/otr/ScOtrKeyManagerListener.java b/src/net/java/sip/communicator/plugin/otr/ScOtrKeyManagerListener.java index ba2213f1c..7ab2c6f02 100755 --- a/src/net/java/sip/communicator/plugin/otr/ScOtrKeyManagerListener.java +++ b/src/net/java/sip/communicator/plugin/otr/ScOtrKeyManagerListener.java @@ -6,7 +6,7 @@ */ package net.java.sip.communicator.plugin.otr; -import net.java.sip.communicator.plugin.otr.OtrContactManager.OtrContact; +import net.java.sip.communicator.service.protocol.*; /** * @@ -14,5 +14,5 @@ */ public interface ScOtrKeyManagerListener { - public void contactVerificationStatusChanged(OtrContact contact); + public void contactVerificationStatusChanged(Contact contact); } diff --git a/src/net/java/sip/communicator/plugin/otr/SwingOtrActionHandler.java b/src/net/java/sip/communicator/plugin/otr/SwingOtrActionHandler.java index 0f5343461..309e38750 100644 --- a/src/net/java/sip/communicator/plugin/otr/SwingOtrActionHandler.java +++ b/src/net/java/sip/communicator/plugin/otr/SwingOtrActionHandler.java @@ -6,12 +6,12 @@ */ package net.java.sip.communicator.plugin.otr; +import net.java.sip.communicator.plugin.otr.authdialog.*; +import net.java.sip.communicator.service.protocol.*; + import java.awt.*; import java.util.*; -import net.java.sip.communicator.plugin.otr.OtrContactManager.OtrContact; -import net.java.sip.communicator.plugin.otr.authdialog.*; - /** * Default OtrActionHandler implementation that opens SWING buddy authenticate * dialog. @@ -24,13 +24,13 @@ public class SwingOtrActionHandler { public void onAuthenticateLinkClicked(UUID uuid) { - OtrContact otrContact = ScOtrEngineImpl.getOtrContact( + Contact contact = ScOtrEngineImpl.getContact( ScOtrEngineImpl.getScSessionForGuid(uuid).getSessionID()); - openAuthDialog(otrContact); + openAuthDialog(contact); } - public static void openAuthDialog(OtrContact contact) + public static void openAuthDialog(Contact contact) { // Launch auth buddy dialog. OtrBuddyAuthenticationDialog authenticateBuddyDialog diff --git a/src/net/java/sip/communicator/plugin/otr/authdialog/FingerprintAuthenticationPanel.java b/src/net/java/sip/communicator/plugin/otr/authdialog/FingerprintAuthenticationPanel.java index 7c6119399..26f88662f 100644 --- a/src/net/java/sip/communicator/plugin/otr/authdialog/FingerprintAuthenticationPanel.java +++ b/src/net/java/sip/communicator/plugin/otr/authdialog/FingerprintAuthenticationPanel.java @@ -7,14 +7,13 @@ package net.java.sip.communicator.plugin.otr.authdialog; import java.awt.*; -import java.security.*; import javax.swing.*; import javax.swing.event.*; import net.java.sip.communicator.plugin.desktoputil.*; import net.java.sip.communicator.plugin.otr.*; -import net.java.sip.communicator.plugin.otr.OtrContactManager.OtrContact; +import net.java.sip.communicator.service.protocol.*; /** * @author George Politis @@ -29,7 +28,7 @@ public class FingerprintAuthenticationPanel /** * The Contact that we are authenticating. */ - private final OtrContact otrContact; + private final Contact contact; private SIPCommTextField txtRemoteFingerprintComparison; @@ -61,9 +60,9 @@ public class FingerprintAuthenticationPanel * * @param contact The contact that this panel refers to. */ - FingerprintAuthenticationPanel(OtrContact contact) + FingerprintAuthenticationPanel(Contact contact) { - this.otrContact = contact; + this.contact = contact; initComponents(); loadContact(); @@ -108,13 +107,8 @@ private void initComponents() cbAction = new JComboBox(); cbAction.addItem(actionIHave); cbAction.addItem(actionIHaveNot); - - PublicKey pubKey = OtrActivator.scOtrEngine.getRemotePublicKey(otrContact); - String remoteFingerprint = - OtrActivator.scOtrKeyManager.getFingerprintFromPublicKey(pubKey); cbAction.setSelectedItem(OtrActivator.scOtrKeyManager - .isVerified(otrContact.contact, remoteFingerprint) - ? actionIHave : actionIHaveNot); + .isVerified(contact) ? actionIHave : actionIHaveNot); pnlAction.add(cbAction, c); @@ -122,14 +116,10 @@ private void initComponents() c.weightx = 1.0; pnlAction.add(txtAction, c); - String resourceName = otrContact.resource != null ? - "/" + otrContact.resource.getResourceName() : ""; - - txtRemoteFingerprintComparison = new SIPCommTextField( + txtRemoteFingerprintComparison = new SIPCommTextField( OtrActivator.resourceService .getI18NString("plugin.otr.authbuddydialog.FINGERPRINT_CHECK", - new String[] - {otrContact.contact.getDisplayName() + resourceName})); + new String[]{contact.getDisplayName()})); txtRemoteFingerprintComparison.getDocument().addDocumentListener(this); c.gridwidth = 2; @@ -146,25 +136,24 @@ public JComboBox getCbAction() /** * Sets up the {@link OtrBuddyAuthenticationDialog} components so that they - * reflect the {@link OtrBuddyAuthenticationDialog#otrContact} + * reflect the {@link OtrBuddyAuthenticationDialog#contact} */ private void loadContact() { // Local fingerprint. String account = - otrContact.contact.getProtocolProvider().getAccountID().getDisplayName(); + contact.getProtocolProvider().getAccountID().getDisplayName(); String localFingerprint = - OtrActivator.scOtrKeyManager.getLocalFingerprint(otrContact.contact + OtrActivator.scOtrKeyManager.getLocalFingerprint(contact .getProtocolProvider().getAccountID()); txtLocalFingerprint.setText(OtrActivator.resourceService.getI18NString( "plugin.otr.authbuddydialog.LOCAL_FINGERPRINT", new String[] { account, localFingerprint })); // Remote fingerprint. - String user = otrContact.contact.getDisplayName(); - PublicKey pubKey = OtrActivator.scOtrEngine.getRemotePublicKey(otrContact); + String user = contact.getDisplayName(); String remoteFingerprint = - OtrActivator.scOtrKeyManager.getFingerprintFromPublicKey(pubKey); + OtrActivator.scOtrKeyManager.getRemoteFingerprint(contact); txtRemoteFingerprint.setText(OtrActivator.resourceService .getI18NString("plugin.otr.authbuddydialog.REMOTE_FINGERPRINT", new String[] @@ -193,10 +182,6 @@ public void changedUpdate(DocumentEvent e) public void compareFingerprints() { - PublicKey pubKey = OtrActivator.scOtrEngine.getRemotePublicKey(otrContact); - String remoteFingerprint = - OtrActivator.scOtrKeyManager.getFingerprintFromPublicKey(pubKey); - if(txtRemoteFingerprintComparison.getText() == null || txtRemoteFingerprintComparison.getText().length() == 0) { @@ -204,7 +189,8 @@ public void compareFingerprints() return; } if(txtRemoteFingerprintComparison.getText().toLowerCase().contains( - remoteFingerprint.toLowerCase())) + OtrActivator.scOtrKeyManager + .getRemoteFingerprint(contact).toLowerCase())) { txtRemoteFingerprintComparison.setBackground(Color.green); cbAction.setSelectedItem(actionIHave); diff --git a/src/net/java/sip/communicator/plugin/otr/authdialog/KnownFingerprintsPanel.java b/src/net/java/sip/communicator/plugin/otr/authdialog/KnownFingerprintsPanel.java index 14f79dc8b..256814a81 100644 --- a/src/net/java/sip/communicator/plugin/otr/authdialog/KnownFingerprintsPanel.java +++ b/src/net/java/sip/communicator/plugin/otr/authdialog/KnownFingerprintsPanel.java @@ -13,9 +13,9 @@ import javax.swing.border.*; import javax.swing.event.*; +import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.plugin.desktoputil.*; import net.java.sip.communicator.plugin.otr.*; -import net.java.sip.communicator.service.protocol.*; /** * @author @George Politis @@ -44,7 +44,7 @@ public KnownFingerprintsPanel() this.setPreferredSize(new Dimension(400, 200)); - openContact(getSelectedContact(), getSelectedFingerprint()); + openContact(getSelectedContact()); } /** @@ -74,7 +74,7 @@ public void valueChanged(ListSelectionEvent e) if (e.getValueIsAdjusting()) return; - openContact(getSelectedContact(), getSelectedFingerprint()); + openContact(getSelectedContact()); } }); @@ -88,16 +88,14 @@ public void valueChanged(ListSelectionEvent e) btnVerifyFingerprint = new JButton(); btnVerifyFingerprint.setText(OtrActivator.resourceService .getI18NString("plugin.otr.configform.VERIFY_FINGERPRINT")); - btnVerifyFingerprint.setEnabled(false); btnVerifyFingerprint.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { OtrActivator.scOtrKeyManager - .verify(OtrContactManager.getOtrContact( - getSelectedContact(), null), getSelectedFingerprint()); - openContact(getSelectedContact(), getSelectedFingerprint()); + .verify(getSelectedContact()); + openContact(getSelectedContact()); contactsTable.updateUI(); } }); @@ -107,16 +105,13 @@ public void actionPerformed(ActionEvent arg0) btnForgetFingerprint = new JButton(); btnForgetFingerprint.setText(OtrActivator.resourceService .getI18NString("plugin.otr.configform.FORGET_FINGERPRINT")); - btnForgetFingerprint.setEnabled(false); - btnForgetFingerprint.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { OtrActivator.scOtrKeyManager - .unverify(OtrContactManager.getOtrContact( - getSelectedContact(), null), getSelectedFingerprint()); - openContact(getSelectedContact(), getSelectedFingerprint()); + .unverify(getSelectedContact()); + openContact(getSelectedContact()); contactsTable.updateUI(); } }); @@ -134,27 +129,10 @@ private Contact getSelectedContact() KnownFingerprintsTableModel model = (KnownFingerprintsTableModel) contactsTable.getModel(); int index = contactsTable.getSelectedRow(); - if (index < 0 || index > model.getRowCount()) - return null; - - return model.getContactFromRow(index); - } - - /** - * Gets the selected fingerprint for this - * {@link KnownFingerprintsTableModel} - * - * return the selected fingerprint - */ - private String getSelectedFingerprint() - { - KnownFingerprintsTableModel model = - (KnownFingerprintsTableModel) contactsTable.getModel(); - int index = contactsTable.getSelectedRow(); - if (index < 0 || index > model.getRowCount()) + if (index < 0 || index > model.allContacts.size()) return null; - return model.getFingerprintFromRow(index); + return model.allContacts.get(index); } /** @@ -162,11 +140,11 @@ private String getSelectedFingerprint() * reflect the {@link Contact} param. * * @param contact the {@link Contact} to setup the components for. - * @param fingerprint the fingerprint to setup the components for. */ - private void openContact(Contact contact, String fingerprint) + private void openContact(Contact contact) { - if (contact == null || fingerprint == null) + if (contact == null + || OtrActivator.scOtrKeyManager.getRemoteFingerprint(contact) == null) { btnForgetFingerprint.setEnabled(false); btnVerifyFingerprint.setEnabled(false); @@ -175,7 +153,7 @@ private void openContact(Contact contact, String fingerprint) { boolean verified = OtrActivator.scOtrKeyManager - .isVerified(contact, fingerprint); + .isVerified(contact); btnForgetFingerprint.setEnabled(verified); btnVerifyFingerprint.setEnabled(!verified); diff --git a/src/net/java/sip/communicator/plugin/otr/authdialog/KnownFingerprintsTableModel.java b/src/net/java/sip/communicator/plugin/otr/authdialog/KnownFingerprintsTableModel.java index 991883dbb..1b32f26dd 100644 --- a/src/net/java/sip/communicator/plugin/otr/authdialog/KnownFingerprintsTableModel.java +++ b/src/net/java/sip/communicator/plugin/otr/authdialog/KnownFingerprintsTableModel.java @@ -8,12 +8,10 @@ import java.awt.*; import java.util.*; -import java.util.List; import javax.swing.table.*; import net.java.sip.communicator.plugin.otr.*; -import net.java.sip.communicator.plugin.otr.OtrContactManager.OtrContact; import net.java.sip.communicator.service.contactlist.*; import net.java.sip.communicator.service.protocol.*; @@ -27,7 +25,6 @@ */ public class KnownFingerprintsTableModel extends AbstractTableModel - implements ScOtrKeyManagerListener { /** * Serial version UID. @@ -40,8 +37,7 @@ public class KnownFingerprintsTableModel public static final int FINGERPRINT_INDEX = 2; - public final LinkedHashMap> allContactsFingerprints = - new LinkedHashMap>(); + public final java.util.List allContacts = new Vector(); public KnownFingerprintsTableModel() { @@ -80,15 +76,10 @@ public KnownFingerprintsTableModel() Iterator contacts = metaContact.getContacts(); while (contacts.hasNext()) { - Contact contact = contacts.next(); - allContactsFingerprints.put( - contact, - OtrActivator.scOtrKeyManager.getAllRemoteFingerprints( - contact)); + allContacts.add(contacts.next()); } } } - OtrActivator.scOtrKeyManager.addListener(this); } /** @@ -121,8 +112,10 @@ public String getColumnName(int column) */ public Object getValueAt(int row, int column) { - Contact contact = getContactFromRow(row); - String fingerprint = getFingerprintFromRow(row); + if (row < 0) + return null; + + Contact contact = allContacts.get(row); switch (column) { case CONTACTNAME_INDEX: @@ -130,84 +123,25 @@ public Object getValueAt(int row, int column) case VERIFIED_INDEX: // TODO: Maybe use a CheckBoxColumn? return (OtrActivator.scOtrKeyManager - .isVerified(contact, fingerprint)) + .isVerified(contact)) ? OtrActivator.resourceService.getI18NString( "plugin.otr.configform.COLUMN_VALUE_VERIFIED_TRUE") : OtrActivator.resourceService.getI18NString( "plugin.otr.configform.COLUMN_VALUE_VERIFIED_FALSE"); case FINGERPRINT_INDEX: - return fingerprint; + return OtrActivator.scOtrKeyManager + .getRemoteFingerprint(contact); default: return null; } } - Contact getContactFromRow(int row) - { - if (row < 0 || row >= getRowCount()) - return null; - - int index = -1; - Contact contact = null; - for (Map.Entry> entry : - allContactsFingerprints.entrySet()) - { - boolean found = false; - contact = entry.getKey(); - List fingerprints = entry.getValue(); - for (String f : fingerprints) - { - index++; - if (index == row) - { - found = true; - break; - } - } - if (found) break; - } - - return contact; - } - - String getFingerprintFromRow(int row) - { - if (row < 0 || row >= getRowCount()) - return null; - - int index = -1; - String fingerprint = null; - for (Map.Entry> entry : - allContactsFingerprints.entrySet()) - { - boolean found = false; - List fingerprints = entry.getValue(); - for (String f : fingerprints) - { - index++; - fingerprint = f; - if (index == row) - { - found = true; - break; - } - } - if (found) break; - } - - return fingerprint; - } - /** * Implements AbstractTableModel#getRowCount(). */ public int getRowCount() { - int rowCount = 0; - for (Map.Entry> entry : - allContactsFingerprints.entrySet()) - rowCount += entry.getValue().size(); - return rowCount; + return allContacts.size(); } /** @@ -217,14 +151,4 @@ public int getColumnCount() { return 3; } - - @Override - public void contactVerificationStatusChanged(OtrContact otrContact) - { - Contact contact = otrContact.contact; - allContactsFingerprints.put( - contact, - OtrActivator.scOtrKeyManager.getAllRemoteFingerprints(contact)); - this.fireTableDataChanged(); - } } diff --git a/src/net/java/sip/communicator/plugin/otr/authdialog/OTRv3OutgoingSessionSwitcher.java b/src/net/java/sip/communicator/plugin/otr/authdialog/OTRv3OutgoingSessionSwitcher.java deleted file mode 100644 index 39b22e373..000000000 --- a/src/net/java/sip/communicator/plugin/otr/authdialog/OTRv3OutgoingSessionSwitcher.java +++ /dev/null @@ -1,438 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.plugin.otr.authdialog; - -import java.awt.*; -import java.awt.event.*; -import java.io.*; -import java.security.*; -import java.util.*; - -import javax.imageio.*; -import javax.swing.*; -import javax.swing.Timer; - -import net.java.otr4j.session.*; -import net.java.sip.communicator.plugin.desktoputil.*; -import net.java.sip.communicator.plugin.otr.*; -import net.java.sip.communicator.plugin.otr.OtrContactManager.OtrContact; -import net.java.sip.communicator.service.contactlist.*; -import net.java.sip.communicator.service.gui.*; -import net.java.sip.communicator.service.gui.Container; -import net.java.sip.communicator.service.protocol.*; -import net.java.sip.communicator.util.*; - -/** - * A special {@link JMenuBar} that controls the switching of OTRv3 outgoing - * sessions in case the remote party is logged in multiple times. - * - * @author Marin Dzhigarov - * - */ -public class OTRv3OutgoingSessionSwitcher - extends SIPCommMenuBar - implements PluginComponent, - ActionListener, - ScOtrEngineListener, - ScOtrKeyManagerListener -{ - - private static final Logger logger - = Logger.getLogger(OTRv3OutgoingSessionSwitcher.class); - - private final PluginComponentFactory parentFactory; - - private static final long serialVersionUID = 0L; - - private final SelectorMenu menu = new SelectorMenu(); - - private ButtonGroup buttonGroup = new ButtonGroup(); - - private OtrContact contact; - - /** - * A map used for storing each Sessions corresponding JMenuItem - * . - */ - private final Map outgoingSessions - = new HashMap(); - - /** - * An animated {@link JMenu} - * @author Marin Dzhigarov - * - */ - private static class SelectorMenu - extends SIPCommMenu - { - /** - * Serial version UID. - */ - private static final long serialVersionUID = 0L; - - Image image = OtrActivator.resourceService.getImage( - "service.gui.icons.DOWN_ARROW_ICON").getImage(); - - private static float alpha = 0.95f; - - private final Timer alphaChanger = new Timer(20, new ActionListener() { - - private float incrementer = -.03f; - - private int fadeCycles = 0; - - @Override - public void actionPerformed(ActionEvent e) - { - float newAlpha = alpha + incrementer; - if (newAlpha < 0.2f) - { - newAlpha = 0.2f; - incrementer = -incrementer; - } else if (newAlpha > 0.85f) - { - newAlpha = 0.85f; - incrementer = -incrementer; - fadeCycles++; - } - alpha = newAlpha; - if (fadeCycles >= 3) - { - alphaChanger.stop(); - fadeCycles = 0; - alpha = 1f; - } - SelectorMenu.this.repaint(); - } - }); - - @Override - public void paintComponent(Graphics g) - { - Graphics2D g2d = (Graphics2D) g; - g2d.setComposite( - AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); - g.drawImage(image, getWidth() - image.getWidth(this) - 1, - (getHeight() - image.getHeight(this) - 1) / 2, this); - - super.paintComponent(g2d); - } - - /** - * Creates a fade in and out effect for this {@link JMenu} - */ - public void fadeAnimation() - { - alphaChanger.stop(); - alpha = 0.85f; - SelectorMenu.this.repaint(); - alphaChanger.start(); - } - }; - - /** - * The OTRv3OutgoingSessionSwitcher constructor - */ - public OTRv3OutgoingSessionSwitcher(Container container, - PluginComponentFactory parentFactory) - { - this.parentFactory = parentFactory; - - setPreferredSize(new Dimension(30, 28)); - setMaximumSize(new Dimension(30, 28)); - setMinimumSize(new Dimension(30, 28)); - - this.menu.setPreferredSize(new Dimension(30, 45)); - this.menu.setMaximumSize(new Dimension(30, 45)); - - this.add(menu); - - this.setBorder(null); - this.menu.setBorder(null); - this.menu.setOpaque(false); - this.setOpaque(false); - this.menu.setVisible(false); - - /* - * XXX This OtrV3OutgoingSessionSwitcher instance cannot be added as a - * listener to scOtrEngine and scOtrKeyManager without being removed - * later on because the latter live forever. Unfortunately, the - * dispose() method of this instance is never executed. OtrWeakListener - * will keep this instance as a listener of scOtrEngine and - * scOtrKeyManager for as long as this instance is necessary. And this - * instance will be strongly referenced by the JMenuItems which depict - * it. So when the JMenuItems are gone, this instance will become - * obsolete and OtrWeakListener will remove it as a listener of - * scOtrEngine and scOtrKeyManager. - */ - new OtrWeakListener( - this, - OtrActivator.scOtrEngine, OtrActivator.scOtrKeyManager); - - try - { - finishedPadlockImage = new ImageIcon(ImageIO.read( - OtrActivator.resourceService.getImageURL( - "plugin.otr.FINISHED_ICON_BLACK_16x16"))); - verifiedLockedPadlockImage = new ImageIcon(ImageIO.read( - OtrActivator.resourceService.getImageURL( - "plugin.otr.ENCRYPTED_ICON_BLACK_16x16"))); - unverifiedLockedPadlockImage = new ImageIcon(ImageIO.read( - OtrActivator.resourceService.getImageURL( - "plugin.otr.ENCRYPTED_UNVERIFIED_ICON_BLACK_16x16"))); - unlockedPadlockImage = new ImageIcon(ImageIO.read( - OtrActivator.resourceService.getImageURL( - "plugin.otr.PLAINTEXT_ICON_16x16"))); - } catch (IOException e) - { - logger.debug("Failed to load padlock image"); - } - - buildMenu(contact); - } - - @Override - public int getPositionIndex() - { - return -1; - } - - /** - * Sets the current contact. Meant to be used by plugin components that - * are interested of the current contact. The current contact is the contact - * for the currently selected chat transport. - * - * @param contact the current contact - */ - public void setCurrentContact(Contact contact) - { - if (this.contact != null && this.contact.contact == contact) - return; - - this.contact = - OtrContactManager.getOtrContact(contact, null); - buildMenu(this.contact); - } - - /** - * Sets the current meta contact. Meant to be used by plugin components that - * are interested of the current contact. The current contact could be the - * contact currently selected in the contact list or the contact for the - * currently selected chat, etc. It depends on the container, where this - * component is meant to be added. - * - * @param metaContact the current meta contact - */ - public void setCurrentContact(MetaContact metaContact) - { - setCurrentContact((metaContact == null) ? null : metaContact - .getDefaultContact()); - } - - /** - * Sets the current contact. Meant to be used by plugin components that - * are interested of the current contact. The current contact is the contact - * for the currently selected chat transport. - * - * @param contact the current contact - * @param resourceName the ContactResource name. Some components - * may be interested in a particular ContactResource of a contact. - */ - public void setCurrentContact(Contact contact, String resourceName) - { - if (this.contact != null && this.contact.contact == contact) - return; - - if (resourceName == null) - { - this.contact = - OtrContactManager.getOtrContact(contact, null); - buildMenu(this.contact); - } - else - { - for (ContactResource resource : contact.getResources()) - { - if (resource.getResourceName().equals(resourceName)) - { - OtrContact otrContact = - OtrContactManager.getOtrContact(contact, resource); - if (this.contact == otrContact) - return; - this.contact = otrContact; - buildMenu(this.contact); - } - } - } - } - - @Override - public void setCurrentContactGroup(MetaContactGroup metaGroup) {} - - @Override - public void setCurrentAccountID(AccountID accountID) {} - - @Override - public PluginComponentFactory getParentFactory() - { - return parentFactory; - } - - /** - * Implements ScOtrKeyManagerListener#contactVerificationStatusChanged( - * Contact). - */ - public void contactVerificationStatusChanged(OtrContact contact) - { - buildMenu(contact); - if (this.menu.isVisible()) - this.menu.fadeAnimation(); - } - - /** - * Implements ScOtrEngineListener#contactPolicyChanged(Contact). - */ - public void contactPolicyChanged(Contact contact) {} - - /** - * Implements ScOtrKeyManagerListener#globalPolicyChanged(). - */ - public void globalPolicyChanged() {} - - /** - * Implements ScOtrEngineListener#sessionStatusChanged(OtrContact). - */ - public void sessionStatusChanged(OtrContact contact) - { - buildMenu(contact); - if (this.menu.isVisible()) - this.menu.fadeAnimation(); - } - - /** - * Implements ScOtrEngineListener#multipleInstancesDetected(OtrContact). - */ - public void multipleInstancesDetected(OtrContact contact) - { - buildMenu(contact); - if (this.menu.isVisible()) - this.menu.fadeAnimation(); - } - - /** - * Implements ScOtrEngineListener#outgoingSessionChanged(OtrContact). - */ - public void outgoingSessionChanged(OtrContact contact) - { - buildMenu(contact); - } - - private ImageIcon verifiedLockedPadlockImage; - - private ImageIcon unverifiedLockedPadlockImage; - - private ImageIcon finishedPadlockImage; - - private ImageIcon unlockedPadlockImage; - - /** - * Builds the JMenu used for switching between outgoing OTRv3 Sessions in - * case the remote party is logged in multiple locations - * - * @param otrContact the contact which is logged in multiple locations - */ - private void buildMenu(OtrContact otrContact) - { - if (otrContact == null || !this.contact.equals(otrContact)) - { - return; - } - menu.removeAll(); - java.util.List multipleInstances = - OtrActivator.scOtrEngine.getSessionInstances( - otrContact); - - Session outgoingSession = - OtrActivator.scOtrEngine.getOutgoingSession(otrContact); - int index = 0; - for (Session session : multipleInstances) - { - index++; - if (!outgoingSessions.containsKey(session)) - { - JMenuItem menuItem = new JRadioButtonMenuItem(); - outgoingSessions.put(session, menuItem); - menuItem.addActionListener(this); - } - - JMenuItem menuItem = outgoingSessions.get(session); - menuItem.setText("Session " + index); - - ImageIcon imageIcon = null; - switch (session.getSessionStatus(session.getReceiverInstanceTag())) - { - case ENCRYPTED: - PublicKey pubKey = - session.getRemotePublicKey(session.getReceiverInstanceTag()); - String fingerprint = - OtrActivator.scOtrKeyManager. - getFingerprintFromPublicKey(pubKey); - imageIcon - = OtrActivator.scOtrKeyManager.isVerified( - otrContact.contact, fingerprint) - ? verifiedLockedPadlockImage - : unverifiedLockedPadlockImage; - break; - case FINISHED: - imageIcon = finishedPadlockImage; - break; - case PLAINTEXT: - imageIcon = unlockedPadlockImage; - break; - } - menuItem.setIcon(imageIcon); - - menu.add(menuItem); - SelectedObject selectedObject = - new SelectedObject(imageIcon, session); - - buttonGroup.add(menuItem); - menuItem.repaint(); - if (session == outgoingSession) - { - this.menu.setSelected(selectedObject); - setSelected(menu.getItem(index - 1)); - } - - } - updateEnableStatus(); - menu.repaint(); - } - - public void actionPerformed(ActionEvent e) - { - for (Map.Entry entry : outgoingSessions.entrySet()) - { - JMenuItem menuItem = (JRadioButtonMenuItem) e.getSource(); - if (menuItem.equals(entry.getValue())) - { - OtrActivator.scOtrEngine.setOutgoingSession( - contact, entry.getKey().getReceiverInstanceTag()); - break; - } - } - } - - /** - * Sets the menu visibility. The menu is visible as soon as it - * contains two or more items. If it is empty, it is invisible. - */ - private void updateEnableStatus() - { - this.menu.setVisible(this.menu.getItemCount() > 1); - } -} diff --git a/src/net/java/sip/communicator/plugin/otr/authdialog/OtrBuddyAuthenticationDialog.java b/src/net/java/sip/communicator/plugin/otr/authdialog/OtrBuddyAuthenticationDialog.java index 3c4b49d61..b67ce810c 100644 --- a/src/net/java/sip/communicator/plugin/otr/authdialog/OtrBuddyAuthenticationDialog.java +++ b/src/net/java/sip/communicator/plugin/otr/authdialog/OtrBuddyAuthenticationDialog.java @@ -8,14 +8,12 @@ import java.awt.*; import java.awt.event.*; -import java.security.*; import javax.swing.*; import net.java.sip.communicator.plugin.desktoputil.*; import net.java.sip.communicator.plugin.otr.*; -import net.java.sip.communicator.plugin.otr.OtrContactManager.OtrContact; -import net.java.sip.communicator.plugin.otr.authdialog.FingerprintAuthenticationPanel.ActionComboBoxItem; +import net.java.sip.communicator.plugin.otr.authdialog.FingerprintAuthenticationPanel.*; import net.java.sip.communicator.service.protocol.*; /** @@ -26,7 +24,7 @@ public class OtrBuddyAuthenticationDialog extends SIPCommDialog { - private final OtrContact contact; + private final Contact contact; /** * The {@link OtrBuddyAuthenticationDialog} ctor. @@ -34,7 +32,7 @@ public class OtrBuddyAuthenticationDialog * @param contact The {@link Contact} this * {@link OtrBuddyAuthenticationDialog} refers to. */ - public OtrBuddyAuthenticationDialog(OtrContact contact) + public OtrBuddyAuthenticationDialog(Contact contact) { super(false); this.contact = contact; @@ -180,20 +178,13 @@ else if (authenticationMethod.equals(am[2])) ActionComboBoxItem actionItem = (ActionComboBoxItem) fingerprintPanel. getCbAction().getSelectedItem(); - PublicKey pubKey = - OtrActivator.scOtrEngine.getRemotePublicKey(contact); - String fingerprint = - OtrActivator.scOtrKeyManager. - getFingerprintFromPublicKey(pubKey); switch (actionItem.action) { case I_HAVE: - OtrActivator.scOtrKeyManager.verify( - contact, fingerprint); + OtrActivator.scOtrKeyManager.verify(contact); break; case I_HAVE_NOT: - OtrActivator.scOtrKeyManager.unverify( - contact, fingerprint); + OtrActivator.scOtrKeyManager.unverify(contact); break; } dispose(); diff --git a/src/net/java/sip/communicator/plugin/otr/authdialog/OtrConfigurationPanel.java b/src/net/java/sip/communicator/plugin/otr/authdialog/OtrConfigurationPanel.java index 3b5b878f2..79ce6bcf6 100644 --- a/src/net/java/sip/communicator/plugin/otr/authdialog/OtrConfigurationPanel.java +++ b/src/net/java/sip/communicator/plugin/otr/authdialog/OtrConfigurationPanel.java @@ -4,7 +4,7 @@ * Distributable under LGPL license. * See terms of license at gnu.org. */ -package net.java.sip.communicator.plugin.otr.authdialog; +package net.java.sip.communicator.plugin.otr; import java.awt.*; import java.awt.event.*; @@ -14,9 +14,9 @@ import javax.swing.border.*; import net.java.otr4j.*; -import net.java.sip.communicator.plugin.desktoputil.*; -import net.java.sip.communicator.plugin.otr.*; import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.plugin.desktoputil.*; +import net.java.sip.communicator.plugin.otr.authdialog.*; /** * A special {@link Panel} that manages the OTR configuration. @@ -249,7 +249,12 @@ public void loadPolicy() cbAutoInitiate.setEnabled(otrEnabled); cbRequireOtr.setEnabled(otrEnabled); + String autoInitPropValue + = OtrActivator.configService.getString( + OtrActivator.AUTO_INIT_OTR_PROP); boolean isAutoInit = otrPolicy.getEnableAlways(); + if (autoInitPropValue != null) + isAutoInit = Boolean.parseBoolean(autoInitPropValue); cbAutoInitiate.setSelected(isAutoInit); @@ -317,7 +322,10 @@ public void actionPerformed(ActionEvent e) boolean isAutoInit = ((JCheckBox) e.getSource()).isSelected(); - otrPolicy.setSendWhitespaceTag(isAutoInit); + otrPolicy.setEnableAlways(isAutoInit); + OtrActivator.configService.setProperty( + OtrActivator.AUTO_INIT_OTR_PROP, + Boolean.toString(isAutoInit)); OtrActivator.scOtrEngine.setGlobalPolicy(otrPolicy); diff --git a/src/net/java/sip/communicator/plugin/otr/authdialog/SmpAuthenticateBuddyDialog.java b/src/net/java/sip/communicator/plugin/otr/authdialog/SmpAuthenticateBuddyDialog.java index 6f72ce8d0..7d91c7ff3 100644 --- a/src/net/java/sip/communicator/plugin/otr/authdialog/SmpAuthenticateBuddyDialog.java +++ b/src/net/java/sip/communicator/plugin/otr/authdialog/SmpAuthenticateBuddyDialog.java @@ -11,10 +11,9 @@ import javax.swing.*; -import net.java.otr4j.session.*; import net.java.sip.communicator.plugin.desktoputil.*; import net.java.sip.communicator.plugin.otr.*; -import net.java.sip.communicator.plugin.otr.OtrContactManager.OtrContact; +import net.java.sip.communicator.service.protocol.*; /** * The dialog that pops up when the remote party send us SMP @@ -27,17 +26,13 @@ public class SmpAuthenticateBuddyDialog extends SIPCommDialog { - private final OtrContact otrContact; + private final Contact contact; private final String question; - private final InstanceTag receiverTag; - - public SmpAuthenticateBuddyDialog( - OtrContact contact, InstanceTag receiverTag, String question) + public SmpAuthenticateBuddyDialog(Contact contact, String question) { - this.otrContact = contact; - this.receiverTag = receiverTag; + this.contact = contact; this.question = question; initComponents(); } @@ -65,17 +60,12 @@ private void initComponents() , Font.BOLD , 14); authenticationFrom.setFont(newFont); - - String resourceName = otrContact.resource != null ? - "/" + otrContact.resource.getResourceName() : ""; String authFromText = String.format( OtrActivator.resourceService .getI18NString( "plugin.otr.authbuddydialog.AUTHENTICATION_FROM", - new String[] - {otrContact.contact.getDisplayName() + - resourceName})); + new String[] {contact.getDisplayName()})); authenticationFrom.setText(authFromText); mainPanel.add(authenticationFrom); @@ -180,7 +170,7 @@ public void actionPerformed(ActionEvent arg0) { public void actionPerformed(ActionEvent e) { - OtrActivator.scOtrEngine.abortSmp(otrContact); + OtrActivator.scOtrEngine.abortSmp(contact); SmpAuthenticateBuddyDialog.this.dispose(); } }); @@ -198,7 +188,7 @@ public void actionPerformed(ActionEvent e) public void actionPerformed(ActionEvent e) { OtrActivator.scOtrEngine.respondSmp( - otrContact, receiverTag, question, answerTextBox.getText()); + contact, question, answerTextBox.getText()); SmpAuthenticateBuddyDialog.this.dispose(); } }); diff --git a/src/net/java/sip/communicator/plugin/otr/otr.manifest.mf b/src/net/java/sip/communicator/plugin/otr/otr.manifest.mf index 07807d412..73f917a57 100644 --- a/src/net/java/sip/communicator/plugin/otr/otr.manifest.mf +++ b/src/net/java/sip/communicator/plugin/otr/otr.manifest.mf @@ -32,5 +32,4 @@ Import-Package: org.osgi.framework, org.bouncycastle.crypto.engines, org.bouncycastle.crypto.modes, org.bouncycastle.util, - org.bouncycastle.util.encoders, - net.java.sip.communicator.service.msghistory + org.bouncycastle.util.encoders