#!/usr/bin/perl # # Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005 Yokogawa Electric Corporation. # All rights reserved. # # Redistribution and use of this software in source and binary # forms, with or without modification, are permitted provided that # the following conditions and disclaimer are agreed and accepted # by the user: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with # the distribution. # # 3. Neither the names of the copyrighters, the name of the project # which is related to this software (hereinafter referred to as # "project") nor the names of the contributors may be used to # endorse or promote products derived from this software without # specific prior written permission. # # 4. No merchantable use may be permitted without prior written # notification to the copyrighters. # # 5. The copyrighters, the project and the contributors may prohibit # the use of this software at any time. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHTERS, THE PROJECT AND # CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING # BUT NOT LIMITED THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE, ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHTERS, THE PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # # $TAHI: ct/ike/SGW/SG_R_RFC2409_5_9.seq,v 1.34.2.3 2005/11/22 10:06:09 ozoe Exp $ # $Id: SG_R_RFC2409_5_9.seq,v 1.34.2.3 2005/11/22 10:06:09 ozoe Exp $ # ###################################################################### BEGIN { } use V6evalTool; use IKE; use IKE_check; my $IF1 = Link1; my $IF0 = Link0; #====== get sequence arguments ====== foreach (@ARGV) { /^test_type=(\S+)/ && do {$TEST_TYPE=$1; next; }; /^support=(\S+)/ && do {$SUPPORT=$1; next; }; /^app_type=(\S+)/ && do {$IKE::APP_TYPE=$1; next; }; /^test_phase=(\S+)/ && do {$IKE::TEST_PHASE=$1; next; }; ikeExitError("Unknown sequence option '$_'"); } #====== check NUT type ====== ikeCheckNUT(sgw, $TEST_TYPE, $SUPPORT); #====== Test Configuration ====== %ikeConfig = ( 'app_type' => 'ICMP', 'isakmp_src' => "$IKE::IKEAddr{IKE_NUT_NET2_SGW1_ADDR}", 'isakmp_dst' => "$IKE::IKEAddr{IKE_TN_NET3_SGW2_ADDR}", 'isakmp_dport' => '500', 'isakmp_ex_mode' => 'main', 'isakmp_doi' => 'ipsec_doi', 'isakmp_situation' => 'identity_only', 'isakmp_key_id' => "$IKE::IKEAddr{IKE_TN_NET3_SGW2_ADDR}", 'isakmp_key_value' => 'IKE-TEST', 'isakmp_enc_alg' => '3des', 'isakmp_hash_alg' => 'sha1', 'isakmp_auth_method' => 'pre_shared_key', 'isakmp_dh_group' => '2', 'isakmp_lt' => '28800', 'isakmp_lt_unit' => 'seconds', 'isakmp_src_id_type' => 'address', 'isakmp_src_id' => "$IKE::IKEAddr{IKE_NUT_NET2_SGW1_ADDR}", 'isakmp_dst_id_type' => 'address', 'isakmp_dst_id' => "$IKE::IKEAddr{IKE_TN_NET3_SGW2_ADDR}", 'isakmp_num_pro' => '1', 'isakmp_num_trans' => '1', 'ipsec_id_type' => 'address', 'ipsec_dst' => "$IKE::IKEAddr{IKE_NET4_ADDR}", 'ipsec_src' => "$IKE::IKEAddr{IKE_NET0_ADDR}", 'ipsec_dst_id' => "$IKE::IKEAddr{IKE_NET4_ADDR}", 'ipsec_src_id' => "$IKE::IKEAddr{IKE_NET0_ADDR}", 'ipsec_tdst' => "$IKE::IKEAddr{IKE_TN_NET3_SGW2_ADDR}", 'ipsec_tsrc' => "$IKE::IKEAddr{IKE_NUT_NET2_SGW1_ADDR}", 'ipsec_end_dst' => "$IKE::IKEAddr{IKE_TN_NET4_HOST2_ADDR}", 'ipsec_end_src' => "$IKE::IKEAddr{IKE_TN_NET0_HOST1_ADDR}", 'ipsec_send_id' => 'on', 'ipsec_supper' => 'any', 'ipsec_dupper' => 'any', 'ipsec_direction' => 'both', 'ipsec_pfs_group' => 'off', 'ipsec_p_num' => '1', 'ipsec_p1_proto' => 'PROTO_IPSEC_ESP', 'ipsec_p1_t_num' => '1', 'ipsec_p1_t1_enc_alg' => 'ESP_3DES', 'ipsec_p1_t1_auth_mtd' => 'HMAC_SHA', 'ipsec_p1_t1_mode' => 'Tunnel', 'ipsec_p1_t1_lt' => '8', 'ipsec_p1_t1_lt_unit' => 'hour', 'ipsec_p_send_proto' => 'PROTO_IPSEC_ESP', 'ipsec_p_send_trans' => '1', 'ipsec_p_select_alg' => 'ESP_3DES', 'ipsec_p_select_auth_mtd' => 'HMAC_SHA', 'ipsec_p_select_mode' => 'Tunnel', 'ipsec_p_select_lt' => '8', 'ipsec_p_select_lt_unit' => 'hour', ); #====== set TN's cookie ======== my $cookie = GetMD5("$IKE::IKEAddr{IKE_TN_NET3_SGW2_ADDR}"."$ikeConfig{'isakmp_dport'}".time()); $cookie = substr($cookie, 0, 16); my $nonce = '00000000000000000000000000000000'; my $nonce_1 = '00000000000000000000000000000001'; $ikeConfig{'isakmp_cookie_i'} = $cookie; $ikeConfig{'isakmp_nonce_i'} = $nonce; $ikeConfig{'ipsec_nonce_i'} = $nonce_1; $ikeConfig{'ipsec_spi_i'} = 4096; $ikeConfig{'ipsec_message_id'} = '0000ffff'; vLogHTML("CKY-I: $ikeConfig{'isakmp_cookie_i'}
") if $IKE::remote_debug; vLogHTML("ISAKMP Ni-b: $ikeConfig{'isakmp_nonce_i'}
") if $IKE::remote_debug; vLogHTML("IPsec Ni-b: $ikeConfig{'ipsec_nonce_i'}
") if $IKE::remote_debug; vLogHTML("sender SPI: $ikeConfig{'ipsec_spi_i'}
") if $IKE::remote_debug; vLogHTML("pre_shared key: $ikeConfig{'isakmp_key_value'}
") if $IKE::remote_debug; #====== set other date about this test ======== #====== set ISAKMP SA, IPSEC SPD #====== vLogHTML("*** Target IKE initialization phase ***
"); ikeInit(%ikeConfig); #====== set Address of NUT ====== vLogHTML("*** Target initialization phase ***
"); vCapture($IF0); vCapture($IF1); ikeSetAddr($IF0,$IF1,$IKE::address_debug); #====== set ISAKMP SA packet frame, parameter #====== my $cpp = undef; my @ike = (); my %ret = ikePh2PreSeqR($IF0,$cpp,\@ike, \%ikeConfig); #====================================================================== vLogHTML("*** Target testing phase start ***
"); #====================================================================== #------------------------------------------------------------------- vLogHTML("*** Phase-2 1st message send ***
"); #------------------------------------------------------------------- vClear($IF1); vClear($IF0); my %ret1 = ikePh2Send1st($IF0, 5, 0, 0, $cpp, \@ike, \%ret, \%ikeConfig); if($ret1{'status'} == $IKE::FAIL) { ikeReset(); exit($V6evalTool::exitFail); } #------------------------------------------------------------------- vLogHTML("*** Phase-2 2nd message recv ***
"); #------------------------------------------------------------------- my @CHECK_FLAG = undef; $CHECK_FLAG[0] = shiftFlag(1) + shiftFlag(2) + shiftFlag(3) + shiftFlag(5) + shiftFlag(8) + shiftFlag(10); #ALL my $OPTION_FLAG = $IKE_check::optionHash{'SAAttributeCheck'} + $IKE_check::optionHash{'phase2OrderCheck'} + $IKE_check::optionHash{'isakmpEncryptionCheck'} + $IKE_check::optionHash{'Phase2Hash2Check'} + $IKE_check::optionHash{'IDPayloadOrderCheck'}; my %ret2 = ikePh2Recv2nd($IF0, 5, 0, 0, $cpp, \@ike, \%ret1, \%ikeConfig,\@CHECK_FLAG,$OPTION_FLAG); if($ret2{'status'} == $IKE::FAIL) { ikeReset(); exit($V6evalTool::exitFail); } #------------------------------------------------------------------- vLogHTML("*** Phase-2 3rd message send ***
"); #------------------------------------------------------------------- vClear($IF0); my %ret3 = ikePh2Send3rd($IF0, 5, 0, 0, $cpp, \@ike, \%ret2, \%ikeConfig); if($ret3{'status'} == $IKE::FAIL) { ikeReset(); exit($V6evalTool::exitFail); } #------------------------------------------------------------------- vLogHTML("*** IPsec SA is esatblished ***
"); #------------------------------------------------------------------- #------------------------------------------------------------------- vLogHTML("*** Encapulated Echo Request/Reply message send/recv ***
"); #------------------------------------------------------------------- #-------- # Request #-------- vClear($IF1); vClear($IF0); $cpp = "-DIPSEC_NEXT_HEADER=41 "; $IKE::pktdesc{'echo_request_send_esp_tunnel_net3sgw2_net2sgw1'} = 'Send Encrypted Echo Request from HOST-2(TN)', $IKE::pktdesc{'echo_request_recv_net4host2_net0host1'} = 'Receive Echo Request from HOST-2(TN) via SGW1(NUT)', my $send_frame = 'echo_request_send_esp_tunnel_net3sgw2_net2sgw1'; my @recv_frame = ('echo_request_recv_net4host2_net0host1'); my $fromside = 'initiator'; my %ret = ipsecSendRecvSGW($fromside, $IF0, $IF1, 5, 0, 0, $cpp, $send_frame, \@recv_frame,\%ikeConfig); if($ret{'status'} == $IKE::FAIL) { ikeReset(); exit($V6evalTool::exitFail); } #------------------------------------------------------------------- vLogHTML("Implementation of Quick Mode(ESP_3DES and HMAC-SHA(Tunnel mode to SGW)) is correct
"); #------------------------------------------------------------------- #====================================================================== vLogHTML("*** Target test finish ***
"); #====================================================================== vStop($IF1); vStop($IF0); ikeReset(); ikeExitPass(); #NOTREACHED ###################################################################### __END__ =head1 NAME SG_R_RFC2409_5_9 - [Responder Test] Implementation of Quick Mode(ESP_3DES and HMAC-SHA(Tunnel mode to SGW)) =head1 TARGET SGW =head1 SYNOPSIS =begin html
  SG_R_RFC2409_5_9.seq [-tooloption ...] -pkt SG_R_RFC2409_5_9.def -tooloption : v6eval tool option
See also ike_common.def and ike_ipsec.def and ike_pkt_ph1_recv.def and ike_pkt_ph2_recv.def
=end html =head1 INITIALIZATION =begin html
  • Network Topology
  •                                  HOST-2(TN)
                                       |3ffe:501:ffff:104::11
                                       |
    Net-v   --+------------------------+-------- 3ffe:501:ffff:104::/64
              |
              |
             SGW-2(TN):initiator
              |3ffe:501:ffff:103::11
              |                     
    Net-w   --+--------+------------------------ 3ffe:501:ffff:103::/64
                       |
                       |
                      ROUTER-2(TN)
                       | 3ffe:501:ffff:102::11
                       |
    Net-x   --+--------+------------------------ 3ffe:501:ffff:102::/64
              |
              |3ffe:501:ffff:102::1
             SGW-1(NUT):responder
              |3ffe:501:ffff:101::1
              |
    Net-y   --+--------+------------------------ 3ffe:501:ffff:101::/64
                       |
                       | 3ffe:501:ffff:101::11
                      ROUTER-1(TN)
                       |
                       |
    Net-z   -----------+---------------+-------- 3ffe:501:ffff:100::/64
                                       |
                                       |3ffe:501:ffff:100::13
                                     HOST-1(TN)
      

  • Verification Points
    • 	   
    • Quick Mode MUST be implemented as a mechanism to generate fresh keying material and negotiate non-ISAKMP security services.

  • Configuration
    •        
    • Initiator and Responder IKE parameter
    • At least, following parameter must be included in proposal.
      Machine Src Dest Phase I Phase II
      Ex mode Key Value Enc Alg Hash Alg Auth Method DH Group PH1 Lt IDx

      Proto ID Trans ID Mode Auth Alg PH2 Lt IDci IDcr Upper
      SGW-1 SGW-1 addr SGW-2 addr Main IKE-TEST 3DES SHA pre-shared key 2 8 Hour SGW-1 addr PROTO_IPSEC_ESP ESP_3DES Tunnel HMAC-SHA 8 Hour Net-v addr Net-z addr any
      SGW-2 SGW-2 addr SGW-1 addr Main IKE-TEST 3DES SHA pre-shared key 2 8 Hour SGW-2 addr PROTO_IPSEC_ESP ESP_3DES Tunnel HMAC-SHA 8 Hour Net-v addr Net-z addr any
      *Ex Mode = Exchange mode(Aggresive mode can also be chosen as Ex Mode) *IDx = identity payload(FQDN or user FQDN can also be chosen as IDx) *IDci = identity payload *IDcr = identity payload *Enc Alg = IKE Encryption Algorithm *Hash Alg = IKE Authentication Algorithm *Key Value = pre-shared key value *PH1 Lt = Phase-1 Lifetime *PH2 Lt = Phase-2 Lifetime *Proto ID = Protocol Identifier *Trans ID = Transform Identifier *Mode = Encapsulation Mode *Auth Alg = Authentication Algorithm *Auth Method = Authentication Method *DH Group = Diffie-Hellman Group *Upper = Upper Layer Protocol *SGW-1 addr = SGW-1 address *SGW-2 addr = SGW-2 address *Net-z = Net-z network address *Net-v = Net-v network address
=end html =head1 TEST PROCEDURE =begin html
  This test check is following.

* PHASE I
Either IDENTITY PROTECTION EXCHANGE or AGGRESSIVE EXCHANGE is performed as a pre sequence.

IDENTITY PROTECTION EXCHANGE
# Initiator(TN) Direction Responder(NUT) (1) HDR; SA ========>
(2) <======== HDR; SA
(3) HDR; KE; NONCE ========>
(4) <======== HDR; KE; NONCE
(5) HDR*; IDii; HASH_I ========>
(6) <======== HDR*; IDir; HASH_R
1. Send the first message from TN In the first message (1), the initiator generates a proposal it considers adequate to protect traffic for the given situation. The Security Association, Proposal, and Transform payloads are included in the Security Association payload (for notation purposes).
2. Receive the second message from NUT In the second message (2), the responder indicates the protection suite it has accepted with the Security Association, Proposal, and Transform payloads.
3. Send the third message from TN In the third (3) message, the initiator send keying material used to arrive at a common shared secret and random information which is used to guarantee liveness and protect against replay attacks.
4. Receive the fourth message from NUT In the fourth (4) message, the responder send keying material used to arrive at a common shared secret and random information which is used to guarantee liveness and protect against replay attacks.
5. Send the fifth message from TN In the fifth (5) message, the initiator send identification information and the results of the agreed upon authentication function(hash function).
6. Receive the sixth message from NUT In the sixth (6) message, the responder send identification information and the results of the agreed upon authentication function(hash function).

AGGRESSIVE EXCHANGE
# Initiator(TN) Direction Responder(NUT) NOTE (1) HDR; SA; KE; => Begin ISAKMP-SA or Proxy negotiation NONCE; IDii and Key Exchange
(2) <= HDR; SA; KE; NONCE; IDir; AUTH Initiator Identity Verified by Responder Key Generated Basic SA agreed upon
(3) HDR*; AUTH => Responder Identity Verified by Initiator SA established
1. Send the first message from TN In the first message (1), the initiator generates a proposal it considers adequate to protect traffic for the given situation. The Security Association, Proposal, and Transform payloads are included in the Security Association payload (for notation purposes). There can be only one Proposal and one Transform offered (i.e. no choices) in order for the aggressive exchange to work. Keying material used to arrive at a common shared secret and random information which is used to guarantee liveness and protect against replay attacks are also transmitted. Random information provided by both parties SHOULD be used by the authentication mechanism to provide shared proof of participation in the exchange. Additionally, the initiator transmits identification information.
2. Recieve the second message from NUT In the second message (2), the responder indicates the protection suite it has accepted with the Security Association, Proposal, and Transform payloads. Keying material used to arrive at a common shared secret and random information which is used to guarantee liveness and protect against replay attacks is also transmitted. Random information provided by both parties SHOULD be used by the authentication mechanism to provide shared proof of participation in the exchange. Additionally, the responder transmits identification information. All of this information is transmitted under the protection of the agreed upon authentication function. Local security policy dictates the action of the responder if no proposed protection suite is accepted. One possible action is the transmission of a Notify payload as part of an Informational Exchange.
3. Send the third message from TN In the third (3) message, the initiator transmits the results of the agreed upon authentication function. This information is transmitted under the protection of the common shared secret. Local security policy dictates the action if an error occurs during these messages. One possible action is the transmission of a Notify payload as part of an Informational Exchange.

The test sequence is following.
* PHASE II
QUICK MODE
# Initiator(TN) Direction Responder(NUT) (1) HDR*, HASH(1), SA, Ni,IDci, IDcr; ========>
(2) <======== HDR*, HASH(2), SA, Nr, IDci, IDcr; Judgement (Check *1)
(3) HDR*, HASH(3) ========>
1. Send the first message from TN In the first message (1), the initiator generates a proposal it considers adequate to protect traffic for the given situation. The Security Association, Proposal, and Transform payloads are included in the Security Association payload (for notation purposes). And initiator send HASH(1) and Nonce. HASH(1) is the prf over the message id (M-ID) from the ISAKMP header concatenated with the entire message that follows the hash including all payload headers, but excluding any padding added for encryption. Nonce is random information which is used to guarantee liveness. IDci and IDcr is identification information.
2. Receive the second message from NUT In the second message (2), the responder indicates the protection suite it has accepted with the Security Association, Proposal, and Transform payloads. And responder send HASH(2) and Nonce. HASH(2) is identical to HASH(1) except the initiator's nonce-- Ni, minus the payload header-- is added after M-ID but before the complete message. Nonce is random information which is used to guarantee liveness. IDci and IDcr is identification information.
3. Send the third message from TN In the third (3) message, the initiator send HASH(3). HASH(3)-- for liveliness-- is the prf over the value zero represented as a single octet, followed by a concatenation of the message id and the two nonces-- the initiator's followed by the responder's-- minus the payload header.
* IPsec transmission
# Initiator(TN) Direction Responder(NUT) (1) IP_HDR; ESP*; ICMP(Echo request) ========> Judgement (Check *2)
1. Send the first message from TN In the first message (1), initiator(TN) forward Echo request from HOST-2(TN) to responder(NUT) with IPsec SA. And NUT(SGW-1) forward decrypted Echo request to HOST-1(TN).
=end html =head1 JUDGEMENT In Phase I , messages must be exchanged correctly. In Phase II , the first to the third message must be exchanged correctly. Check *1 Hash, Security Association, Nonce, Identification Payload Format must be base on description of RFC. In IPsec SA transmission, the first message must be forwarded to HOST-1(TN). Check *2 NUT must forward Echo Reply to HOST-1. And must conform to above Configuration. =head1 TERMINATION Clean up SAD and SPD =head1 REFERENCE =begin html
  RFC2409 
  5. Exchanges

There are two basic methods used to establish an authenticated key exchange: Main Mode and Aggressive Mode. Each generates authenticated keying material from an ephemeral Diffie-Hellman exchange. Main Mode MUST be implemented; Aggressive Mode SHOULD be implemented. In addition, Quick Mode MUST be implemented as a mechanism to generate fresh keying material and negotiate non-ISAKMP security services. In addition, New Group Mode SHOULD be implemented as a mechanism to define private groups for Diffie-Hellman exchanges. Implementations MUST NOT switch exchange types in the middle of an exchange.
(omit)
=end html =head1 SEE ALSO perldoc V6evalTool =begin html
  IKE.html IKE Test Common Utility
=end html =cut