inline
*/
String getKeyMethod();
/**
* Encodes the information contained in this object for use in the complete
* crypto attribute.
*
* @return Textual representation of the key parameter.
*/
String encode();
}
sdes4j-1.1.4/src/main/java/ch/imvs/sdes4j/SDesFactory.java 0000664 0000000 0000000 00000004504 12756343045 0023156 0 ustar 00root root 0000000 0000000 /*
* SDES4J
* Java implementation of SDES (Security Descriptions for Media Streams,
* RFC 4568).
*
* Copyright (C) 2011 FHNW
* University of Applied Sciences Northwestern Switzerland (FHNW)
* School of Engineering
* Institute of Mobile and Distributed Systems (IMVS)
* http://sdes4j.imvs.ch
*
* Distributable under LGPL license, see terms of license at gnu.org.
*/
package ch.imvs.sdes4j;
import java.util.Random;
/**
* Interface to create instances of specific grammar
*
* @author Ingo Bauersachs
*/
public interface SDesFactory {
/**
* Creates a crypto suite instance for the grammar implementing this interface.
*
* @param suite The suite name that defines the cryptographic parameters.
* @return A crypto suite instance based on the supplied suite name.
*/
CryptoSuite createCryptoSuite(String suite);
/**
* Creates a key parameter instance for the grammar implementing this interface.
*
* @param keyParam The textual representation of the key parameter field.
* @return The parsed key parameter.
*/
KeyParam createKeyParam(String keyParam);
/**
* Utility method to create a typed array of KeyParameter
s.
*
* @param size The size of the array to create.
* @return KeyParam array of the specified size.
*/
KeyParam[] createKeyParamArray(int size);
/**
* Creates a session parameter instance for the grammar implementing this interface.
*
* @param sessionParam The textual representation of the session parameter.
* @return The parsed session parameter.
*/
SessionParam createSessionParam(String sessionParam);
/**
* Utility method to create a typed array of SessionParam
s.
*
* @param size The size of the array to create.
* @return SessionParam array of the specified size.
*/
SessionParam[] createSessionParamArray(int size);
/**
* Creates an empty crypto attribute for the grammar implementing this interface.
*
* @return Empty crypto attribute to be filled by a parser.
*/
CryptoAttribute createCryptoAttribute();
/**
* Sets the random number generator to be used for generating the SDES keys.
*
* @param r The random number generator.
*/
void setRandomGenerator(Random r);
}
sdes4j-1.1.4/src/main/java/ch/imvs/sdes4j/SessionParam.java 0000664 0000000 0000000 00000001407 12756343045 0023373 0 ustar 00root root 0000000 0000000 /*
* SDES4J
* Java implementation of SDES (Security Descriptions for Media Streams,
* RFC 4568).
*
* Copyright (C) 2011 FHNW
* University of Applied Sciences Northwestern Switzerland (FHNW)
* School of Engineering
* Institute of Mobile and Distributed Systems (IMVS)
* http://sdes4j.imvs.ch
*
* Distributable under LGPL license, see terms of license at gnu.org.
*/
package ch.imvs.sdes4j;
/**
* Interface for Session parameters that are specific to a given transport.
*
* @author Ingo Bauersachs
*/
public interface SessionParam {
/**
* Encodes the information contained in this object for use in the complete
* crypto attribute.
*
* @return Textual representation of the session parameter.
*/
String encode();
}
sdes4j-1.1.4/src/main/java/ch/imvs/sdes4j/srtp/ 0000775 0000000 0000000 00000000000 12756343045 0021112 5 ustar 00root root 0000000 0000000 sdes4j-1.1.4/src/main/java/ch/imvs/sdes4j/srtp/FecKeySessionParam.java 0000664 0000000 0000000 00000004320 12756343045 0025447 0 ustar 00root root 0000000 0000000 /*
* SDES4J
* Java implementation of SDES (Security Descriptions for Media Streams,
* RFC 4568).
*
* Copyright (C) 2011 FHNW
* University of Applied Sciences Northwestern Switzerland (FHNW)
* School of Engineering
* Institute of Mobile and Distributed Systems (IMVS)
* http://sdes4j.imvs.ch
*
* Distributable under LGPL license, see terms of license at gnu.org.
*/
package ch.imvs.sdes4j.srtp;
/**
* FEC_KEY signals the use of separate master key(s) for a Forward Error
* Correction (FEC) stream.
*
* @author Ingo Bauersachs
*/
public class FecKeySessionParam extends SrtpSessionParam {
private SrtpKeyParam[] keyParams;
/**
* Creates a new instance of this class from known key parameters.
* @param keyParams The key parameters to use for this FEC session parameter.
*/
public FecKeySessionParam(SrtpKeyParam[] keyParams) {
this.keyParams = keyParams;
}
/**
* Creates a new instance of this class from the textual representation of the session parameter.
* @param param The textual representation of the session parameter.
*/
public FecKeySessionParam(String param) {
String[] params = param.substring("FEC_KEY=".length()).split(";");
this.keyParams = new SrtpKeyParam[params.length];
for (int i = 0; i < this.keyParams.length; i++) {
this.keyParams[i] = createSrtpKeyParam(params[i]);
}
}
/**
* Factory method to create the key parameter objects.
*
* @param p The key parameter to parse.
* @return The parsed key parameter.
*/
protected SrtpKeyParam createSrtpKeyParam(String p) {
return new SrtpKeyParam(p);
}
/**
* Gets the key parameters of this session parameter.
* @return The key parameters of this session parameter.
*/
public SrtpKeyParam[] getKeyParams() {
return keyParams;
}
@Override
public String encode() {
StringBuilder sb = new StringBuilder();
sb.append("FEC_KEY=");
for (int i = 0; i < keyParams.length; i++) {
sb.append(keyParams[i].encode());
if (i < keyParams.length - 1)
sb.append(';');
}
return sb.toString();
}
}
sdes4j-1.1.4/src/main/java/ch/imvs/sdes4j/srtp/FecOrderSessionParam.java 0000664 0000000 0000000 00000005370 12756343045 0026000 0 ustar 00root root 0000000 0000000 /*
* SDES4J
* Java implementation of SDES (Security Descriptions for Media Streams,
* RFC 4568).
*
* Copyright (C) 2011 FHNW
* University of Applied Sciences Northwestern Switzerland (FHNW)
* School of Engineering
* Institute of Mobile and Distributed Systems (IMVS)
* http://sdes4j.imvs.ch
*
* Distributable under LGPL license, see terms of license at gnu.org.
*/
package ch.imvs.sdes4j.srtp;
/**
* FEC_ORDER signals the use of forward error correction for the RTP packets
* [RFC2733]. The forward error correction values for "order" are FEC_SRTP or
* SRTP_FEC. FEC_SRTP signals that FEC is applied before SRTP processing by the
* sender of the SRTP media and after SRTP processing by the receiver of the
* SRTP media; FEC_SRTP is the default. SRTP_FEC is the reverse processing.
*
* @author Ingo Bauersachs
*/
public class FecOrderSessionParam extends SrtpSessionParam {
/**
* FEC_SRTP signals that FEC is applied before SRTP processing by the sender
* of the SRTP media and after SRTP processing by the receiver of the SRTP
* media; FEC_SRTP is the default.
*/
public final static int FEC_SRTP = 1;
/**
* SRTP_FEC signals that SRTP processing is performed before applying FEC by
* the sender of the SRTP media and after FEC processing by the receiver of
* the SRTP media.
*/
public final static int SRTP_FEC = 2;
private int mode;
/**
* Creates a new instance of this class from a known order value.
*
* @param mode {@value #FEC_SRTP} or {@value #SRTP_FEC}
*/
public FecOrderSessionParam(int mode) {
if (mode != FEC_SRTP && mode != SRTP_FEC)
throw new IllegalArgumentException("mode must be one of FEC_SRTP or SRTP_FEC");
this.mode = mode;
}
/**
* Creates a new instance of this class from the textual representation of
* the session parameter.
*
* @param param The textual representation of the session parameter.
*/
public FecOrderSessionParam(String param) {
param = param.substring("FEC_ORDER=".length());
if (param.equals("FEC_SRTP"))
mode = FEC_SRTP;
else if (param.equals("SRTP_FEC"))
mode = SRTP_FEC;
else
throw new IllegalArgumentException("unknown value");
}
/**
* Gets the forward error correction mode.
*
* @return {@value #SRTP_FEC} or {@value #FEC_SRTP}
*/
public int getMode() {
return mode;
}
@Override
public String encode() {
switch (mode) {
case FEC_SRTP:
return "FEC_ORDER=FEC_SRTP";
case SRTP_FEC:
return "FEC_ORDER=SRTP_FEC";
}
throw new IllegalArgumentException("invalid mode");
}
}
sdes4j-1.1.4/src/main/java/ch/imvs/sdes4j/srtp/KdrSessionParam.java 0000664 0000000 0000000 00000004514 12756343045 0025026 0 ustar 00root root 0000000 0000000 /*
* SDES4J
* Java implementation of SDES (Security Descriptions for Media Streams,
* RFC 4568).
*
* Copyright (C) 2011 FHNW
* University of Applied Sciences Northwestern Switzerland (FHNW)
* School of Engineering
* Institute of Mobile and Distributed Systems (IMVS)
* http://sdes4j.imvs.ch
*
* Distributable under LGPL license, see terms of license at gnu.org.
*/
package ch.imvs.sdes4j.srtp;
/**
* KDR specifies the Key Derivation Rate, as described in Section 4.3.1 of
* [RFC3711].
*
* The value n MUST be a decimal integer in the set {1,2,...,24}, which denotes
* a power of 2 from 2^1 to 2^24, inclusive; leading zeroes MUST NOT be used.
* The SRTP key derivation rate controls how frequently a new session key is
* derived from an SRTP master key(s) [RFC3711] given in the declaration. When
* the key derivation rate is not specified (i.e., the KDR parameter is
* omitted), a single initial key derivation is performed [RFC3711].
*
* @author Ingo Bauersachs
*/
public class KdrSessionParam extends SrtpSessionParam {
private int kdr;
/**
* Creates a new instance of this class from a known derivation rate.
*
* @param kdr The key derivation rate.
*/
public KdrSessionParam(int kdr) {
if (kdr < 0 || kdr > 24)
throw new IllegalArgumentException("kdr must be in range 0..24 inclusive");
this.kdr = kdr;
}
/**
* Creates a new instance of this class from the textual representation.
*
* @param param The textual representation of the key derivation rate parameter.
*/
public KdrSessionParam(String param) {
kdr = Integer.valueOf(param.substring("KDR=".length()));
if (kdr < 0 || kdr > 24)
throw new IllegalArgumentException("kdr must be in range 0..24 inclusive");
}
/**
* The key derivation rate as encoded in the session parameters.
*
* @return decimal integer in the set {1,2,...,24}
*/
public int getKeyDerivationRate() {
return kdr;
}
/**
* The key derivation rate in its exponentiated form.
*
* @return integer in the range from 2 to 16'777'216.
*/
public int getKeyDerivationRateExpanded() {
return (int) Math.pow(2, kdr);
}
@Override
public String encode() {
return "KDR=" + String.valueOf(kdr);
}
}
sdes4j-1.1.4/src/main/java/ch/imvs/sdes4j/srtp/NoAuthSessionParam.java 0000664 0000000 0000000 00000002156 12756343045 0025504 0 ustar 00root root 0000000 0000000 /*
* SDES4J
* Java implementation of SDES (Security Descriptions for Media Streams,
* RFC 4568).
*
* Copyright (C) 2011 FHNW
* University of Applied Sciences Northwestern Switzerland (FHNW)
* School of Engineering
* Institute of Mobile and Distributed Systems (IMVS)
* http://sdes4j.imvs.ch
*
* Distributable under LGPL license, see terms of license at gnu.org.
*/
package ch.imvs.sdes4j.srtp;
/**
* SRTP and SRTCP packet payloads are authenticated by default. The
* UNAUTHENTICATED_SRTP session parameter signals that SRTP messages are not
* authenticated. Use of UNAUTHENTICATED_SRTP is NOT RECOMMENDED (see Security
* Considerations).
*
* @author Ingo Bauersachs
*/
public class NoAuthSessionParam extends SrtpSessionParam {
private static final String UNAUTHENTICATED_SRTP = "UNAUTHENTICATED_SRTP";
@Override
public String encode() {
return UNAUTHENTICATED_SRTP;
}
@Override
public int hashCode() {
return UNAUTHENTICATED_SRTP.hashCode();
}
@Override
public boolean equals(Object obj) {
return UNAUTHENTICATED_SRTP.equals(obj);
}
}
sdes4j-1.1.4/src/main/java/ch/imvs/sdes4j/srtp/PlainSrtcpSessionParam.java 0000664 0000000 0000000 00000002214 12756343045 0026360 0 ustar 00root root 0000000 0000000 /*
* SDES4J
* Java implementation of SDES (Security Descriptions for Media Streams,
* RFC 4568).
*
* Copyright (C) 2011 FHNW
* University of Applied Sciences Northwestern Switzerland (FHNW)
* School of Engineering
* Institute of Mobile and Distributed Systems (IMVS)
* http://sdes4j.imvs.ch
*
* Distributable under LGPL license, see terms of license at gnu.org.
*/
package ch.imvs.sdes4j.srtp;
/**
* SRTP and SRTCP packet payloads are encrypted by default. The
* UNENCRYPTED_SRTCP and UNENCRYPTED_SRTP session parameters modify the default
* behavior of the crypto-suites with which they are used.
*
* UNENCRYPTED_SRTCP signals that the SRTP packet payloads are not encrypted.
*
* @author Ingo Bauersachs
*/
public class PlainSrtcpSessionParam extends SrtpSessionParam {
private static final String UNENCRYPTED_SRTCP = "UNENCRYPTED_SRTCP";
@Override
public String encode() {
return UNENCRYPTED_SRTCP;
}
@Override
public int hashCode() {
return UNENCRYPTED_SRTCP.hashCode();
}
@Override
public boolean equals(Object obj) {
return UNENCRYPTED_SRTCP.equals(obj);
}
}
sdes4j-1.1.4/src/main/java/ch/imvs/sdes4j/srtp/PlainSrtpSessionParam.java 0000664 0000000 0000000 00000002205 12756343045 0026215 0 ustar 00root root 0000000 0000000 /*
* SDES4J
* Java implementation of SDES (Security Descriptions for Media Streams,
* RFC 4568).
*
* Copyright (C) 2011 FHNW
* University of Applied Sciences Northwestern Switzerland (FHNW)
* School of Engineering
* Institute of Mobile and Distributed Systems (IMVS)
* http://sdes4j.imvs.ch
*
* Distributable under LGPL license, see terms of license at gnu.org.
*/
package ch.imvs.sdes4j.srtp;
/**
* SRTP and SRTCP packet payloads are encrypted by default. The
* UNENCRYPTED_SRTCP and UNENCRYPTED_SRTP session parameters modify the default
* behavior of the crypto-suites with which they are used.
*
* UNENCRYPTED_SRTP signals that the SRTP packet payloads are not encrypted.
*
* @author Ingo Bauersachs
*/
public class PlainSrtpSessionParam extends SrtpSessionParam {
private static final String UNENCRYPTED_SRTP = "UNENCRYPTED_SRTP";
@Override
public String encode() {
return UNENCRYPTED_SRTP;
}
@Override
public int hashCode() {
return UNENCRYPTED_SRTP.hashCode();
}
@Override
public boolean equals(Object obj) {
return UNENCRYPTED_SRTP.equals(obj);
}
}
sdes4j-1.1.4/src/main/java/ch/imvs/sdes4j/srtp/SrtpCryptoAttribute.java 0000664 0000000 0000000 00000004652 12756343045 0026001 0 ustar 00root root 0000000 0000000 package ch.imvs.sdes4j.srtp;
import ch.imvs.sdes4j.CryptoAttribute;
/**
* Security descriptions attribute for SRTP media streams.
*
* @author Ingo Bauersachs
*/
public class SrtpCryptoAttribute extends CryptoAttribute {
SrtpCryptoAttribute(){
}
/**
* Creates an SRTP crypto attribute from its textual representation.
*
* @param encoded The textual representation of the attribute.
* @return The parsed crypto data.
*/
public static SrtpCryptoAttribute create(String encoded){
return (SrtpCryptoAttribute)CryptoAttribute.create(encoded, new SrtpSDesFactory());
}
/**
* Creates an instance of a SrtpCryptoAttribute from SDES attributes (tag,
* crypto suite, key params and session params).
*
* @param tag unparsed tag as a string.
* @param cryptoSuite the crypto suite as an unparsed string.
* @param keyParams An unparsed string representation of the key param list
* (each key must be separated by a ";").
* @param sessionParams An unparsed string representation of the session
* param list (each key must be separated by a " ").
*
* @return a parsed SRTP crypto attribute.
*/
public static SrtpCryptoAttribute create(String tag, String cryptoSuite, String keyParams, String sessionParams){
return (SrtpCryptoAttribute) CryptoAttribute.create(tag, cryptoSuite, keyParams, sessionParams, new SrtpSDesFactory());
}
/**
* Creates a crypto attribute from already instantiated objects.
*
* @param tag identifier for this particular crypto attribute
* @param cryptoSuite identifier that describes the encryption and
* authentication algorithms
* @param keyParams one or more sets of keying material
* @param sessionParams the additional key parameters
*/
public SrtpCryptoAttribute(int tag, SrtpCryptoSuite cryptoSuite, SrtpKeyParam[] keyParams, SrtpSessionParam[] sessionParams) {
super(tag, cryptoSuite, keyParams, sessionParams == null ? new SrtpSessionParam[0] : sessionParams);
}
@Override
public SrtpCryptoSuite getCryptoSuite() {
return (SrtpCryptoSuite) super.getCryptoSuite();
}
@Override
public SrtpKeyParam[] getKeyParams() {
return (SrtpKeyParam[]) super.getKeyParams();
}
@Override
public SrtpSessionParam[] getSessionParams() {
return (SrtpSessionParam[]) super.getSessionParams();
}
}
sdes4j-1.1.4/src/main/java/ch/imvs/sdes4j/srtp/SrtpCryptoSuite.java 0000664 0000000 0000000 00000020743 12756343045 0025126 0 ustar 00root root 0000000 0000000 /*
* SDES4J
* Java implementation of SDES (Security Descriptions for Media Streams,
* RFC 4568).
*
* Copyright (C) 2011 FHNW
* University of Applied Sciences Northwestern Switzerland (FHNW)
* School of Engineering
* Institute of Mobile and Distributed Systems (IMVS)
* http://sdes4j.imvs.ch
*
* Distributable under LGPL license, see terms of license at gnu.org.
*/
package ch.imvs.sdes4j.srtp;
import ch.imvs.sdes4j.CryptoSuite;
/**
* Crypto suite details for the SRTP grammar.
*
* @author Ingo Bauersachs
*/
public class SrtpCryptoSuite implements CryptoSuite {
public static final String AES_256_CM_HMAC_SHA1_32 = "AES_256_CM_HMAC_SHA1_32";
public static final String AES_256_CM_HMAC_SHA1_80 = "AES_256_CM_HMAC_SHA1_80";
public static final String AES_192_CM_HMAC_SHA1_32 = "AES_192_CM_HMAC_SHA1_32";
public static final String AES_192_CM_HMAC_SHA1_80 = "AES_192_CM_HMAC_SHA1_80";
public static final String SEED_128_GCM_96 = "SEED_128_GCM_96";
public static final String SEED_128_CCM_80 = "SEED_128_CCM_80";
public static final String SEED_CTR_128_HMAC_SHA1_80 = "SEED_CTR_128_HMAC_SHA1_80";
public static final String F8_128_HMAC_SHA1_80 = "F8_128_HMAC_SHA1_80";
public static final String AES_CM_128_HMAC_SHA1_32 = "AES_CM_128_HMAC_SHA1_32";
public static final String AES_CM_128_HMAC_SHA1_80 = "AES_CM_128_HMAC_SHA1_80";
public final static int ENCRYPTION_AES128_CM = 1;
public final static int ENCRYPTION_AES128_F8 = 2;
public final static int ENCRYPTION_SEED128_CTR = 5;
public final static int ENCRYPTION_SEED128_CCM_80 = 6;
public final static int ENCRYPTION_SEED128_GCM_96 = 7;
public final static int ENCRYPTION_AES192_CM = 8;
public final static int ENCRYPTION_AES256_CM = 9;
public final static int HASH_HMAC_SHA1 = 1;
public final static int HASH_SEED128_CCM_80 = 3;
public final static int HASH_SEED128_GCM_96 = 4;
private final String suite;
private int encryptionAlgorithm;
private int hashAlgoritm;
private int encKeyLength;
private int saltKeyLength;
private int srtpAuthTagLength;
private int srtcpAuthTagLength;
private int srtpAuthKeyLength;
private int srtcpAuthKeyLength;
private long srtpLifetime;
private long srtcpLifetime;
public SrtpCryptoSuite(String suite) {
this.suite = suite;
// as per http://www.iana.org/assignments/sdp-security-descriptions
if (suite.equals(AES_CM_128_HMAC_SHA1_80)) {
encryptionAlgorithm = ENCRYPTION_AES128_CM;
hashAlgoritm = HASH_HMAC_SHA1;
encKeyLength = 128;
saltKeyLength = 112;
srtpAuthTagLength = 80;
srtcpAuthTagLength = 80;
srtpAuthKeyLength = 160;
srtcpAuthKeyLength = 160;
srtpLifetime = 0x1000000000000L;
srtcpLifetime = 0x80000000L;
}
else if (suite.equals(AES_CM_128_HMAC_SHA1_32)) {
encryptionAlgorithm = ENCRYPTION_AES128_CM;
hashAlgoritm = HASH_HMAC_SHA1;
encKeyLength = 128;
saltKeyLength = 112;
srtpAuthTagLength = 32;
srtcpAuthTagLength = 80;
srtpAuthKeyLength = 160;
srtcpAuthKeyLength = 160;
srtpLifetime = 0x1000000000000L;
srtcpLifetime = 0x80000000L;
}
else if (suite.equals(F8_128_HMAC_SHA1_80)) {
encryptionAlgorithm = ENCRYPTION_AES128_F8;
hashAlgoritm = HASH_HMAC_SHA1;
encKeyLength = 128;
saltKeyLength = 112;
srtpAuthTagLength = 80;
srtcpAuthTagLength = 80;
srtpAuthKeyLength = 160;
srtcpAuthKeyLength = 160;
srtpLifetime = 0x1000000000000L;
srtcpLifetime = 0x80000000L;
}
// FIXME all that SEED stuff is not precisely declared in RFC5669
else if (suite.equals(SEED_CTR_128_HMAC_SHA1_80)) {
encryptionAlgorithm = ENCRYPTION_SEED128_CTR;
hashAlgoritm = HASH_HMAC_SHA1;
encKeyLength = 128;
saltKeyLength = 128;
srtpAuthTagLength = 80;
srtcpAuthTagLength = 80;
srtpAuthKeyLength = -1;
srtcpAuthKeyLength = -1;
srtpLifetime = 0x1000000000000L;
srtcpLifetime = 0x80000000L;
throw new UnsupportedOperationException("SEED parameters are not known for sure");
}
else if (suite.equals(SEED_128_CCM_80)) {
encryptionAlgorithm = ENCRYPTION_SEED128_CCM_80;
hashAlgoritm = HASH_SEED128_CCM_80;
encKeyLength = 128;
saltKeyLength = 128;
srtpAuthTagLength = 80;
srtcpAuthTagLength = 80;
srtpAuthKeyLength = -1;
srtcpAuthKeyLength = -1;
srtpLifetime = 0x1000000000000L;
srtcpLifetime = 0x80000000L;
throw new UnsupportedOperationException("SEED parameters are not known for sure");
}
else if (suite.equals(SEED_128_GCM_96)) {
encryptionAlgorithm = ENCRYPTION_SEED128_GCM_96;
hashAlgoritm = HASH_SEED128_GCM_96;
encKeyLength = 128;
saltKeyLength = 128;
srtpAuthTagLength = 96;
srtcpAuthTagLength = 96;
srtpAuthKeyLength = -1;
srtcpAuthKeyLength = -1;
srtpLifetime = 0x1000000000000L;
srtcpLifetime = 0x80000000L;
throw new UnsupportedOperationException("SEED parameters are not known for sure");
}
else if (suite.equals(AES_192_CM_HMAC_SHA1_80)) {
encryptionAlgorithm = ENCRYPTION_AES192_CM;
hashAlgoritm = HASH_HMAC_SHA1;
encKeyLength = 192;
saltKeyLength = 112;
srtpAuthTagLength = 80;
srtcpAuthTagLength = 80;
srtpAuthKeyLength = 160;
srtcpAuthKeyLength = 160;
srtpLifetime = 0x80000000L;
srtcpLifetime = 0x80000000L;
}
else if (suite.equals(AES_192_CM_HMAC_SHA1_32)) {
encryptionAlgorithm = ENCRYPTION_AES192_CM;
hashAlgoritm = HASH_HMAC_SHA1;
encKeyLength = 192;
saltKeyLength = 112;
srtpAuthTagLength = 32;
srtcpAuthTagLength = 80;
srtpAuthKeyLength = 160;
srtcpAuthKeyLength = 160;
srtpLifetime = 0x80000000L;
srtcpLifetime = 0x80000000L;
}
else if (suite.equals(AES_256_CM_HMAC_SHA1_80)) {
encryptionAlgorithm = ENCRYPTION_AES256_CM;
hashAlgoritm = HASH_HMAC_SHA1;
encKeyLength = 256;
saltKeyLength = 112;
srtpAuthTagLength = 80;
srtcpAuthTagLength = 80;
srtpAuthKeyLength = 160;
srtcpAuthKeyLength = 160;
srtpLifetime = 0x80000000L;
srtcpLifetime = 0x80000000L;
}
else if (suite.equals(AES_256_CM_HMAC_SHA1_32)) {
encryptionAlgorithm = ENCRYPTION_AES256_CM;
hashAlgoritm = HASH_HMAC_SHA1;
encKeyLength = 256;
saltKeyLength = 112;
srtpAuthTagLength = 32;
srtcpAuthTagLength = 80;
srtpAuthKeyLength = 160;
srtcpAuthKeyLength = 160;
srtpLifetime = 0x80000000L;
srtcpLifetime = 0x80000000L;
}
else
throw new IllegalArgumentException("Unknown crypto suite");
}
public int getEncryptionAlgorithm() {
return encryptionAlgorithm;
}
public int getHashAlgorithm() {
return hashAlgoritm;
}
public int getEncKeyLength() {
return encKeyLength;
}
public int getSaltKeyLength() {
return saltKeyLength;
}
public int getSrtpAuthTagLength() {
return srtpAuthTagLength;
}
public int getSrtcpAuthTagLength() {
return srtcpAuthTagLength;
}
public int getSrtpAuthKeyLength() {
return srtpAuthKeyLength;
}
public int getSrtcpAuthKeyLength() {
return srtcpAuthKeyLength;
}
public long getSrtpLifetime() {
return srtpLifetime;
}
public long getSrtcpLifetime() {
return srtcpLifetime;
}
@Override
public String encode() {
return suite;
}
@Override
public boolean equals(Object obj) {
if(obj instanceof SrtpCryptoSuite && obj != null)
return suite.equals(((SrtpCryptoSuite)obj).suite);
return false;
}
@Override
public int hashCode() {
return suite.hashCode();
}
}
sdes4j-1.1.4/src/main/java/ch/imvs/sdes4j/srtp/SrtpKeyParam.java 0000664 0000000 0000000 00000012573 12756343045 0024347 0 ustar 00root root 0000000 0000000 /*
* SDES4J
* Java implementation of SDES (Security Descriptions for Media Streams,
* RFC 4568).
*
* Copyright (C) 2011 FHNW
* University of Applied Sciences Northwestern Switzerland (FHNW)
* School of Engineering
* Institute of Mobile and Distributed Systems (IMVS)
* http://sdes4j.imvs.ch
*
* Distributable under LGPL license, see terms of license at gnu.org.
*/
package ch.imvs.sdes4j.srtp;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.StringUtils;
import ch.imvs.sdes4j.KeyParam;
/**
* SRTP security descriptions define the use of the "inline" key method. Use of
* any other keying method (e.g., URL) for SRTP security descriptions is for
* further study.
*
* The "inline" type of key contains the keying material (master key and salt)
* and all policy related to that master key, including how long it can be used
* (lifetime) and whether it uses a master key identifier (MKI) to associate an
* incoming SRTP packet with a particular master key.
*
* @author Ingo Bauersachs
*
*/
public class SrtpKeyParam implements KeyParam {
/**
* Constant for the inline
key method.
*/
public final static String KEYMETHOD_INLINE = "inline";
private final String keyMethod = KEYMETHOD_INLINE;
private byte[] key;
private int lifetime;
private int mki;
private int mkiLength;
/**
* Creates a new instance of this class from known parameters.
*
* @param keyMethod The key method for this key parameter. Only
* {@value #KEYMETHOD_INLINE} is currently supported.
* @param key Concatenated master key and salt; MUST be a unique
* cryptographically random value with respect to other master
* keys in the entire SDP message (i.e., including master keys
* for other streams)
* @param lifetime The master key lifetime (max number of SRTP or SRTCP packets
* using this master key)
* @param mki The master key identifier in the SRTP packets.
* @param mkiLength Length of the MKI field in SRTP packets.
*/
public SrtpKeyParam(String keyMethod, byte[] key, int lifetime, int mki, int mkiLength) {
if (!keyMethod.equals(KEYMETHOD_INLINE))
throw new IllegalArgumentException("key method must be inline");
if (mkiLength < 0 || mkiLength > 128)
throw new IllegalArgumentException("mki length must be in range 1..128 inclusive or 0 to indicate default");
this.key = key;
this.lifetime = lifetime;
this.mki = mki;
this.mkiLength = mkiLength;
}
/**
* Creates a new instance of this class from the textual representation.
*
* @param keyParam The textual representation of the key parameter.
*/
public SrtpKeyParam(String keyParam) {
if (!keyParam.startsWith(keyMethod + ":"))
throw new IllegalArgumentException("Unknown key method in <" + keyParam + ">");
keyParam = keyParam.substring(KEYMETHOD_INLINE.length() + 1);
String[] parts = keyParam.split("\\|");
key = Base64.decodeBase64(parts[0]);
if(key.length == 0)
throw new IllegalArgumentException("key must be present");
int partIndex = 1;
if (parts.length > 1 && !parts[1].contains(":")) {
if(parts[1].startsWith("2^"))
lifetime = (int)Math.pow(2, Double.valueOf(parts[1].substring(2)));
else
lifetime = Integer.valueOf(parts[1]);
partIndex++;
}
if (parts.length > partIndex && parts[partIndex].contains(":")) {
String[] mkiParts = parts[partIndex].split(":");
mki = Integer.valueOf(mkiParts[0]);
mkiLength = Integer.valueOf(mkiParts[1]);
if (mkiLength < 1 || mkiLength > 128)
throw new IllegalArgumentException("mki length must be in range 1..128 inclusive");
}
}
/**
* The key method for this key parameter.
* @return {@value #KEYMETHOD_INLINE}
*/
@Override
public String getKeyMethod() {
return keyMethod;
}
/**
* Gets the concatenated master key and salt.
* @return the concatenated master key and salt.
*/
public byte[] getKey() {
return key;
}
/**
* Gets the master key lifetime (max number of SRTP or SRTCP packets using
* this master key)
*
* @return The master key lifetime.
*/
public int getLifetime() {
return lifetime;
}
/**
* Gets the master key identifier in the SRTP packets.
* @return The master key identifier in the SRTP packets.
*/
public int getMki() {
return mki;
}
/**
* Gets the length of the MKI field in SRTP packets
* @return The length of the MKI field in SRTP packets.
*/
public int getMkiLength() {
return mkiLength;
}
@Override
public String encode() {
StringBuilder sb = new StringBuilder();
sb.append(keyMethod);
sb.append(':');
sb.append(StringUtils.newStringUtf8(Base64.encodeBase64(key, false)));
if (lifetime > 0) {
sb.append('|');
sb.append(lifetime);
}
if (mkiLength > 0) {
sb.append('|');
sb.append(mki);
sb.append(':');
sb.append(mkiLength);
}
return sb.toString();
}
}
sdes4j-1.1.4/src/main/java/ch/imvs/sdes4j/srtp/SrtpSDesFactory.java 0000664 0000000 0000000 00000006677 12756343045 0025034 0 ustar 00root root 0000000 0000000 /*
* SDES4J
* Java implementation of SDES (Security Descriptions for Media Streams,
* RFC 4568).
*
* Copyright (C) 2011 FHNW
* University of Applied Sciences Northwestern Switzerland (FHNW)
* School of Engineering
* Institute of Mobile and Distributed Systems (IMVS)
* http://sdes4j.imvs.ch
*
* Distributable under LGPL license, see terms of license at gnu.org.
*/
package ch.imvs.sdes4j.srtp;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Random;
import ch.imvs.sdes4j.*;
/**
* Factory for the SRTP grammar of RFC4568.
*
* @author Ingo Bauersachs
*/
public class SrtpSDesFactory implements SDesFactory {
private Random r = null;
/**
* Creates an SRTP crypto attribute with the specified parameters, for use in an SDP.
* * If no random generator is set with {@link #setRandomGenerator(Random)} then the * SHA1PRNG, or if not available, the system's default {@link SecureRandom} will be used. * * @param tag decimal number used as an identifier for a particular crypto attribute * @param keyAlg identifier that describes the encryption and authentication algorithms * @return SRTP crypto attribute without session parameters. */ public SrtpCryptoAttribute createCryptoAttribute(int tag, String keyAlg) { return createCryptoAttribute(tag, keyAlg, null); } /** * Creates an SRTP crypto attribute with the specified parameters, for use in an SDP. * * @param tag decimal number used as an identifier for a particular crypto attribute * @param keyAlg identifier that describes the encryption and authentication algorithms * @param params Session parameters for the crypto attribute * @return SRTP crypto attribute without session parameters. */ public SrtpCryptoAttribute createCryptoAttribute(int tag, String keyAlg, SrtpSessionParam[] params) { SrtpCryptoSuite suite = createCryptoSuite(keyAlg); byte[] keyData = new byte[(suite.getEncKeyLength() + suite.getSaltKeyLength()) / 8]; getRandom().nextBytes(keyData); SrtpKeyParam key = new SrtpKeyParam( SrtpKeyParam.KEYMETHOD_INLINE, keyData, 0, 0, 0 ); return new SrtpCryptoAttribute(tag, suite, new SrtpKeyParam[] { key }, params); } private Random getRandom(){ if(r == null){ try { r = SecureRandom.getInstance("SHA1PRNG"); } catch (NoSuchAlgorithmException e) { r = new SecureRandom(); } } return r; } @Override public void setRandomGenerator(Random r) { this.r = r; } @Override public SrtpCryptoAttribute createCryptoAttribute() { return new SrtpCryptoAttribute(); } @Override public SrtpCryptoSuite createCryptoSuite(String suite) { return new SrtpCryptoSuite(suite); } @Override public SrtpKeyParam createKeyParam(String keyParam) { return new SrtpKeyParam(keyParam); } @Override public SrtpKeyParam[] createKeyParamArray(int size) { return new SrtpKeyParam[size]; } @Override public SrtpSessionParam createSessionParam(String sessionParam) { return SrtpSessionParam.create(sessionParam); } @Override public SrtpSessionParam[] createSessionParamArray(int size) { return new SrtpSessionParam[size]; } } sdes4j-1.1.4/src/main/java/ch/imvs/sdes4j/srtp/SrtpSessionParam.java 0000664 0000000 0000000 00000003243 12756343045 0025234 0 ustar 00root root 0000000 0000000 /* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j.srtp; import ch.imvs.sdes4j.SessionParam; /** * Base class for SRTP specific session parameters. * * @author Ingo Bauersachs */ public abstract class SrtpSessionParam implements SessionParam { SrtpSessionParam() { } /** * Creates instances from the text based representation of SRTP session parameters. * * @param param The text based representation of a session parameter. * @return The instance of a SRTP session parameter. */ public static SrtpSessionParam create(String param) { if (param.startsWith("KDR=")) return new KdrSessionParam(param); else if (param.equals("UNENCRYPTED_SRTP")) return new PlainSrtpSessionParam(); else if (param.equals("UNENCRYPTED_SRTCP")) return new PlainSrtcpSessionParam(); else if (param.equals("UNAUTHENTICATED_SRTP")) return new NoAuthSessionParam(); else if (param.startsWith("FEC_ORDER=")) return new FecOrderSessionParam(param); else if (param.startsWith("FEC_KEY=")) return new FecKeySessionParam(param); else if (param.startsWith("WSH=")) return new WshSessionParam(param); throw new IllegalArgumentException("Unknown session parameter"); } } sdes4j-1.1.4/src/main/java/ch/imvs/sdes4j/srtp/WshSessionParam.java 0000664 0000000 0000000 00000003414 12756343045 0025045 0 ustar 00root root 0000000 0000000 /* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j.srtp; /** * SRTP defines the SRTP-WINDOW-SIZE [RFC3711, Section 3.3.2] parameter to * protect against replay attacks. The Window Size Hint (WSH) session parameter * provides a hint for how big this window should be to work satisfactorily. * * The minimum value is 64 [RFC3711]; however, this value may be considered too * low for some applications (e.g., video). * * @author Ingo Bauersachs */ public class WshSessionParam extends SrtpSessionParam { private int wsh; /** * Creates a new instance of this class from an integer. * * @param wsh The size of the window hint. */ public WshSessionParam(int wsh) { if (wsh < 64) throw new IllegalArgumentException("Minimum size is 64"); this.wsh = wsh; } /** * Creates a new instance of this class from the textual representation. * * @param param The textual representation of the WSH parameter. */ public WshSessionParam(String param) { wsh = Integer.valueOf(param.split("=")[1]); if (wsh < 64) throw new IllegalArgumentException("Minimum size is 64"); } /** * Gets the size of the window hint. * * @return the size of the window hint. */ public int getWindowSizeHint() { return wsh; } @Override public String encode() { return "WSH=" + wsh; } } sdes4j-1.1.4/src/test/ 0000775 0000000 0000000 00000000000 12756343045 0014470 5 ustar 00root root 0000000 0000000 sdes4j-1.1.4/src/test/java/ 0000775 0000000 0000000 00000000000 12756343045 0015411 5 ustar 00root root 0000000 0000000 sdes4j-1.1.4/src/test/java/AllTests.java 0000664 0000000 0000000 00000003033 12756343045 0020006 0 ustar 00root root 0000000 0000000 /* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ import org.junit.runner.RunWith; import org.junit.runners.Suite; import ch.imvs.sdes4j.CryptoAttributeTest; import ch.imvs.sdes4j.srtp.FecKeySessionParamTest; import ch.imvs.sdes4j.srtp.FecOrderSessionParamTest; import ch.imvs.sdes4j.srtp.KdrSessionParamTest; import ch.imvs.sdes4j.srtp.NoAuthSessionParamTest; import ch.imvs.sdes4j.srtp.PlainSrtcpSessionParamTest; import ch.imvs.sdes4j.srtp.PlainSrtpSessionParamTest; import ch.imvs.sdes4j.srtp.SrtpCryptoSuiteTest; import ch.imvs.sdes4j.srtp.SrtpKeyParamTest; import ch.imvs.sdes4j.srtp.WshSessionParamTest; @RunWith(Suite.class) @Suite.SuiteClasses({ FecKeySessionParamTest.class, FecOrderSessionParamTest.class, KdrSessionParamTest.class, NoAuthSessionParamTest.class, PlainSrtcpSessionParamTest.class, PlainSrtpSessionParamTest.class, SrtpCryptoSuiteTest.class, SrtpKeyParamTest.class, WshSessionParamTest.class, CryptoAttributeTest.class }) public class AllTests { // the class remains completely empty, // being used only as a holder for the above annotations public static void main(String args[]) { org.junit.runner.JUnitCore.main("AllTests"); } } sdes4j-1.1.4/src/test/java/ch/ 0000775 0000000 0000000 00000000000 12756343045 0016003 5 ustar 00root root 0000000 0000000 sdes4j-1.1.4/src/test/java/ch/imvs/ 0000775 0000000 0000000 00000000000 12756343045 0016761 5 ustar 00root root 0000000 0000000 sdes4j-1.1.4/src/test/java/ch/imvs/sdes4j/ 0000775 0000000 0000000 00000000000 12756343045 0020155 5 ustar 00root root 0000000 0000000 sdes4j-1.1.4/src/test/java/ch/imvs/sdes4j/CryptoAttributeTest.java 0000664 0000000 0000000 00000030601 12756343045 0025024 0 ustar 00root root 0000000 0000000 /* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j; import static org.junit.Assert.*; import org.junit.Before; import org.junit.Test; import ch.imvs.sdes4j.srtp.FecOrderSessionParam; import ch.imvs.sdes4j.srtp.NoAuthSessionParam; import ch.imvs.sdes4j.srtp.SrtpCryptoSuite; import ch.imvs.sdes4j.srtp.SrtpKeyParam; import ch.imvs.sdes4j.srtp.SrtpSDesFactory; public class CryptoAttributeTest { private SrtpSDesFactory f; @Before public void setUp() { f = new SrtpSDesFactory(); } @Test public void testEncodeSessionParamsString() { byte[] bkey = new byte[]{0}; SrtpCryptoSuite suite = f.createCryptoSuite(SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_80); SrtpKeyParam key = new SrtpKeyParam( SrtpKeyParam.KEYMETHOD_INLINE, bkey, 0, 0, 0 ); CryptoAttribute a = new CryptoAttribute( 1, suite, new KeyParam[] { key }, new SessionParam[] { new FecOrderSessionParam(FecOrderSessionParam.FEC_SRTP), new NoAuthSessionParam() } ); assertEquals(2, a.getSessionParams().length); assertEquals("FEC_ORDER=FEC_SRTP UNAUTHENTICATED_SRTP", a.getSessionParamsString()); } @Test public void testEncodeKeyParamsString() { byte[] bkey = new byte[]{0}; SrtpCryptoSuite suite = f.createCryptoSuite(SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_80); SrtpKeyParam key = new SrtpKeyParam( SrtpKeyParam.KEYMETHOD_INLINE, bkey, 0, 0, 0 ); CryptoAttribute a = new CryptoAttribute( 1, suite, new KeyParam[] { key, key }, null ); assertEquals(2, a.getKeyParams().length); assertEquals("inline:AA==;inline:AA==", a.getKeyParamsString()); assertEquals(0, a.getSessionParams().length); } @Test public void testParseMultipleKeyParams() { CryptoAttribute a = CryptoAttribute.create("1 AES_CM_128_HMAC_SHA1_80 inline:AA==|2^20|1:4;inline:AA==;inline:AA==|1024", f); assertEquals(3, a.getKeyParams().length); SrtpKeyParam kp1 = (SrtpKeyParam) a.getKeyParams()[0]; assertEquals(SrtpKeyParam.KEYMETHOD_INLINE, kp1.getKeyMethod()); assertEquals(0x100000, kp1.getLifetime()); assertEquals(1, kp1.getMki()); assertEquals(4, kp1.getMkiLength()); SrtpKeyParam kp2 = (SrtpKeyParam) a.getKeyParams()[1]; assertEquals(SrtpKeyParam.KEYMETHOD_INLINE, kp2.getKeyMethod()); assertEquals(0, kp2.getLifetime()); assertEquals(0, kp2.getMki()); assertEquals(0, kp2.getMkiLength()); SrtpKeyParam kp3 = (SrtpKeyParam) a.getKeyParams()[2]; assertEquals(SrtpKeyParam.KEYMETHOD_INLINE, kp3.getKeyMethod()); assertEquals(1024, kp3.getLifetime()); assertEquals(0, kp3.getMki()); assertEquals(0, kp3.getMkiLength()); assertEquals("inline:AA==|1048576|1:4;inline:AA==;inline:AA==|1024", a.getKeyParamsString()); } @Test public void testParseExample1() { CryptoAttribute a = CryptoAttribute.create("1 AES_CM_128_HMAC_SHA1_80 inline:WVNfX19zZW1jdGwgKCkgewkyMjA7fQp9CnVubGVz|2^20|1:4 FEC_ORDER=FEC_SRTP", f); validateExample2(a); } @Test(expected=IllegalArgumentException.class) public void testParseWithoutKeyParameter() { new CryptoAttribute(1, new SrtpCryptoSuite(SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_80), null, null); } @Test(expected=IllegalArgumentException.class) public void testParseWithoutKeyParameterString() { CryptoAttribute.create("1 AES_CM_128_HMAC_SHA1_80", f); } @Test(expected=IllegalArgumentException.class) public void testParseWithTagAboveLimitString() { CryptoAttribute.create("1234567890 AES_CM_128_HMAC_SHA1_80", f); } @Test(expected=IllegalArgumentException.class) public void testParseWithTagBelowLimitString() { CryptoAttribute.create("-1 AES_CM_128_HMAC_SHA1_80", f); } @Test(expected=IllegalArgumentException.class) public void testParseWithTagAboveLimit() { new CryptoAttribute(1234567890, null, null, null); } @Test(expected=IllegalArgumentException.class) public void testParseWithTagBelowLimit() { new CryptoAttribute(-1, null, null, null); } @Test(expected=IllegalArgumentException.class) public void testParseWithoutCryptoSuite() { new CryptoAttribute(1, null, null, null); } @Test public void testParseExample1Xmpp() { CryptoAttribute a = CryptoAttribute.create("1", "AES_CM_128_HMAC_SHA1_80", "inline:WVNfX19zZW1jdGwgKCkgewkyMjA7fQp9CnVubGVz|2^20|1:4", "FEC_ORDER=FEC_SRTP", f); validateExample2(a); } private void validateExample2(CryptoAttribute a) { assertEquals(1, a.getTag()); assertEquals(SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_80, a.getCryptoSuite().encode()); assertEquals(1, a.getKeyParams().length); SrtpKeyParam kp = (SrtpKeyParam) a.getKeyParams()[0]; assertEquals(SrtpKeyParam.KEYMETHOD_INLINE, kp.getKeyMethod()); assertEquals(0x100000, kp.getLifetime()); assertEquals(1, kp.getMki()); assertEquals(4, kp.getMkiLength()); assertEquals(1, a.getSessionParams().length); assertEquals(FecOrderSessionParam.FEC_SRTP, ((FecOrderSessionParam) a.getSessionParams()[0]).getMode()); assertEquals("FEC_ORDER=FEC_SRTP", a.getSessionParamsString()); } @Test public void testParseExample2() { CryptoAttribute a = CryptoAttribute.create("2 F8_128_HMAC_SHA1_80 inline:MTIzNDU2Nzg5QUJDREUwMTIzNDU2Nzg5QUJjZGVm|2^20|1:4;inline:QUJjZGVmMTIzNDU2Nzg5QUJDREUwMTIzNDU2Nzg5|2^20|2:4\t\tFEC_ORDER=FEC_SRTP", f); assertEquals(2, a.getTag()); assertEquals(SrtpCryptoSuite.F8_128_HMAC_SHA1_80, a.getCryptoSuite().encode()); assertEquals(2, a.getKeyParams().length); SrtpKeyParam kp1 = (SrtpKeyParam) a.getKeyParams()[0]; assertEquals(SrtpKeyParam.KEYMETHOD_INLINE, kp1.getKeyMethod()); assertEquals(0x100000, kp1.getLifetime()); assertEquals(1, kp1.getMki()); assertEquals(4, kp1.getMkiLength()); assertEquals(1, ((SrtpKeyParam) a.getKeyParams()[0]).getMki()); assertEquals(2, ((SrtpKeyParam) a.getKeyParams()[1]).getMki()); assertEquals(1, a.getSessionParams().length); assertEquals(FecOrderSessionParam.FEC_SRTP, ((FecOrderSessionParam) a.getSessionParams()[0]).getMode()); assertEquals("2 F8_128_HMAC_SHA1_80 inline:MTIzNDU2Nzg5QUJDREUwMTIzNDU2Nzg5QUJjZGVm|1048576|1:4;inline:QUJjZGVmMTIzNDU2Nzg5QUJDREUwMTIzNDU2Nzg5|1048576|2:4 FEC_ORDER=FEC_SRTP", a.encode()); } @Test public void testParseExample3() { CryptoAttribute a = CryptoAttribute.create("1 AES_CM_128_HMAC_SHA1_80 inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4", f); validateExample3(a); } @Test public void testParseExample3Xmpp() { CryptoAttribute a = CryptoAttribute.create("1", "AES_CM_128_HMAC_SHA1_80", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4", null, f); validateExample3(a); } @Test public void testParseExample3bXmpp() { CryptoAttribute a = CryptoAttribute.create("1", "AES_CM_128_HMAC_SHA1_80", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4", "", f); validateExample3(a); } private void validateExample3(CryptoAttribute a) { assertEquals(1, a.getTag()); assertEquals(SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_80, a.getCryptoSuite().encode()); assertEquals(1, a.getKeyParams().length); SrtpKeyParam kp = (SrtpKeyParam) a.getKeyParams()[0]; assertEquals(SrtpKeyParam.KEYMETHOD_INLINE, kp.getKeyMethod()); assertEquals(0x100000, kp.getLifetime()); assertEquals(1, kp.getMki()); assertEquals(4, kp.getMkiLength()); assertEquals(0, a.getSessionParams().length); assertEquals("inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|1048576|1:4", a.getKeyParamsString()); assertEquals(null, a.getSessionParamsString()); } @Test public void testCreateAttribute() { byte[] bkey = new byte[]{0}; SrtpCryptoSuite suite = f.createCryptoSuite(SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_80); SrtpKeyParam key = new SrtpKeyParam( SrtpKeyParam.KEYMETHOD_INLINE, bkey, 0, 0, 0 ); CryptoAttribute a = new CryptoAttribute(1, suite, new KeyParam[] { key }, null); assertEquals("1 AES_CM_128_HMAC_SHA1_80 inline:AA==", a.encode()); assertEquals(0, a.getSessionParams().length); } @Test public void testEquals() { CryptoAttribute a = CryptoAttribute.create("1", "AES_CM_128_HMAC_SHA1_80", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4", "", f); CryptoAttribute b = CryptoAttribute.create("1", "AES_CM_128_HMAC_SHA1_80", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4", "", f); CryptoAttribute c = CryptoAttribute.create("2", "AES_CM_128_HMAC_SHA1_80", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4", "", f); CryptoAttribute d = CryptoAttribute.create("1", "AES_CM_128_HMAC_SHA1_32", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4", "", f); CryptoAttribute e = CryptoAttribute.create("1", "AES_CM_128_HMAC_SHA1_80", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^21|1:4", "", f); CryptoAttribute g = CryptoAttribute.create("1", "AES_CM_128_HMAC_SHA1_80", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4", "FEC_ORDER=FEC_SRTP", f); CryptoAttribute h = CryptoAttribute.create("1", "AES_CM_128_HMAC_SHA1_80", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4", "FEC_ORDER=FEC_SRTP", f); CryptoAttribute i = CryptoAttribute.create("1", "AES_CM_128_HMAC_SHA1_80", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR", "FEC_ORDER=FEC_SRTP", f); assertEquals(a, b); assertEquals(g, h); assertNotEquals(a, c); assertNotEquals(a, d); assertNotEquals(a, e); assertNotEquals(a, g); assertNotEquals(a, h); assertNotEquals(a, i); assertNotEquals(d, e); assertNotEquals(h, i); } @Test public void testHashcode() { CryptoAttribute a = CryptoAttribute.create("1", "AES_CM_128_HMAC_SHA1_80", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4", "", f); CryptoAttribute b = CryptoAttribute.create("1", "AES_CM_128_HMAC_SHA1_80", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4", "", f); CryptoAttribute c = CryptoAttribute.create("2", "AES_CM_128_HMAC_SHA1_80", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4", "", f); CryptoAttribute d = CryptoAttribute.create("1", "AES_CM_128_HMAC_SHA1_32", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4", "", f); CryptoAttribute e = CryptoAttribute.create("1", "AES_CM_128_HMAC_SHA1_80", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^21|1:4", "", f); CryptoAttribute g = CryptoAttribute.create("1", "AES_CM_128_HMAC_SHA1_80", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4", "FEC_ORDER=FEC_SRTP", f); CryptoAttribute h = CryptoAttribute.create("1", "AES_CM_128_HMAC_SHA1_80", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4", "FEC_ORDER=FEC_SRTP", f); CryptoAttribute i = CryptoAttribute.create("1", "AES_CM_128_HMAC_SHA1_80", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR", "FEC_ORDER=FEC_SRTP", f); assertEquals(a.hashCode(), b.hashCode()); assertEquals(g.hashCode(), h.hashCode()); assertNotEquals(a.hashCode(), c.hashCode()); assertNotEquals(a.hashCode(), d.hashCode()); assertNotEquals(a.hashCode(), e.hashCode()); assertNotEquals(a.hashCode(), g.hashCode()); assertNotEquals(a.hashCode(), h.hashCode()); assertNotEquals(a.hashCode(), i.hashCode()); assertNotEquals(d.hashCode(), e.hashCode()); assertNotEquals(h.hashCode(), i.hashCode()); } } sdes4j-1.1.4/src/test/java/ch/imvs/sdes4j/srtp/ 0000775 0000000 0000000 00000000000 12756343045 0021145 5 ustar 00root root 0000000 0000000 sdes4j-1.1.4/src/test/java/ch/imvs/sdes4j/srtp/FecKeySessionParamTest.java 0000664 0000000 0000000 00000005770 12756343045 0026354 0 ustar 00root root 0000000 0000000 /* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j.srtp; import static org.junit.Assert.*; import org.junit.Before; import org.junit.Test; public class FecKeySessionParamTest { private SrtpKeyParam kp1; private SrtpKeyParam kp2; @Before public void setUp() { kp1 = new SrtpKeyParam(SrtpKeyParam.KEYMETHOD_INLINE, new byte[0], 0, 0, 0){ @Override public String encode() { return "KP1"; } }; kp2 = new SrtpKeyParam(SrtpKeyParam.KEYMETHOD_INLINE, new byte[0], 0, 0, 0){ @Override public String encode() { return "KP2"; } }; } @Test public void testFecKeySessionParamSrtpKeyParamArray() { FecKeySessionParam fecOne = new FecKeySessionParam(new SrtpKeyParam[] { kp1 }); assertEquals("FEC_KEY=KP1", fecOne.encode()); FecKeySessionParam fecTwo = new FecKeySessionParam(new SrtpKeyParam[] { kp1, kp2 }); assertEquals("FEC_KEY=KP1;KP2", fecTwo.encode()); } @Test public void testFecKeySessionParamString() { String oneKeyParam = "FEC_KEY=KP1"; FecKeySessionParam fecKeyOne = new FecKeySessionParam(oneKeyParam){ @Override protected SrtpKeyParam createSrtpKeyParam(final String p) { SrtpKeyParam kp = new SrtpKeyParam(SrtpKeyParam.KEYMETHOD_INLINE, new byte[0], 0, 0, 0){ @Override public String encode() { return p; } }; return kp; } }; assertEquals(1, fecKeyOne.getKeyParams().length); assertEquals(oneKeyParam, fecKeyOne.encode()); String twoKeyParam = "FEC_KEY=KP1;KP2"; FecKeySessionParam fecKeyTwo = new FecKeySessionParam(twoKeyParam){ @Override protected SrtpKeyParam createSrtpKeyParam(final String p) { SrtpKeyParam kp = new SrtpKeyParam(SrtpKeyParam.KEYMETHOD_INLINE, new byte[0], 0, 0, 0){ @Override public String encode() { return p; } }; return kp; } }; assertEquals(2, fecKeyTwo.getKeyParams().length); assertEquals(twoKeyParam, fecKeyTwo.encode()); } @Test public void testGetKeyParams() { FecKeySessionParam fecTwo = new FecKeySessionParam(new SrtpKeyParam[] { kp1, kp2 }); assertEquals(2, fecTwo.getKeyParams().length); assertEquals(kp1, fecTwo.getKeyParams()[0]); assertEquals(kp2, fecTwo.getKeyParams()[1]); } } sdes4j-1.1.4/src/test/java/ch/imvs/sdes4j/srtp/FecOrderSessionParamTest.java 0000664 0000000 0000000 00000003147 12756343045 0026673 0 ustar 00root root 0000000 0000000 /* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j.srtp; import static org.junit.Assert.*; import org.junit.Test; public class FecOrderSessionParamTest { @Test public void testFecOrderSessionParamInt() { FecOrderSessionParam fecSrtp = new FecOrderSessionParam(FecOrderSessionParam.FEC_SRTP); assertEquals(FecOrderSessionParam.FEC_SRTP, fecSrtp.getMode()); FecOrderSessionParam srtpFec = new FecOrderSessionParam(FecOrderSessionParam.SRTP_FEC); assertEquals(FecOrderSessionParam.SRTP_FEC, srtpFec.getMode()); } @Test(expected=IllegalArgumentException.class) public void testFecOrderSessionParamIntInvalid() { new FecOrderSessionParam(3); } @Test public void testFecOrderSessionParamString() { String input1 = "FEC_ORDER=FEC_SRTP"; FecOrderSessionParam fecSrtp = new FecOrderSessionParam(input1); assertEquals(FecOrderSessionParam.FEC_SRTP, fecSrtp.getMode()); assertEquals(input1, fecSrtp.encode()); String input2 = "FEC_ORDER=SRTP_FEC"; FecOrderSessionParam srtpFec = new FecOrderSessionParam(FecOrderSessionParam.SRTP_FEC); assertEquals(FecOrderSessionParam.SRTP_FEC, srtpFec.getMode()); assertEquals(input2, srtpFec.encode()); } } sdes4j-1.1.4/src/test/java/ch/imvs/sdes4j/srtp/KdrSessionParamTest.java 0000664 0000000 0000000 00000005177 12756343045 0025727 0 ustar 00root root 0000000 0000000 /* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j.srtp; import static org.junit.Assert.*; import org.junit.Test; public class KdrSessionParamTest { @Test public void testKdrSessionParamInt() { KdrSessionParam kdr0 = new KdrSessionParam(0); assertEquals(0, kdr0.getKeyDerivationRate()); assertEquals(1, kdr0.getKeyDerivationRateExpanded()); assertEquals("KDR=0", kdr0.encode()); KdrSessionParam kdr1 = new KdrSessionParam(1); assertEquals(1, kdr1.getKeyDerivationRate()); assertEquals(2, kdr1.getKeyDerivationRateExpanded()); assertEquals("KDR=1", kdr1.encode()); KdrSessionParam kdr24 = new KdrSessionParam(24); assertEquals(24, kdr24.getKeyDerivationRate()); assertEquals(0x1000000, kdr24.getKeyDerivationRateExpanded()); assertEquals("KDR=24", kdr24.encode()); } @Test(expected=IllegalArgumentException.class) public void testKdrSessionParamIntInvalidLower() { new KdrSessionParam(-1); } @Test(expected=IllegalArgumentException.class) public void testKdrSessionParamIntInvalidUpper() { new KdrSessionParam(25); } @Test public void testKdrSessionParamString() { String input0 = "KDR=0"; KdrSessionParam kdr0 = new KdrSessionParam(input0); assertEquals(0, kdr0.getKeyDerivationRate()); assertEquals(1, kdr0.getKeyDerivationRateExpanded()); assertEquals(input0, kdr0.encode()); String input1 = "KDR=1"; KdrSessionParam kdr1 = new KdrSessionParam(input1); assertEquals(1, kdr1.getKeyDerivationRate()); assertEquals(2, kdr1.getKeyDerivationRateExpanded()); assertEquals(input1, kdr1.encode()); String input24 = "KDR=24"; KdrSessionParam kdr24 = new KdrSessionParam(input24); assertEquals(24, kdr24.getKeyDerivationRate()); assertEquals(0x1000000, kdr24.getKeyDerivationRateExpanded()); assertEquals(input24, kdr24.encode()); } @Test(expected=IllegalArgumentException.class) public void testKdrSessionParamStringInvalidLower() { new KdrSessionParam("KDR=-1"); } @Test(expected=IllegalArgumentException.class) public void testKdrSessionParamStringInvalidUpper() { new KdrSessionParam("KDR=25"); } } sdes4j-1.1.4/src/test/java/ch/imvs/sdes4j/srtp/NoAuthSessionParamTest.java 0000664 0000000 0000000 00000001210 12756343045 0026365 0 ustar 00root root 0000000 0000000 /* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j.srtp; import static org.junit.Assert.*; import org.junit.Test; public class NoAuthSessionParamTest { @Test public void testToString() { assertEquals("UNAUTHENTICATED_SRTP", new NoAuthSessionParam().encode()); } } sdes4j-1.1.4/src/test/java/ch/imvs/sdes4j/srtp/PlainSrtcpSessionParamTest.java 0000664 0000000 0000000 00000001215 12756343045 0027253 0 ustar 00root root 0000000 0000000 /* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j.srtp; import static org.junit.Assert.*; import org.junit.Test; public class PlainSrtcpSessionParamTest { @Test public void testToString() { assertEquals("UNENCRYPTED_SRTCP", new PlainSrtcpSessionParam().encode()); } } sdes4j-1.1.4/src/test/java/ch/imvs/sdes4j/srtp/PlainSrtpSessionParamTest.java 0000664 0000000 0000000 00000001212 12756343045 0027105 0 ustar 00root root 0000000 0000000 /* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j.srtp; import static org.junit.Assert.*; import org.junit.Test; public class PlainSrtpSessionParamTest { @Test public void testToString() { assertEquals("UNENCRYPTED_SRTP", new PlainSrtpSessionParam().encode()); } } sdes4j-1.1.4/src/test/java/ch/imvs/sdes4j/srtp/SrtpCryptoAttributeTest.java 0000664 0000000 0000000 00000002207 12756343045 0026666 0 ustar 00root root 0000000 0000000 /* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j.srtp; import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; public class SrtpCryptoAttributeTest { private SrtpSDesFactory f; @Before public void setUp() { f = new SrtpSDesFactory(); } @Test public void testGetSessionParams(){ byte[] bkey = new byte[]{0}; SrtpCryptoSuite suite = f.createCryptoSuite(SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_80); SrtpKeyParam key = new SrtpKeyParam( SrtpKeyParam.KEYMETHOD_INLINE, bkey, 0, 0, 0 ); SrtpCryptoAttribute ca = new SrtpCryptoAttribute(1, suite, new SrtpKeyParam[] { key }, null); assertEquals(0, ca.getSessionParams().length); } } sdes4j-1.1.4/src/test/java/ch/imvs/sdes4j/srtp/SrtpCryptoSuiteTest.java 0000664 0000000 0000000 00000001641 12756343045 0026015 0 ustar 00root root 0000000 0000000 /* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j.srtp; import static org.junit.Assert.*; import org.junit.Test; public class SrtpCryptoSuiteTest { @Test public void testToString() { assertEquals("AES_CM_128_HMAC_SHA1_80", new SrtpCryptoSuite(SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_80).encode()); } @Test(expected=IllegalArgumentException.class) public void testSrtpCryptoSuiteInvalid() { new SrtpCryptoSuite("invalid suite"); } // more tests would only duplicate the dumb behavior of the constructor... } sdes4j-1.1.4/src/test/java/ch/imvs/sdes4j/srtp/SrtpKeyParamTest.java 0000664 0000000 0000000 00000011653 12756343045 0025240 0 ustar 00root root 0000000 0000000 /* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j.srtp; import static org.junit.Assert.*; import org.junit.Test; public class SrtpKeyParamTest { @Test(expected=IllegalArgumentException.class) public void testSrtpKeyParamInvalidKeyMethod() { new SrtpKeyParam("invalid", null, 0, 0, 0); } @Test public void testSrtpKeyParamKeyOnly() { String input = "inline:YUJDZGVmZ2hpSktMbW9QUXJzVHVWd3l6MTIzNDU2"; SrtpKeyParam kp = new SrtpKeyParam(input); assertEquals(SrtpKeyParam.KEYMETHOD_INLINE, kp.getKeyMethod()); assertEquals(30, kp.getKey().length); assertEquals(0, kp.getLifetime()); assertEquals(0, kp.getMki()); assertEquals(0, kp.getMkiLength()); assertEquals(input, kp.encode()); } @Test public void testSrtpKeyParamKeyAndLifetimeNumeric() { String input = "inline:YUJDZGVmZ2hpSktMbW9QUXJzVHVWd3l6MTIzNDU2|1234"; SrtpKeyParam kp = new SrtpKeyParam(input); assertEquals(SrtpKeyParam.KEYMETHOD_INLINE, kp.getKeyMethod()); assertEquals(30, kp.getKey().length); assertEquals(1234, kp.getLifetime()); assertEquals(0, kp.getMki()); assertEquals(0, kp.getMkiLength()); assertEquals(input, kp.encode()); } @Test public void testSrtpKeyParamKeyAndLifetimeExponential() { String input = "inline:YUJDZGVmZ2hpSktMbW9QUXJzVHVWd3l6MTIzNDU2|2^10"; SrtpKeyParam kp = new SrtpKeyParam(input); assertEquals(SrtpKeyParam.KEYMETHOD_INLINE, kp.getKeyMethod()); assertEquals(30, kp.getKey().length); assertEquals(1024, kp.getLifetime()); assertEquals(0, kp.getMki()); assertEquals(0, kp.getMkiLength()); assertEquals("inline:YUJDZGVmZ2hpSktMbW9QUXJzVHVWd3l6MTIzNDU2|1024", kp.encode()); } @Test public void testSrtpKeyParamKeyAndMki() { String input = "inline:YUJDZGVmZ2hpSktMbW9QUXJzVHVWd3l6MTIzNDU2|1:128"; SrtpKeyParam kp = new SrtpKeyParam(input); assertEquals(SrtpKeyParam.KEYMETHOD_INLINE, kp.getKeyMethod()); assertEquals(30, kp.getKey().length); assertEquals(0, kp.getLifetime()); assertEquals(1, kp.getMki()); assertEquals(128, kp.getMkiLength()); assertEquals(input, kp.encode()); } @Test(expected=IllegalArgumentException.class) public void testSrtpKeyParamKeyAndMkiLower() { String input = "inline:YUJDZGVmZ2hpSktMbW9QUXJzVHVWd3l6MTIzNDU2|1:0"; new SrtpKeyParam(input); } @Test(expected=IllegalArgumentException.class) public void testSrtpKeyParamKeyAndMkiUpper() { String input = "inline:YUJDZGVmZ2hpSktMbW9QUXJzVHVWd3l6MTIzNDU2|1:129"; new SrtpKeyParam(input); } @Test(expected=IllegalArgumentException.class) public void testSrtpKeyParamKeyAndMkiInvalidNoMki() { String input = "inline:YUJDZGVmZ2hpSktMbW9QUXJzVHVWd3l6MTIzNDU2|:129"; new SrtpKeyParam(input); } @Test(expected=ArrayIndexOutOfBoundsException.class) public void testSrtpKeyParamKeyAndMkiInvalidNoMkiLength() { String input = "inline:YUJDZGVmZ2hpSktMbW9QUXJzVHVWd3l6MTIzNDU2|1:"; new SrtpKeyParam(input); } @Test(expected=IllegalArgumentException.class) public void testSrtpKeyParamKeyInvalidLifetime() { String input = "inline:YUJDZGVmZ2hpSktMbW9QUXJzVHVWd3l6MTIzNDU2||1:129"; new SrtpKeyParam(input); } @Test(expected=IllegalArgumentException.class) public void testSrtpKeyParamInvalidKey() { String input = "inline:{=="; new SrtpKeyParam(input); } @Test public void testSrtpKeyParamKeyAndLifetimeNumericAndMki() { String input = "inline:YUJDZGVmZ2hpSktMbW9QUXJzVHVWd3l6MTIzNDU2|1234|1:1"; SrtpKeyParam kp = new SrtpKeyParam(input); assertEquals(SrtpKeyParam.KEYMETHOD_INLINE, kp.getKeyMethod()); assertEquals(30, kp.getKey().length); assertEquals(1234, kp.getLifetime()); assertEquals(1, kp.getMki()); assertEquals(1, kp.getMkiLength()); assertEquals(input, kp.encode()); } @Test public void testSrtpKeyParamKeyAndLifetimeExponetialAndMki() { String input = "inline:YUJDZGVmZ2hpSktMbW9QUXJzVHVWd3l6MTIzNDU2|2^10|1:1"; SrtpKeyParam kp = new SrtpKeyParam(input); assertEquals(SrtpKeyParam.KEYMETHOD_INLINE, kp.getKeyMethod()); assertEquals(30, kp.getKey().length); assertEquals(1024, kp.getLifetime()); assertEquals(1, kp.getMki()); assertEquals(1, kp.getMkiLength()); assertEquals("inline:YUJDZGVmZ2hpSktMbW9QUXJzVHVWd3l6MTIzNDU2|1024|1:1", kp.encode()); } } sdes4j-1.1.4/src/test/java/ch/imvs/sdes4j/srtp/WshSessionParamTest.java 0000664 0000000 0000000 00000002353 12756343045 0025741 0 ustar 00root root 0000000 0000000 /* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j.srtp; import static org.junit.Assert.*; import org.junit.Test; public class WshSessionParamTest { @Test public void testWshSessionParamInt() { WshSessionParam wsh = new WshSessionParam(64); assertEquals(64, wsh.getWindowSizeHint()); assertEquals("WSH=64", wsh.encode()); } @Test(expected=IllegalArgumentException.class) public void testWshSessionParamIntLower() { new WshSessionParam(63); } @Test public void testWshSessionParamString() { String input = "WSH=64"; WshSessionParam wsh = new WshSessionParam(input); assertEquals(64, wsh.getWindowSizeHint()); assertEquals(input, wsh.encode()); } @Test(expected=IllegalArgumentException.class) public void testWshSessionParamStringLower() { new WshSessionParam("WSH=63"); } }