mirror of https://github.com/sipwise/jitsi.git
cusax-fix
parent
55b0e3520a
commit
e2974c6817
Binary file not shown.
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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 org.bouncycastle.util.encoders.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author George Politis
|
||||
*
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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.*;
|
||||
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author George Politis
|
||||
*
|
||||
*/
|
||||
public interface ScOtrKeyManager
|
||||
{
|
||||
|
||||
public abstract void addListener(ScOtrKeyManagerListener l);
|
||||
|
||||
public abstract void removeListener(ScOtrKeyManagerListener l);
|
||||
|
||||
public abstract void verify(Contact contact);
|
||||
|
||||
public abstract void unverify(Contact contact);
|
||||
|
||||
public abstract boolean isVerified(Contact contact);
|
||||
|
||||
public abstract String getRemoteFingerprint(Contact contact);
|
||||
|
||||
public abstract String getLocalFingerprint(AccountID account);
|
||||
|
||||
public abstract void savePublicKey(Contact contact, PublicKey pubKey);
|
||||
|
||||
public abstract PublicKey loadPublicKey(Contact contact);
|
||||
|
||||
public abstract KeyPair loadKeyPair(AccountID accountID);
|
||||
|
||||
public abstract void generateKeyPair(AccountID accountID);
|
||||
|
||||
}
|
||||
@ -0,0 +1,243 @@
|
||||
/*
|
||||
* 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.*;
|
||||
import java.security.spec.*;
|
||||
import java.util.*;
|
||||
|
||||
import net.java.otr4j.crypto.*;
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author George Politis
|
||||
*
|
||||
*/
|
||||
public class ScOtrKeyManagerImpl
|
||||
implements ScOtrKeyManager
|
||||
{
|
||||
private List<ScOtrKeyManagerListener> listeners =
|
||||
new Vector<ScOtrKeyManagerListener>();
|
||||
|
||||
public void addListener(ScOtrKeyManagerListener l)
|
||||
{
|
||||
synchronized (listeners)
|
||||
{
|
||||
if (!listeners.contains(l))
|
||||
listeners.add(l);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeListener(ScOtrKeyManagerListener l)
|
||||
{
|
||||
synchronized (listeners)
|
||||
{
|
||||
listeners.remove(l);
|
||||
}
|
||||
}
|
||||
|
||||
private Configurator configurator = new Configurator();
|
||||
|
||||
public void verify(Contact contact)
|
||||
{
|
||||
if (contact == null)
|
||||
return;
|
||||
|
||||
if (this.isVerified(contact))
|
||||
return;
|
||||
|
||||
this.configurator.setProperty(contact.getAddress()
|
||||
+ ".publicKey.verified", true);
|
||||
|
||||
for (ScOtrKeyManagerListener l : listeners)
|
||||
l.contactVerificationStatusChanged(contact);
|
||||
}
|
||||
|
||||
public void unverify(Contact contact)
|
||||
{
|
||||
if (contact == null)
|
||||
return;
|
||||
|
||||
if (!isVerified(contact))
|
||||
return;
|
||||
|
||||
this.configurator.removeProperty(contact.getAddress()
|
||||
+ ".publicKey.verified");
|
||||
|
||||
for (ScOtrKeyManagerListener l : listeners)
|
||||
l.contactVerificationStatusChanged(contact);
|
||||
}
|
||||
|
||||
public boolean isVerified(Contact contact)
|
||||
{
|
||||
if (contact == null)
|
||||
return false;
|
||||
|
||||
return this.configurator.getPropertyBoolean(contact.getAddress()
|
||||
+ ".publicKey.verified", false);
|
||||
}
|
||||
|
||||
public String getRemoteFingerprint(Contact contact)
|
||||
{
|
||||
PublicKey remotePublicKey = loadPublicKey(contact);
|
||||
if (remotePublicKey == null)
|
||||
return null;
|
||||
try
|
||||
{
|
||||
return new OtrCryptoEngineImpl().getFingerprint(remotePublicKey);
|
||||
}
|
||||
catch (OtrCryptoException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String getLocalFingerprint(AccountID account)
|
||||
{
|
||||
KeyPair keyPair = loadKeyPair(account);
|
||||
|
||||
if (keyPair == null)
|
||||
return null;
|
||||
|
||||
PublicKey pubKey = keyPair.getPublic();
|
||||
|
||||
try
|
||||
{
|
||||
return new OtrCryptoEngineImpl().getFingerprint(pubKey);
|
||||
}
|
||||
catch (OtrCryptoException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void savePublicKey(Contact contact, PublicKey pubKey)
|
||||
{
|
||||
if (contact == null)
|
||||
return;
|
||||
|
||||
X509EncodedKeySpec x509EncodedKeySpec =
|
||||
new X509EncodedKeySpec(pubKey.getEncoded());
|
||||
|
||||
this.configurator.setProperty(contact.getAddress() + ".publicKey",
|
||||
x509EncodedKeySpec.getEncoded());
|
||||
|
||||
this.configurator.removeProperty(contact.getAddress()
|
||||
+ ".publicKey.verified");
|
||||
}
|
||||
|
||||
public PublicKey loadPublicKey(Contact contact)
|
||||
{
|
||||
if (contact == null)
|
||||
return null;
|
||||
|
||||
String userID = contact.getAddress();
|
||||
|
||||
byte[] b64PubKey =
|
||||
this.configurator.getPropertyBytes(userID + ".publicKey");
|
||||
if (b64PubKey == null)
|
||||
return null;
|
||||
|
||||
X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(b64PubKey);
|
||||
|
||||
// Generate KeyPair.
|
||||
KeyFactory keyFactory;
|
||||
try
|
||||
{
|
||||
keyFactory = KeyFactory.getInstance("DSA");
|
||||
return keyFactory.generatePublic(publicKeySpec);
|
||||
}
|
||||
catch (NoSuchAlgorithmException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
catch (InvalidKeySpecException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public KeyPair loadKeyPair(AccountID account)
|
||||
{
|
||||
String accountID = account.getAccountUniqueID();
|
||||
// Load Private Key.
|
||||
byte[] b64PrivKey =
|
||||
this.configurator.getPropertyBytes(accountID + ".privateKey");
|
||||
if (b64PrivKey == null)
|
||||
return null;
|
||||
|
||||
PKCS8EncodedKeySpec privateKeySpec =
|
||||
new PKCS8EncodedKeySpec(b64PrivKey);
|
||||
|
||||
// Load Public Key.
|
||||
byte[] b64PubKey =
|
||||
this.configurator.getPropertyBytes(accountID + ".publicKey");
|
||||
if (b64PubKey == null)
|
||||
return null;
|
||||
|
||||
X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(b64PubKey);
|
||||
|
||||
PublicKey publicKey;
|
||||
PrivateKey privateKey;
|
||||
|
||||
// Generate KeyPair.
|
||||
KeyFactory keyFactory;
|
||||
try
|
||||
{
|
||||
keyFactory = KeyFactory.getInstance("DSA");
|
||||
publicKey = keyFactory.generatePublic(publicKeySpec);
|
||||
privateKey = keyFactory.generatePrivate(privateKeySpec);
|
||||
}
|
||||
catch (NoSuchAlgorithmException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
catch (InvalidKeySpecException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
return new KeyPair(publicKey, privateKey);
|
||||
}
|
||||
|
||||
public void generateKeyPair(AccountID account)
|
||||
{
|
||||
String accountID = account.getAccountUniqueID();
|
||||
KeyPair keyPair;
|
||||
try
|
||||
{
|
||||
keyPair = KeyPairGenerator.getInstance("DSA").genKeyPair();
|
||||
}
|
||||
catch (NoSuchAlgorithmException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
// Store Public Key.
|
||||
PublicKey pubKey = keyPair.getPublic();
|
||||
X509EncodedKeySpec x509EncodedKeySpec =
|
||||
new X509EncodedKeySpec(pubKey.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());
|
||||
}
|
||||
}
|
||||
@ -0,0 +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.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author George Politis
|
||||
*
|
||||
*/
|
||||
public interface ScOtrKeyManagerListener
|
||||
{
|
||||
public abstract void contactVerificationStatusChanged(Contact contact);
|
||||
}
|
||||
Loading…
Reference in new issue