Introduce the new ZRTP configure feature that enables users to select which algorithms ZRTP shall use.

cusax-fix
Werner Dittmann 16 years ago
parent 9e17612c9c
commit 2394d225d6

@ -821,7 +821,7 @@
bundle-argdelegation,bundle-zrtp4j,
bundle-filehistory,bundle-metahistory,bundle-metahistory-slick,
bundle-facebook,bundle-plugin-facebookaccregwizz,
bundle-bouncycastle,bundle-plugin-otr"/>
bundle-bouncycastle,bundle-plugin-otr,bundle-plugin-zrtpconfigure"/>
<!--BUNDLE-SC-LAUNCHER-->
<target name="bundle-sc-launcher">
@ -2199,4 +2199,13 @@ org.apache.http.util"/>
prefix="net/java/sip/communicator/slick/metahistory"/>
</jar>
</target>
<target name="bundle-plugin-zrtpconfigure">
<jar compress="false" destfile="${bundles.dest}/zrtpconfigure.jar"
manifest="${src}/net/java/sip/communicator/plugin/zrtpconfigure/zrtp.manifest.mf">
<zipfileset dir="${dest}/net/java/sip/communicator/plugin/zrtpconfigure"
prefix="net/java/sip/communicator/plugin/zrtpconfigure"/>
</jar>
</target>
</project>

@ -167,7 +167,8 @@ felix.auto.start.67= \
reference:file:sc-bundles/generalconfig.jar \
reference:file:sc-bundles/dictaccregwizz.jar \
reference:file:sc-bundles/otr.jar \
reference:file:sc-bundles/facebookaccregwizz.jar
reference:file:sc-bundles/facebookaccregwizz.jar \
reference:file:sc-bundles/zrtpconfigure.jar
#level 68 is for profiler, don't use it or change the build.xml file accordingly

@ -424,6 +424,9 @@ plugin.notificationconfig.ACTIVATED_ICON=resources/images/plugin/notificationcon
plugin.notificationconfig.DEACTIVATED_ICON=resources/images/plugin/notificationconfiguration/desactivatedIcon.png
plugin.notificationconfig.FOLDER_ICON=resources/images/plugin/notificationconfiguration/folder.png
# ZRTP configuration form
impl.media.security.zrtp.CONF_ICON=resources/images/impl/media/zrtpConfig.png
# media configuration form
plugin.mediaconfig.PLUGIN_ICON=resources/images/impl/media/media.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

@ -799,23 +799,18 @@ impl.media.security.RETRY_RATE_EXCEEDED=<html>Too much retries during security n
impl.media.security.DATA_SEND_FAILED=<html>Failed to send encryption data. Internet data connection or peer is down.<br/><b>Your call is not secure</b><br/>Error code: {0}</html>
impl.media.security.SECURITY_OFF=Call encryption support off
impl.media.security.SECURITY_ON=Call encryption support on
#impl.media.security.ENGINE_INIT_FAILURE=Securing engine initialization failure
#impl.media.security.ALLOW_CLEAR_REQUEST_FAILURE=Peer doesn't support unsecuring the call
#impl.media.security.DEFAULT_TOOLTIP=Secure status field
#impl.media.security.DEFAULT_MESSAGE=Not in call
#impl.media.security.SECURED_TOOLTIP=Check this string by voice with your peer to verify secure comm link
#impl.media.security.SECURED_MESSAGE=Secured:
#impl.media.security.NOT_SECURED_TOOLTIP=Secure mode not enabled
#impl.media.security.NOT_SECURED_MESSAGE=Not secured
#impl.media.security.ENGINE_FAIL_TOOLTIP=Engine failed at initialization
#impl.media.security.ENGINE_FAIL_MESSAGE=Engine failure
#impl.media.security.SECURING_FAIL_TOOLTIP=Securing call failed
#impl.media.security.UNSECURED_AT_REQUEST=Call unsecured at request
#impl.media.security.PEER_UNSUPPORTED_SECURITY=<html>You have enabled secure init mode<br/>You can't switch off this mode at this moment<br/>The call is not secured yet anyway</html>
#impl.media.security.PEER_UNSUPPORTED_TOOLTIP=Securing call not supported/enabled by the other peer
#impl.media.security.PEER_TOGGLED_OFF_SECURITY_MESSAGE=Call peer toggled secure mode off
#impl.media.security.PEER_TOGGLED_OFF_SECURITY_SECTION=Secure Off
#impl.media.security.UNSECURED_AT_PEER_REQUEST_TOOLTIP=Call unsecured at peer request
# ZRTP Configuration
impl.media.security.zrtp.TITLE=ZRTP
impl.media.security.zrtp.PUB_KEYS=Public key algorithms
impl.media.security.zrtp.HASHES=Hash algorithms
impl.media.security.zrtp.SYM_CIPHERS=Symmetric cipher algorithms
impl.media.security.zrtp.SAS_TYPES=SAS types
impl.media.security.zrtp.SRTP_LENGTHS=SRTP authentication length
impl.media.security.zrtp.STANDARD=Standard
impl.media.security.zrtp.MANDATORY=Mandatory
impl.media.security.zrtp.TRUSTED=Trusted MitM
impl.media.security.zrtp.SASSIGNATURE=SAS signature processing
# Profiler4J
plugin.profiler.PLUGIN_NAME=Profiler4j

@ -27,6 +27,7 @@
import net.java.sip.communicator.impl.media.keyshare.*;
import net.java.sip.communicator.impl.media.transform.*;
import net.java.sip.communicator.impl.media.transform.zrtp.*;
import net.java.sip.communicator.plugin.zrtpconfigure.ZrtpConfigureUtils;
import net.java.sip.communicator.service.media.*;
import net.java.sip.communicator.service.media.MediaException;
import net.java.sip.communicator.service.media.event.*;
@ -2374,7 +2375,8 @@ else if (rtpManager.equals(videoRtpManager))
// the account registration wizard
if (this.getCall().isDefaultEncrypted())
{
if (engine.initialize("GNUZRTP4J.zid", zrtpAutoStart))
ZrtpConfigure config = ZrtpConfigureUtils.getZrtpConfiguration();
if (engine.initialize("GNUZRTP4J.zid", zrtpAutoStart, config))
{
usingZRTP = true;
engine.sendInfo(

@ -28,6 +28,7 @@ Import-Package: org.osgi.framework,
net.java.sip.communicator.service.resources,
net.java.sip.communicator.util,
net.java.sip.communicator.util.swing,
net.java.sip.communicator.plugin.zrtpconfigure,
quicktime,
quicktime.std.sg,
quicktime.qd,

@ -0,0 +1,153 @@
/*
* 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.plugin.zrtpconfigure;
import net.java.sip.communicator.service.configuration.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.resources.ResourceManagementService;
import net.java.sip.communicator.service.resources.ResourceManagementServiceUtils;
import org.osgi.framework.*;
/**
* The <tt>BundleActivator</tt> for ZrtpConfigure.
*
* @author Werner Dittmann
*/
public class ZrtpConfigureActivator
implements BundleActivator
{
public static BundleContext bundleContext;
/**
* The {@link ResourceManagementService} of the {@link ZrtpConfigureActivator}.
*/
public static ResourceManagementService resourceService;
/**
* The {@link UIService} of the {@link ZrtpConfigureActivator}.
*/
private static UIService uiService;
/**
* The {@link ConfigurationService} of the {@link ZrtpConfigureActivator}.
*/
protected static ConfigurationService configService;
/**
* Starts this bundle and adds the <td>ZrtpConfigurePanel</tt>.
*/
public void start(BundleContext bc) throws Exception
{
bundleContext = bc;
bundleContext
.registerService(
ConfigurationForm.class.getName(),
new LazyConfigurationForm(
"net.java.sip.communicator.plugin.zrtpconfigure.ZrtpConfigurePanel",
getClass().getClassLoader(),
"impl.media.security.zrtp.CONF_ICON",
"impl.media.security.zrtp.TITLE",
1100),
null);
resourceService =
ResourceManagementServiceUtils
.getService(bundleContext);
if (resourceService == null)
return;
ServiceReference refConfigService =
bundleContext
.getServiceReference(ConfigurationService.class.getName());
if (refConfigService == null)
return;
configService =
(ConfigurationService)bundleContext
.getService(refConfigService);
}
/**
* Stops this bundles.
*/
public void stop(BundleContext arg0) throws Exception
{
resourceService = null;
configService = null;
uiService = null;
}
/**
* Returns the <tt>UIService</tt> obtained from the bundle context.
*
* @return the <tt>UIService</tt> obtained from the bundle context
*/
public static UIService getUIService()
{
if (uiService == null)
{
ServiceReference uiReference =
bundleContext.getServiceReference(UIService.class.getName());
uiService =
(UIService) bundleContext
.getService(uiReference);
}
return uiService;
}
/**
* Returns the <tt>ConfigurationService</tt> obtained from the bundle
* context.
*
* @return the <tt>ConfigurationService</tt> obtained from the bundle
* context
*/
public static ConfigurationService getConfigurationService()
{
if (configService == null)
{
ServiceReference configReference =
bundleContext.getServiceReference(ConfigurationService.class
.getName());
configService =
(ConfigurationService) bundleContext
.getService(configReference);
}
return configService;
}
/**
* Determines whether <tt>bundle</tt> is system or not. We consider system
* bundles those that we have explicitly marked as such with the
* <tt>System-Bundle</tt> manifest property or those that belong to the
* Apache framework itself.
*
* @param bundle the bundle that we need to determine as system or not.
* @return true if <tt>bundle</tt> is a system bundle and <tt>false</tt>
* otherwise.
*/
public static boolean isSystemBundle(Bundle bundle)
{
if (bundle.getBundleId() <= 1)
{
//this is one of the felix bundles
return true;
}
Object sysBundleProp = bundle.getHeaders().get("System-Bundle");
//ignore if this is a system bundle
return (sysBundleProp != null && sysBundleProp.equals("yes"));
}
}

@ -0,0 +1,420 @@
/*
* 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.plugin.zrtpconfigure;
import gnu.java.zrtp.ZrtpConfigure;
import gnu.java.zrtp.ZrtpConstants;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.EtchedBorder;
import javax.swing.event.*;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import net.java.sip.communicator.util.swing.*;
/**
*/
@SuppressWarnings("serial")
public class ZrtpConfigurePanel
extends TransparentPanel
{
private static String TRUSTED_PROP = "net.java.sip.communicator.gnu.java.zrtp.trustedmitm";
private static String SASSIGN_PROP = "net.java.sip.communicator.gnu.java.zrtp.sassignature";
private ZrtpConfigure active = new ZrtpConfigure();
private ZrtpConfigure inActive = new ZrtpConfigure();
PublicKeyControls pkc = new PublicKeyControls();
HashControls hc = new HashControls();
CipherControls cc = new CipherControls();
SasControls sc = new SasControls();
LengthControls lc = new LengthControls();
public ZrtpConfigurePanel() {
JPanel mainPanel = new TransparentPanel();
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
JPanel panel = new TransparentPanel();
panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
panel.setLayout(new GridLayout(5, 1));
final JButton stdButton = new JButton(ZrtpConfigureActivator.resourceService
.getI18NString("impl.media.security.zrtp.STANDARD"));
stdButton.setOpaque(false);
final JButton mandButton = new JButton(ZrtpConfigureActivator.resourceService
.getI18NString("impl.media.security.zrtp.MANDATORY"));
mandButton.setOpaque(false);
final JButton saveButton = new JButton(ZrtpConfigureActivator.resourceService
.getI18NString("service.gui.SAVE"));
saveButton.setOpaque(false);
JPanel buttonBar = new TransparentPanel(new GridLayout(1, 7));
buttonBar.add(stdButton);
buttonBar.add(mandButton);
buttonBar.add(Box.createHorizontalStrut(10));
buttonBar.add(saveButton);
mainPanel.add(buttonBar);
mainPanel.add(Box.createVerticalStrut(7));
boolean trusted = ZrtpConfigureActivator.configService.getBoolean(TRUSTED_PROP, false);
boolean sasSign = ZrtpConfigureActivator.configService.getBoolean(SASSIGN_PROP, false);
JPanel checkBar = new JPanel(new GridLayout(1,2));
final JCheckBox trustedMitM = new JCheckBox(ZrtpConfigureActivator.resourceService
.getI18NString("impl.media.security.zrtp.TRUSTED"), trusted);
final JCheckBox sasSignature = new JCheckBox(ZrtpConfigureActivator.resourceService
.getI18NString("impl.media.security.zrtp.SASSIGNATURE"), sasSign);
checkBar.add(trustedMitM);
checkBar.add(sasSignature);
mainPanel.add(checkBar);
mainPanel.add(Box.createVerticalStrut(7));
ActionListener buttonListener = new ActionListener() {
public void actionPerformed(ActionEvent event) {
Object source = event.getSource();
if (source == stdButton) {
inActive.clear();
active.setStandardConfig();
pkc.setStandard();
hc.setStandard();
sc.setStandard();
cc.setStandard();
lc.setStandard();
}
else if (source == mandButton) {
inActive.clear();
active.setMandatoryOnly();
pkc.setStandard();
hc.setStandard();
sc.setStandard();
cc.setStandard();
lc.setStandard();
}
else if (source == saveButton) {
Boolean t = new Boolean(active.isTrustedMitM());
Boolean s = new Boolean(active.isSasSignature());
ZrtpConfigureActivator.configService.setProperty(TRUSTED_PROP, t);
ZrtpConfigureActivator.configService.setProperty(SASSIGN_PROP, s);
pkc.saveConfig();
hc.saveConfig();
sc.saveConfig();
cc.saveConfig();
lc.saveConfig();
}
else
return;
}
};
stdButton.addActionListener(buttonListener);
mandButton.addActionListener(buttonListener);
saveButton.addActionListener(buttonListener);
ItemListener itemListener = new ItemListener() {
public void itemStateChanged(ItemEvent e) {
Object source = e.getItemSelectable();
if (source == trustedMitM) {
active.setTrustedMitM(trustedMitM.isSelected());
} else if (source == sasSignature) {
active.setSasSignature(sasSignature.isSelected());
}
}
};
trustedMitM.addItemListener(itemListener);
sasSignature.addItemListener(itemListener);
panel.add(pkc);
panel.add(hc);
panel.add(cc);
panel.add(sc);
panel.add(lc);
mainPanel.add(panel);
add(mainPanel);
setSize(panel.getPreferredSize());
setVisible(true);
}
private <T extends Enum<T>>String getPropertyValue(T algo) {
StringBuffer strb = new StringBuffer();
for (T it : active.algos(algo)) {
strb.append(it.name());
strb.append(';');
}
return strb.toString();
}
class PublicKeyControls extends JPanel {
private final ZrtpConfigureTableModel<ZrtpConstants.SupportedPubKeys> dataModel;
PublicKeyControls() {
String id = ZrtpConfigureUtils.getPropertyID(ZrtpConstants.SupportedPubKeys.DH2K);
String savedConf = ZrtpConfigureActivator.configService.getString(id);
if (savedConf == null)
savedConf = "";
dataModel = new ZrtpConfigureTableModel<ZrtpConstants.SupportedPubKeys>(
ZrtpConstants.SupportedPubKeys.DH2K, active, inActive, savedConf);
createControls(this, dataModel, ZrtpConfigureActivator.resourceService
.getI18NString("impl.media.security.zrtp.PUB_KEYS"));
}
void setStandard() {
dataModel.setStandardConfig();
}
void saveConfig() {
String value = getPropertyValue(ZrtpConstants.SupportedPubKeys.DH2K);
String id = ZrtpConfigureUtils.getPropertyID(ZrtpConstants.SupportedPubKeys.DH2K);
ZrtpConfigureActivator.configService.setProperty(id, value);
}
}
class HashControls extends JPanel {
private final ZrtpConfigureTableModel<ZrtpConstants.SupportedHashes> dataModel;
HashControls() {
String id = ZrtpConfigureUtils.getPropertyID(ZrtpConstants.SupportedHashes.S256);
String savedConf = ZrtpConfigureActivator.configService.getString(id);
if (savedConf == null)
savedConf = "";
dataModel = new ZrtpConfigureTableModel<ZrtpConstants.SupportedHashes>(
ZrtpConstants.SupportedHashes.S256, active, inActive, savedConf);
createControls(this, dataModel, ZrtpConfigureActivator.resourceService
.getI18NString("impl.media.security.zrtp.HASHES"));
}
void setStandard() {
dataModel.setStandardConfig();
}
void saveConfig() {
String value = getPropertyValue(ZrtpConstants.SupportedHashes.S256);
String id = ZrtpConfigureUtils.getPropertyID(ZrtpConstants.SupportedHashes.S256);
ZrtpConfigureActivator.configService.setProperty(id, value);
}
}
class CipherControls extends JPanel {
private final ZrtpConfigureTableModel<ZrtpConstants.SupportedSymCiphers> dataModel;
CipherControls() {
String id = ZrtpConfigureUtils.getPropertyID(ZrtpConstants.SupportedSymCiphers.AES1);
String savedConf = ZrtpConfigureActivator.configService.getString(id);
if (savedConf == null)
savedConf = "";
dataModel = new ZrtpConfigureTableModel<ZrtpConstants.SupportedSymCiphers>(
ZrtpConstants.SupportedSymCiphers.AES1, active, inActive, savedConf);
createControls(this, dataModel, ZrtpConfigureActivator.resourceService
.getI18NString("impl.media.security.zrtp.SYM_CIPHERS"));
}
void setStandard() {
dataModel.setStandardConfig();
}
void saveConfig() {
String value = getPropertyValue(ZrtpConstants.SupportedSymCiphers.AES1);
String id = ZrtpConfigureUtils.getPropertyID(ZrtpConstants.SupportedSymCiphers.AES1);
ZrtpConfigureActivator.configService.setProperty(id, value);
}
}
class SasControls extends JPanel {
private final ZrtpConfigureTableModel<ZrtpConstants.SupportedSASTypes> dataModel;
SasControls() {
String id = ZrtpConfigureUtils.getPropertyID(ZrtpConstants.SupportedSASTypes.B32);
String savedConf = ZrtpConfigureActivator.configService.getString(id);
if (savedConf == null)
savedConf = "";
dataModel = new ZrtpConfigureTableModel<ZrtpConstants.SupportedSASTypes>(
ZrtpConstants.SupportedSASTypes.B32, active, inActive, savedConf);
createControls(this, dataModel, ZrtpConfigureActivator.resourceService
.getI18NString("impl.media.security.zrtp.SAS_TYPES"));
}
void setStandard() {
dataModel.setStandardConfig();
}
void saveConfig() {
String value = getPropertyValue(ZrtpConstants.SupportedSASTypes.B32);
String id = ZrtpConfigureUtils.getPropertyID(ZrtpConstants.SupportedSASTypes.B32);
ZrtpConfigureActivator.configService.setProperty(id, value);
}
}
class LengthControls extends JPanel {
private final ZrtpConfigureTableModel<ZrtpConstants.SupportedAuthLengths> dataModel;
LengthControls() {
String id = ZrtpConfigureUtils.getPropertyID(ZrtpConstants.SupportedAuthLengths.HS32);
String savedConf = ZrtpConfigureActivator.configService.getString(id);
if (savedConf == null)
savedConf = "";
dataModel = new ZrtpConfigureTableModel<ZrtpConstants.SupportedAuthLengths>(
ZrtpConstants.SupportedAuthLengths.HS32, active, inActive, savedConf);
createControls(this, dataModel, ZrtpConfigureActivator.resourceService
.getI18NString("impl.media.security.zrtp.SRTP_LENGTHS"));
}
void setStandard() {
dataModel.setStandardConfig();
}
void saveConfig() {
String value = getPropertyValue(ZrtpConstants.SupportedAuthLengths.HS32);
String id = ZrtpConfigureUtils.getPropertyID(ZrtpConstants.SupportedAuthLengths.HS32);
ZrtpConfigureActivator.configService.setProperty(id, value);
}
}
private <T extends Enum<T>> void createControls(JPanel panel,
ZrtpConfigureTableModel<T> model, String title) {
final JButton upButton = new JButton(ZrtpConfigureActivator.resourceService
.getI18NString("impl.media.configform.UP"));
upButton.setOpaque(false);
final JButton downButton = new JButton(ZrtpConfigureActivator.resourceService
.getI18NString("impl.media.configform.DOWN"));
downButton.setOpaque(false);
Container buttonBar = new JPanel(new GridLayout(0, 1));
buttonBar.add(upButton);
buttonBar.add(downButton);
panel.setLayout(new GridBagLayout());
panel.setBorder(BorderFactory.createTitledBorder(BorderFactory
.createEtchedBorder(EtchedBorder.LOWERED), title));
final JTable table = new JTable(model.getRowCount(), 2);
table.setShowGrid(false);
table.setTableHeader(null);
table.setModel(model);
table.setPreferredScrollableViewportSize(new Dimension(400, 60));
// table.setFillsViewportHeight(true); // Since 1.6 only - nicer view
/*
* The first column contains the check boxes which enable/disable their
* associated encodings and it doesn't make sense to make it wider than
* the check boxes.
*/
TableColumnModel tableColumnModel = table.getColumnModel();
TableColumn tableColumn = tableColumnModel.getColumn(0);
tableColumn.setMaxWidth(tableColumn.getMinWidth() + 5);
table.doLayout();
GridBagConstraints constraints = new GridBagConstraints();
constraints.anchor = GridBagConstraints.CENTER;
constraints.fill = GridBagConstraints.BOTH;
constraints.gridwidth = 1;
constraints.gridx = 0;
constraints.gridy = 1;
constraints.weightx = 1;
constraints.weighty = 1;
panel.add(new JScrollPane(table), constraints);
constraints.anchor = GridBagConstraints.NORTHEAST;
constraints.fill = GridBagConstraints.NONE;
constraints.gridwidth = 1;
constraints.gridx = 1;
constraints.gridy = 1;
constraints.weightx = 0;
constraints.weighty = 0;
panel.add(buttonBar, constraints);
ListSelectionListener tableSelectionListener = new ListSelectionListener() {
@SuppressWarnings("unchecked")
public void valueChanged(ListSelectionEvent event) {
if (table.getSelectedRowCount() == 1) {
int selectedRow = table.getSelectedRow();
if (selectedRow > -1) {
ZrtpConfigureTableModel<T> model = (ZrtpConfigureTableModel<T>) table
.getModel();
upButton.setEnabled(selectedRow > 0
&& model.checkEnableUp(selectedRow));
downButton.setEnabled(selectedRow < (table
.getRowCount() - 1)
&& model.checkEnableDown(selectedRow));
return;
}
}
upButton.setEnabled(false);
downButton.setEnabled(false);
}
};
table.getSelectionModel().addListSelectionListener(
tableSelectionListener);
TableModelListener tableListener = new TableModelListener() {
@SuppressWarnings("unchecked")
public void tableChanged(TableModelEvent e) {
if (table.getSelectedRowCount() == 1) {
int selectedRow = table.getSelectedRow();
if (selectedRow > -1) {
ZrtpConfigureTableModel<T> model = (ZrtpConfigureTableModel<T>) table
.getModel();
upButton.setEnabled(selectedRow > 0
&& model.checkEnableUp(selectedRow));
downButton.setEnabled(selectedRow < (table
.getRowCount() - 1)
&& model.checkEnableDown(selectedRow));
return;
}
}
upButton.setEnabled(false);
downButton.setEnabled(false);
}
};
table.getModel().addTableModelListener(tableListener);
tableSelectionListener.valueChanged(null);
ActionListener buttonListener = new ActionListener() {
@SuppressWarnings("unchecked")
public void actionPerformed(ActionEvent event) {
Object source = event.getSource();
boolean up;
if (source == upButton)
up = true;
else if (source == downButton)
up = false;
else
return;
int index = ((ZrtpConfigureTableModel<T>) table.getModel())
.move(table.getSelectedRow(), up, up);
table.getSelectionModel().setSelectionInterval(index, index);
}
};
upButton.addActionListener(buttonListener);
downButton.addActionListener(buttonListener);
}
}

@ -0,0 +1,213 @@
package net.java.sip.communicator.plugin.zrtpconfigure;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;
import gnu.java.zrtp.ZrtpConfigure;
import gnu.java.zrtp.ZrtpConstants;
public class ZrtpConfigureTableModel<T extends Enum<T>> extends AbstractTableModel {
private final ZrtpConfigure active;
private final ZrtpConfigure inActive;
// used to identify the Enum class when calling ZrtpConfigure methods.
private final T algorithm;
private final Class<T> clazz;
boolean onOff[];
public ZrtpConfigureTableModel(T algo, ZrtpConfigure act,
ZrtpConfigure inAct, String savedConf) {
active = act;
inActive = inAct;
algorithm = algo;
clazz = algorithm.getDeclaringClass();
initialize(savedConf);
}
private void initialize(String savedConf) {
// Get all enums constants of this Enum to process
T enumValues[] = clazz.getEnumConstants();
// first build a list of all available algorithms of this type
ArrayList<String> fullList = new ArrayList<String>(enumValues.length);
for (T sh : enumValues) {
fullList.add(sh.name());
}
String savedAlgos[] = savedConf.split(";");
// Configure saved algorithms as active, remove them from full list of
// algos
for (String str : savedAlgos) {
try {
T algoEnum = Enum.valueOf(clazz, str);
if (algoEnum != null) {
active.addAlgo(algoEnum);
fullList.remove(str);
}
} catch (IllegalArgumentException e) {
continue;
}
}
// rest of algorithms are inactive
for (String str : fullList) {
T algoEnum = Enum.valueOf(clazz, str);
if (algoEnum != null) {
inActive.addAlgo(algoEnum);
}
}
}
public int getColumnCount() {
return 2;
}
public int getRowCount() {
return active.getNumConfiguredAlgos(algorithm) + inActive.getNumConfiguredAlgos(algorithm);
}
public Object getValueAt(int row, int col) {
switch (col)
{
case 0:
if (row >= active.getNumConfiguredAlgos(algorithm)) {
return (new Boolean(false));
}
return (new Boolean(true));
case 1:
if (row >= active.getNumConfiguredAlgos(algorithm)) {
row -= active.getNumConfiguredAlgos(algorithm);
return (inActive.getAlgoAt(row, algorithm).name());
}
else
return (active.getAlgoAt(row, algorithm).name());
default:
return null;
}
}
public boolean isCellEditable(int rowIndex, int columnIndex)
{
return (columnIndex == 0);
}
public Class<?> getColumnClass(int columnIndex)
{
return (columnIndex == 0) ? Boolean.class : super
.getColumnClass(columnIndex);
}
public void setValueAt(Object value, int row, int column)
{
if ((column == 0) && (value instanceof Boolean))
{
if (row >= active.getNumConfiguredAlgos(algorithm)) {
row -= active.getNumConfiguredAlgos(algorithm);
active.addAlgo(inActive.getAlgoAt(row, algorithm));
inActive.removeAlgo(inActive.getAlgoAt(row, algorithm));
}
else {
inActive.addAlgo(active.getAlgoAt(row, algorithm));
active.removeAlgo(active.getAlgoAt(row, algorithm));
}
fireTableRowsUpdated(0, getRowCount());
}
}
/**
* Move a Configuration entry up or down one position.
*
* The "move up" is Converted to a "move down" with modified row index
* and flags.
*
* @param row
* Which row to move
* @param up
* If true move up, else move down
* @param upSave
* Because the functions converts a move up into a move down
* this flag shows what the caller intented. Needed to adjust
* an index return value.
* @return
*/
public int move(int row, boolean up, boolean upSave) {
if (up) {
if (row <= 0)
throw new IllegalArgumentException("rowIndex");
return move(row - 1, false, upSave) - 1;
}
T swap;
if (row >= (getRowCount() - 1))
throw new IllegalArgumentException("rowIndex");
// Can't move down last last entry of active list.
// if (row == active.getNumConfiguredPubKeys() - 1) {
// // this was a "move up" of the first inActive member adjust index
// return upSave ? row + 2 : row;
// }
// if (row >= active.getNumConfiguredPubKeys()) {
// if (inActive.getNumConfiguredPubKeys() <= 1) {
// return row + 2;
// }
// row -= active.getNumConfiguredPubKeys();
// swap = inActive.getPubKeyAlgoAt(row);
// inActive.removePubKeyAlgo(swap);
// inActive.addPubKeyAlgoAt(row + 1, swap);
// row++; // take active rows into account
// }
// else {
if (active.getNumConfiguredAlgos(algorithm) <= 1) {
return row;
}
swap = active.getAlgoAt(row, algorithm);
active.removeAlgo(swap);
active.addAlgoAt(row + 1, swap);
// }
fireTableRowsUpdated(0, getRowCount());
return row + 1;
}
public boolean checkEnableUp(int row) {
return (row < active.getNumConfiguredAlgos(algorithm));
}
public boolean checkEnableDown(int row) {
return (row < active.getNumConfiguredAlgos(algorithm) - 1);
}
/**
* Saves the ZrtpConfigure data for this algorithm to configure file
*/
public void saveConfig() {
StringBuffer algoStr = new StringBuffer();
for (T sh: active.algos(algorithm)) {
algoStr.append(sh.name());
algoStr.append(';');
}
// save in configuration data using the appropriate key
}
/**
* Sets the ZrtpConfigure data for this algorithm to a predefined set.
*
* The caller prepared active ZrtpConfigureto contain a standard set of
* algorithms. Get the names and construct a string, then call initialize
* to setup the inActive ZrtpConfigure data.
*/
public void setStandardConfig() {
StringBuffer algoStr = new StringBuffer();
for (T sh: active.algos(algorithm)) {
algoStr.append(sh.name());
algoStr.append(';');
}
initialize(algoStr.toString());
fireTableRowsUpdated(0, getRowCount());
}
}

@ -0,0 +1,46 @@
package net.java.sip.communicator.plugin.zrtpconfigure;
import gnu.java.zrtp.ZrtpConfigure;
import gnu.java.zrtp.ZrtpConstants;
public class ZrtpConfigureUtils {
public static <T extends Enum<T>>String getPropertyID(T algo) {
Class<T> clazz = algo.getDeclaringClass();
return "net.java.sip.communicator." + clazz.getName().replace('$', '_');
}
public static ZrtpConfigure getZrtpConfiguration() {
ZrtpConfigure active = new ZrtpConfigure();
setupConfigure(ZrtpConstants.SupportedPubKeys.DH2K, active);
setupConfigure(ZrtpConstants.SupportedHashes.S256, active);
setupConfigure(ZrtpConstants.SupportedSymCiphers.AES1, active);
setupConfigure(ZrtpConstants.SupportedSASTypes.B32, active);
setupConfigure(ZrtpConstants.SupportedAuthLengths.HS32, active);
return active;
}
private static <T extends Enum<T>> void setupConfigure(T algo, ZrtpConfigure active) {
String id = ZrtpConfigureUtils.getPropertyID(algo);
String savedConf = ZrtpConfigureActivator.configService.getString(id);
if (savedConf == null)
savedConf = "";
Class <T> clazz = algo.getDeclaringClass();
String savedAlgos[] = savedConf.split(";");
// Configure saved algorithms as active
for (String str : savedAlgos) {
try {
T algoEnum = Enum.valueOf(clazz, str);
if (algoEnum != null) {
active.addAlgo(algoEnum);
}
} catch (IllegalArgumentException e) {
continue;
}
}
}
}

@ -0,0 +1,29 @@
Bundle-Activator: net.java.sip.communicator.plugin.zrtpconfigure.ZrtpConfigureActivator
Bundle-Name: ZRTP configuration plugin
Bundle-Description: Provides ZRTP configuration functions.
Bundle-Vendor: sip-communicator.org
Bundle-Version: 0.0.1
System-Bundle: yes
Import-Package: org.osgi.framework,
net.java.sip.communicator.service.configuration,
net.java.sip.communicator.service.gui,
net.java.sip.communicator.service.gui.event,
net.java.sip.communicator.service.resources,
net.java.sip.communicator.util,
net.java.sip.communicator.util.swing,
javax.swing,
javax.swing.event,
javax.swing.table,
javax.swing.text,
javax.swing.text.html,
javax.accessibility,
javax.swing.plaf,
javax.swing.plaf.metal,
javax.swing.plaf.basic,
javax.imageio,
javax.swing.filechooser,
javax.swing.tree,
javax.swing.undo,
javax.swing.border,
gnu.java.zrtp
Export-Package: net.java.sip.communicator.plugin.zrtpconfigure
Loading…
Cancel
Save