Adds the ability for the OTR plugin to work with Jabber resources

cusax-fix 5013
Marin 12 years ago
parent c164b0aa0a
commit e0e0cf4921

Binary file not shown.

@ -548,14 +548,18 @@ plugin.securityconfig.ICON=resources/images/plugin/securityconfig/security.png
# otr plugin icons
plugin.otr.ENCRYPTED_ICON_16x16=resources/images/plugin/otr/encrypted16x16.png
plugin.otr.ENCRYPTED_ICON_BLACK_16x16=resources/images/plugin/otr/encrypted_verified-black16x16.png
plugin.otr.ENCRYPTED_ICON_22x22=resources/images/plugin/otr/encrypted_verified22x22.png
plugin.otr.ENCRYPTED_UNVERIFIED_ICON_16x16=resources/images/plugin/otr/encrypted_unverified16x16.png
plugin.otr.ENCRYPTED_UNVERIFIED_ICON_BLACK_16x16=resources/images/plugin/otr/encrypted_unverified-black16x16.png
plugin.otr.ENCRYPTED_UNVERIFIED_ICON_22x22=resources/images/plugin/otr/encrypted_unverified22x22.png
plugin.otr.PLAINTEXT_ICON_16x16=resources/images/plugin/otr/plaintext16x16.png
plugin.otr.PLAINTEXT_ICON_22x22=resources/images/plugin/otr/plaintext22x22.png
plugin.otr.FINISHED_ICON_16x16=resources/images/plugin/otr/finished16x16.png
plugin.otr.FINISHED_ICON_BLACK_16x16=resources/images/plugin/otr/finished-black16x16.png
plugin.otr.FINISHED_ICON_22x22=resources/images/plugin/otr/finished22x22.png
plugin.otr.LOADING_ICON_22x22=resources/images/plugin/otr/padlockLoading.gif
plugin.otr.BROKEN_ICON_16x16=resources/images/plugin/otr/padlockBrokenOpen16x16.png
plugin.otr.BROKEN_ICON_22x22=resources/images/plugin/otr/padlockBrokenOpen.png
plugin.otr.HELP_ICON_15x15=resources/images/plugin/otr/help15x15.png
plugin.otr.MENU_ITEM_ICON_16x16=resources/images/plugin/otr/otr_menu_icon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 415 B

After

Width:  |  Height:  |  Size: 1.1 KiB

@ -1612,7 +1612,7 @@ plugin.otr.activator.fallbackmessage=<span style="font-weight: bold;">{0} is try
Off-The-Record messaging. For more information see <a href="http://en.wikipedia.org/wiki/Off-the-Record_Messaging">\
http://en.wikipedia.org/wiki/Off-the-Record_Messaging</a></span>
plugin.otr.activator.multipleinstancesdetected=Your buddy {0} is logged in multiple times and OTR has established multiple sessions. You can select \
an outgoing session from the menu above.
an outgoing session from the menu below.
plugin.otr.activator.msgfromanotherinstance={0} sent you a message that was intended for another session. If you are logged in multiple times \
another session may have received this message.

@ -24,7 +24,6 @@
import net.java.sip.communicator.impl.gui.main.chat.menus.*;
import net.java.sip.communicator.impl.gui.utils.*;
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.event.*;
import net.java.sip.communicator.service.protocol.*;
@ -1559,12 +1558,20 @@ void initPluginComponents()
PluginComponent component =
factory.getPluginComponentInstance(this);
ChatSession chatSession = chatPanel.getChatSession();
if (chatSession instanceof MetaContactChatSession)
if (chatSession != null)
{
ChatTransport currentTransport =
chatSession.getCurrentChatTransport();
Object currentDescriptor = currentTransport.getDescriptor();
if (currentDescriptor instanceof Contact)
{
MetaContact metaContact =
(MetaContact) chatSession.getDescriptor();
component.setCurrentContact(metaContact);
Contact contact = (Contact) currentDescriptor;
component.setCurrentContact(
contact, currentTransport.getResourceName());
}
}
if (component.getComponent() == null)
continue;
@ -1589,14 +1596,24 @@ public void pluginComponentAdded(PluginComponentEvent event)
net.java.sip.communicator.service.
gui.Container.CONTAINER_CHAT_WRITE_PANEL))
return;
PluginComponent c = factory.getPluginComponentInstance(this);
PluginComponent component = factory.getPluginComponentInstance(this);
ChatSession chatSession = chatPanel.getChatSession();
if (chatSession instanceof MetaContactChatSession)
if (chatSession != null)
{
ChatTransport currentTransport =
chatSession.getCurrentChatTransport();
Object currentDescriptor = currentTransport.getDescriptor();
if (currentDescriptor instanceof Contact)
{
MetaContact metaContact = (MetaContact) chatSession.getDescriptor();
c.setCurrentContact(metaContact);
Contact contact = (Contact) currentDescriptor;
component.setCurrentContact(
contact, currentTransport.getResourceName());
}
centerPanel.add((Component) c.getComponent());
}
centerPanel.add((Component) component.getComponent());
this.centerPanel.repaint();
}

@ -365,6 +365,8 @@ else if(contact != null)
setCallButtonsName();
setCallButtonsIcons();
currentChatTransportChanged(chatSession);
}
}
@ -435,7 +437,7 @@ public void currentChatTransportChanged(ChatSession chatSession)
Contact contact = (Contact) currentDescriptor;
for (PluginComponent c : pluginContainer.getPluginComponents())
c.setCurrentContact(contact);
c.setCurrentContact(contact, currentTransport.getResourceName());
}
}

@ -20,7 +20,7 @@
import org.jivesoftware.smack.filter.*;
import org.jivesoftware.smack.packet.*;
import org.jivesoftware.smack.provider.*;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smack.util.*;
import org.jivesoftware.smackx.*;
import org.jivesoftware.smackx.packet.*;
@ -456,7 +456,7 @@ private MessageDeliveredEvent sendMessage( Contact to,
+ " chat.tid=" + chat.getThreadID());
MessageDeliveredEvent msgDeliveryPendingEvt
= new MessageDeliveredEvent(message, to);
= new MessageDeliveredEvent(message, to, toResource);
msgDeliveryPendingEvt
= messageDeliveryPendingTransform(msgDeliveryPendingEvt);
@ -496,7 +496,7 @@ private MessageDeliveredEvent sendMessage( Contact to,
chat.sendMessage(msg);
MessageDeliveredEvent msgDeliveredEvt
= new MessageDeliveredEvent(message, to);
= new MessageDeliveredEvent(message, to, toResource);
// msgDeliveredEvt = messageDeliveredTransform(msgDeliveredEvt);

@ -308,6 +308,7 @@ public void start(Object dependentService)
// Register Transformation Layer
bundleContext.addServiceListener(this);
bundleContext.addServiceListener((ServiceListener) scOtrEngine);
bundleContext.addServiceListener(new OtrContactManager());
ServiceReference[] protocolProviderRefs
= ServiceUtils.getServiceReferences(
@ -380,7 +381,7 @@ public void start(Object dependentService)
{
protected PluginComponent getPluginInstance()
{
return new OtrV3OutgoingSessionSwitcher(
return new OTRv3OutgoingSessionSwitcher(
getContainer(), this);
}
},

@ -0,0 +1,180 @@
/*
* 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 <tt>OtrContact</tt>s in a static
* way.
*
* The <tt>OtrContact</tt> class is just a wrapper of [Contact, ContactResource]
* pairs. Its purpose is for the otr plugin to be able to create different
* <tt>Session</tt>s 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<Contact, List<OtrContact>> contactsMap =
new ConcurrentHashMap<Contact, List<OtrContact>>();
/**
* The <tt>OtrContact</tt> class is just a wrapper of
* [Contact, ContactResource] pairs. Its purpose is for the otr plugin to be
* able to create different <tt>Session</tt>s 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 <tt>OtrContact</tt> 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 <tt>Contact</tt> that the returned OtrContact
* represents.
* @param resource the <tt>ContactResource</tt> that the returned OtrContact
* represents.
* @return The <tt>OtrContact</tt> that represents this
* [Contact, ContactResource] pair.
*/
public static OtrContact getOtrContact(
Contact contact, ContactResource resource)
{
if (contact == null)
return null;
List<OtrContact> 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<OtrContact>();
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<Contact> i = contactsMap.keySet().iterator();
while (i.hasNext())
{
if (provider.equals(i.next().getProtocolProvider()))
i.remove();
}
}
}
}
}

@ -13,6 +13,7 @@
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.*;
/**
@ -46,7 +47,7 @@ class OtrContactMenu
private static final String ACTION_COMMAND_START_OTR = "START_OTR";
private final Contact contact;
private final OtrContact contact;
/**
* The indicator which determines whether this <tt>JMenu</tt> is displayed
@ -70,23 +71,27 @@ class OtrContactMenu
/**
* The OtrContactMenu constructor.
*
* @param contact the Contact this menu refers to.
* @param otrContact the OtrContact this menu refers to.
* @param inMacOSXScreenMenuBar <tt>true</tt> if the new menu is to be
* displayed in the Mac OS X screen menu bar; <tt>false</tt>, otherwise
* @param menu the parent menu
*/
public OtrContactMenu( Contact contact,
public OtrContactMenu( OtrContact otrContact,
boolean inMacOSXScreenMenuBar,
JMenu menu,
boolean isSeparateMenu)
{
this.contact = contact;
this.contact = otrContact;
this.inMacOSXScreenMenuBar = inMacOSXScreenMenuBar;
this.parentMenu = menu;
String resourceName =
otrContact.resource != null
? "/" + otrContact.resource.getResourceName()
: "";
separateMenu
= isSeparateMenu
? new SIPCommMenu(contact.getDisplayName())
? new SIPCommMenu(otrContact.contact.getDisplayName()
+ resourceName)
: null;
/*
@ -104,8 +109,10 @@ public OtrContactMenu( Contact contact,
this,
OtrActivator.scOtrEngine, OtrActivator.scOtrKeyManager);
setSessionStatus(OtrActivator.scOtrEngine.getSessionStatus(contact));
setOtrPolicy(OtrActivator.scOtrEngine.getContactPolicy(contact));
setSessionStatus(
OtrActivator.scOtrEngine.getSessionStatus(this.contact));
setOtrPolicy(
OtrActivator.scOtrEngine.getContactPolicy(otrContact.contact));
buildMenu();
}
@ -136,22 +143,23 @@ else if (ACTION_COMMAND_AUTHENTICATE_BUDDY.equals(actionCommand))
else if (ACTION_COMMAND_CB_ENABLE.equals(actionCommand))
{
OtrPolicy policy =
OtrActivator.scOtrEngine.getContactPolicy(contact);
OtrActivator.scOtrEngine.getContactPolicy(contact.contact);
boolean state = ((JCheckBoxMenuItem) e.getSource()).isSelected();
policy.setEnableManual(state);
OtrActivator.scOtrEngine.setContactPolicy(contact, policy);
OtrActivator.scOtrEngine.setContactPolicy(contact.contact, policy);
}
else if (ACTION_COMMAND_CB_AUTO.equals(actionCommand))
{
OtrPolicy policy =
OtrActivator.scOtrEngine.getContactPolicy(contact);
OtrActivator.scOtrEngine.getContactPolicy(contact.contact);
boolean state = ((JCheckBoxMenuItem) e.getSource()).isSelected();
policy.setEnableAlways(state);
policy.setSendWhitespaceTag(state);
OtrActivator.scOtrEngine.setContactPolicy(contact, policy);
OtrActivator.scOtrEngine.setContactPolicy(contact.contact, policy);
}
else if (ACTION_COMMAND_CB_AUTO_ALL.equals(actionCommand))
@ -161,6 +169,8 @@ else if (ACTION_COMMAND_CB_AUTO_ALL.equals(actionCommand))
boolean state = ((JCheckBoxMenuItem) e.getSource()).isSelected();
globalPolicy.setEnableAlways(state);
globalPolicy.setSendWhitespaceTag(state);
OtrActivator.configService.setProperty(
OtrActivator.AUTO_INIT_OTR_PROP,
Boolean.toString(state));
@ -171,17 +181,17 @@ else if (ACTION_COMMAND_CB_AUTO_ALL.equals(actionCommand))
else if (ACTION_COMMAND_CB_REQUIRE.equals(actionCommand))
{
OtrPolicy policy =
OtrActivator.scOtrEngine.getContactPolicy(contact);
OtrActivator.scOtrEngine.getContactPolicy(contact.contact);
boolean state = ((JCheckBoxMenuItem) e.getSource()).isSelected();
policy.setRequireEncryption(state);
OtrActivator.configService.setProperty(
OtrActivator.OTR_MANDATORY_PROP,
Boolean.toString(state));
OtrActivator.scOtrEngine.setContactPolicy(contact, policy);
OtrActivator.scOtrEngine.setContactPolicy(contact.contact, policy);
}
else if (ACTION_COMMAND_CB_RESET.equals(actionCommand))
OtrActivator.scOtrEngine.setContactPolicy(contact, null);
OtrActivator.scOtrEngine.setContactPolicy(contact.contact, null);
}
/*
@ -198,10 +208,11 @@ public void contactPolicyChanged(Contact contact)
* Implements ScOtrKeyManagerListener#contactVerificationStatusChanged(
* Contact).
*/
public void contactVerificationStatusChanged(Contact contact)
public void contactVerificationStatusChanged(OtrContact otrContact)
{
if (contact.equals(OtrContactMenu.this.contact))
setSessionStatus(OtrActivator.scOtrEngine.getSessionStatus(contact));
if (otrContact.equals(OtrContactMenu.this.contact))
setSessionStatus(
OtrActivator.scOtrEngine.getSessionStatus(otrContact));
}
/**
@ -221,7 +232,7 @@ void dispose()
*/
public void globalPolicyChanged()
{
setOtrPolicy(OtrActivator.scOtrEngine.getContactPolicy(contact));
setOtrPolicy(OtrActivator.scOtrEngine.getContactPolicy(contact.contact));
}
/**
@ -233,7 +244,8 @@ private void buildMenu()
if(separateMenu != null)
separateMenu.removeAll();
OtrPolicy policy = OtrActivator.scOtrEngine.getContactPolicy(contact);
OtrPolicy policy =
OtrActivator.scOtrEngine.getContactPolicy(contact.contact);
JMenuItem endOtr = new JMenuItem();
endOtr.setText(OtrActivator.resourceService
@ -327,7 +339,8 @@ private void buildMenu()
OtrActivator.resourceService
.getI18NString(
"plugin.otr.menu.CB_AUTO",
new String[] {contact.getDisplayName()})));
new String[]
{contact.contact.getDisplayName()})));
cbAlways.setEnabled(policy.getEnableManual());
cbAlways.setSelected(policy.getEnableAlways());
@ -408,10 +421,11 @@ else if (!isMandatory && defaultOtrPropValue != null)
/*
* Implements ScOtrEngineListener#sessionStatusChanged(Contact).
*/
public void sessionStatusChanged(Contact contact)
public void sessionStatusChanged(OtrContact otrContact)
{
if (contact.equals(OtrContactMenu.this.contact))
setSessionStatus(OtrActivator.scOtrEngine.getSessionStatus(contact));
if (otrContact.equals(OtrContactMenu.this.contact))
setSessionStatus(
OtrActivator.scOtrEngine.getSessionStatus(otrContact));
}
/**
@ -477,7 +491,8 @@ private void updateIcon()
OtrActivator.scOtrKeyManager.
getFingerprintFromPublicKey(pubKey);
imageID
= OtrActivator.scOtrKeyManager.isVerified(contact, fingerprint)
= OtrActivator.scOtrKeyManager.isVerified(
contact.contact, fingerprint)
? "plugin.otr.ENCRYPTED_ICON_16x16"
: "plugin.otr.ENCRYPTED_UNVERIFIED_ICON_16x16";
break;
@ -498,12 +513,13 @@ private void updateIcon()
}
@Override
public void multipleInstancesDetected(Contact contact) {}
public void multipleInstancesDetected(OtrContact contact) {}
@Override
public void outgoingSessionChanged(Contact contact)
public void outgoingSessionChanged(OtrContact otrContact)
{
if (contact.equals(OtrContactMenu.this.contact))
setSessionStatus(OtrActivator.scOtrEngine.getSessionStatus(contact));
if (otrContact.equals(OtrContactMenu.this.contact))
setSessionStatus(
OtrActivator.scOtrEngine.getSessionStatus(otrContact));
}
}

@ -16,6 +16,7 @@
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;
@ -40,7 +41,7 @@ public class OtrMetaContactButton
private SIPCommButton button;
private Contact contact;
private OtrContact otrContact;
private AnimatedImage animatedPadlockImage;
@ -58,21 +59,20 @@ public class OtrMetaContactButton
* The timer task that changes the padlock icon to "loading" and
* then to "broken" if the specified timeout passed
*/
public void sessionStatusChanged(Contact contact)
public void sessionStatusChanged(OtrContact otrContact)
{
// OtrMetaContactButton.this.contact can be null.
if (contact.equals(OtrMetaContactButton.this.contact))
if (otrContact.equals(OtrMetaContactButton.this.otrContact))
{
setStatus(
OtrActivator.scOtrEngine.getSessionStatus(contact));
OtrActivator.scOtrEngine.getSessionStatus(otrContact));
}
}
public void contactPolicyChanged(Contact contact)
{
// OtrMetaContactButton.this.contact can be null.
if (contact.equals(OtrMetaContactButton.this.contact))
if (contact.equals(OtrMetaContactButton.this.otrContact.contact))
{
setPolicy(
OtrActivator.scOtrEngine.getContactPolicy(contact));
@ -81,18 +81,18 @@ public void contactPolicyChanged(Contact contact)
public void globalPolicyChanged()
{
if (OtrMetaContactButton.this.contact != null)
if (OtrMetaContactButton.this.otrContact != null)
setPolicy(
OtrActivator.scOtrEngine.getContactPolicy(contact));
OtrActivator.scOtrEngine.getContactPolicy(otrContact.contact));
}
public void contactVerificationStatusChanged(Contact contact)
public void contactVerificationStatusChanged(OtrContact otrContact)
{
// OtrMetaContactButton.this.contact can be null.
if (contact.equals(OtrMetaContactButton.this.contact))
if (otrContact.equals(OtrMetaContactButton.this.otrContact))
{
setStatus(
OtrActivator.scOtrEngine.getSessionStatus(contact));
OtrActivator.scOtrEngine.getSessionStatus(otrContact));
}
}
@ -173,23 +173,23 @@ private SIPCommButton getButton()
{
public void actionPerformed(ActionEvent e)
{
if (contact == null)
if (otrContact == null)
return;
switch (OtrActivator.scOtrEngine.getSessionStatus(contact))
switch (OtrActivator.scOtrEngine.getSessionStatus(otrContact))
{
case ENCRYPTED:
case FINISHED:
case LOADING:
// Default action for finished, encrypted and loading
// sessions is end session.
OtrActivator.scOtrEngine.endSession(contact);
OtrActivator.scOtrEngine.endSession(otrContact);
break;
case TIMED_OUT:
case PLAINTEXT:
// Default action for timed_out and plaintext sessions
// is start session.
OtrActivator.scOtrEngine.startSession(contact);
OtrActivator.scOtrEngine.startSession(otrContact);
break;
}
}
@ -222,20 +222,49 @@ public String getName()
@Override
public void setCurrentContact(Contact contact)
{
if (this.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);
return;
}
this.contact = contact;
if (contact != null)
if (resourceName == null)
{
this.setStatus(OtrActivator.scOtrEngine.getSessionStatus(contact));
this.setPolicy(OtrActivator.scOtrEngine.getContactPolicy(contact));
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;
}
else
for (ContactResource resource : contact.getResources())
{
this.setStatus(ScSessionStatus.PLAINTEXT);
this.setPolicy(null);
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;
}
}
logger.debug("Could not find resource for contact " + contact);
}
/*
@ -274,16 +303,18 @@ private void setStatus(ScSessionStatus status)
{
case ENCRYPTED:
PublicKey pubKey =
OtrActivator.scOtrEngine.getRemotePublicKey(contact);
OtrActivator.scOtrEngine.getRemotePublicKey(otrContact);
String fingerprint =
OtrActivator.scOtrKeyManager.
getFingerprintFromPublicKey(pubKey);
image
= OtrActivator.scOtrKeyManager.isVerified(contact, fingerprint)
= OtrActivator.scOtrKeyManager.isVerified(
otrContact.contact, fingerprint)
? verifiedLockedPadlockImage
: unverifiedLockedPadlockImage;
tipKey =
OtrActivator.scOtrKeyManager.isVerified(contact, fingerprint)
OtrActivator.scOtrKeyManager.isVerified(
otrContact.contact, fingerprint)
? "plugin.otr.menu.VERIFIED"
: "plugin.otr.menu.UNVERIFIED";
break;
@ -316,17 +347,17 @@ private void setStatus(ScSessionStatus status)
}
@Override
public void multipleInstancesDetected(Contact contact)
public void multipleInstancesDetected(OtrContact contact)
{}
@Override
public void outgoingSessionChanged(Contact contact)
public void outgoingSessionChanged(OtrContact otrContact)
{
// OtrMetaContactButton.this.contact can be null.
if (contact.equals(OtrMetaContactButton.this.contact))
if (otrContact.equals(OtrMetaContactButton.this.otrContact))
{
setStatus(
OtrActivator.scOtrEngine.getSessionStatus(contact));
OtrActivator.scOtrEngine.getSessionStatus(otrContact));
}
}
}

@ -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,14 +95,54 @@ private void createOtrContactMenus(MetaContact metaContact)
if (metaContact.getContactCount() == 1)
{
Contact contact = contacts.next();
Collection<ContactResource> 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(
contacts.next(), inMacOSXScreenMenuBar, menu, false);
OtrContactManager.getOtrContact(contact, null),
inMacOSXScreenMenuBar,
menu,
false);
}
else
while (contacts.hasNext())
{
Contact contact = contacts.next();
Collection<ContactResource> 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(
contacts.next(), inMacOSXScreenMenuBar, menu, true);
OtrContactManager.getOtrContact(contact, null),
inMacOSXScreenMenuBar,
menu,
true);
}
}
}

@ -7,6 +7,7 @@
package net.java.sip.communicator.plugin.otr;
import net.java.otr4j.*;
import net.java.sip.communicator.plugin.otr.OtrContactManager.OtrContact;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
@ -24,10 +25,12 @@ 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(contact);
OtrActivator.scOtrEngine.getSessionStatus(otrContact);
// If OTR is disabled and we are not over an encrypted session, don't
// process anything.
if (!policy.getEnableManual()
@ -61,10 +64,12 @@ 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(contact);
OtrActivator.scOtrEngine.getSessionStatus(otrContact);
// If OTR is disabled and we are not over an encrypted session, don't
// process anything.
if (!policy.getEnableManual()
@ -80,7 +85,7 @@ public MessageDeliveredEvent messageDeliveryPending(
// Process the outgoing message.
String msgContent = evt.getSourceMessage().getContent();
String processedMessageContent =
OtrActivator.scOtrEngine.transformSending(contact, msgContent);
OtrActivator.scOtrEngine.transformSending(otrContact, msgContent);
if (processedMessageContent == null
|| processedMessageContent.length() < 1)
@ -114,10 +119,12 @@ 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(contact);
OtrActivator.scOtrEngine.getSessionStatus(otrContact);
// If OTR is disabled and we are not over an encrypted session, don't
// process anything.
if (!policy.getEnableManual()
@ -129,7 +136,7 @@ public MessageReceivedEvent messageReceived(MessageReceivedEvent evt)
String msgContent = evt.getSourceMessage().getContent();
String processedMessageContent =
OtrActivator.scOtrEngine.transformReceiving(contact, msgContent);
OtrActivator.scOtrEngine.transformReceiving(otrContact, msgContent);
if (processedMessageContent == null
|| processedMessageContent.length() < 1)

@ -8,6 +8,7 @@
import java.lang.ref.*;
import net.java.sip.communicator.plugin.otr.OtrContactManager.OtrContact;
import net.java.sip.communicator.service.protocol.*;
/**
@ -93,7 +94,7 @@ public void contactPolicyChanged(Contact contact)
* Forwards the event/notification to the associated
* <tt>T</tt> if it is still needed by the application.
*/
public void contactVerificationStatusChanged(Contact contact)
public void contactVerificationStatusChanged(OtrContact contact)
{
ScOtrKeyManagerListener l = getListener();
@ -145,7 +146,7 @@ public void globalPolicyChanged()
* Forwards the event/notification to the associated
* <tt>T</tt> if it is still needed by the application.
*/
public void sessionStatusChanged(Contact contact)
public void sessionStatusChanged(OtrContact contact)
{
ScOtrEngineListener l = getListener();
@ -157,7 +158,7 @@ public void sessionStatusChanged(Contact contact)
* Forwards the event/notification to the associated
* <tt>T</tt> if it is still needed by the application.
*/
public void multipleInstancesDetected(Contact contact)
public void multipleInstancesDetected(OtrContact contact)
{
ScOtrEngineListener l = getListener();
@ -169,7 +170,7 @@ public void multipleInstancesDetected(Contact contact)
* Forwards the event/notification to the associated
* <tt>T</tt> if it is still needed by the application.
*/
public void outgoingSessionChanged(Contact contact)
public void outgoingSessionChanged(OtrContact contact)
{
ScOtrEngineListener l = getListener();

@ -11,6 +11,7 @@
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.*;
/**
@ -33,7 +34,7 @@ public interface ScOtrEngine
* @param secret The secret answer for the question.
*/
public abstract void initSmp(
Contact contact, String question, String secret);
OtrContact contact, String question, String secret);
/**
* Responds to a question that is asked during the Smp negotiation process.
@ -42,11 +43,15 @@ public abstract void initSmp(
*
* @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
* @param question The question that is asked during the Smp negotiation.
* @param secret The secret answer for the question.
*/
public abstract void respondSmp(
Contact contact, String question, String secret);
public abstract void respondSmp(OtrContact contact,
InstanceTag receiverTag,
String question,
String secret);
/**
* Aborts the Smp negotiation process.
@ -56,52 +61,66 @@ public abstract void respondSmp(
* @param contact The contact with whom we want to abort the
* Smp negotiation process.
*/
public abstract void abortSmp(Contact contact);
public abstract void abortSmp(OtrContact contact);
/**
* Transforms an outgoing message.
*
* @param contact the destination {@link Contact}.
* @param contact the destination {@link OtrContact}.
* @param content the original message content.
* @return the transformed message content.
*/
public abstract String transformSending(Contact contact, String content);
public abstract String transformSending(OtrContact contact, String content);
/**
* Transforms an incoming message.
*
* @param contact the source {@link Contact}.
* @param contact the source {@link OtrContact}.
* @param content the original message content.
* @return the transformed message content.
*/
public abstract String transformReceiving(Contact contact, String content);
public abstract String transformReceiving(OtrContact contact, String content);
/**
* Starts the Off-the-Record session for the given {@link Contact}, if it's
* Starts the Off-the-Record session for the given {@link OtrContact}, if it's
* not already started.
*
* @param contact the {@link Contact} with whom we want to start an OTR
* @param contact the {@link OtrContact} with whom we want to start an OTR
* session.
*/
public abstract void startSession(Contact contact);
public abstract void startSession(OtrContact contact);
/**
* Ends the Off-the-Record session for the given {@link Contact}, if it is
* Ends the Off-the-Record session for the given {@link OtrContact}, if it is
* not already started.
*
* @param contact the {@link Contact} with whom we want to end the OTR
* @param contact the {@link OtrContact} with whom we want to end the OTR
* session.
*/
public abstract void endSession(Contact contact);
public abstract void endSession(OtrContact contact);
/**
* Refreshes the Off-the-Record session for the given {@link Contact}. If
* Refreshes the Off-the-Record session for the given {@link OtrContact}. If
* the session does not exist, a new session is established.
*
* @param contact the {@link Contact} with whom we want to refresh the OTR
* @param contact the {@link OtrContact} with whom we want to refresh the OTR
* session.
*/
public abstract void refreshSession(Contact contact);
public abstract void refreshSession(OtrContact contact);
/**
* Get the outgoing OTRv3 <tt>Session</tt>. 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.
*
* @return the <tt>Session</tt> 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
@ -113,11 +132,11 @@ public abstract void respondSmp(
* Returns a list containing all instances of a session. The 'master'
* session is always first in the list.
*
* @param contact the {@link Contact} for whom we want to get the instances
* @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<Session> getSessionInstances(Contact contact);
public abstract List<Session> getSessionInstances(OtrContact contact);
/**
* Some IM networks always relay all messages to all sessions of a client
@ -130,23 +149,23 @@ public abstract void respondSmp(
* specific session of his buddy who is logged in multiple times, he can set
* the outgoing instance of his buddy by specifying his <tt>InstanceTag</tt>.
*
* @param contact the {@link Contact} to whom we want to set the outgoing
* @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(Contact contact, InstanceTag tag);
public abstract boolean setOutgoingSession(OtrContact contact, InstanceTag tag);
/**
* Gets the {@link ScSessionStatus} for the given {@link Contact}.
* Gets the {@link ScSessionStatus} for the given {@link OtrContact}.
*
* @param contact the {@link Contact} whose {@link ScSessionStatus} we are
* @param contact the {@link OtrContact} whose {@link ScSessionStatus} we are
* interested in.
* @return the {@link ScSessionStatus}.
*/
public abstract ScSessionStatus getSessionStatus(Contact contact);
public abstract ScSessionStatus getSessionStatus(OtrContact contact);
// New Methods (Misc)
@ -175,7 +194,7 @@ public abstract void respondSmp(
*/
public abstract void removeListener(ScOtrEngineListener listener);
public abstract PublicKey getRemotePublicKey(Contact contact);
public abstract PublicKey getRemotePublicKey(OtrContact otrContact);
// New Methods (Policy management)
/**

@ -14,6 +14,7 @@
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.*;
@ -52,12 +53,31 @@ public KeyPair getLocalKeyPair(SessionID sessionID)
public OtrPolicy getSessionPolicy(SessionID sessionID)
{
return getContactPolicy(getContact(sessionID));
return getContactPolicy(getOtrContact(sessionID).contact);
}
public void injectMessage(SessionID sessionID, String messageText)
{
Contact contact = getContact(sessionID);
OtrContact otrContact = getOtrContact(sessionID);
Contact contact = otrContact.contact;
ContactResource resource = null;
if (contact.supportResources())
{
Collection<ContactResource> resources = contact.getResources();
if (resources != null)
{
for (ContactResource r : resources)
{
if (r.equals(otrContact.resource))
{
resource = r;
break;
}
}
}
}
OperationSetBasicInstantMessaging imOpSet
= contact
.getProtocolProvider()
@ -86,7 +106,7 @@ public void injectMessage(SessionID sessionID, String messageText)
null);
injectedMessageUIDs.add(message.getMessageUID());
imOpSet.sendInstantMessage(contact, message);
imOpSet.sendInstantMessage(contact, resource, message);
}
public void showError(SessionID sessionID, String err)
@ -96,10 +116,11 @@ public void showError(SessionID sessionID, String err)
public void showWarning(SessionID sessionID, String warn)
{
Contact contact = getContact(sessionID);
if (contact == null)
OtrContact otrContact = getOtrContact(sessionID);
if (otrContact == null)
return;
Contact contact = otrContact.contact;
OtrActivator.uiService.getChat(contact).addMessage(
contact.getDisplayName(), new Date(),
Chat.SYSTEM_MESSAGE, warn,
@ -110,14 +131,16 @@ public void showWarning(SessionID sessionID, String warn)
public void unreadableMessageReceived(SessionID sessionID)
throws OtrException
{
Contact contact = getContact(sessionID);
if (contact == null)
return;
OtrContact otrContact = getOtrContact(sessionID);
String resourceName = otrContact.resource != null ?
"/" + otrContact.resource.getResourceName() : "";
Contact contact = otrContact.contact;
String error =
OtrActivator.resourceService.getI18NString(
"plugin.otr.activator.unreadablemsgreceived",
new String[] {contact.getDisplayName()});
new String[]
{contact.getDisplayName() + resourceName});
OtrActivator.uiService.getChat(contact).addMessage(
contact.getDisplayName(), new Date(),
Chat.ERROR_MESSAGE, error,
@ -128,10 +151,11 @@ public void unreadableMessageReceived(SessionID sessionID)
public void unencryptedMessageReceived(SessionID sessionID, String msg)
throws OtrException
{
Contact contact = getContact(sessionID);
if (contact == null)
OtrContact otrContact = getOtrContact(sessionID);
if (otrContact == null)
return;
Contact contact = otrContact.contact;
String warn =
OtrActivator.resourceService.getI18NString(
"plugin.otr.activator.unencryptedmsgreceived");
@ -145,10 +169,11 @@ public void unencryptedMessageReceived(SessionID sessionID, String msg)
public void smpError(SessionID sessionID, int tlvType, boolean cheated)
throws OtrException
{
Contact contact = getContact(sessionID);
if (contact == null)
OtrContact otrContact = getOtrContact(sessionID);
if (otrContact == null)
return;
Contact contact = otrContact.contact;
logger.debug("SMP error occurred"
+ ". Contact: " + contact.getDisplayName()
+ ". TLV type: " + tlvType
@ -162,11 +187,11 @@ public void smpError(SessionID sessionID, int tlvType, boolean cheated)
Chat.ERROR_MESSAGE, error,
OperationSetBasicInstantMessaging.DEFAULT_MIME_TYPE);
SmpProgressDialog progressDialog = progressDialogMap.get(contact);
SmpProgressDialog progressDialog = progressDialogMap.get(otrContact);
if (progressDialog == null)
{
progressDialog = new SmpProgressDialog(contact);
progressDialogMap.put(contact, progressDialog);
progressDialogMap.put(otrContact, progressDialog);
}
progressDialog.setProgressFail();
@ -176,10 +201,11 @@ public void smpError(SessionID sessionID, int tlvType, boolean cheated)
@Override
public void smpAborted(SessionID sessionID) throws OtrException
{
Contact contact = getContact(sessionID);
if (contact == null)
OtrContact otrContact = getOtrContact(sessionID);
if (otrContact == null)
return;
Contact contact = otrContact.contact;
Session session = otrEngine.getSession(sessionID);
if (session.isSmpInProgress())
{
@ -192,11 +218,12 @@ public void smpAborted(SessionID sessionID) throws OtrException
Chat.SYSTEM_MESSAGE, warn,
OperationSetBasicInstantMessaging.DEFAULT_MIME_TYPE);
SmpProgressDialog progressDialog = progressDialogMap.get(contact);
SmpProgressDialog progressDialog =
progressDialogMap.get(otrContact);
if (progressDialog == null)
{
progressDialog = new SmpProgressDialog(contact);
progressDialogMap.put(contact, progressDialog);
progressDialogMap.put(otrContact, progressDialog);
}
progressDialog.setProgressFail();
@ -208,14 +235,18 @@ public void smpAborted(SessionID sessionID) throws OtrException
public void finishedSessionMessage(SessionID sessionID)
throws OtrException
{
Contact contact = getContact(sessionID);
if (contact == null)
OtrContact otrContact = getOtrContact(sessionID);
if (otrContact == 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[] {contact.getDisplayName()});
new String[]
{contact.getDisplayName() + resourceName});
OtrActivator.uiService.getChat(contact).addMessage(
contact.getDisplayName(), new Date(),
Chat.ERROR_MESSAGE, error,
@ -226,14 +257,19 @@ public void finishedSessionMessage(SessionID sessionID)
public void requireEncryptedMessage(SessionID sessionID, String msgText)
throws OtrException
{
Contact contact = getContact(sessionID);
if (contact == null)
OtrContact otrContact = getOtrContact(sessionID);
if (otrContact == null)
return;
String resourceName = otrContact.resource != null ?
"/" + otrContact.resource.getResourceName() : "";
Contact contact = otrContact.contact;
String error =
OtrActivator.resourceService.getI18NString(
"plugin.otr.activator.requireencryption",
new String[] {contact.getDisplayName()});
new String[]
{contact.getDisplayName() + resourceName});
OtrActivator.uiService.getChat(contact).addMessage(
contact.getDisplayName(), new Date(),
Chat.ERROR_MESSAGE, error,
@ -250,21 +286,24 @@ public byte[] getLocalFingerprintRaw(SessionID sessionID)
}
@Override
public void askForSecret(SessionID sessionID, String question)
public void askForSecret(
SessionID sessionID, InstanceTag receiverTag, String question)
{
Contact contact = getContact(sessionID);
if (contact == null)
OtrContact otrContact = getOtrContact(sessionID);
if (otrContact == null)
return;
Contact contact = otrContact.contact;
SmpAuthenticateBuddyDialog dialog =
new SmpAuthenticateBuddyDialog(contact, question);
new SmpAuthenticateBuddyDialog(
otrContact, receiverTag, question);
dialog.setVisible(true);
SmpProgressDialog progressDialog = progressDialogMap.get(contact);
SmpProgressDialog progressDialog = progressDialogMap.get(otrContact);
if (progressDialog == null)
{
progressDialog = new SmpProgressDialog(contact);
progressDialogMap.put(contact, progressDialog);
progressDialogMap.put(otrContact, progressDialog);
}
progressDialog.init();
@ -275,17 +314,18 @@ public void askForSecret(SessionID sessionID, String question)
public void verify(
SessionID sessionID, String fingerprint, boolean approved)
{
Contact contact = getContact(sessionID);
if (contact == null)
OtrContact otrContact = getOtrContact(sessionID);
if (otrContact == null)
return;
OtrActivator.scOtrKeyManager.verify(contact, fingerprint);
Contact contact = otrContact.contact;
OtrActivator.scOtrKeyManager.verify(otrContact, fingerprint);
SmpProgressDialog progressDialog = progressDialogMap.get(contact);
SmpProgressDialog progressDialog = progressDialogMap.get(otrContact);
if (progressDialog == null)
{
progressDialog = new SmpProgressDialog(contact);
progressDialogMap.put(contact, progressDialog);
progressDialogMap.put(otrContact, progressDialog);
}
progressDialog.setProgressSuccess();
@ -295,17 +335,18 @@ public void verify(
@Override
public void unverify(SessionID sessionID, String fingerprint)
{
Contact contact = getContact(sessionID);
if (contact == null)
OtrContact otrContact = getOtrContact(sessionID);
if (otrContact == null)
return;
OtrActivator.scOtrKeyManager.unverify(contact, fingerprint);
Contact contact = otrContact.contact;
OtrActivator.scOtrKeyManager.unverify(otrContact, fingerprint);
SmpProgressDialog progressDialog = progressDialogMap.get(contact);
SmpProgressDialog progressDialog = progressDialogMap.get(otrContact);
if (progressDialog == null)
{
progressDialog = new SmpProgressDialog(contact);
progressDialogMap.put(contact, progressDialog);
progressDialogMap.put(otrContact, progressDialog);
}
progressDialog.setProgressFail();
@ -338,14 +379,18 @@ public String getFallbackMessage(SessionID sessionID)
@Override
public void multipleInstancesDetected(SessionID sessionID)
{
Contact contact = getContact(sessionID);
if (contact == null)
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()});
new String[]
{contact.getDisplayName() + resourceName});
OtrActivator.uiService.getChat(contact).addMessage(
contact.getDisplayName(),
new Date(), Chat.SYSTEM_MESSAGE,
@ -356,14 +401,18 @@ public void multipleInstancesDetected(SessionID sessionID)
@Override
public void messageFromAnotherInstanceReceived(SessionID sessionID)
{
Contact contact = getContact(sessionID);
if (contact == null)
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()});
new String[]
{contact.getDisplayName() + resourceName});
OtrActivator.uiService.getChat(contact).addMessage(
contact.getDisplayName(),
new Date(), Chat.SYSTEM_MESSAGE,
@ -393,13 +442,13 @@ public void messageFromAnotherInstanceReceived(SessionID sessionID)
private Map<SessionID, ScSessionStatus> scSessionStatusMap =
new ConcurrentHashMap<SessionID, ScSessionStatus>();
private static final Map<ScSessionID, Contact> contactsMap =
new Hashtable<ScSessionID, Contact>();
private static final Map<ScSessionID, OtrContact> contactsMap =
new Hashtable<ScSessionID, OtrContact>();
private static final Map<Contact, SmpProgressDialog> progressDialogMap =
new ConcurrentHashMap<Contact, SmpProgressDialog>();
private static final Map<OtrContact, SmpProgressDialog> progressDialogMap =
new ConcurrentHashMap<OtrContact, SmpProgressDialog>();
public static Contact getContact(SessionID sessionID)
public static OtrContact getOtrContact(SessionID sessionID)
{
return contactsMap.get(new ScSessionID(sessionID));
}
@ -422,13 +471,15 @@ public static ScSessionID getScSessionForGuid(UUID guid)
return null;
}
public static SessionID getSessionID(Contact contact)
public static SessionID getSessionID(OtrContact otrContact)
{
ProtocolProviderService pps = contact.getProtocolProvider();
ProtocolProviderService pps = otrContact.contact.getProtocolProvider();
String resourceName = otrContact.resource != null ?
"/" + otrContact.resource.getResourceName() : "";
SessionID sessionID
= new SessionID(
pps.getAccountID().getAccountUniqueID(),
contact.getAddress(),
otrContact.contact.getAddress() + resourceName,
pps.getProtocolName());
synchronized (contactsMap)
@ -438,7 +489,7 @@ public static SessionID getSessionID(Contact contact)
ScSessionID scSessionID = new ScSessionID(sessionID);
contactsMap.put(scSessionID, contact);
contactsMap.put(scSessionID, otrContact);
}
return sessionID;
@ -473,15 +524,18 @@ public ScOtrEngineImpl()
{
public void sessionStatusChanged(SessionID sessionID)
{
Contact contact = getContact(sessionID);
if (contact == null)
OtrContact otrContact = getOtrContact(sessionID);
if (otrContact == 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(contact);
scheduler.cancel(otrContact);
ScSessionStatus scSessionStatus = getSessionStatus(contact);
ScSessionStatus scSessionStatus = getSessionStatus(otrContact);
String message = "";
switch (otrEngine.getSessionStatus(sessionID))
{
@ -522,7 +576,7 @@ public void sessionStatusChanged(SessionID sessionID)
contact, remoteFingerprint))
{
OtrActivator.scOtrKeyManager.unverify(
contact, remoteFingerprint);
otrContact, remoteFingerprint);
UUID sessionGuid = null;
for(ScSessionID scSessionID : contactsMap.keySet())
{
@ -542,7 +596,7 @@ public void sessionStatusChanged(SessionID sessionID)
+ ".unverifiedsessionwarning",
new String[]
{
contact.getDisplayName(),
contact.getDisplayName() + resourceName,
this.getClass().getName(),
"AUTHENTIFICATION",
sessionGuid.toString()
@ -590,6 +644,21 @@ 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(
@ -597,7 +666,8 @@ public void sessionStatusChanged(SessionID sessionID)
? "plugin.otr.activator.sessionstared"
: "plugin.otr.activator"
+ ".unverifiedsessionstared",
new String[] { contact.getDisplayName() });
new String[]
{contact.getDisplayName() + resourceName});
break;
case FINISHED:
@ -607,7 +677,7 @@ public void sessionStatusChanged(SessionID sessionID)
OtrActivator.resourceService.getI18NString(
"plugin.otr.activator.sessionfinished",
new String[]
{ contact.getDisplayName() });
{contact.getDisplayName() + resourceName});
break;
case PLAINTEXT:
scSessionStatus = ScSessionStatus.PLAINTEXT;
@ -615,7 +685,7 @@ public void sessionStatusChanged(SessionID sessionID)
message =
OtrActivator.resourceService.getI18NString(
"plugin.otr.activator.sessionlost", new String[]
{ contact.getDisplayName() });
{contact.getDisplayName() + resourceName});
break;
}
@ -625,27 +695,27 @@ public void sessionStatusChanged(SessionID sessionID)
OperationSetBasicInstantMessaging.HTML_MIME_TYPE);
for (ScOtrEngineListener l : getListeners())
l.sessionStatusChanged(contact);
l.sessionStatusChanged(otrContact);
}
public void multipleInstancesDetected(SessionID sessionID)
{
Contact contact = getContact(sessionID);
if (contact == null)
OtrContact otrContact = getOtrContact(sessionID);
if (otrContact == null)
return;
for (ScOtrEngineListener l : getListeners())
l.multipleInstancesDetected(contact);
l.multipleInstancesDetected(otrContact);
}
public void outgoingSessionChanged(SessionID sessionID)
{
Contact contact = getContact(sessionID);
if (contact == null)
OtrContact otrContact = getOtrContact(sessionID);
if (otrContact == null)
return;
for (ScOtrEngineListener l : getListeners())
l.outgoingSessionChanged(contact);
l.outgoingSessionChanged(otrContact);
}
});
}
@ -705,12 +775,12 @@ public void chatLinkClicked(URI url)
}
}
public void endSession(Contact contact)
public void endSession(OtrContact otrContact)
{
SessionID sessionID = getSessionID(contact);
SessionID sessionID = getSessionID(otrContact);
try
{
setSessionStatus(contact, ScSessionStatus.PLAINTEXT);
setSessionStatus(otrContact, ScSessionStatus.PLAINTEXT);
otrEngine.endSession(sessionID);
}
@ -722,8 +792,14 @@ public void endSession(Contact contact)
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(getSessionID(contact) + "policy",
this.configurator.getPropertyInt(sessionID + "policy",
-1);
if (policy < 0)
return getGlobalPolicy();
@ -734,7 +810,7 @@ public OtrPolicy getContactPolicy(Contact contact)
public OtrPolicy getGlobalPolicy()
{
return new OtrPolicyImpl(this.configurator.getPropertyInt("POLICY",
OtrPolicy.OTRL_POLICY_MANUAL));
OtrPolicy.OTRL_POLICY_DEFAULT));
}
/**
@ -764,31 +840,31 @@ private class ScSessionStatusScheduler
{
private final Timer timer = new Timer();
private final Map<Contact, TimerTask> tasks =
new ConcurrentHashMap<Contact, TimerTask>();
private final Map<OtrContact, TimerTask> tasks =
new ConcurrentHashMap<OtrContact, TimerTask>();
public void scheduleScSessionStatusChange(
final Contact contact, final ScSessionStatus status)
final OtrContact otrContact, final ScSessionStatus status)
{
cancel(contact);
cancel(otrContact);
TimerTask task = new TimerTask() {
@Override
public void run()
{
setSessionStatus(contact, status);
setSessionStatus(otrContact, status);
}
};
timer.schedule(task, SESSION_TIMEOUT);
tasks.put(contact, task);
tasks.put(otrContact, task);
}
public void cancel(final Contact contact)
public void cancel(final OtrContact otrContact)
{
TimerTask task = tasks.get(contact);
TimerTask task = tasks.get(otrContact);
if (task != null)
task.cancel();
tasks.remove(contact);
tasks.remove(otrContact);
}
public void serviceChanged(ServiceEvent ev)
@ -805,13 +881,15 @@ public void serviceChanged(ServiceEvent ev)
ProtocolProviderService provider
= (ProtocolProviderService) service;
Iterator<Contact> i = tasks.keySet().iterator();
Iterator<OtrContact> i = tasks.keySet().iterator();
while (i.hasNext())
{
Contact contact = i.next();
if (provider.equals(contact.getProtocolProvider())) {
cancel(contact);
OtrContact otrContact = i.next();
if (provider.equals(
otrContact.contact.getProtocolProvider()))
{
cancel(otrContact);
i.remove();
}
}
@ -819,14 +897,15 @@ public void serviceChanged(ServiceEvent ev)
}
}
private void setSessionStatus(Contact contact, ScSessionStatus status)
private void setSessionStatus(OtrContact contact, ScSessionStatus status)
{
scSessionStatusMap.put(getSessionID(contact), status);
scheduler.cancel(contact);
for (ScOtrEngineListener l : getListeners())
l.sessionStatusChanged(contact);
}
public ScSessionStatus getSessionStatus(Contact contact)
public ScSessionStatus getSessionStatus(OtrContact contact)
{
SessionID sessionID = getSessionID(contact);
SessionStatus sessionStatus = otrEngine.getSessionStatus(sessionID);
@ -871,9 +950,9 @@ public void launchHelp()
.getI18NString("plugin.otr.authbuddydialog.HELP_URI"));
}
public void refreshSession(Contact contact)
public void refreshSession(OtrContact otrContact)
{
SessionID sessionID = getSessionID(contact);
SessionID sessionID = getSessionID(otrContact);
try
{
otrEngine.refreshSession(sessionID);
@ -922,24 +1001,25 @@ public void serviceChanged(ServiceEvent ev)
synchronized(contactsMap)
{
Iterator<Contact> i = contactsMap.values().iterator();
Iterator<OtrContact> i = contactsMap.values().iterator();
while (i.hasNext())
{
Contact contact = i.next();
if (provider.equals(contact.getProtocolProvider()))
OtrContact otrContact = i.next();
if (provider.equals(
otrContact.contact.getProtocolProvider()))
{
scSessionStatusMap.remove(getSessionID(contact));
scSessionStatusMap.remove(getSessionID(otrContact));
i.remove();
}
}
}
Iterator<Contact> i = progressDialogMap.keySet().iterator();
Iterator<OtrContact> i = progressDialogMap.keySet().iterator();
while (i.hasNext())
{
if (provider.equals(i.next().getProtocolProvider()))
if (provider.equals(i.next().contact.getProtocolProvider()))
i.remove();
}
scheduler.serviceChanged(ev);
@ -948,7 +1028,14 @@ public void serviceChanged(ServiceEvent ev)
public void setContactPolicy(Contact contact, OtrPolicy policy)
{
String propertyID = getSessionID(contact) + "policy";
ProtocolProviderService pps = contact.getProtocolProvider();
SessionID sessionID
= new SessionID(
pps.getAccountID().getAccountUniqueID(),
contact.getAddress(),
pps.getProtocolName());
String propertyID = sessionID + "policy";
if (policy == null)
this.configurator.removeProperty(propertyID);
else
@ -971,28 +1058,29 @@ public void setGlobalPolicy(OtrPolicy policy)
public void showError(SessionID sessionID, String err)
{
Contact contact = getContact(sessionID);
if (contact == null)
OtrContact otrContact = getOtrContact(sessionID);
if (otrContact == 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(Contact contact)
public void startSession(OtrContact otrContact)
{
SessionID sessionID = getSessionID(contact);
SessionID sessionID = getSessionID(otrContact);
ScSessionStatus scSessionStatus = getSessionStatus(contact);
ScSessionStatus scSessionStatus = getSessionStatus(otrContact);
scSessionStatus = ScSessionStatus.LOADING;
scSessionStatusMap.put(sessionID, scSessionStatus);
for (ScOtrEngineListener l : getListeners())
{
l.sessionStatusChanged(contact);
l.sessionStatusChanged(otrContact);
scheduler.scheduleScSessionStatusChange(
contact, ScSessionStatus.TIMED_OUT);
otrContact, ScSessionStatus.TIMED_OUT);
}
try
@ -1006,9 +1094,9 @@ public void startSession(Contact contact)
}
}
public String transformReceiving(Contact contact, String msgText)
public String transformReceiving(OtrContact otrContact, String msgText)
{
SessionID sessionID = getSessionID(contact);
SessionID sessionID = getSessionID(otrContact);
try
{
return otrEngine.transformReceiving(sessionID, msgText);
@ -1021,9 +1109,9 @@ public String transformReceiving(Contact contact, String msgText)
}
}
public String transformSending(Contact contact, String msgText)
public String transformSending(OtrContact otrContact, String msgText)
{
SessionID sessionID = getSessionID(contact);
SessionID sessionID = getSessionID(otrContact);
try
{
return otrEngine.transformSending(sessionID, msgText);
@ -1036,25 +1124,25 @@ public String transformSending(Contact contact, String msgText)
}
}
private Session getSession(Contact contact)
private Session getSession(OtrContact contact)
{
SessionID sessionID = getSessionID(contact);
return otrEngine.getSession(sessionID);
}
@Override
public void initSmp(Contact contact, String question, String secret)
public void initSmp(OtrContact otrContact, String question, String secret)
{
Session session = getSession(contact);
Session session = getSession(otrContact);
try
{
session.initSmp(question, secret);
SmpProgressDialog progressDialog = progressDialogMap.get(contact);
SmpProgressDialog progressDialog = progressDialogMap.get(otrContact);
if (progressDialog == null)
{
progressDialog = new SmpProgressDialog(contact);
progressDialogMap.put(contact, progressDialog);
progressDialog = new SmpProgressDialog(otrContact.contact);
progressDialogMap.put(otrContact, progressDialog);
}
progressDialog.init();
@ -1063,24 +1151,27 @@ public void initSmp(Contact contact, String question, String secret)
catch (OtrException e)
{
logger.error("Error initializing SMP session with contact "
+ contact.getDisplayName(), e);
+ otrContact.contact.getDisplayName(), e);
showError(session.getSessionID(), e.getMessage());
}
}
@Override
public void respondSmp(Contact contact, String question, String secret)
public void respondSmp( OtrContact otrContact,
InstanceTag receiverTag,
String question,
String secret)
{
Session session = getSession(contact);
Session session = getSession(otrContact);
try
{
session.respondSmp(question, secret);
session.respondSmp(receiverTag, question, secret);
SmpProgressDialog progressDialog = progressDialogMap.get(contact);
SmpProgressDialog progressDialog = progressDialogMap.get(otrContact);
if (progressDialog == null)
{
progressDialog = new SmpProgressDialog(contact);
progressDialogMap.put(contact, progressDialog);
progressDialog = new SmpProgressDialog(otrContact.contact);
progressDialogMap.put(otrContact, progressDialog);
}
progressDialog.incrementProgress();
@ -1090,24 +1181,24 @@ public void respondSmp(Contact contact, String question, String secret)
{
logger.error(
"Error occured when sending SMP response to contact "
+ contact.getDisplayName(), e);
+ otrContact.contact.getDisplayName(), e);
showError(session.getSessionID(), e.getMessage());
}
}
@Override
public void abortSmp(Contact contact)
public void abortSmp(OtrContact otrContact)
{
Session session = getSession(contact);
Session session = getSession(otrContact);
try
{
session.abortSmp();
SmpProgressDialog progressDialog = progressDialogMap.get(contact);
SmpProgressDialog progressDialog = progressDialogMap.get(otrContact);
if (progressDialog == null)
{
progressDialog = new SmpProgressDialog(contact);
progressDialogMap.put(contact, progressDialog);
progressDialog = new SmpProgressDialog(otrContact.contact);
progressDialogMap.put(otrContact, progressDialog);
}
progressDialog.dispose();
@ -1115,30 +1206,30 @@ public void abortSmp(Contact contact)
catch (OtrException e)
{
logger.error("Error aborting SMP session with contact "
+ contact.getDisplayName(), e);
+ otrContact.contact.getDisplayName(), e);
showError(session.getSessionID(), e.getMessage());
}
}
public PublicKey getRemotePublicKey(Contact contact)
public PublicKey getRemotePublicKey(OtrContact otrContact)
{
if (contact == null)
if (otrContact == null)
return null;
Session session = getSession(contact);
Session session = getSession(otrContact);
return session.getRemotePublicKey();
}
public List<Session> getSessionInstances(Contact contact)
public List<Session> getSessionInstances(OtrContact otrContact)
{
if (contact == null)
if (otrContact == null)
return null;
return getSession(contact).getInstances();
return getSession(otrContact).getInstances();
}
public boolean setOutgoingSession(Contact contact, InstanceTag tag)
public boolean setOutgoingSession(OtrContact contact, InstanceTag tag)
{
if (contact == null)
return false;
@ -1148,4 +1239,14 @@ public boolean setOutgoingSession(Contact contact, InstanceTag tag)
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);
}
}

@ -6,6 +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.*;
/**
@ -18,9 +19,9 @@ public interface ScOtrEngineListener
public void globalPolicyChanged();
public void sessionStatusChanged(Contact contact);
public void sessionStatusChanged(OtrContact contact);
public void multipleInstancesDetected(Contact contact);
public void multipleInstancesDetected(OtrContact contact);
public void outgoingSessionChanged(Contact contact);
public void outgoingSessionChanged(OtrContact contact);
}

@ -9,6 +9,7 @@
import java.security.*;
import java.util.*;
import net.java.sip.communicator.plugin.otr.OtrContactManager.OtrContact;
import net.java.sip.communicator.service.protocol.*;
/**
@ -23,9 +24,9 @@ public interface ScOtrKeyManager
public abstract void removeListener(ScOtrKeyManagerListener l);
public abstract void verify(Contact contact, String fingerprint);
public abstract void verify(OtrContact contact, String fingerprint);
public abstract void unverify(Contact contact, String fingerprint);
public abstract void unverify(OtrContact contact, String fingerprint);
public abstract boolean isVerified(Contact contact, String fingerprint);
@ -39,8 +40,6 @@ public interface ScOtrKeyManager
public abstract void saveFingerprint(Contact contact, String fingerprint);
public abstract PublicKey loadPublicKey(Contact contact);
public abstract KeyPair loadKeyPair(AccountID accountID);
public abstract void generateKeyPair(AccountID accountID);

@ -11,6 +11,7 @@
import java.util.*;
import net.java.otr4j.crypto.*;
import net.java.sip.communicator.plugin.otr.OtrContactManager.OtrContact;
import net.java.sip.communicator.service.protocol.*;
/**
@ -62,28 +63,28 @@ public void removeListener(ScOtrKeyManagerListener l)
}
}
public void verify(Contact contact, String fingerprint)
public void verify(OtrContact otrContact, String fingerprint)
{
if ((fingerprint == null) || contact == null)
if ((fingerprint == null) || otrContact == null)
return;
this.configurator.setProperty(contact.getAddress() + fingerprint
this.configurator.setProperty(otrContact.contact.getAddress() + fingerprint
+ ".fingerprint.verified", true);
for (ScOtrKeyManagerListener l : getListeners())
l.contactVerificationStatusChanged(contact);
l.contactVerificationStatusChanged(otrContact);
}
public void unverify(Contact contact, String fingerprint)
public void unverify(OtrContact otrContact, String fingerprint)
{
if ((fingerprint == null) || contact == null)
if ((fingerprint == null) || otrContact == null)
return;
this.configurator.setProperty(contact.getAddress() + fingerprint
this.configurator.setProperty(otrContact.contact.getAddress() + fingerprint
+ ".fingerprint.verified", false);
for (ScOtrKeyManagerListener l : getListeners())
l.contactVerificationStatusChanged(contact);
l.contactVerificationStatusChanged(otrContact);
}
public boolean isVerified(Contact contact, String fingerprint)
@ -139,9 +140,9 @@ public List<String> getAllRemoteFingerprints(Contact contact)
// Now we can store the old properties in the new format.
if (isVerified)
verify(contact, fingerprint);
verify(OtrContactManager.getOtrContact(contact, null), fingerprint);
else
unverify(contact, fingerprint);
unverify(OtrContactManager.getOtrContact(contact, null), fingerprint);
// Finally we append the new fingerprint to out stored list of
// fingerprints.
@ -229,39 +230,6 @@ public void saveFingerprint(Contact contact, String fingerprint)
+ ".fingerprint.verified", false);
}
public PublicKey loadPublicKey(Contact contact)
{
if (contact == null)
return null;
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)
{
if (account == null)

@ -6,7 +6,7 @@
*/
package net.java.sip.communicator.plugin.otr;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.plugin.otr.OtrContactManager.OtrContact;
/**
*
@ -14,5 +14,5 @@
*/
public interface ScOtrKeyManagerListener
{
public void contactVerificationStatusChanged(Contact contact);
public void contactVerificationStatusChanged(OtrContact contact);
}

@ -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)
{
Contact contact = ScOtrEngineImpl.getContact(
OtrContact otrContact = ScOtrEngineImpl.getOtrContact(
ScOtrEngineImpl.getScSessionForGuid(uuid).getSessionID());
openAuthDialog(contact);
openAuthDialog(otrContact);
}
public static void openAuthDialog(Contact contact)
public static void openAuthDialog(OtrContact contact)
{
// Launch auth buddy dialog.
OtrBuddyAuthenticationDialog authenticateBuddyDialog

@ -14,7 +14,7 @@
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.otr.OtrContactManager.OtrContact;
/**
* @author George Politis
@ -29,7 +29,7 @@ public class FingerprintAuthenticationPanel
/**
* The Contact that we are authenticating.
*/
private final Contact contact;
private final OtrContact otrContact;
private SIPCommTextField txtRemoteFingerprintComparison;
@ -61,9 +61,9 @@ public class FingerprintAuthenticationPanel
*
* @param contact The contact that this panel refers to.
*/
FingerprintAuthenticationPanel(Contact contact)
FingerprintAuthenticationPanel(OtrContact contact)
{
this.contact = contact;
this.otrContact = contact;
initComponents();
loadContact();
@ -109,11 +109,11 @@ private void initComponents()
cbAction.addItem(actionIHave);
cbAction.addItem(actionIHaveNot);
PublicKey pubKey = OtrActivator.scOtrEngine.getRemotePublicKey(contact);
PublicKey pubKey = OtrActivator.scOtrEngine.getRemotePublicKey(otrContact);
String remoteFingerprint =
OtrActivator.scOtrKeyManager.getFingerprintFromPublicKey(pubKey);
cbAction.setSelectedItem(OtrActivator.scOtrKeyManager
.isVerified(contact, remoteFingerprint)
.isVerified(otrContact.contact, remoteFingerprint)
? actionIHave : actionIHaveNot);
pnlAction.add(cbAction, c);
@ -122,10 +122,14 @@ private void initComponents()
c.weightx = 1.0;
pnlAction.add(txtAction, c);
String resourceName = otrContact.resource != null ?
"/" + otrContact.resource.getResourceName() : "";
txtRemoteFingerprintComparison = new SIPCommTextField(
OtrActivator.resourceService
.getI18NString("plugin.otr.authbuddydialog.FINGERPRINT_CHECK",
new String[]{contact.getDisplayName()}));
new String[]
{otrContact.contact.getDisplayName() + resourceName}));
txtRemoteFingerprintComparison.getDocument().addDocumentListener(this);
c.gridwidth = 2;
@ -142,23 +146,23 @@ public JComboBox getCbAction()
/**
* Sets up the {@link OtrBuddyAuthenticationDialog} components so that they
* reflect the {@link OtrBuddyAuthenticationDialog#contact}
* reflect the {@link OtrBuddyAuthenticationDialog#otrContact}
*/
private void loadContact()
{
// Local fingerprint.
String account =
contact.getProtocolProvider().getAccountID().getDisplayName();
otrContact.contact.getProtocolProvider().getAccountID().getDisplayName();
String localFingerprint =
OtrActivator.scOtrKeyManager.getLocalFingerprint(contact
OtrActivator.scOtrKeyManager.getLocalFingerprint(otrContact.contact
.getProtocolProvider().getAccountID());
txtLocalFingerprint.setText(OtrActivator.resourceService.getI18NString(
"plugin.otr.authbuddydialog.LOCAL_FINGERPRINT", new String[]
{ account, localFingerprint }));
// Remote fingerprint.
String user = contact.getDisplayName();
PublicKey pubKey = OtrActivator.scOtrEngine.getRemotePublicKey(contact);
String user = otrContact.contact.getDisplayName();
PublicKey pubKey = OtrActivator.scOtrEngine.getRemotePublicKey(otrContact);
String remoteFingerprint =
OtrActivator.scOtrKeyManager.getFingerprintFromPublicKey(pubKey);
txtRemoteFingerprint.setText(OtrActivator.resourceService
@ -189,7 +193,7 @@ public void changedUpdate(DocumentEvent e)
public void compareFingerprints()
{
PublicKey pubKey = OtrActivator.scOtrEngine.getRemotePublicKey(contact);
PublicKey pubKey = OtrActivator.scOtrEngine.getRemotePublicKey(otrContact);
String remoteFingerprint =
OtrActivator.scOtrKeyManager.getFingerprintFromPublicKey(pubKey);

@ -95,7 +95,8 @@ public void valueChanged(ListSelectionEvent e)
public void actionPerformed(ActionEvent arg0)
{
OtrActivator.scOtrKeyManager
.verify(getSelectedContact(), getSelectedFingerprint());
.verify(OtrContactManager.getOtrContact(
getSelectedContact(), null), getSelectedFingerprint());
openContact(getSelectedContact(), getSelectedFingerprint());
contactsTable.updateUI();
}
@ -113,7 +114,8 @@ public void actionPerformed(ActionEvent arg0)
public void actionPerformed(ActionEvent arg0)
{
OtrActivator.scOtrKeyManager
.unverify(getSelectedContact(), getSelectedFingerprint());
.unverify(OtrContactManager.getOtrContact(
getSelectedContact(), null), getSelectedFingerprint());
openContact(getSelectedContact(), getSelectedFingerprint());
contactsTable.updateUI();
}

@ -13,6 +13,7 @@
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.*;
@ -218,8 +219,9 @@ public int getColumnCount()
}
@Override
public void contactVerificationStatusChanged(Contact contact)
public void contactVerificationStatusChanged(OtrContact otrContact)
{
Contact contact = otrContact.contact;
allContactsFingerprints.put(
contact,
OtrActivator.scOtrKeyManager.getAllRemoteFingerprints(contact));

@ -1,3 +1,9 @@
/*
* 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.*;
@ -13,13 +19,21 @@
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.*;
public class OtrV3OutgoingSessionSwitcher
/**
* 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,
@ -28,7 +42,9 @@ public class OtrV3OutgoingSessionSwitcher
{
private static final Logger logger
= Logger.getLogger(OtrV3OutgoingSessionSwitcher.class);
= Logger.getLogger(OTRv3OutgoingSessionSwitcher.class);
private final PluginComponentFactory parentFactory;
private static final long serialVersionUID = 0L;
@ -36,10 +52,20 @@ public class OtrV3OutgoingSessionSwitcher
private ButtonGroup buttonGroup = new ButtonGroup();
Contact contact;
private OtrContact contact;
/**
* A map used for storing each <tt>Session</tt>s corresponding <tt>JMenuItem
* </tt>.
*/
private final Map<Session, JMenuItem> outgoingSessions
= new HashMap<Session, JMenuItem>();
/**
* An animated {@link JMenu}
* @author Marin Dzhigarov
*
*/
private static class SelectorMenu
extends SIPCommMenu
{
@ -74,9 +100,10 @@ public void actionPerformed(ActionEvent e)
fadeCycles++;
}
alpha = newAlpha;
if (fadeCycles == 3)
if (fadeCycles >= 3)
{
alphaChanger.stop();
fadeCycles = 0;
alpha = 1f;
}
SelectorMenu.this.repaint();
@ -95,18 +122,22 @@ public void paintComponent(Graphics g)
super.paintComponent(g2d);
}
/**
* Creates a fade in and out effect for this {@link JMenu}
*/
public void fadeAnimation()
{
alphaChanger.stop();
alpha = 0.85f;
repaint();
SelectorMenu.this.repaint();
alphaChanger.start();
}
};
private final PluginComponentFactory parentFactory;
public OtrV3OutgoingSessionSwitcher(Container container,
/**
* The OTRv3OutgoingSessionSwitcher constructor
*/
public OTRv3OutgoingSessionSwitcher(Container container,
PluginComponentFactory parentFactory)
{
this.parentFactory = parentFactory;
@ -140,7 +171,7 @@ public OtrV3OutgoingSessionSwitcher(Container container,
* obsolete and OtrWeakListener will remove it as a listener of
* scOtrEngine and scOtrKeyManager.
*/
new OtrWeakListener<OtrV3OutgoingSessionSwitcher>(
new OtrWeakListener<OTRv3OutgoingSessionSwitcher>(
this,
OtrActivator.scOtrEngine, OtrActivator.scOtrKeyManager);
@ -148,13 +179,13 @@ public OtrV3OutgoingSessionSwitcher(Container container,
{
finishedPadlockImage = new ImageIcon(ImageIO.read(
OtrActivator.resourceService.getImageURL(
"plugin.otr.FINISHED_ICON_16x16")));
"plugin.otr.FINISHED_ICON_BLACK_16x16")));
verifiedLockedPadlockImage = new ImageIcon(ImageIO.read(
OtrActivator.resourceService.getImageURL(
"plugin.otr.ENCRYPTED_ICON_16x16")));
"plugin.otr.ENCRYPTED_ICON_BLACK_16x16")));
unverifiedLockedPadlockImage = new ImageIcon(ImageIO.read(
OtrActivator.resourceService.getImageURL(
"plugin.otr.ENCRYPTED_UNVERIFIED_ICON_16x16")));
"plugin.otr.ENCRYPTED_UNVERIFIED_ICON_BLACK_16x16")));
unlockedPadlockImage = new ImageIcon(ImageIO.read(
OtrActivator.resourceService.getImageURL(
"plugin.otr.PLAINTEXT_ICON_16x16")));
@ -170,24 +201,75 @@ public int getPositionIndex()
return -1;
}
@Override
/**
* 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 == contact)
if (this.contact != null && this.contact.contact == contact)
return;
this.contact = contact;
System.out.println("ot tuk1");
buildMenu(contact);
this.contact =
OtrContactManager.getOtrContact(contact, null);
buildMenu(this.contact);
}
@Override
/**
* 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 <tt>ContactResource</tt> 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) {}
@ -200,52 +282,92 @@ public PluginComponentFactory getParentFactory()
return parentFactory;
}
@Override
public void contactVerificationStatusChanged(Contact contact)
/**
* Implements ScOtrKeyManagerListener#contactVerificationStatusChanged(
* Contact).
*/
public void contactVerificationStatusChanged(OtrContact contact)
{
if (contact == null || this.contact != contact) return;
buildMenu(contact);
if (this.menu.isVisible())
this.menu.fadeAnimation();
}
@Override
/**
* Implements ScOtrEngineListener#contactPolicyChanged(Contact).
*/
public void contactPolicyChanged(Contact contact) {}
@Override
/**
* Implements ScOtrKeyManagerListener#globalPolicyChanged().
*/
public void globalPolicyChanged() {}
@Override
public void sessionStatusChanged(Contact contact)
/**
* Implements ScOtrEngineListener#sessionStatusChanged(OtrContact).
*/
public void sessionStatusChanged(OtrContact contact)
{
System.out.println("ot tuk2");
buildMenu(contact);
if (this.menu.isVisible())
this.menu.fadeAnimation();
}
@Override
public void multipleInstancesDetected(Contact contact)
/**
* 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)
{
System.out.println("ot tuk3");
buildMenu(contact);
}
private ImageIcon verifiedLockedPadlockImage;
private ImageIcon unverifiedLockedPadlockImage;
private ImageIcon finishedPadlockImage;
private ImageIcon unlockedPadlockImage;
void buildMenu(Contact contact)
/**
* 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))
{
if (contact == null || this.contact != contact) {
return;
}
menu.removeAll();
java.util.List<Session> multipleInstances =
OtrActivator.scOtrEngine.getSessionInstances(contact);
OtrActivator.scOtrEngine.getSessionInstances(
otrContact);
Session outgoingSession =
OtrActivator.scOtrEngine.getOutgoingSession(otrContact);
int index = 0;
for (Session session : multipleInstances)
{
index++;
if (!outgoingSessions.containsKey(session))
outgoingSessions.put(session, new JRadioButtonMenuItem());
{
JMenuItem menuItem = new JRadioButtonMenuItem();
outgoingSessions.put(session, menuItem);
menuItem.addActionListener(this);
}
JMenuItem menuItem = outgoingSessions.get(session);
menuItem.setText("Session " + index);
@ -260,7 +382,8 @@ void buildMenu(Contact contact)
OtrActivator.scOtrKeyManager.
getFingerprintFromPublicKey(pubKey);
imageIcon
= OtrActivator.scOtrKeyManager.isVerified(contact, fingerprint)
= OtrActivator.scOtrKeyManager.isVerified(
otrContact.contact, fingerprint)
? verifiedLockedPadlockImage
: unverifiedLockedPadlockImage;
break;
@ -276,17 +399,20 @@ void buildMenu(Contact contact)
menu.add(menuItem);
SelectedObject selectedObject =
new SelectedObject(imageIcon, session);
this.menu.setSelected(selectedObject);
buttonGroup.add(menuItem);
menuItem.addActionListener(this);
setSelected(menu.getItem(0));
menuItem.repaint();
if (session == outgoingSession)
{
this.menu.setSelected(selectedObject);
setSelected(menu.getItem(index - 1));
}
}
System.out.println("da");
updateEnableStatus();
menu.repaint();
}
@Override
public void actionPerformed(ActionEvent e)
{
for (Map.Entry<Session, JMenuItem> entry : outgoingSessions.entrySet())
@ -301,19 +427,12 @@ public void actionPerformed(ActionEvent e)
}
}
@Override
public void outgoingSessionChanged(Contact contact)
{
buildMenu(contact);
}
/**
* Sets the menu to enabled or disabled. The menu is enabled, as soon as it
* contains two or more items. If it is empty, it is disabled.
* 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);
this.menu.fadeAnimation();
}
}

@ -14,6 +14,7 @@
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.service.protocol.*;
@ -25,7 +26,7 @@
public class OtrBuddyAuthenticationDialog
extends SIPCommDialog
{
private final Contact contact;
private final OtrContact contact;
/**
* The {@link OtrBuddyAuthenticationDialog} ctor.
@ -33,7 +34,7 @@ public class OtrBuddyAuthenticationDialog
* @param contact The {@link Contact} this
* {@link OtrBuddyAuthenticationDialog} refers to.
*/
public OtrBuddyAuthenticationDialog(Contact contact)
public OtrBuddyAuthenticationDialog(OtrContact contact)
{
super(false);
this.contact = contact;

@ -14,10 +14,9 @@
import javax.swing.border.*;
import net.java.otr4j.*;
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.plugin.otr.authdialog.*;
import net.java.sip.communicator.service.protocol.*;
/**
* A special {@link Panel} that manages the OTR configuration.

@ -11,9 +11,10 @@
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.service.protocol.*;
import net.java.sip.communicator.plugin.otr.OtrContactManager.OtrContact;
/**
* The dialog that pops up when the remote party send us SMP
@ -26,13 +27,17 @@
public class SmpAuthenticateBuddyDialog
extends SIPCommDialog
{
private final Contact contact;
private final OtrContact otrContact;
private final String question;
public SmpAuthenticateBuddyDialog(Contact contact, String question)
private final InstanceTag receiverTag;
public SmpAuthenticateBuddyDialog(
OtrContact contact, InstanceTag receiverTag, String question)
{
this.contact = contact;
this.otrContact = contact;
this.receiverTag = receiverTag;
this.question = question;
initComponents();
}
@ -60,12 +65,17 @@ 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[] {contact.getDisplayName()}));
new String[]
{otrContact.contact.getDisplayName() +
resourceName}));
authenticationFrom.setText(authFromText);
mainPanel.add(authenticationFrom);
@ -170,7 +180,7 @@ public void actionPerformed(ActionEvent arg0)
{
public void actionPerformed(ActionEvent e)
{
OtrActivator.scOtrEngine.abortSmp(contact);
OtrActivator.scOtrEngine.abortSmp(otrContact);
SmpAuthenticateBuddyDialog.this.dispose();
}
});
@ -188,7 +198,7 @@ public void actionPerformed(ActionEvent e)
public void actionPerformed(ActionEvent e)
{
OtrActivator.scOtrEngine.respondSmp(
contact, question, answerTextBox.getText());
otrContact, receiverTag, question, answerTextBox.getText());
SmpAuthenticateBuddyDialog.this.dispose();
}
});

@ -692,4 +692,9 @@ public int getPositionIndex()
{
return -1;
}
@Override
public void setCurrentContact(Contact contact, String resourceName)
{
}
}

@ -92,6 +92,14 @@ public void setCurrentContact(Contact contact)
{
}
/*
* Implements PluginComponent#setCurrentContact(Contact).
*/
public void setCurrentContact(Contact contact, String resourceName)
{
setCurrentContact(contact);
}
/*
* Implements PluginComponent#setCurrentContact(MetaContact).
*/

@ -69,6 +69,17 @@ public interface PluginComponent
*/
public void setCurrentContact(Contact contact);
/**
* 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 <tt>ContactResource</tt> name. Some components
* may be interested in a particular ContactResource of a contact.
*/
public void setCurrentContact(Contact contact, String resourceName);
/**
* 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

@ -29,6 +29,11 @@ public class MessageDeliveredEvent
*/
private Contact to = null;
/**
* The <tt>ContactResource</tt>, to which the message was sent.
*/
private ContactResource toResource = null;
/**
* A timestamp indicating the exact date when the event occurred.
*/
@ -88,6 +93,42 @@ public MessageDeliveredEvent(Message source, Contact to, Date timestamp)
this.timestamp = timestamp;
}
/**
* Creates a <tt>MessageDeliveredEvent</tt> representing delivery of the
* <tt>source</tt> message to the specified <tt>to</tt> contact.
*
* @param source the <tt>Message</tt> whose delivery this event represents.
* @param to the <tt>Contact</tt> that this message was sent to.
* @param timestamp a date indicating the exact moment when the event
* ocurred
*/
public MessageDeliveredEvent(
Message source, Contact to, ContactResource toResource, Date timestamp)
{
super(source);
this.to = to;
this.toResource = toResource;
this.timestamp = timestamp;
}
/**
* Creates a <tt>MessageDeliveredEvent</tt> representing delivery of the
* <tt>source</tt> message to the specified <tt>to</tt> contact.
*
* @param source the <tt>Message</tt> whose delivery this event represents.
* @param to the <tt>Contact</tt> that this message was sent to.
* @param timestamp a date indicating the exact moment when the event
* ocurred
*/
public MessageDeliveredEvent(
Message source, Contact to, ContactResource toResource)
{
this(source, to, new Date());
this.toResource = toResource;
}
/**
* Returns a reference to the <tt>Contact</tt> that <tt>Message</tt> was
* sent to.
@ -158,4 +199,16 @@ public boolean isSmsMessage()
{
return smsMessage;
}
/**
* Returns a reference to the <tt>ContactResource</tt> that has sent the
* <tt>Message</tt> whose reception this event represents.
*
* @return a reference to the <tt>ContactResource</tt> that has sent the
* <tt>Message</tt> whose reception this event represents.
*/
public ContactResource getContactResource()
{
return toResource;
}
}

Loading…
Cancel
Save