Skip to content
Snippets Groups Projects
Commit 43aa1b15 authored by Vincent Lucas's avatar Vincent Lucas
Browse files

Adds SDES for XMPP. Works with Jingle and GTalk (only for gmail web app, doesn...

Adds SDES for XMPP. Works with Jingle and GTalk (only for gmail web app, doesn not work on "talk" for android).
parent 4e98f547
No related branches found
No related tags found
No related merge requests found
......@@ -150,63 +150,97 @@ public void setMultistream(SrtpControl master)
public TransformEngine getTransformEngine()
{
if(engine == null)
{
engine = new SDesTransformEngine(this);
}
return engine;
}
public String[] getInitiatorCryptoAttributes()
/**
* Initializes the available SRTP crypto attributes containing: he
* crypto-suite, the key-param and the session-param.
*/
private void initAttributes()
{
if(attributes == null)
{
attributes = new SrtpCryptoAttribute[enabledCryptoSuites.size()];
for (int i = 0; i < attributes.length; i++)
{
attributes[i] =
sdesFactory.createCryptoAttribute(i + 1,
attributes[i] = sdesFactory.createCryptoAttribute(
i + 1,
enabledCryptoSuites.get(i));
}
}
String[] result = new String[attributes.length];
for(int i = 0; i < attributes.length; i++)
result[i] = attributes[i].encode();
return result;
}
public String responderSelectAttribute(Iterable<String> peerAttributes)
/**
* Returns the crypto attributes enabled on this computer.
*
* @return The crypto attributes enabled on this computer.
*/
public SrtpCryptoAttribute[] getInitiatorCryptoAttributes()
{
for (String suite : enabledCryptoSuites)
initAttributes();
return attributes;
}
/**
* Chooses a supported crypto attribute from the peer's list of supplied
* attributes and creates the local crypto attribute. Used when the control
* is running in the role as responder.
*
* @param peerAttributes The peer's crypto attribute offering.
*
* @return The local crypto attribute for the answer of the offer or null if
* no matching cipher suite could be found.
*/
public SrtpCryptoAttribute responderSelectAttribute(
Iterable<SrtpCryptoAttribute> peerAttributes)
{
for (SrtpCryptoAttribute ea : peerAttributes)
{
for (String ea : peerAttributes)
for (String suite : enabledCryptoSuites)
{
SrtpCryptoAttribute peerCA = SrtpCryptoAttribute.create(ea);
if (suite.equals(peerCA.getCryptoSuite().encode()))
if (suite.equals(ea.getCryptoSuite().encode()))
{
selectedInAttribute = peerCA;
selectedOutAttribute =
sdesFactory.createCryptoAttribute(1, suite);
return selectedOutAttribute.encode();
selectedInAttribute = ea;
selectedOutAttribute
= sdesFactory.createCryptoAttribute(1, suite);
return selectedOutAttribute;
}
}
}
return null;
}
public boolean initiatorSelectAttribute(Iterable<String> peerAttributes)
/**
* Select the local crypto attribute from the initial offering (@see
* {@link #getInitiatorCryptoAttributes()}) based on the peer's first
* matching cipher suite.
*
* @param peerAttributes The peer's crypto offers.
*
* @return A SrtpCryptoAttribute when a matching cipher suite was found.
* Null otherwise.
*/
public SrtpCryptoAttribute initiatorSelectAttribute(
Iterable<SrtpCryptoAttribute> peerAttributes)
{
for (SrtpCryptoAttribute localCA : attributes)
for (SrtpCryptoAttribute peerCA : peerAttributes)
{
for (String ea : peerAttributes)
for (SrtpCryptoAttribute localCA : attributes)
{
SrtpCryptoAttribute peerCA = SrtpCryptoAttribute.create(ea);
if (localCA.getCryptoSuite().equals(peerCA.getCryptoSuite()))
{
selectedInAttribute = peerCA;
selectedOutAttribute = localCA;
return true;
return peerCA;
}
}
}
return false;
return null;
}
public SrtpCryptoAttribute getInAttribute()
......
......@@ -90,12 +90,12 @@ private SRTCPCryptoContext getContext(
SRTPTransformEngine engine)
{
long ssrc = pkt.getRTCPSSRC();
SRTCPCryptoContext context;
SRTCPCryptoContext context = null;
synchronized (contexts)
{
context = contexts.get(ssrc);
if (context == null)
if (context == null && engine != null)
{
context = engine.getDefaultContextControl();
if (context != null)
......@@ -136,7 +136,15 @@ public RawPacket transform(RawPacket pkt)
{
SRTCPCryptoContext context = getContext(pkt, forwardEngine);
context.transformPacket(pkt);
return pkt;
if(context != null)
{
context.transformPacket(pkt);
return pkt;
}
else
{
// The packet can not be encrypted. Thus, does not send it.
return null;
}
}
}
......@@ -38,12 +38,11 @@ public interface SDesControl
public Iterable<String> getSupportedCryptoSuites();
/**
* Gets the encoded SDES crypto-attributes for all enabled ciphers when the
* control is used as the initiator.
*
* @return the encoded SDES crypto-attributes for all enabled ciphers.
* Returns the crypto attributes enabled on this computer.
*
* @return The crypto attributes enabled on this computer.
*/
public String[] getInitiatorCryptoAttributes();
public SrtpCryptoAttribute[] getInitiatorCryptoAttributes();
/**
* Chooses a supported crypto attribute from the peer's list of supplied
......@@ -51,10 +50,12 @@ public interface SDesControl
* is running in the role as responder.
*
* @param peerAttributes The peer's crypto attribute offering.
*
* @return The local crypto attribute for the answer of the offer or null if
* no matching cipher suite could be found.
*/
public String responderSelectAttribute(Iterable<String> peerAttributes);
public SrtpCryptoAttribute responderSelectAttribute(
Iterable<SrtpCryptoAttribute> peerAttributes);
/**
* Select the local crypto attribute from the initial offering (@see
......@@ -62,9 +63,12 @@ public interface SDesControl
* matching cipher suite.
*
* @param peerAttributes The peer's crypto offers.
* @return True when a matching cipher suite was found, false otherwise.
*
* @return A SrtpCryptoAttribute when a matching cipher suite was found.
* Null otherwise.
*/
public boolean initiatorSelectAttribute(Iterable<String> peerAttributes);
public SrtpCryptoAttribute initiatorSelectAttribute(
Iterable<SrtpCryptoAttribute> peerAttributes);
/**
* Gets the crypto attribute of the incoming MediaStream.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment