Added license headers and fixed coding convension issues (usage of spaces instead of tabs in two cases and max chars per line in some cases) to otr specific files

cusax-fix
George Politis 17 years ago
parent 8c358cb8f1
commit 9a79088847

@ -1,15 +1,25 @@
/*
* 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.otr;
import java.util.*;
import net.java.sip.communicator.service.configuration.ConfigurationService;
import net.java.sip.communicator.service.configuration.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.resources.ResourceManagementService;
import net.java.sip.communicator.service.resources.*;
import net.java.sip.communicator.util.*;
import org.osgi.framework.*;
/**
*
* @author George Politis
*
*/
public class OtrActivator
implements BundleActivator, ServiceListener
{

@ -1,3 +1,8 @@
/*
* 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.otr;
import java.awt.*;
@ -7,6 +12,11 @@
import net.java.sip.communicator.service.protocol.*;
/**
*
* @author George Politis
*
*/
@SuppressWarnings("serial")
public class OtrBuddyAuthenticationDialog
extends JDialog

@ -1,28 +1,31 @@
/*
* 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.otr;
import java.awt.*;
import java.awt.event.*;
import java.util.Iterator;
import java.util.Vector;
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.AbstractTableModel;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import net.java.otr4j.OtrPolicy;
import net.java.sip.communicator.service.contactlist.MetaContact;
import net.java.sip.communicator.service.contactlist.MetaContactListService;
import net.java.sip.communicator.service.protocol.AccountID;
import net.java.sip.communicator.service.protocol.Contact;
import net.java.sip.communicator.service.protocol.ProtocolProviderFactory;
import net.java.sip.communicator.service.protocol.ProtocolProviderService;
import javax.swing.event.*;
import javax.swing.table.*;
import org.osgi.framework.*;
import net.java.otr4j.*;
import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.util.swing.*;
/**
*
* @author George Politis
*
*/
@SuppressWarnings("serial")
public class OtrConfigurationPanel
extends TransparentPanel
@ -309,8 +312,6 @@ private void initComponents()
.getI18NString("plugin.otr.configform.KNOWN_FINGERPRINTS")));
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
contactsTable = new JTable();
contactsTable.setModel(new ContactsTableModel());
contactsTable
@ -330,10 +331,9 @@ public void valueChanged(ListSelectionEvent e)
}
});
JScrollPane pnlContacts = new JScrollPane(contactsTable);
this.add(pnlContacts);
JPanel pnlButtons = new TransparentPanel();
this.add(pnlButtons);
@ -489,7 +489,8 @@ private void initComponents()
this.add(pnlPolicy, c);
JPanel pnlFingerprints = new KnownFingerprintsPanel();
pnlFingerprints.setMinimumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
pnlFingerprints.setMinimumSize(new Dimension(Short.MAX_VALUE,
Short.MAX_VALUE));
c.weighty = 1.0;
c.gridy = 2;
this.add(pnlFingerprints, c);

@ -1,17 +1,24 @@
/*
* 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.otr;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.*;
import net.java.otr4j.OtrPolicy;
import net.java.otr4j.session.SessionStatus;
import net.java.sip.communicator.service.protocol.Contact;
import net.java.otr4j.*;
import net.java.otr4j.session.*;
import net.java.sip.communicator.service.protocol.*;
/**
*
* @author George Politis
*
*/
@SuppressWarnings("serial")
class OtrContactMenu
extends JMenu

@ -1,3 +1,8 @@
/*
* 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.otr;
import java.awt.*;
@ -6,7 +11,7 @@
import javax.imageio.*;
import net.java.otr4j.OtrPolicy;
import net.java.otr4j.*;
import net.java.otr4j.session.*;
import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.service.gui.Container;
@ -14,6 +19,11 @@
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.util.swing.*;
/**
*
* @author George Politis
*
*/
@SuppressWarnings("serial")
public class OtrMetaContactButton
extends SIPCommButton
@ -54,7 +64,8 @@ public void contactPolicyChanged(Contact contact)
public void globalPolicyChanged()
{
if (OtrMetaContactButton.this.contact != null)
setPolicy(OtrActivator.scOtrEngine.getContactPolicy(contact));
setPolicy(OtrActivator.scOtrEngine
.getContactPolicy(contact));
}
});

@ -1,8 +1,13 @@
/*
* 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.otr;
import java.awt.Component; /* Explicit import required */
import java.awt.event.*;
import java.util.Iterator;
import java.util.*;
import javax.swing.*;
@ -10,6 +15,11 @@
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.protocol.*;
/**
*
* @author George Politis
*
*/
@SuppressWarnings("serial")
public class OtrMetaContactMenu
extends JMenu

@ -1,8 +1,18 @@
/*
* 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.otr;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
/**
*
* @author George Politis
*
*/
public class OtrTransformLayer
implements TransformLayer
{

@ -1,10 +1,19 @@
/*
* 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.otr;
import net.java.otr4j.OtrPolicy;
import net.java.otr4j.session.SessionStatus;
import net.java.sip.communicator.service.protocol.AccountID;
import net.java.sip.communicator.service.protocol.Contact;
import net.java.otr4j.*;
import net.java.otr4j.session.*;
import net.java.sip.communicator.service.protocol.*;
/**
*
* @author George Politis
*
*/
public interface ScOtrEngine
{
// Proxy methods OtrEngine.

@ -1,37 +1,29 @@
/*
* 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.otr;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.*;
import java.security.spec.*;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import org.bouncycastle.util.encoders.Base64;
import org.osgi.framework.ServiceReference;
import net.java.otr4j.OtrEngine;
import net.java.otr4j.OtrEngineImpl;
import net.java.otr4j.OtrEngineHost;
import net.java.otr4j.OtrKeyManager;
import net.java.otr4j.OtrPolicy;
import net.java.otr4j.OtrPolicyImpl;
import net.java.otr4j.crypto.OtrCryptoEngineImpl;
import net.java.otr4j.crypto.OtrCryptoException;
import net.java.otr4j.session.SessionID;
import net.java.otr4j.session.SessionStatus;
import net.java.sip.communicator.service.browserlauncher.BrowserLauncherService;
import net.java.sip.communicator.service.gui.PopupDialog;
import net.java.sip.communicator.service.protocol.AccountID;
import net.java.sip.communicator.service.protocol.Contact;
import net.java.sip.communicator.service.protocol.Message;
import net.java.sip.communicator.service.protocol.OperationSetBasicInstantMessaging;
import java.util.*;
import org.bouncycastle.util.encoders.*;
import org.osgi.framework.*;
import net.java.otr4j.*;
import net.java.otr4j.crypto.*;
import net.java.otr4j.session.*;
import net.java.sip.communicator.service.browserlauncher.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.protocol.*;
/**
*
* @author George Politis
*
*/
public class ScOtrEngineImpl
implements ScOtrEngine
{
@ -136,7 +128,8 @@ public void sessionStatusChanged(SessionID sessionID)
public boolean isContactVerified(Contact contact)
{
return this.configurator.getPropertyBoolean(getSessionID(contact) + "publicKey.verified", false);
return this.configurator.getPropertyBoolean(getSessionID(contact)
+ "publicKey.verified", false);
}
Map<SessionID, Contact> contactsMap = new Hashtable<SessionID, Contact>();
@ -219,72 +212,88 @@ public String getLocalFingerprint(AccountID account)
}
private Configurator configurator = new Configurator();
class Configurator {
private String getXmlFriendlyString(String s){
if (s == null || s.length() < 1)
return s;
// XML Tags are not allowed to start with digits,
// insert a dummy "p" char.
if (Character.isDigit(s.charAt(0)))
s = "p" + s;
char[] cId = new char[s.length()];
for (int i = 0; i < cId.length; i++) {
char c = s.charAt(i);
cId[i] = (Character.isLetterOrDigit(c)) ? c : '_';
}
return new String(cId);
}
private String getID(String id){
return "net.java.sip.communicator.plugin.otr." + getXmlFriendlyString(id);
}
public byte[] getPropertyBytes(String id){
String value = (String)OtrActivator.configService.getProperty(this.getID(id));
if (value == null)
return null;
return Base64.decode(value.getBytes());
}
public Boolean getPropertyBoolean(String id, boolean defaultValue){
return OtrActivator.configService.getBoolean(this.getID(id), defaultValue);
}
public void setProperty(String id, byte[] value){
String valueToStore = new String(Base64.encode(value));
OtrActivator.configService.setProperty(this.getID(id), valueToStore);
}
public void setProperty(String id, boolean value){
OtrActivator.configService.setProperty(this.getID(id), value);
}
public void setProperty(String id, Integer value){
OtrActivator.configService.setProperty(this.getID(id), value);
}
public void removeProperty(String id){
OtrActivator.configService.removeProperty(this.getID(id));
}
public int getPropertyInt(String id, int defaultValue) {
return OtrActivator.configService.getInt(getID(id), defaultValue);
}
class Configurator
{
private String getXmlFriendlyString(String s)
{
if (s == null || s.length() < 1)
return s;
// XML Tags are not allowed to start with digits,
// insert a dummy "p" char.
if (Character.isDigit(s.charAt(0)))
s = "p" + s;
char[] cId = new char[s.length()];
for (int i = 0; i < cId.length; i++)
{
char c = s.charAt(i);
cId[i] = (Character.isLetterOrDigit(c)) ? c : '_';
}
return new String(cId);
}
private String getID(String id)
{
return "net.java.sip.communicator.plugin.otr."
+ getXmlFriendlyString(id);
}
public byte[] getPropertyBytes(String id)
{
String value =
(String) OtrActivator.configService.getProperty(this.getID(id));
if (value == null)
return null;
return Base64.decode(value.getBytes());
}
public Boolean getPropertyBoolean(String id, boolean defaultValue)
{
return OtrActivator.configService.getBoolean(this.getID(id),
defaultValue);
}
public void setProperty(String id, byte[] value)
{
String valueToStore = new String(Base64.encode(value));
OtrActivator.configService
.setProperty(this.getID(id), valueToStore);
}
public void setProperty(String id, boolean value)
{
OtrActivator.configService.setProperty(this.getID(id), value);
}
public void setProperty(String id, Integer value)
{
OtrActivator.configService.setProperty(this.getID(id), value);
}
public void removeProperty(String id)
{
OtrActivator.configService.removeProperty(this.getID(id));
}
public int getPropertyInt(String id, int defaultValue)
{
return OtrActivator.configService.getInt(getID(id), defaultValue);
}
}
public void verifyContactFingerprint(Contact contact)
{
if (contact == null)
return;
this.configurator.setProperty(getSessionID(contact) + "publicKey.verified", true);
this.configurator.setProperty(getSessionID(contact)
+ "publicKey.verified", true);
}
public void forgetContactFingerprint(Contact contact)
@ -292,14 +301,15 @@ public void forgetContactFingerprint(Contact contact)
if (contact == null)
return;
this.configurator.removeProperty(getSessionID(contact) + "publicKey.verified");
this.configurator.removeProperty(getSessionID(contact)
+ "publicKey.verified");
}
public OtrPolicy getGlobalPolicy()
{
return new OtrPolicyImpl(this.configurator
.getPropertyInt("POLICY", OtrPolicy.OTRL_POLICY_DEFAULT));
return new OtrPolicyImpl(this.configurator.getPropertyInt("POLICY",
OtrPolicy.OTRL_POLICY_DEFAULT));
}
public void setGlobalPolicy(OtrPolicy policy)
@ -315,22 +325,25 @@ public void setGlobalPolicy(OtrPolicy policy)
public void launchHelp()
{
ServiceReference ref = OtrActivator.bundleContext
.getServiceReference(BrowserLauncherService.class.getName());
if (ref == null)
return;
BrowserLauncherService service = (BrowserLauncherService)
OtrActivator.bundleContext.getService(ref);
service.openURL(OtrActivator.resourceService
.getI18NString("plugin.otr.authbuddydialog.HELP_URI"));
ServiceReference ref =
OtrActivator.bundleContext
.getServiceReference(BrowserLauncherService.class.getName());
if (ref == null)
return;
BrowserLauncherService service =
(BrowserLauncherService) OtrActivator.bundleContext.getService(ref);
service.openURL(OtrActivator.resourceService
.getI18NString("plugin.otr.authbuddydialog.HELP_URI"));
}
public OtrPolicy getContactPolicy(Contact contact)
{
int policy = this.configurator.getPropertyInt(getSessionID(contact) + "policy", -1);
int policy =
this.configurator.getPropertyInt(getSessionID(contact) + "policy",
-1);
if (policy < 0)
return getGlobalPolicy();
else
@ -339,11 +352,11 @@ public OtrPolicy getContactPolicy(Contact contact)
public void setContactPolicy(Contact contact, OtrPolicy policy)
{
String propertyID = getSessionID(contact) + "policy";
String propertyID = getSessionID(contact) + "policy";
if (policy == null)
this.configurator.removeProperty(propertyID);
this.configurator.removeProperty(propertyID);
else
this.configurator.setProperty(propertyID, policy.getPolicy());
this.configurator.setProperty(propertyID, policy.getPolicy());
for (ScOtrEngineListener l : listeners)
l.contactPolicyChanged(contact);
@ -353,14 +366,17 @@ public void setContactPolicy(Contact contact, OtrPolicy policy)
private KeyPair loadKeyPair(String accountID)
{
// Load Private Key.
byte[] b64PrivKey = this.configurator.getPropertyBytes(accountID + ".privateKey");
byte[] b64PrivKey =
this.configurator.getPropertyBytes(accountID + ".privateKey");
if (b64PrivKey == null)
return null;
PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(b64PrivKey);
PKCS8EncodedKeySpec privateKeySpec =
new PKCS8EncodedKeySpec(b64PrivKey);
// Load Public Key.
byte[] b64PubKey = this.configurator.getPropertyBytes(accountID + ".publicKey");
byte[] b64PubKey =
this.configurator.getPropertyBytes(accountID + ".publicKey");
if (b64PubKey == null)
return null;
@ -408,15 +424,17 @@ public void generateKeyPair(String accountID)
PublicKey pubKey = keyPair.getPublic();
X509EncodedKeySpec x509EncodedKeySpec =
new X509EncodedKeySpec(pubKey.getEncoded());
this.configurator.setProperty(accountID + ".publicKey", x509EncodedKeySpec.getEncoded());
this.configurator.setProperty(accountID + ".publicKey",
x509EncodedKeySpec.getEncoded());
// Store Private Key.
PrivateKey privKey = keyPair.getPrivate();
PKCS8EncodedKeySpec pkcs8EncodedKeySpec =
new PKCS8EncodedKeySpec(privKey.getEncoded());
this.configurator.setProperty(accountID + ".privateKey", pkcs8EncodedKeySpec.getEncoded());
this.configurator.setProperty(accountID + ".privateKey",
pkcs8EncodedKeySpec.getEncoded());
}
private void savePublicKey(String userID, PublicKey pubKey)
@ -424,14 +442,16 @@ private void savePublicKey(String userID, PublicKey pubKey)
X509EncodedKeySpec x509EncodedKeySpec =
new X509EncodedKeySpec(pubKey.getEncoded());
this.configurator.setProperty(userID + ".publicKey", x509EncodedKeySpec.getEncoded());
this.configurator.setProperty(userID + ".publicKey", x509EncodedKeySpec
.getEncoded());
this.configurator.removeProperty(userID + ".publicKey.verified");
}
private PublicKey loadPublicKey(String userID)
{
byte[] b64PubKey = this.configurator.getPropertyBytes(userID + ".publicKey");
byte[] b64PubKey =
this.configurator.getPropertyBytes(userID + ".publicKey");
if (b64PubKey == null)
return null;

@ -1,7 +1,17 @@
/*
* 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.otr;
import net.java.sip.communicator.service.protocol.Contact;
import net.java.sip.communicator.service.protocol.*;
/**
*
* @author George Politis
*
*/
public interface ScOtrEngineListener
{
public abstract void sessionStatusChanged(Contact contact);

@ -1,47 +1,68 @@
/*
* 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.service.protocol;
import java.util.*;
public class OperationSetInstantMessageTransformImpl implements
OperationSetInstantMessageTransform {
public final Map<Integer, Vector<TransformLayer>> transformLayers = new Hashtable<Integer, Vector<TransformLayer>>();
private static final int defaultPriority = 1;
public void addTransformLayer(TransformLayer transformLayer) {
this.addTransformLayer(defaultPriority, transformLayer);
}
public void addTransformLayer(int priority, TransformLayer transformLayer) {
synchronized (transformLayers) {
if (!transformLayers.containsKey(defaultPriority))
transformLayers.put(defaultPriority,
new Vector<TransformLayer>());
transformLayers.get(defaultPriority).add(transformLayer);
}
}
public boolean containsLayer(TransformLayer layer) {
synchronized (transformLayers) {
for (Map.Entry<Integer, Vector<TransformLayer>> entry : transformLayers
.entrySet()) {
if (entry.getValue().contains(layer))
return true;
}
}
return false;
}
public void removeTransformLayer(TransformLayer transformLayer) {
synchronized (transformLayers) {
for (Map.Entry<Integer, Vector<TransformLayer>> entry : transformLayers
.entrySet()) {
entry.getValue().remove(transformLayer);
}
}
}
/**
*
* @author George Politis
*
*/
public class OperationSetInstantMessageTransformImpl
implements OperationSetInstantMessageTransform
{
public final Map<Integer, Vector<TransformLayer>> transformLayers =
new Hashtable<Integer, Vector<TransformLayer>>();
private static final int defaultPriority = 1;
public void addTransformLayer(TransformLayer transformLayer)
{
this.addTransformLayer(defaultPriority, transformLayer);
}
public void addTransformLayer(int priority, TransformLayer transformLayer)
{
synchronized (transformLayers)
{
if (!transformLayers.containsKey(defaultPriority))
transformLayers.put(defaultPriority,
new Vector<TransformLayer>());
transformLayers.get(defaultPriority).add(transformLayer);
}
}
public boolean containsLayer(TransformLayer layer)
{
synchronized (transformLayers)
{
for (Map.Entry<Integer, Vector<TransformLayer>> entry : transformLayers
.entrySet())
{
if (entry.getValue().contains(layer))
return true;
}
}
return false;
}
public void removeTransformLayer(TransformLayer transformLayer)
{
synchronized (transformLayers)
{
for (Map.Entry<Integer, Vector<TransformLayer>> entry : transformLayers
.entrySet())
{
entry.getValue().remove(transformLayer);
}
}
}
}

Loading…
Cancel
Save