mirror of https://github.com/sipwise/jitsi.git
parent
0509a03f4f
commit
f95066b360
@ -0,0 +1,519 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.impl.media.transform.zrtp;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
|
||||
import net.java.sip.communicator.service.gui.*;
|
||||
import net.java.sip.communicator.service.media.*;
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
import net.java.sip.communicator.util.Logger;
|
||||
import net.java.sip.communicator.impl.media.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import gnu.java.zrtp.*;
|
||||
import org.osgi.framework.*;
|
||||
|
||||
/**
|
||||
* The user callback class used by the ZRTP4J.
|
||||
* This class provides means to communicate events to the user through
|
||||
* GUI elements, and also allows the user to control the ZRTP activation
|
||||
* and deactivation.
|
||||
*
|
||||
* @author Emanuel Onica
|
||||
*
|
||||
*/
|
||||
public class SCCallback
|
||||
extends ZrtpUserCallback
|
||||
implements ActionListener
|
||||
{
|
||||
private static final Logger logger
|
||||
= Logger.getLogger(SCCallback.class);
|
||||
|
||||
/**
|
||||
* The UI Service needed to provide the means to display
|
||||
* popup dialogs and other possible informative elements
|
||||
*/
|
||||
private UIService uiService;
|
||||
|
||||
/**
|
||||
* The popup dialog used to display announcements to the user
|
||||
*/
|
||||
private PopupDialog popupDialog;
|
||||
|
||||
/**
|
||||
* The label from the ZRTP GUI plugin used to display the SAS
|
||||
*/
|
||||
private JLabel zrtpLabel = null;
|
||||
|
||||
/**
|
||||
* The button from the ZRTP GUI plugin used to activate and
|
||||
* deactivate the secure state of the call
|
||||
*/
|
||||
private JButton zrtpButton = null;
|
||||
|
||||
/**
|
||||
* The panel from the ZRTP GUI plugin holding the ZRTP related
|
||||
* GUI components
|
||||
*/
|
||||
private JPanel zrtpPanel = null;
|
||||
|
||||
/**
|
||||
* Flags needed for specific GUI setting indicating if the call
|
||||
* securing change was issued by a GoClear/GoSecure request from the other peer
|
||||
*/
|
||||
private boolean gcgsByPeerFlag = true;
|
||||
private boolean firstSecuring = true;
|
||||
|
||||
ActionListener [] listeners;
|
||||
|
||||
private CallSession callSession = null;
|
||||
|
||||
/**
|
||||
* The class constructor.
|
||||
* Gets a reference to the ZRTP GUI plugin and initializes the
|
||||
* ZRTP GUI component members.
|
||||
*/
|
||||
public SCCallback(CallSession callSession)
|
||||
{
|
||||
BundleContext bc = MediaActivator.getBundleContext();
|
||||
|
||||
ServiceReference uiServiceRef =
|
||||
bc.getServiceReference(UIService.class.getName());
|
||||
|
||||
uiService = (UIService)bc.getService(uiServiceRef);
|
||||
|
||||
popupDialog = uiService.getPopupDialog();
|
||||
|
||||
ServiceReference[] serRefs = null;
|
||||
|
||||
this.callSession = callSession;
|
||||
|
||||
String osgiFilter = "("
|
||||
+ Container.CONTAINER_ID
|
||||
+ "="+Container.CONTAINER_MAIN_TOOL_BAR.getID()+")";
|
||||
|
||||
zrtpButton = (JButton) callSession.getCall().getSecureGUIComponent("secureButton");
|
||||
zrtpLabel = (JLabel) callSession.getCall().getSecureGUIComponent("secureLabel");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see gnu.java.zrtp.ZrtpUserCallback#init()
|
||||
*/
|
||||
public void init()
|
||||
{
|
||||
gcgsByPeerFlag = true;
|
||||
firstSecuring = true;
|
||||
|
||||
listeners = zrtpButton.getActionListeners();
|
||||
|
||||
for (int i=0; i<listeners.length; i++)
|
||||
zrtpButton.removeActionListener(listeners[i]);
|
||||
|
||||
zrtpButton.addActionListener(this);
|
||||
|
||||
zrtpButton.setActionCommand("firstZRTPTrigger");
|
||||
|
||||
logger.info("ZRTP engine Initialized");
|
||||
System.err.println("ZRTP engine Initialized");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see gnu.java.zrtp.ZrtpUserCallback#secureOn(java.lang.String)
|
||||
*/
|
||||
public void secureOn(String cipher)
|
||||
{
|
||||
logger.info("Cipher: " + cipher);
|
||||
System.err.println("Cipher: " + cipher);
|
||||
|
||||
zrtpButton.setActionCommand("defaultZRTPAction");
|
||||
zrtpButton.setToolTipText(SCCallbackResources.TOGGLE_OFF_SECURITY);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see gnu.java.zrtp.ZrtpUserCallback#showSAS(java.lang.String, boolean)
|
||||
*/
|
||||
public void showSAS(String sas, boolean verified)
|
||||
{
|
||||
logger.info("SAS: " + sas);
|
||||
System.err.println("SAS: " + sas);
|
||||
|
||||
zrtpLabel.setBorder(BorderFactory.createLineBorder(Color.GREEN));
|
||||
zrtpLabel.setText(SCCallbackResources.SAS_SECURED_MESSAGE+sas);
|
||||
zrtpLabel.setToolTipText(SCCallbackResources.SAS_SECURED_TOOLTIP);
|
||||
showTooltip();
|
||||
|
||||
if (!firstSecuring && gcgsByPeerFlag)
|
||||
{
|
||||
zrtpButton.setActionCommand("goSecureRemoteToggle");
|
||||
zrtpButton.doClick();
|
||||
zrtpButton.setActionCommand("defaultZRTPAction");
|
||||
}
|
||||
else
|
||||
if (!firstSecuring)
|
||||
{
|
||||
// the case of call securing initiated by peer after a previous GoClear
|
||||
// - be sure to reset the flag
|
||||
gcgsByPeerFlag = true;
|
||||
}
|
||||
|
||||
firstSecuring = false;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see gnu.java.zrtp.ZrtpUserCallback#showMessage(gnu.java.zrtp.ZrtpCodes.MessageSeverity, java.util.EnumSet)
|
||||
*/
|
||||
public void showMessage(ZrtpCodes.MessageSeverity sev, EnumSet<?> subCode)
|
||||
{
|
||||
Iterator ii = subCode.iterator();
|
||||
Object msgCode = ii.next();
|
||||
logger.info("Show message sub code: " + msgCode);
|
||||
System.err.println("Show message sub code: " + msgCode);
|
||||
|
||||
if (msgCode.equals(CallSessionImpl.ZRTPCustomInfoCodes.ZRTPNotEnabledByUser))
|
||||
{
|
||||
zrtpLabel.setBorder(BorderFactory.createLineBorder(Color.RED));
|
||||
zrtpLabel.setText(SCCallbackResources.SAS_NOT_SECURED_MESSAGE);
|
||||
zrtpLabel.setToolTipText(SCCallbackResources.SAS_NOT_SECURED_TOOLTIP);
|
||||
showTooltip();
|
||||
}
|
||||
|
||||
if (msgCode.equals(CallSessionImpl.ZRTPCustomInfoCodes.ZRTPDisabledByCallEnd))
|
||||
{
|
||||
zrtpLabel.setBorder(BorderFactory.createLineBorder(Color.BLUE));
|
||||
zrtpLabel.setText(SCCallbackResources.DEFAULT_SAS_MESSAGE);
|
||||
zrtpLabel.setToolTipText(SCCallbackResources.DEFAULT_SAS_TOOLTIP);
|
||||
|
||||
String command = zrtpButton.getActionCommand();
|
||||
if (!command.equals("startSecureMode"))
|
||||
{
|
||||
zrtpButton.removeActionListener(this);
|
||||
|
||||
for (int i=0; i<listeners.length; i++)
|
||||
zrtpButton.addActionListener(listeners[i]);
|
||||
|
||||
zrtpButton.setActionCommand("startSecureMode");
|
||||
}
|
||||
}
|
||||
|
||||
if (msgCode.equals(CallSessionImpl.ZRTPCustomInfoCodes.ZRTPEngineInitFailure))
|
||||
{
|
||||
zrtpLabel.setBorder(BorderFactory.createLineBorder(Color.RED));
|
||||
zrtpLabel.setText(SCCallbackResources.ENGINE_FAIL_SAS_MESSAGE);
|
||||
zrtpLabel.setToolTipText(SCCallbackResources.ENGINE_FAIL_SAS_TOOLTIP);
|
||||
zrtpButton.setActionCommand("zrtpInitFail");
|
||||
zrtpButton.doClick();
|
||||
showTooltip();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see gnu.java.zrtp.ZrtpUserCallback#zrtpNegotiationFailed(gnu.java.zrtp.ZrtpCodes.MessageSeverity, java.util.EnumSet)
|
||||
*/
|
||||
public void zrtpNegotiationFailed(ZrtpCodes.MessageSeverity severity,
|
||||
EnumSet<?> subCode)
|
||||
{
|
||||
Iterator ii = subCode.iterator();
|
||||
Object msgCode = ii.next();
|
||||
logger.warn("Negotiation failed sub code: " + msgCode);
|
||||
System.err.println("Negotiation failed sub code: " + msgCode);
|
||||
|
||||
zrtpLabel.setBorder(BorderFactory.createLineBorder(Color.RED));
|
||||
zrtpLabel.setText(SCCallbackResources.SAS_NOT_SECURED_MESSAGE);
|
||||
zrtpLabel.setToolTipText(SCCallbackResources.SAS_SECURING_FAIL_TOOLTIP);
|
||||
|
||||
String prevCommand = zrtpButton.getActionCommand();
|
||||
zrtpButton.setActionCommand("revertToUnsecured");
|
||||
zrtpButton.doClick();
|
||||
zrtpButton.setActionCommand(prevCommand);
|
||||
|
||||
showTooltip();
|
||||
}
|
||||
|
||||
public void goClearProcedureFailed(ZrtpCodes.MessageSeverity severity,
|
||||
EnumSet<?> subCode, boolean maintainSecurity)
|
||||
{
|
||||
Iterator ii = subCode.iterator();
|
||||
Object msgCode = ii.next();
|
||||
logger.warn("ZRTP negotiation failed sub code: " + msgCode);
|
||||
System.err.println("ZRTP negotiation failed sub code: " + msgCode);
|
||||
|
||||
String prevCommand = zrtpButton.getActionCommand();
|
||||
|
||||
if (msgCode.equals(ZrtpCodes.WarningCodes.WarningGoClearRequestInvalid))
|
||||
{
|
||||
zrtpButton.setActionCommand("revertFromAllowClearFailure");
|
||||
zrtpButton.doClick();
|
||||
}
|
||||
else
|
||||
if (maintainSecurity == false)
|
||||
{
|
||||
zrtpLabel.setBorder(BorderFactory.createLineBorder(Color.RED));
|
||||
zrtpLabel.setText(SCCallbackResources.SAS_NOT_SECURED_MESSAGE);
|
||||
zrtpLabel.setToolTipText(SCCallbackResources.SAS_SECURING_FAIL_TOOLTIP);
|
||||
|
||||
zrtpButton.setActionCommand("revertToUnsecured");
|
||||
zrtpButton.doClick();
|
||||
zrtpButton.setActionCommand(prevCommand);
|
||||
}
|
||||
else
|
||||
if (maintainSecurity == true)
|
||||
{
|
||||
zrtpButton.setActionCommand("revertToSecured");
|
||||
zrtpButton.doClick();
|
||||
zrtpButton.setActionCommand(prevCommand);
|
||||
}
|
||||
|
||||
showTooltip();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see gnu.java.zrtp.ZrtpUserCallback#secureOff()
|
||||
*/
|
||||
public void secureOff()
|
||||
{
|
||||
logger.info("Security off");
|
||||
System.err.println("Security off");
|
||||
|
||||
// this is the case of locally GoClear request
|
||||
// be sure to reset the flag after handling it
|
||||
if (!gcgsByPeerFlag)
|
||||
{
|
||||
zrtpLabel.setBorder(BorderFactory.createLineBorder(Color.RED));
|
||||
zrtpLabel.setText(SCCallbackResources.SAS_NOT_SECURED_MESSAGE);
|
||||
zrtpLabel.setToolTipText(SCCallbackResources.SAS_UNSECURED_AT_REQUEST_TOOLTIP);
|
||||
showTooltip();
|
||||
gcgsByPeerFlag = true;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see gnu.java.zrtp.ZrtpUserCallback#zrtpNotSuppOther()
|
||||
*/
|
||||
public void zrtpNotSuppOther()
|
||||
{
|
||||
logger.info("ZRTP not supported");
|
||||
System.err.println("ZRTP not supported");
|
||||
|
||||
zrtpButton.setToolTipText(SCCallbackResources.PEER_UNSUPORTED_SECURITY);
|
||||
zrtpLabel.setBorder(BorderFactory.createLineBorder(Color.RED));
|
||||
zrtpLabel.setText(SCCallbackResources.SAS_NOT_SECURED_MESSAGE);
|
||||
zrtpLabel.setToolTipText(SCCallbackResources.SAS_PEER_UNSUPORTED_TOOLTIP);
|
||||
showTooltip();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see gnu.java.zrtp.ZrtpUserCallback#confirmGoClear()
|
||||
*/
|
||||
public void confirmGoClear()
|
||||
{
|
||||
logger.info("GoClear confirmation requested");
|
||||
System.err.println("GoClear confirmation requested");
|
||||
|
||||
popupDialog.showMessagePopupDialog(SCCallbackResources.PEER_TOGGLED_SECURITY_OFF_MESSAGE,
|
||||
SCCallbackResources.PEER_TOGGLED_SECURITY_OFF_CAPTION,
|
||||
PopupDialog.INFORMATION_MESSAGE);
|
||||
zrtpLabel.setBorder(BorderFactory.createLineBorder(Color.RED));
|
||||
zrtpLabel.setText(SCCallbackResources.SAS_NOT_SECURED_MESSAGE);
|
||||
zrtpLabel.setToolTipText(SCCallbackResources.SAS_UNSECURED_AT_PEER_REQUEST_TOOLTIP);
|
||||
zrtpButton.setActionCommand("goClearRemoteToggle");
|
||||
zrtpButton.doClick();
|
||||
zrtpButton.setActionCommand("defaultZRTPAction");
|
||||
showTooltip();
|
||||
}
|
||||
|
||||
public void setGCGSByPeerFlag(boolean gcgsByPeerFlag)
|
||||
{
|
||||
this.gcgsByPeerFlag = gcgsByPeerFlag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Force tooltip show function
|
||||
* (Not really necessary but could draw user's attention on some events;
|
||||
* Seems no version from below works however...
|
||||
* TODO: Search some other way - or better see what's wrong with the ones found)
|
||||
*
|
||||
*/
|
||||
public void showTooltip()
|
||||
{
|
||||
//version 1
|
||||
/*ToolTipManager.sharedInstance().mouseMoved(
|
||||
new MouseEvent(zrtpLabel, 0, 0, 0,
|
||||
0, 0,
|
||||
0, false));*/
|
||||
|
||||
//version 2
|
||||
/*Action toolTipAction = component.getActionMap().get("postTip");
|
||||
if (toolTipAction != null)
|
||||
{
|
||||
ActionEvent postTip = new ActionEvent(component, ActionEvent.ACTION_PERFORMED, "");
|
||||
toolTipAction.actionPerformed( postTip );
|
||||
}*/
|
||||
|
||||
//version 3
|
||||
zrtpLabel.dispatchEvent(new KeyEvent
|
||||
(
|
||||
zrtpLabel,
|
||||
KeyEvent.KEY_PRESSED,
|
||||
0,
|
||||
KeyEvent.CTRL_MASK,
|
||||
KeyEvent.VK_F1,
|
||||
KeyEvent.CHAR_UNDEFINED
|
||||
));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
||||
*/
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
String command = e.getActionCommand();
|
||||
|
||||
|
||||
if (command.equals("defaultZRTPAction"))
|
||||
{
|
||||
if(callSession.getSecureCommunicationStatus())
|
||||
{
|
||||
updateSecureButton(false);
|
||||
|
||||
callSession.
|
||||
setSecureCommunicationStatus(false,
|
||||
OperationSetBasicTelephony.
|
||||
SecureStatusChangeSource.
|
||||
SECURE_STATUS_CHANGE_BY_LOCAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
updateSecureButton(true);
|
||||
|
||||
callSession.
|
||||
setSecureCommunicationStatus(true,
|
||||
OperationSetBasicTelephony.
|
||||
SecureStatusChangeSource.
|
||||
SECURE_STATUS_CHANGE_BY_LOCAL);
|
||||
}
|
||||
}
|
||||
else
|
||||
if (command.equals("firstZRTPTrigger"))
|
||||
{
|
||||
ToolTipManager.sharedInstance().mouseMoved(
|
||||
new MouseEvent(zrtpButton, 0, 0, 0,
|
||||
0, 0,
|
||||
0, false));
|
||||
}
|
||||
else
|
||||
if (command.equals("revertFromAllowClearFailure"))
|
||||
{
|
||||
updateSecureButton(true);
|
||||
|
||||
callSession.
|
||||
setSecureCommunicationStatus(true,
|
||||
OperationSetBasicTelephony.
|
||||
SecureStatusChangeSource.
|
||||
SECURE_STATUS_REVERTED);
|
||||
|
||||
zrtpButton.setToolTipText(SCCallbackResources.GOCLEAR_REQUEST_AC_FLAG_FAILURE);
|
||||
}
|
||||
else
|
||||
if (command.equals("zrtpInitFail"))
|
||||
{
|
||||
updateSecureButton(false);
|
||||
|
||||
callSession.
|
||||
setSecureCommunicationStatus(false,
|
||||
OperationSetBasicTelephony.
|
||||
SecureStatusChangeSource.
|
||||
SECURE_STATUS_REVERTED);
|
||||
|
||||
zrtpButton.setToolTipText(SCCallbackResources.ZRTP_ENGINE_INIT_FAILURE);
|
||||
}
|
||||
else
|
||||
if (command.equals("revertToSecured"))
|
||||
{
|
||||
updateSecureButton(true);
|
||||
|
||||
callSession.
|
||||
setSecureCommunicationStatus(true,
|
||||
OperationSetBasicTelephony.
|
||||
SecureStatusChangeSource.
|
||||
SECURE_STATUS_REVERTED);
|
||||
|
||||
}
|
||||
else
|
||||
if (command.equals("revertToUnsecured"))
|
||||
{
|
||||
updateSecureButton(false);
|
||||
|
||||
callSession.
|
||||
setSecureCommunicationStatus(false,
|
||||
OperationSetBasicTelephony.
|
||||
SecureStatusChangeSource.
|
||||
SECURE_STATUS_REVERTED);
|
||||
|
||||
}
|
||||
else
|
||||
if (command.equals("goClearRemoteToggle"))
|
||||
{
|
||||
updateSecureButton(false);
|
||||
|
||||
callSession.
|
||||
setSecureCommunicationStatus(false,
|
||||
OperationSetBasicTelephony.
|
||||
SecureStatusChangeSource.
|
||||
SECURE_STATUS_CHANGE_BY_REMOTE);
|
||||
|
||||
}
|
||||
else
|
||||
if (command.equals("goSecureRemoteToggle"))
|
||||
{
|
||||
updateSecureButton(true);
|
||||
|
||||
callSession.
|
||||
setSecureCommunicationStatus(true,
|
||||
OperationSetBasicTelephony.
|
||||
SecureStatusChangeSource.
|
||||
SECURE_STATUS_CHANGE_BY_REMOTE);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The method used to update the secure button state (pressed or not pressed)
|
||||
*
|
||||
* @param isSecured parameter reflecting the current button state
|
||||
*/
|
||||
public void updateSecureButton(boolean isSecured)
|
||||
{
|
||||
if(isSecured)
|
||||
{
|
||||
zrtpButton.setIcon(
|
||||
new ImageIcon(SCCallbackResources.getImage
|
||||
(SCCallbackResources.SECURE_ON_ICON)));
|
||||
zrtpButton.setToolTipText(SCCallbackResources.TOGGLE_OFF_SECURITY);
|
||||
}
|
||||
else
|
||||
{
|
||||
zrtpButton.setIcon(
|
||||
new ImageIcon(SCCallbackResources.getImage
|
||||
(SCCallbackResources.SECURE_OFF_ICON)));
|
||||
zrtpButton.setToolTipText(SCCallbackResources.TOGGLE_ON_SECURITY);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,198 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.impl.media.transform.zrtp;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.net.URL;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import net.java.sip.communicator.service.resources.*;
|
||||
import net.java.sip.communicator.impl.media.*;
|
||||
|
||||
import org.osgi.framework.*;
|
||||
|
||||
/**
|
||||
* The <tt>Resources</tt> class manages the access to the internationalization
|
||||
* properties files and the image resources used in this plugin.
|
||||
*
|
||||
* @author Emanuel Onica
|
||||
*
|
||||
*/
|
||||
public class SCCallbackResources
|
||||
{
|
||||
/**
|
||||
* Contains the secure button icons
|
||||
*/
|
||||
private static Hashtable loadedImages = new Hashtable();
|
||||
|
||||
public static String TOGGLE_OFF_SECURITY
|
||||
= getString("toggleOffSecurity");
|
||||
|
||||
public static String TOGGLE_ON_SECURITY
|
||||
= getString("toggleOnSecurity");
|
||||
|
||||
public static String SAS_SECURED_MESSAGE
|
||||
= getString("sasSecuredMessage");
|
||||
|
||||
public static String SAS_SECURED_TOOLTIP
|
||||
= getString("sasSecuredTooltip");
|
||||
|
||||
public static String SAS_NOT_SECURED_MESSAGE
|
||||
= getString("sasNotSecuredMessage");
|
||||
|
||||
public static String SAS_NOT_SECURED_TOOLTIP
|
||||
= getString("sasNotSecuredTooltip");
|
||||
|
||||
public static String DEFAULT_SAS_TOOLTIP
|
||||
= getString("defaultSASTooltip");
|
||||
|
||||
public static String DEFAULT_SAS_MESSAGE
|
||||
= getString("defaultSASMessage");
|
||||
|
||||
public static String ENGINE_FAIL_SAS_TOOLTIP
|
||||
= getString("sasEngineFailTooltip");
|
||||
|
||||
public static String ENGINE_FAIL_SAS_MESSAGE
|
||||
= getString("sasEngineFailMessage");
|
||||
|
||||
public static String SAS_SECURING_FAIL_TOOLTIP
|
||||
= getString("sasSecuringFailTooltip");
|
||||
|
||||
public static String SAS_UNSECURED_AT_REQUEST_TOOLTIP
|
||||
= getString("sasUnsecuredAtRequestTooltip");
|
||||
|
||||
public static String PEER_UNSUPORTED_SECURITY
|
||||
= getString("peerUnsuportedSecurity");
|
||||
|
||||
public static String SAS_PEER_UNSUPORTED_TOOLTIP
|
||||
= getString("sasPeerUnsuportedTooltip");
|
||||
|
||||
public static String PEER_TOGGLED_SECURITY_OFF_MESSAGE
|
||||
= getString("peerToggledOffSecurityMessage");
|
||||
|
||||
public static String PEER_TOGGLED_SECURITY_OFF_CAPTION
|
||||
= getString("peerToggledOffSecurityCaption");
|
||||
|
||||
public static String SAS_UNSECURED_AT_PEER_REQUEST_TOOLTIP
|
||||
= getString("sasUnsecuredAtPeerRequestTooltip");
|
||||
|
||||
public static String ZRTP_ENGINE_INIT_FAILURE
|
||||
= getString("engineInitFailure");
|
||||
|
||||
public static String GOCLEAR_REQUEST_AC_FLAG_FAILURE
|
||||
= getString("allowClearRequestFailure");
|
||||
|
||||
/**
|
||||
* The icon on the "Secure" button in the <tt>QuickMenu</tt>.
|
||||
*/
|
||||
public static final ImageID SECURE_ON_ICON
|
||||
= new ImageID("SECURE_BUTTON_ON");
|
||||
|
||||
/**
|
||||
* The icon on the "Secure" button in the <tt>QuickMenu</tt>.
|
||||
*/
|
||||
public static final ImageID SECURE_OFF_ICON
|
||||
= new ImageID("SECURE_BUTTON_OFF");
|
||||
|
||||
/**
|
||||
* The resource management service used to get the needed
|
||||
* resources: button images, text predefined messages, etc
|
||||
*/
|
||||
private static ResourceManagementService resourcesService;
|
||||
|
||||
/**
|
||||
* Returns an internationalized string corresponding to the given key.
|
||||
*
|
||||
* @param key The key of the string.
|
||||
* @return An internationalized string corresponding to the given key.
|
||||
*/
|
||||
public static String getString(String key)
|
||||
{
|
||||
return getResources().getI18NString(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the resource management service
|
||||
*
|
||||
* @return the resource management service
|
||||
*/
|
||||
public static ResourceManagementService getResources()
|
||||
{
|
||||
if (resourcesService == null)
|
||||
{
|
||||
ServiceReference serviceReference = MediaActivator.getBundleContext()
|
||||
.getServiceReference(ResourceManagementService.class.getName());
|
||||
|
||||
if(serviceReference == null)
|
||||
return null;
|
||||
|
||||
resourcesService =
|
||||
(ResourceManagementService)MediaActivator.getBundleContext()
|
||||
.getService(serviceReference);
|
||||
}
|
||||
|
||||
return resourcesService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for getting the images used by the ZRTP GUI plugin
|
||||
*
|
||||
* @param imageID the component's image ID
|
||||
* @return the buffered image
|
||||
*/
|
||||
public static BufferedImage getImage(ImageID imageID)
|
||||
{
|
||||
BufferedImage image = null;
|
||||
|
||||
if (loadedImages.containsKey(imageID))
|
||||
{
|
||||
image = (BufferedImage) loadedImages.get(imageID);
|
||||
}
|
||||
else
|
||||
{
|
||||
URL path = getResources().getImageURL(imageID.getId());
|
||||
|
||||
if (path == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
image = ImageIO.read(path);
|
||||
|
||||
loadedImages.put(imageID, image);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
exc.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the Image Identifier.
|
||||
*/
|
||||
public static class ImageID
|
||||
{
|
||||
private String id;
|
||||
|
||||
private ImageID(String id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,77 @@
|
||||
/**
|
||||
* Copyright (C) 2006-2008 Werner Dittmann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors: Werner Dittmann <Werner.Dittmann@t-online.de>
|
||||
*/
|
||||
|
||||
package net.java.sip.communicator.impl.media.transform.zrtp;
|
||||
|
||||
import net.java.sip.communicator.impl.media.transform.*;
|
||||
|
||||
/**
|
||||
* @author Werner Dittmann <Werner.Dittmann@t-online.de>
|
||||
*
|
||||
*/
|
||||
public class ZRTPCTransformer implements PacketTransformer
|
||||
{
|
||||
/**
|
||||
* ZRTCPTransformer implements PacketTransformer.
|
||||
* It encapsulate the encryption / decryption logic for SRTCP packets
|
||||
*
|
||||
* This class is currently not used.
|
||||
*
|
||||
* @author Bing SU (nova.su@gmail.com)
|
||||
*/
|
||||
//private ZRTPTransformEngine engine;
|
||||
|
||||
/**
|
||||
* Constructs a SRTCPTransformer object
|
||||
*
|
||||
* @param engine The associated ZRTPTransformEngine object
|
||||
*/
|
||||
public ZRTPCTransformer(ZRTPTransformEngine engine)
|
||||
{
|
||||
//this.engine = engine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encrypt a SRTCP packet
|
||||
*
|
||||
* Currently SRTCP packet encryption / decryption is not supported
|
||||
* So this method does not change the packet content
|
||||
*
|
||||
* @param pkt plain SRTCP packet to be encrypted
|
||||
* @return encrypted SRTCP packet
|
||||
*/
|
||||
public RawPacket transform(RawPacket pkt)
|
||||
{
|
||||
return pkt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrypt a SRTCP packet
|
||||
*
|
||||
* Currently SRTCP packet encryption / decryption is not supported
|
||||
* So this method does not change the packet content
|
||||
*
|
||||
* @param pkt encrypted SRTCP packet to be decrypted
|
||||
* @return decrypted SRTCP packet
|
||||
*/
|
||||
public RawPacket reverseTransform(RawPacket pkt)
|
||||
{
|
||||
return pkt;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,206 @@
|
||||
/**
|
||||
* Copyright (C) 2006-2008 Werner Dittmann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors: Werner Dittmann <Werner.Dittmann@t-online.de>
|
||||
*/
|
||||
|
||||
package net.java.sip.communicator.impl.media.transform.zrtp;
|
||||
|
||||
import net.java.sip.communicator.impl.media.transform.*;
|
||||
import gnu.java.zrtp.packets.*;
|
||||
import gnu.java.zrtp.utils.*;
|
||||
|
||||
|
||||
/**
|
||||
* ZRTP packet representation.
|
||||
*
|
||||
* This class extends the RawPacket class and adds some methods
|
||||
* required by the ZRTP transformer.
|
||||
*
|
||||
* @author Werner Dittmann <Werner.Dittmann@t-online.de>
|
||||
*
|
||||
*/
|
||||
public class ZrtpRawPacket extends RawPacket
|
||||
{
|
||||
/**
|
||||
* Each ZRTP packet conatins this magic number.
|
||||
*/
|
||||
public static byte[] zrtpMagic;
|
||||
|
||||
static {
|
||||
zrtpMagic = new byte[4];
|
||||
zrtpMagic[0]= 0x5a;
|
||||
zrtpMagic[1]= 0x52;
|
||||
zrtpMagic[2]= 0x54;
|
||||
zrtpMagic[3]= 0x50;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an input ZrtpRawPacket using a received RTP raw packet.
|
||||
*
|
||||
* @param pkt a raw RTP packet as received
|
||||
*/
|
||||
public ZrtpRawPacket(RawPacket pkt)
|
||||
{
|
||||
super (pkt.getBuffer(), pkt.getOffset(), pkt.getLength());
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an output ZrtpRawPacket using specified value.
|
||||
*
|
||||
* Initialize this packet and set the ZRTP magic value
|
||||
* to mark it as a ZRTP packet.
|
||||
*
|
||||
* @param buf Byte array holding the content of this Packet
|
||||
* @param off Start offset of packet content inside buffer
|
||||
* @param len Length of the packet's data
|
||||
*/
|
||||
public ZrtpRawPacket(byte[] buf, int off, int len)
|
||||
{
|
||||
super (buf, off, len);
|
||||
buffer[offset] = 0x10;
|
||||
buffer[offset+1] = 0;
|
||||
|
||||
int at = 4;
|
||||
buffer[offset + at++] = zrtpMagic[0];
|
||||
buffer[offset + at++] = zrtpMagic[1];
|
||||
buffer[offset + at++] = zrtpMagic[2];
|
||||
buffer[offset + at] = zrtpMagic[3];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if it could be a ZRTP packet.
|
||||
*
|
||||
* The method checks if the first byte of the received data
|
||||
* matches the defined ZRTP pattern 0x10
|
||||
*
|
||||
* @return true if could be a ZRTP packet, false otherwise.
|
||||
*/
|
||||
protected boolean isZrtpPacket()
|
||||
{
|
||||
if ((buffer[offset] & 0x10) == 0x10)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if it is really a ZRTP packet.
|
||||
*
|
||||
* The method checks if the packet contains the ZRTP magic
|
||||
* number.
|
||||
*
|
||||
* @return true if packet contains the magic number, false otherwise.
|
||||
*/
|
||||
protected boolean hasMagic()
|
||||
{
|
||||
if (buffer[offset + 4] == zrtpMagic[0]
|
||||
&& buffer[offset + 5] == zrtpMagic[1]
|
||||
&& buffer[offset + 6] == zrtpMagic[2]
|
||||
&& buffer[offset + 7] == zrtpMagic[3])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the sequence number in this packet.
|
||||
* @param seq
|
||||
*/
|
||||
protected void setSeqNum(short seq)
|
||||
{
|
||||
int at = 2;
|
||||
buffer[offset + at++] = (byte)(seq>>8);
|
||||
buffer[offset + at] = (byte)seq;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set SSRC in this packet
|
||||
* @param ssrc
|
||||
*/
|
||||
protected void setSSRC(int ssrc)
|
||||
{
|
||||
setIntegerAt(ssrc, 8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the SSRC data from packet.
|
||||
*
|
||||
* @return SSRC data
|
||||
*/
|
||||
protected int getSSRC()
|
||||
{
|
||||
return (int)(readUnsignedIntAsLong(8) & 0xffffffff);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the CRC of this packet is ok.
|
||||
* @param crc
|
||||
* @return
|
||||
*/
|
||||
protected boolean checkCrc()
|
||||
{
|
||||
int crc = readInt(length-ZrtpPacketBase.CRC_SIZE);
|
||||
return ZrtpCrc32.zrtpCheckCksum(buffer, offset, length-ZrtpPacketBase.CRC_SIZE, crc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set ZRTP CRC in this packet
|
||||
* @param crc
|
||||
*/
|
||||
protected void setCrc()
|
||||
{
|
||||
int crc = ZrtpCrc32.zrtpGenerateCksum(buffer, offset,length-ZrtpPacketBase.CRC_SIZE);
|
||||
// convert and store CRC in crc field of ZRTP packet.
|
||||
crc = ZrtpCrc32.zrtpEndCksum(crc);
|
||||
setIntegerAt(crc, length - ZrtpPacketBase.CRC_SIZE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ZRTP message part from the ZRTP packet.
|
||||
*
|
||||
* @return The ZRTP message part.
|
||||
*/
|
||||
protected byte[] getMessagePart()
|
||||
{
|
||||
return readRegion(ZRTPTransformEngine.ZRTP_PACKET_HEADER, length-ZRTPTransformEngine.ZRTP_PACKET_HEADER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an integer at specified offset in network order.
|
||||
*
|
||||
* @param data The integer to store in the packet
|
||||
* @param at Offset into the buffer
|
||||
*/
|
||||
private void setIntegerAt(int data, int at)
|
||||
{
|
||||
buffer[offset + at++] = (byte)(data>>24);
|
||||
buffer[offset + at++] = (byte)(data>>16);
|
||||
buffer[offset + at++] = (byte)(data>>8);
|
||||
buffer[offset + at] = (byte)data;
|
||||
}
|
||||
|
||||
public static void main(String argv[])
|
||||
{
|
||||
byte[] buf = new byte[30];
|
||||
ZrtpRawPacket pkt = new ZrtpRawPacket(buf, 0, buf.length);
|
||||
ZrtpUtils.hexdump("zrtp raw", pkt.buffer, pkt.length);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Copyright (C) 2006-2008 Werner Dittmann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors: Werner Dittmann <Werner.Dittmann@t-online.de>
|
||||
*/
|
||||
|
||||
package net.java.sip.communicator.impl.media.transform.zrtp;
|
||||
|
||||
import net.java.sip.communicator.impl.media.transform.*;
|
||||
|
||||
import javax.media.rtp.InvalidSessionAddressException;
|
||||
import javax.media.rtp.SessionAddress;
|
||||
|
||||
|
||||
/**
|
||||
* ZRTP specific Transform Connector.
|
||||
*
|
||||
* This class just adds ZRTP specific functions.
|
||||
*
|
||||
* @author Werner Dittmann <Werner.Dittmann@t-online.de>
|
||||
*
|
||||
*/
|
||||
public class ZrtpTransformConnector extends TransformConnector
|
||||
{
|
||||
|
||||
public ZrtpTransformConnector(SessionAddress localAddr,
|
||||
TransformEngine engine)
|
||||
throws InvalidSessionAddressException
|
||||
{
|
||||
super(localAddr, engine);
|
||||
}
|
||||
|
||||
public ZRTPTransformEngine getEngine()
|
||||
{
|
||||
if (!(engine instanceof ZRTPTransformEngine))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return (ZRTPTransformEngine) engine;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue