# Title

      Test IKEv2.EN.I.1.1.1.1: Sending IKE_SA_INIT request
      Part A: IKE Header Format (BASIC)
      Part B: SA Payload Format (BASIC)
      Part C: KE Payload Format (BASIC)
      Part D: Nonce Payload Format (BASIC)

# Purpose

      To verify an IKEv2 device transmits IKE_SA_INIT request using
      properly Header and Payloads format.

# References

      [RFC4306] - Section 1.2, 2.10, 3.1, 3.3, 3.4 and 3.9
      [RFC4718] - Sections 7.4

# Test Setup

      * Network Topology
         Connect the devices according to the Common Topology.
      * Configuration
         In each part, configure the devices according to the Common Configuration.
      * Pre-Sequence and Cleanup Sequence
         IKEv2 on the NUT is disabled after each part.

# Procedure

>        NUT                  TN1
>     (End-Node)           (End-Node)
>         |                    |
>         |------------------->| IKE_SA_INIT request (HDR, SAi1, KEi, Ni)
>         |                    | (Judgement #1)
>         |                    |
>         V                    V

      Part A: IKE Header Format (BASIC)
        1. NUT starts to negotiate with TN1 by sending IKE_SA_INIT request.
        2. Observe the messages transmitted on Link A.

      Part B: SA Payload Format (BASIC)
        3. NUT starts to negotiate with TN1 by sending IKE_SA_INIT request.
        4. Observe the messages transmitted on Link A.

      Part C: KE Payload Format (BASIC)
        5. NUT starts to negotiate with TN1 by sending IKE_SA_INIT request.
        6. Observe the messages transmitted on Link A.

      Part D: Nonce Payload Format (BASIC)
        7. NUT starts to negotiate with TN1 by sending IKE_SA_INIT request.
        8. Observe the messages transmitted on Link A.

# Observable Results

      Part A
        Step 2: Judgement #1
        The NUT transmits an IKE_SA_INIT request including properly
        formatted IKE Header containing following values:

>                           1                   2                   3
>       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
>      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
>      !                      IKE_SA Initiator s SPI                   !
>      !                                                               !
>      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
>      !                      IKE_SA responder s SPI                   !
>      !                                                               !
>      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
>      !  Next Payload ! MjVer ! MnVer ! Exchange Type !     Flags     !
>      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
>      !                            Message ID                         !
>      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
>      !                              Length                           !
>      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
>                              Figure 1 Header format

          * An IKE_SA Initiator's SPI fieled set to a 64-bits
            value chosen by the NUT.It MUST not be Zero.
          * An IKE_SA Responder's SPI field set to zero.
          * A next Payload field set to SA Payload (33).
          * A Major Version field is set to 2.
          * A Minor Version field is set to zero.
          * An Exchange Type field is set to IKE_SA_INIT (34).
          * A Flags field is set to (00010000)2 = (16)10.
          * A Message ID field is set to zero.
          * A Length field is set to the lemgth of the message (header + payloads) in octets.

      Part B
        Step 4: Judgment #1

>                                        1                   2                   3
>                    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
>                   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+--------------
>                   ! Next    34    !0!      0      ! Length          44            !             |
>                   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+---          |
>                   !       0       !       0       ! Length          40            !  |          |
>                   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+  |          |
>                   ! Number    1   ! Prot ID   1   ! SPI Size  0   ! Trans Cnt  4  !  |          |
>               --- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+  |          |
>                |  !       3       !       0       ! Length           8            !  |          |
>      Transform |  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+  |          |
>                |  ! Type  1  (EN) !       0       ! Transform ID     3     (3DES) !  |          |
>               --- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+  |          |
>                |  !       3       !       0       ! Length           8            !  |          | SA Payload
>      Transform |  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+  | Proposal |
>                |  ! Type  2  (PR) !       0       ! Transform ID     2     (SHA1) !  |          |
>               --- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+  |          |
>                |  !       3       !       0       ! Length           8            !  |          |
>      Transform |  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+  |          |
>                |  ! Type  3  (IN) !       0       ! Transform ID     2     (SHA1) !  |          |
>               --- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+  |          |
>                |  !       0       !       0       ! Length           8            !  |          |
>      Transform |  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+  |          |
>                |  ! Type  4  (DH) !       0       ! Transform ID     2     (1024) !  |          |
>               --- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+  |          |

>                                       Figure 2 SA Payload contents

>                   The NUT transmits an IKE_SA_INIT request including properly formatted SA Payload
>                   containing following values (refer following figures):

>                                       1                   2                   3
>                   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
>                  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
>                  ! Next Payload  |C|  RESERVED   |         Payload Length        !
>                  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
>                  !                                                               !
>                  ~                        <Proposals>                            ~
>                  !                                                               !
>                  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

>                                      Figure 3 SA Payload format

>                         * A Next Payload field is set to KE Payload (34).
>                         * A Critical field is set to zero.
>                         * A RESERVED field is set to zero.
>                         * A Payload Length field is set to length of the current payload.

>                  The following proposal must be included in Proposals field.
>                                      1                   2                   3
>                  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
>                 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
>                 ! 0 (last) or 2 !   RESERVED    !         Proposal Length       !
>                 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
>                 ! Proposal #    !  Protocol ID  !    SPI Size   !# of Transforms!
>                 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
>                 !                        SPI (variable)                         !
>                 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
>                 !                                                               !
>                 ~                         <Transforms>                          ~
>                 !                                                               !
>                 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

>                                Figure 4 Proposal sub-structure format

>          Proposal #1
>           * A 0 or 2 firld is set to zero if this structure is the last proposal, otherwise set to 2.
>           * A RESREVD field is set to zero.
>           * A Proposal Length field is set to length of this proposal, including all transforms
>             and attributes. It is 40 bytes for this proposal according to Common Configuration
>           * A Proposal # field is set to 1 if this structure is the first proposal, otherwise set
>             to 1 greater than the previous proposal.
>           * A Protocol ID field is set to IKE (1).
>           * A SPI Size field is set to zero.
>           * A # of Transforms field is set to 4.

>                  A Transform field is set to following (There are 4 Transform Structures).
>                                      1                   2                   3
>                  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
>                 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
>                 ! 0 (last) or 3 !   RESERVED    !       Transform Length        !
>                 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
>                 !Transform Type !   RESERVED    !          Transform ID         !
>                 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
>                 !                                                               !
>                 ~                      Transform Attributes                     !
>                 !                                                               !
>                 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

>                                Figure 5 Transform sub-structure format

>         Transform #1
>          * A 0 or 3 field is set to zero if this structure is the last transform, otherwise set to 3.
>          * A RESERVED field is set to zero.
>          * A Transform Length set to length of the Transform Substructure including
>            Header and Attribute. It is 8 bytes for ENCR_3DES.
>          * A Transform Type field is set to ENCR (1).
>          * A RESERVED field is set to zero.
>          * A Transform ID set to ENCR_3DES (3).

>         Transform #2

>          * A 0 or 3 field is set to zero if this structure is the last transform, otherwise set to 3.
>          * A RESERVED field is set to zero.
>          * A Transform Length set to length of the Transform Substructure including
>            Header and Attribute. It is 8 bytes for PRF_HMAC_SHA1.
>          * A Transform Type field is set to PRF (2).
>          * A RESERVED field is set to zero.
>          * A Transform ID set to PRF_HMAC_SHA1 (2).    Transform #3

>          * A 0 or 3 field is set to zero if this structure is the last transform, otherwise set to 3.
>          * A RESERVED field is set to zero.
>          * A Transform Length set to length of the Transform Substructure including
>            Header and Attribute. It is 8 bytes for AUTH_HMAC_SHA1.
>          * A Transform Type field is set to INTEG (3).
>          * A RESERVED field is set to zero.
>          * A Transform ID set to AUTH_HMAC_SHA1 (2).

>         Transform #4

>          * A 0 or 3 field is set to zero if this structure is the last transform, otherwise set to 3.
>          * A RESERVED field is set to zero.
>          * A Transform Length set to length of the Transform Substructure including
>            Header and Attribute. It is 8 bytes for 1024 MODP Group.
>          * A Transform Type field is set to D-H (4).
>          * A RESERVED field is set to zero.
>          * A Transform ID set to Group2 (2).

      part C
        Step 6: Judgment #1
          The NUT transmits an IKE_SA_INIT request including properly formatted KE Payload
          containing following values:

>                                      1                   2                   3
>                  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
>                 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
>                 ! Next Payload  !C!  RESERVED   !         Payload Length        !
>                 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
>                 !          DH Group #           !             RESERVED          !
>                 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
>                 !                                                               !
>                 ~                        Key Exchange Data                      ~
>                 !                                                               !
>                 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

>                                    Figure 6 KE Payload format

>                  * A Next Payload field is set to Nonce Payload (40).
>                  * A Critical field is set to zero.
>                  * A RESERVED field is set to zero.
>                  * A Payload Length field is set to length of the current payload.
>                    It is 136 bytes for Group 2.
>                  * A DH Group field is set to Group2 (2).
>                  * A RESERVED field is set to zero.
>                  * A Key Exchange Data field is set to Diffie-Hellman public value. The length of
>                    the Key Exchange Data field must be equal to 1024bit.

      Part D
        Step 8: Judgment #1
          The NUT transmits an IKE_SA_INIT request including properly formatted Nonce Payload
          containing following values:

>                                      1                   2                   3
>                  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
>                 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
>                 ! Next Payload  !C!  RESERVED   !         Payload Length        !
>                 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
>                 !                                                               !
>                 ~                           Nonce Data                          ~
>                 !                                                               !
>                 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

>                                    Figure 7 Nonce Payload format

>                   * A Next Payload field is set to zero.
>                   * A Critical field is set to zero.
>                   * A RESERVED field is set to zero.
>                   * A Payload Length field is set to length of the current payload.
>                   * A Nonce Data field is set to random data generated by the transmitting entity.
>                   * The size of the Nonce must between 16 and 256 octets.

# Possible Problems

      * IKE_SA_INIT request has following packet format. It may have additional payloads
        described below. Additional payloads can be ignored by this test. The order of payload
        may be different from this sample.

>         [N(COOKIE)],
>         SA, KE, Ni,
>         [N(NAT_DETECTION_SOURCE_IP)+,
>         N(NAT_DETECTION_DESTINATION_IP)],
>         [V+]

      * The implementation may not set single proposal by the implementation policy. In this
        case, Security Association Payload contains multiple proposals.

      * Each of transforms can be located in the any order.