Skip to content

Commit

Permalink
Some code cleanup to use Java 7 language features
Browse files Browse the repository at this point in the history
  • Loading branch information
wernerd committed Jan 3, 2016
1 parent ad0203c commit 9afa895
Show file tree
Hide file tree
Showing 27 changed files with 277 additions and 307 deletions.
2 changes: 1 addition & 1 deletion build.xml
Expand Up @@ -109,7 +109,7 @@

<!-- Compile classes and store them to ${*-build.classes} -->
<target name="compile" depends="prepare">
<javac target="1.5" srcdir="${common-src}" destdir="${common-build.classes}" debug="on">
<javac source="1.7" target="1.7" srcdir="${common-src}" destdir="${common-build.classes}" debug="on">
<classpath refid="common.libraries"/>
</javac>
</target>
Expand Down
58 changes: 21 additions & 37 deletions src/gnu/java/zrtp/ZRtp.java
Expand Up @@ -19,46 +19,30 @@

package gnu.java.zrtp;

import djb.Curve25519;
import gnu.java.bigintcrypto.BigIntegerCrypto;
import gnu.java.zrtp.ZrtpConstants.SupportedSASTypes;
import gnu.java.zrtp.packets.ZrtpPacketBase;
import gnu.java.zrtp.packets.ZrtpPacketCommit;
import gnu.java.zrtp.packets.ZrtpPacketConf2Ack;
import gnu.java.zrtp.packets.ZrtpPacketConfirm;
import gnu.java.zrtp.packets.ZrtpPacketDHPart;
import gnu.java.zrtp.packets.ZrtpPacketError;
import gnu.java.zrtp.packets.ZrtpPacketErrorAck;
import gnu.java.zrtp.packets.ZrtpPacketHello;
import gnu.java.zrtp.packets.ZrtpPacketHelloAck;
import gnu.java.zrtp.packets.ZrtpPacketPingAck;
import gnu.java.zrtp.packets.ZrtpPacketPing;
import gnu.java.zrtp.packets.ZrtpPacketRelayAck;
import gnu.java.zrtp.packets.ZrtpPacketSASRelay;
import gnu.java.zrtp.packets.*;
import gnu.java.zrtp.utils.Base32;
import gnu.java.zrtp.utils.EmojiBase32;
import gnu.java.zrtp.utils.ZrtpUtils;
import gnu.java.zrtp.utils.ZrtpFortuna;
import gnu.java.zrtp.utils.ZrtpUtils;
import gnu.java.zrtp.zidfile.ZidFile;
import gnu.java.zrtp.zidfile.ZidRecord;

import java.util.EnumSet;
import java.util.Arrays;

import gnu.java.bigintcrypto.BigIntegerCrypto;

import org.bouncycastle.crypto.Digest;
import org.bouncycastle.crypto.digests.SHA256Digest;
import org.bouncycastle.crypto.digests.SHA384Digest;
import org.bouncycastle.crypto.macs.HMac;
import org.bouncycastle.crypto.params.KeyParameter;
import org.bouncycastle.crypto.params.ParametersWithIV;

import org.bouncycastle.cryptozrtp.AsymmetricCipherKeyPair;
import org.bouncycastle.cryptozrtp.params.DHPublicKeyParameters;
import org.bouncycastle.cryptozrtp.params.Djb25519PublicKeyParameters;
import org.bouncycastle.cryptozrtp.params.ECPublicKeyParameters;
import org.bouncycastle.mathzrtp.ec.ECPoint;

import java.util.Arrays;
import java.util.EnumSet;

/**
* The main ZRTP class.
*
Expand Down Expand Up @@ -1311,7 +1295,7 @@ private boolean fillPubKey() {

if (pubKey == ZrtpConstants.SupportedPubKeys.DH2K || pubKey == ZrtpConstants.SupportedPubKeys.DH3K) {

dhKeyPair = pubKey.dhKeyPairGen.generateKeyPair();
dhKeyPair = pubKey.keyPairGen.generateKeyPair();
pubKeyBytes = ((DHPublicKeyParameters) dhKeyPair.getPublic()).getY().toByteArray();

if (pubKeyBytes.length != pubKey.pubKeySize) {
Expand All @@ -1322,13 +1306,13 @@ private boolean fillPubKey() {
// Here produce the ECDH stuff
else if (pubKey == ZrtpConstants.SupportedPubKeys.EC25 || pubKey == ZrtpConstants.SupportedPubKeys.EC38) {

ecKeyPair = pubKey.ecKeyPairGen.generateKeyPair();
ecKeyPair = pubKey.keyPairGen.generateKeyPair();
byte[] encoded = ((ECPublicKeyParameters) ecKeyPair.getPublic()).getQ().getEncoded();
pubKeyBytes = new byte[pubKey.pubKeySize];
System.arraycopy(encoded, 1, pubKeyBytes, 0, pubKey.pubKeySize);
}
else if (pubKey == ZrtpConstants.SupportedPubKeys.E255) {
ecKeyPair = pubKey.ecKeyPairGen.generateKeyPair();
ecKeyPair = pubKey.keyPairGen.generateKeyPair();
pubKeyBytes = ((Djb25519PublicKeyParameters)ecKeyPair.getPublic()).getP();
}
else {
Expand Down Expand Up @@ -1596,18 +1580,18 @@ else if (pubKey == ZrtpConstants.SupportedPubKeys.EC25 || pubKey == ZrtpConstant
System.arraycopy(pvrBytes, 0, encoded, 1, pvrBytes.length);
ECPoint point = pubKey.curve.decodePoint(encoded);
dhSize = pubKey.pubKeySize / 2;
pubKey.ecdhContext.init(ecKeyPair.getPrivate());
BigIntegerCrypto bi = pubKey.ecdhContext.calculateAgreement(new ECPublicKeyParameters(point, null));
pubKey.dhContext.init(ecKeyPair.getPrivate());
BigIntegerCrypto bi = pubKey.dhContext.calculateAgreement(new ECPublicKeyParameters(point, null));
DHss = bi.toByteArray();
pubKey.ecdhContext.clear();
pubKey.dhContext.clear();
bi.zeroize(); // clear secret big integer data
}
else if (pubKey == ZrtpConstants.SupportedPubKeys.E255) {
dhSize = pubKey.pubKeySize;
pubKey.ecdhContext.init(ecKeyPair.getPrivate());
BigIntegerCrypto bi = pubKey.ecdhContext.calculateAgreement(new Djb25519PublicKeyParameters(pvrBytes));
pubKey.dhContext.init(ecKeyPair.getPrivate());
BigIntegerCrypto bi = pubKey.dhContext.calculateAgreement(new Djb25519PublicKeyParameters(pvrBytes));
DHss = bi.toByteArray();
pubKey.ecdhContext.clear();
pubKey.dhContext.clear();
bi.zeroize(); // clear secret big integer data
}
else {
Expand Down Expand Up @@ -1719,18 +1703,18 @@ else if (pubKey == ZrtpConstants.SupportedPubKeys.EC25 || pubKey == ZrtpConstant
System.arraycopy(pviBytes, 0, encoded, 1, pviBytes.length);
ECPoint pubPoint = pubKey.curve.decodePoint(encoded);
dhSize = pubKey.pubKeySize / 2;
pubKey.ecdhContext.init(ecKeyPair.getPrivate());
BigIntegerCrypto bi = pubKey.ecdhContext.calculateAgreement(new ECPublicKeyParameters(pubPoint, null));
pubKey.dhContext.init(ecKeyPair.getPrivate());
BigIntegerCrypto bi = pubKey.dhContext.calculateAgreement(new ECPublicKeyParameters(pubPoint, null));
DHss = bi.toByteArray();
pubKey.ecdhContext.clear();
pubKey.dhContext.clear();
bi.zeroize(); // clear secret big integer data
}
else if (pubKey == ZrtpConstants.SupportedPubKeys.E255) {
dhSize = pubKey.pubKeySize;
pubKey.ecdhContext.init(ecKeyPair.getPrivate());
BigIntegerCrypto bi = pubKey.ecdhContext.calculateAgreement(new Djb25519PublicKeyParameters(pviBytes));
pubKey.dhContext.init(ecKeyPair.getPrivate());
BigIntegerCrypto bi = pubKey.dhContext.calculateAgreement(new Djb25519PublicKeyParameters(pviBytes));
DHss = bi.toByteArray();
pubKey.ecdhContext.clear();
pubKey.dhContext.clear();
bi.zeroize(); // clear secret big integer data
}
else {
Expand Down
38 changes: 19 additions & 19 deletions src/gnu/java/zrtp/ZrtpCallback.java
Expand Up @@ -54,12 +54,12 @@ public interface ZrtpCallback {
* </li>
* </ul>
*/
public static enum Role {
enum Role {
Responder,
Initiator
}

public static enum EnableSecurity {
enum EnableSecurity {
ForReceiver,
ForSender
}
Expand All @@ -74,7 +74,7 @@ public static enum EnableSecurity {
* @return
* false if sending failed, true if packet was send
*/
public boolean sendDataZRTP(byte[] data);
boolean sendDataZRTP(byte[] data);

/**
* Activate timer.
Expand All @@ -84,15 +84,15 @@ public static enum EnableSecurity {
* @return
* zero if activation failed, one if timer was activated
*/
public int activateTimer(int time);
int activateTimer(int time);

/**
* Cancel the active timer.
*
* @return
* zero if cancel action failed, one if timer was canceled
*/
public int cancelTimer();
int cancelTimer();

/**
* Send information messages to the hosting environment.
Expand All @@ -106,9 +106,9 @@ public static enum EnableSecurity {
* This defines the message's severity
* @param subCode
* The subcode identifying the reason.
* @see gnu.java.zrtp.ZrtpCodes#MessageSeverity
* @see gnu.java.zrtp.ZrtpCodes.MessageSeverity
*/
public void sendInfo(ZrtpCodes.MessageSeverity severity, EnumSet<?> subCode);
void sendInfo(ZrtpCodes.MessageSeverity severity, EnumSet<?> subCode);

/**
* SRTP crypto data ready for the sender or receiver.
Expand Down Expand Up @@ -139,15 +139,15 @@ public static enum EnableSecurity {
* true if secrets could be set and crypto contexts created.
*
*/
public boolean srtpSecretsReady(ZrtpSrtpSecrets secrets, EnableSecurity part);
boolean srtpSecretsReady(ZrtpSrtpSecrets secrets, EnableSecurity part);

/**
* Switch off the security for the defined part.
*
* @param part Defines for which part (sender or receiver) to
* switch on security
*/
public void srtpSecretsOff(EnableSecurity part);
void srtpSecretsOff(EnableSecurity part);

/**
* Switch on the security.
Expand All @@ -167,7 +167,7 @@ public static enum EnableSecurity {
* @param verified if <code>verified</code> is true then SAS was
* verified by both parties during a previous call.
*/
public void srtpSecretsOn(String c, String s, boolean verified);
void srtpSecretsOn(String c, String s, boolean verified);

/**
* This method handles GoClear requests.
Expand All @@ -179,7 +179,8 @@ public static enum EnableSecurity {
* <b>Note:</b> GoClear is not yet implemented in GNU ZRTP.
*
*/
public void handleGoClear();
@SuppressWarnings("unused")
void handleGoClear();

/**
* Handle ZRTP negotiation failed.
Expand All @@ -191,9 +192,9 @@ public static enum EnableSecurity {
* This defines the message's severity
* @param subCode
* The subcode identifying the reason.
* @see gnu.java.zrtp.ZrtpCodes#MessageSeverity
* @see gnu.java.zrtp.ZrtpCodes.MessageSeverity
*/
public void zrtpNegotiationFailed(ZrtpCodes.MessageSeverity severity, EnumSet<?> subCode);
void zrtpNegotiationFailed(ZrtpCodes.MessageSeverity severity, EnumSet<?> subCode);

/**
* ZRTP calls this method if the other side does not support ZRTP.
Expand All @@ -202,7 +203,7 @@ public static enum EnableSecurity {
* ZRTP calls this method,
*
*/
public void zrtpNotSuppOther();
void zrtpNotSuppOther();

/**
* Inform about a PBX enrollment request.
Expand All @@ -213,7 +214,7 @@ public static enum EnableSecurity {
* @param info Give some information to the user about the PBX
* requesting an enrollment.
*/
public void zrtpAskEnrollment(ZrtpCodes.InfoEnrollment info);
void zrtpAskEnrollment(ZrtpCodes.InfoEnrollment info);

/**
* Inform about PBX enrollment result.
Expand All @@ -224,7 +225,7 @@ public static enum EnableSecurity {
* @param info Give some information to the user about the result
* of an enrollment.
*/
public void zrtpInformEnrollment(ZrtpCodes.InfoEnrollment info);
void zrtpInformEnrollment(ZrtpCodes.InfoEnrollment info);

/**
* Request a SAS signature.
Expand All @@ -246,7 +247,7 @@ public static enum EnableSecurity {
*
* @see gnu.java.zrtp.jmf.transform.zrtp.ZRTPTransformEngine#setSignatureData
*/
public void signSAS(byte[] sasHash);
void signSAS(byte[] sasHash);

/**
* ZRTP calls this method to request a SAS signature check.
Expand All @@ -272,6 +273,5 @@ public static enum EnableSecurity {
*
* @see gnu.java.zrtp.jmf.transform.zrtp.ZRTPTransformEngine#getSignatureData
*/
public boolean checkSASSignature(byte[] sasHash);

boolean checkSASSignature(byte[] sasHash);
}

0 comments on commit 9afa895

Please sign in to comment.