Commit a72fb284 authored by tepelmann's avatar tepelmann
Browse files

Added check for initiator for checkIntegrity, etc.

parent b45f6f84
Loading
Loading
Loading
Loading
+10 −9
Changes for javasrc/com/testingtech/ttcn/tci/codec/ike/EncryptedPayloadCodec.java: 10 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -168,7 +168,7 @@ public class EncryptedPayloadCodec implements IEnumDefinitions{
		// -- integrityChecksumData
//		int icvLen = handleICV(integrityChecksumData, rv, rb, completeMessage.toByteArray(), ta);
		int icvLen = ta.getIkeIcvLen();
		handleICV(icvLen, integrityChecksumData, rv, rb, completeMessage.toByteArray(), ta);
		handleICV(icvLen, integrityChecksumData, rv, rb, completeMessage.toByteArray(), ta, (TabularObject.valueOf(dec.getTag("iFlag"))==1)?true:false);

		//decode now the ciphered stuff
		
@@ -381,7 +381,7 @@ public class EncryptedPayloadCodec implements IEnumDefinitions{
	 * @return
	 * @throws TabularException
	 */
	private static void handleICV(int icvLen, TabularOctetstring icv, RecordValue rv, RB rb, byte[] completeMessage, IPv6TestAdapter ta) throws TabularException {
	private static void handleICV(int icvLen, TabularOctetstring icv, RecordValue rv, RB rb, byte[] completeMessage, IPv6TestAdapter ta, boolean initiator) throws TabularException {
//	private static int handleICV(TabularOctetstring icv, RecordValue rv, RB rb, byte[] completeMessage, IPv6TestAdapter ta) throws TabularException {
//		int icvLen = 0;
		String algo = ta.getIkeIntegrityAlgo();
@@ -394,7 +394,7 @@ public class EncryptedPayloadCodec implements IEnumDefinitions{
			else if (algo.equals(INTEGRITY_E_AUTH_HMACSHA1_96)) {
//				icvLen = 12;
				icv = getOctetstring(rb, completeMessage, icvLen, completeMessage.length - icvLen);
				if (checkIntegrity((char)0, "HmacSHA1", 96, icv, rb, completeMessage, ta)) {
				if (checkIntegrity((char)0, "HmacSHA1", 96, icv, rb, completeMessage, ta, initiator)) {
					rv.setField("integrityChecksumData", icv.toValue());
				}
				else {
@@ -405,7 +405,7 @@ public class EncryptedPayloadCodec implements IEnumDefinitions{
//				icvLen = 12;
				icv = getOctetstring(rb, completeMessage, icvLen, completeMessage.length - icvLen);
				throw new TabularException("decodeEncryptedPayload: IntegrityAlgo_E_AES_XCBC_MAC_96 not yet implemented!");
//				if (checkIntegrity((char)0, "AesXCBCMac", 96, icv, rb, completeMessage, ta)) {
//				if (checkIntegrity((char)0, "AesXCBCMac", 96, icv, rb, completeMessage, ta, initiator)) {
//					rv.setField("integrityChecksumData", icv.toValue());
//				}
//				else {
@@ -415,7 +415,7 @@ public class EncryptedPayloadCodec implements IEnumDefinitions{
			else if (algo.equals(INTEGRITY_E_AUTH_HMACMD5_96)) {
//				icvLen = 12;
				icv = getOctetstring(rb, completeMessage, icvLen, completeMessage.length - icvLen);
				if (checkIntegrity((char)0, "HmacMD5", 96, icv, rb, completeMessage, ta)) {
				if (checkIntegrity((char)0, "HmacMD5", 96, icv, rb, completeMessage, ta, initiator)) {
					rv.setField("integrityChecksumData", icv.toValue());
				}
				else {
@@ -425,7 +425,7 @@ public class EncryptedPayloadCodec implements IEnumDefinitions{
			else if (algo.equals(INTEGRITY_E_AUTH_SHA1_96)) {
//				icvLen = 0; //TODO unknown length
				icv = getOctetstring(rb, completeMessage, icvLen, completeMessage.length - icvLen);
				if (checkIntegrity((char)1, "SHA1", 96, icv, rb, completeMessage, ta)) {
				if (checkIntegrity((char)1, "SHA1", 96, icv, rb, completeMessage, ta, initiator)) {
					rv.setField("integrityChecksumData", icv.toValue());
				}
				else {
@@ -435,7 +435,7 @@ public class EncryptedPayloadCodec implements IEnumDefinitions{
			else if (algo.equals(INTEGRITY_E_AUTH_HMACSHA1_64)) {
//				icvLen = 0; //TODO unknown length
				icv = getOctetstring(rb, completeMessage, icvLen, completeMessage.length - icvLen);
				if (checkIntegrity((char)0, "HmacSHA1", 96, icv, rb, completeMessage, ta)) {
				if (checkIntegrity((char)0, "HmacSHA1", 96, icv, rb, completeMessage, ta, initiator)) {
					rv.setField("integrityChecksumData", icv.toValue());
				}
				else {
@@ -547,16 +547,17 @@ public class EncryptedPayloadCodec implements IEnumDefinitions{
	 * @param rb
	 * @param completeMessage
	 * @param ta
	 * @param initiator TODO
	 * @return
	 * @throws TabularException
	 */
	private static boolean checkIntegrity(char algoType, String algoName, int algoLen, TabularOctetstring icv, RB rb, byte [] completeMessage, IPv6TestAdapter ta) throws TabularException {
	private static boolean checkIntegrity(char algoType, String algoName, int algoLen, TabularOctetstring icv, RB rb, byte [] completeMessage, IPv6TestAdapter ta, boolean initiator) throws TabularException {
		int i = completeMessage.length-icv.length;
		OctetString ikeWithoutICV = new OctetString(rb, i, getBytes(i, completeMessage, 0));
		OctetString os;
		switch (algoType) {
			case 0:
				os = (OctetString)Encryption.getEncryptHMACx(rb, algoName, ta.getIkeIntegrityKey(false), ikeWithoutICV, algoLen);
				os = (OctetString)Encryption.getEncryptHMACx(rb, algoName, ta.getIkeIntegrityKey(initiator), ikeWithoutICV, algoLen);
				break;
			case 1:
				os = (OctetString)Encryption.getSHA1Integrity(rb, ikeWithoutICV, algoLen);