mirror of https://github.com/sipwise/jitsi.git
Introduce the new ZRTP configure feature that enables users to select which algorithms ZRTP shall use.
parent
9e17612c9c
commit
2394d225d6
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
@ -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…
Reference in new issue