aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYan Yan <evitayan@google.com>2018-11-26 22:47:42 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2018-11-26 22:47:42 +0000
commit6ee9837e14cf1ba51ac94a8c83e962ab435300b9 (patch)
treeaa0f372d5087937567c5fbe09ce44f3308ae6058
parentc41fcd8b60adde12a215f30666aa159d1d6c2043 (diff)
parentd2eda7d20a0e6127d5c176e1ed48b74d6b015f0b (diff)
downloadike-6ee9837e14cf1ba51ac94a8c83e962ab435300b9.tar.gz
Merge "Create Identification Payload"
-rw-r--r--src/java/com/android/ike/ikev2/message/IkeIdPayload.java81
-rw-r--r--src/java/com/android/ike/ikev2/message/IkePayload.java6
-rw-r--r--src/java/com/android/ike/ikev2/message/IkePayloadFactory.java4
-rw-r--r--tests/iketests/src/java/com/android/ike/ikev2/message/IkeIdPayloadTest.java32
4 files changed, 122 insertions, 1 deletions
diff --git a/src/java/com/android/ike/ikev2/message/IkeIdPayload.java b/src/java/com/android/ike/ikev2/message/IkeIdPayload.java
new file mode 100644
index 00000000..57533df9
--- /dev/null
+++ b/src/java/com/android/ike/ikev2/message/IkeIdPayload.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.ike.ikev2.message;
+
+import com.android.ike.ikev2.exceptions.IkeException;
+import com.android.ike.ikev2.message.IkePayload.PayloadType;
+
+import java.nio.ByteBuffer;
+
+/**
+ * IkeIdPayload represents an Identification Initiator Payload or an Identification Responder
+ * Payload.
+ *
+ * <p>Identification Initiator Payload and Identification Responder Payload have same format but
+ * different payload type.
+ *
+ * @see <a href="https://tools.ietf.org/html/rfc7296#section-3.5">RFC 7296, Internet Key Exchange
+ * Protocol Version 2 (IKEv2).
+ */
+public final class IkeIdPayload extends IkePayload {
+ IkeIdPayload(boolean critical, byte[] payloadBody, boolean isInitiator) throws IkeException {
+ super((isInitiator ? PAYLOAD_TYPE_ID_INITIATOR : PAYLOAD_TYPE_ID_RESPONDER), critical);
+ // TODO: Decode and validate syntax of payloadBody.
+ }
+
+ /**
+ * Encode Identification Payload to ByteBuffer.
+ *
+ * @param nextPayload type of payload that follows this payload.
+ * @param byteBuffer destination ByteBuffer that stores encoded payload.
+ */
+ @Override
+ protected void encodeToByteBuffer(@PayloadType int nextPayload, ByteBuffer byteBuffer) {
+ throw new UnsupportedOperationException(
+ "It is not supported to encode a " + getTypeString());
+ }
+
+ /**
+ * Get entire payload length.
+ *
+ * @return entire payload length.
+ */
+ @Override
+ protected int getPayloadLength() {
+ throw new UnsupportedOperationException(
+ "It is not supported to get payload length of " + getTypeString());
+ }
+
+ /**
+ * Return the payload type as a String.
+ *
+ * @return the payload type as a String.
+ */
+ @Override
+ public String getTypeString() {
+ switch (payloadType) {
+ case PAYLOAD_TYPE_ID_INITIATOR:
+ return "Identification Initiator Payload";
+ case PAYLOAD_TYPE_ID_RESPONDER:
+ return "Identification Responder Payload";
+ default:
+ // Won't reach here.
+ throw new IllegalArgumentException(
+ "Invalid Payload Type for Identification Payload.");
+ }
+ }
+}
diff --git a/src/java/com/android/ike/ikev2/message/IkePayload.java b/src/java/com/android/ike/ikev2/message/IkePayload.java
index 2d4d0dd0..080b48a5 100644
--- a/src/java/com/android/ike/ikev2/message/IkePayload.java
+++ b/src/java/com/android/ike/ikev2/message/IkePayload.java
@@ -55,11 +55,15 @@ public abstract class IkePayload {
public static final int PAYLOAD_TYPE_SA = 33;
/** Key Exchange Payload */
public static final int PAYLOAD_TYPE_KE = 34;
+ /** Identification Payload for IKE SA Initiator */
+ public static final int PAYLOAD_TYPE_ID_INITIATOR = 35;
+ /** Identification Payload for IKE SA Responder */
+ public static final int PAYLOAD_TYPE_ID_RESPONDER = 36;
/** Nonce Payload */
public static final int PAYLOAD_TYPE_NONCE = 40;
/** Notify Payload */
public static final int PAYLOAD_TYPE_NOTIFY = 41;
- /** VENDOR Payload */
+ /** Vendor Payload */
public static final int PAYLOAD_TYPE_VENDOR = 43;
/** Encrypted and Authenticated Payload */
public static final int PAYLOAD_TYPE_SK = 46;
diff --git a/src/java/com/android/ike/ikev2/message/IkePayloadFactory.java b/src/java/com/android/ike/ikev2/message/IkePayloadFactory.java
index 0993f394..86edb585 100644
--- a/src/java/com/android/ike/ikev2/message/IkePayloadFactory.java
+++ b/src/java/com/android/ike/ikev2/message/IkePayloadFactory.java
@@ -45,6 +45,10 @@ final class IkePayloadFactory {
return new IkeSaPayload(isCritical, payloadBody);
case IkePayload.PAYLOAD_TYPE_KE:
return new IkeKePayload(isCritical, payloadBody);
+ case IkePayload.PAYLOAD_TYPE_ID_INITIATOR:
+ return new IkeIdPayload(isCritical, payloadBody, true);
+ case IkePayload.PAYLOAD_TYPE_ID_RESPONDER:
+ return new IkeIdPayload(isCritical, payloadBody, false);
case IkePayload.PAYLOAD_TYPE_NONCE:
return new IkeNoncePayload(isCritical, payloadBody);
case IkePayload.PAYLOAD_TYPE_NOTIFY:
diff --git a/tests/iketests/src/java/com/android/ike/ikev2/message/IkeIdPayloadTest.java b/tests/iketests/src/java/com/android/ike/ikev2/message/IkeIdPayloadTest.java
new file mode 100644
index 00000000..a4b3c603
--- /dev/null
+++ b/tests/iketests/src/java/com/android/ike/ikev2/message/IkeIdPayloadTest.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.ike.ikev2.message;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public final class IkeIdPayloadTest {
+ private static final String ID_PAYLOAD_INITIATOR_FQDN_HEX_STRING = "020000006576697461";
+
+ @Test
+ public void testDecodeIdPayload() throws Exception {
+ byte[] inputPacket = TestUtils.hexStringToByteArray(ID_PAYLOAD_INITIATOR_FQDN_HEX_STRING);
+ IkeIdPayload payload = new IkeIdPayload(false, inputPacket, true);
+ assertEquals(IkePayload.PAYLOAD_TYPE_ID_INITIATOR, payload.payloadType);
+ }
+}