Skip to content
Snippets Groups Projects
Commit 189e34da authored by Ingo Bauersachs's avatar Ingo Bauersachs
Browse files

Fix a spelling mistake

parent f1ff821a
No related branches found
No related tags found
No related merge requests found
/* /*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client. * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
* *
* Distributable under LGPL license. * Distributable under LGPL license.
* See terms of license at gnu.org. * See terms of license at gnu.org.
*/ */
package org.jitsi.impl.neomedia.transform.sdes; package org.jitsi.impl.neomedia.transform.sdes;
import gnu.java.zrtp.utils.*; import gnu.java.zrtp.utils.*;
import java.util.*; import java.util.*;
import org.jitsi.impl.neomedia.*; import org.jitsi.impl.neomedia.*;
import org.jitsi.service.neomedia.*; import org.jitsi.service.neomedia.*;
import org.jitsi.service.neomedia.event.*; import org.jitsi.service.neomedia.event.*;
import ch.imvs.sdes4j.srtp.*; import ch.imvs.sdes4j.srtp.*;
/** /**
* Default implementation of {@link SDesControl} that supports the crypto suites * Default implementation of {@link SDesControl} that supports the crypto suites
* of the original RFC4568 and the KDR parameter, but nothing else. * of the original RFC4568 and the KDR parameter, but nothing else.
* *
* @author Ingo Bauersachs * @author Ingo Bauersachs
*/ */
public class SDesControlImpl public class SDesControlImpl
extends AbstractSrtpControl<SDesTransformEngine> extends AbstractSrtpControl<SDesTransformEngine>
implements SDesControl implements SDesControl
{ {
/** /**
* List of enabled crypto suites. * List of enabled crypto suites.
*/ */
private final List<String> enabledCryptoSuites = new ArrayList<String>(3); private final List<String> enabledCryptoSuites = new ArrayList<String>(3);
/** /**
* List of supported crypto suites. * List of supported crypto suites.
*/ */
private final List<String> supportedCryptoSuites = new ArrayList<String>(3); private final List<String> supportedCryptoSuites = new ArrayList<String>(3);
private SrtpCryptoAttribute[] attributes; private SrtpCryptoAttribute[] attributes;
private SrtpSDesFactory sdesFactory; private SrtpSDesFactory sdesFactory;
private SrtpCryptoAttribute selectedInAttribute; private SrtpCryptoAttribute selectedInAttribute;
private SrtpCryptoAttribute selectedOutAttribute; private SrtpCryptoAttribute selectedOutAttribute;
/** /**
* SDESControl * SDESControl
*/ */
public SDesControlImpl() public SDesControlImpl()
{ {
super(SrtpControlType.SDES); super(SrtpControlType.SDES);
{ {
enabledCryptoSuites.add(SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_80); enabledCryptoSuites.add(SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_80);
enabledCryptoSuites.add(SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_32); enabledCryptoSuites.add(SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_32);
enabledCryptoSuites.add(SrtpCryptoSuite.F8_128_HMAC_SHA1_80); enabledCryptoSuites.add(SrtpCryptoSuite.F8_128_HMAC_SHA1_80);
} }
{ {
supportedCryptoSuites.add(SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_80); supportedCryptoSuites.add(SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_80);
supportedCryptoSuites.add(SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_32); supportedCryptoSuites.add(SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_32);
supportedCryptoSuites.add(SrtpCryptoSuite.F8_128_HMAC_SHA1_80); supportedCryptoSuites.add(SrtpCryptoSuite.F8_128_HMAC_SHA1_80);
} }
sdesFactory = new SrtpSDesFactory(); sdesFactory = new SrtpSDesFactory();
sdesFactory.setRandomGenerator( sdesFactory.setRandomGenerator(
new Random() new Random()
{ {
private static final long serialVersionUID = 0L; private static final long serialVersionUID = 0L;
@Override @Override
public void nextBytes(byte[] bytes) public void nextBytes(byte[] bytes)
{ {
ZrtpFortuna.getInstance().getFortuna().nextBytes(bytes); ZrtpFortuna.getInstance().getFortuna().nextBytes(bytes);
} }
}); });
} }
public SrtpCryptoAttribute getInAttribute() public SrtpCryptoAttribute getInAttribute()
{ {
return selectedInAttribute; return selectedInAttribute;
} }
/** /**
* Returns the crypto attributes enabled on this computer. * Returns the crypto attributes enabled on this computer.
* *
* @return The crypto attributes enabled on this computer. * @return The crypto attributes enabled on this computer.
*/ */
public SrtpCryptoAttribute[] getInitiatorCryptoAttributes() public SrtpCryptoAttribute[] getInitiatorCryptoAttributes()
{ {
initAttributes(); initAttributes();
return attributes; return attributes;
} }
public SrtpCryptoAttribute getOutAttribute() public SrtpCryptoAttribute getOutAttribute()
{ {
return selectedOutAttribute; return selectedOutAttribute;
} }
public boolean getSecureCommunicationStatus() public boolean getSecureCommunicationStatus()
{ {
return transformEngine != null; return transformEngine != null;
} }
public Iterable<String> getSupportedCryptoSuites() public Iterable<String> getSupportedCryptoSuites()
{ {
return Collections.unmodifiableList(supportedCryptoSuites); return Collections.unmodifiableList(supportedCryptoSuites);
} }
/** /**
* Initializes a new <tt>SDesTransformEngine</tt> instance to be associated * Initializes a new <tt>SDesTransformEngine</tt> instance to be associated
* with and used by this <tt>SDesControlImpl</tt> instance. * with and used by this <tt>SDesControlImpl</tt> instance.
* *
* @return a new <tt>SDesTransformEngine</tt> instance to be associated with * @return a new <tt>SDesTransformEngine</tt> instance to be associated with
* and used by this <tt>SDesControlImpl</tt> instance * and used by this <tt>SDesControlImpl</tt> instance
* @see AbstractSrtpControl#createTransformEngine() * @see AbstractSrtpControl#createTransformEngine()
*/ */
protected SDesTransformEngine createTransformEngine() protected SDesTransformEngine createTransformEngine()
{ {
return return
new SDesTransformEngine(selectedInAttribute, selectedOutAttribute); new SDesTransformEngine(selectedInAttribute, selectedOutAttribute);
} }
/** /**
* Initializes the available SRTP crypto attributes containing: he * Initializes the available SRTP crypto attributes containing: the
* crypto-suite, the key-param and the session-param. * crypto-suite, the key-param and the session-param.
*/ */
private void initAttributes() private void initAttributes()
{ {
if(attributes == null) if(attributes == null)
{ {
attributes = new SrtpCryptoAttribute[enabledCryptoSuites.size()]; attributes = new SrtpCryptoAttribute[enabledCryptoSuites.size()];
for (int i = 0; i < attributes.length; i++) for (int i = 0; i < attributes.length; i++)
{ {
attributes[i] attributes[i]
= sdesFactory.createCryptoAttribute( = sdesFactory.createCryptoAttribute(
i + 1, i + 1,
enabledCryptoSuites.get(i)); enabledCryptoSuites.get(i));
} }
} }
} }
/** /**
* Select the local crypto attribute from the initial offering (@see * Select the local crypto attribute from the initial offering (@see
* {@link #getInitiatorCryptoAttributes()}) based on the peer's first * {@link #getInitiatorCryptoAttributes()}) based on the peer's first
* matching cipher suite. * matching cipher suite.
* *
* @param peerAttributes The peer's crypto offers. * @param peerAttributes The peer's crypto offers.
* @return A SrtpCryptoAttribute when a matching cipher suite was found; * @return A SrtpCryptoAttribute when a matching cipher suite was found;
* <tt>null</tt>, otherwise. * <tt>null</tt>, otherwise.
*/ */
public SrtpCryptoAttribute initiatorSelectAttribute( public SrtpCryptoAttribute initiatorSelectAttribute(
Iterable<SrtpCryptoAttribute> peerAttributes) Iterable<SrtpCryptoAttribute> peerAttributes)
{ {
for (SrtpCryptoAttribute peerCA : peerAttributes) for (SrtpCryptoAttribute peerCA : peerAttributes)
{ {
for (SrtpCryptoAttribute localCA : attributes) for (SrtpCryptoAttribute localCA : attributes)
{ {
if (localCA.getCryptoSuite().equals(peerCA.getCryptoSuite())) if (localCA.getCryptoSuite().equals(peerCA.getCryptoSuite()))
{ {
selectedInAttribute = peerCA; selectedInAttribute = peerCA;
selectedOutAttribute = localCA; selectedOutAttribute = localCA;
return peerCA; return peerCA;
} }
} }
} }
return null; return null;
} }
/** /**
* Returns <tt>true</tt>, SDES always requires the secure transport of its * Returns <tt>true</tt>, SDES always requires the secure transport of its
* keys. * keys.
* *
* @return <tt>true</tt> * @return <tt>true</tt>
*/ */
public boolean requiresSecureSignalingTransport() public boolean requiresSecureSignalingTransport()
{ {
return true; return true;
} }
/** /**
* Chooses a supported crypto attribute from the peer's list of supplied * Chooses a supported crypto attribute from the peer's list of supplied
* attributes and creates the local crypto attribute. Used when the control * attributes and creates the local crypto attribute. Used when the control
* is running in the role as responder. * is running in the role as responder.
* *
* @param peerAttributes The peer's crypto attribute offering. * @param peerAttributes The peer's crypto attribute offering.
* @return The local crypto attribute for the answer of the offer or * @return The local crypto attribute for the answer of the offer or
* <tt>null</tt> if no matching cipher suite could be found. * <tt>null</tt> if no matching cipher suite could be found.
*/ */
public SrtpCryptoAttribute responderSelectAttribute( public SrtpCryptoAttribute responderSelectAttribute(
Iterable<SrtpCryptoAttribute> peerAttributes) Iterable<SrtpCryptoAttribute> peerAttributes)
{ {
for (SrtpCryptoAttribute ea : peerAttributes) for (SrtpCryptoAttribute ea : peerAttributes)
{ {
for (String suite : enabledCryptoSuites) for (String suite : enabledCryptoSuites)
{ {
if (suite.equals(ea.getCryptoSuite().encode())) if (suite.equals(ea.getCryptoSuite().encode()))
{ {
selectedInAttribute = ea; selectedInAttribute = ea;
selectedOutAttribute selectedOutAttribute
= sdesFactory.createCryptoAttribute(1, suite); = sdesFactory.createCryptoAttribute(1, suite);
return selectedOutAttribute; return selectedOutAttribute;
} }
} }
} }
return null; return null;
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
* *
* The implementation of <tt>SDesControlImpl</tt> does nothing because * The implementation of <tt>SDesControlImpl</tt> does nothing because
* <tt>SDesControlImpl</tt> does not utilize the <tt>RTPConnector</tt>. * <tt>SDesControlImpl</tt> does not utilize the <tt>RTPConnector</tt>.
*/ */
public void setConnector(AbstractRTPConnector connector) public void setConnector(AbstractRTPConnector connector)
{ {
} }
public void setEnabledCiphers(Iterable<String> ciphers) public void setEnabledCiphers(Iterable<String> ciphers)
{ {
enabledCryptoSuites.clear(); enabledCryptoSuites.clear();
for(String c : ciphers) for(String c : ciphers)
enabledCryptoSuites.add(c); enabledCryptoSuites.add(c);
} }
public void start(MediaType mediaType) public void start(MediaType mediaType)
{ {
SrtpListener srtpListener = getSrtpListener(); SrtpListener srtpListener = getSrtpListener();
// in srtp the started and security event is one after another in some // in srtp the started and security event is one after another in some
// other security mechanisms (e.g. zrtp) there can be started and no // other security mechanisms (e.g. zrtp) there can be started and no
// security one or security timeout event // security one or security timeout event
srtpListener.securityNegotiationStarted(mediaType, this); srtpListener.securityNegotiationStarted(mediaType, this);
srtpListener.securityTurnedOn( srtpListener.securityTurnedOn(
mediaType, mediaType,
selectedInAttribute.getCryptoSuite().encode(), selectedInAttribute.getCryptoSuite().encode(),
this); this);
} }
} }
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