#!/usr/bin/perl
#
# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
# 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.
#
# $Id: IKEv2-SGW-I-1-2-6-5-A.seq,v 1.4 2009/05/28 07:26:46 akisada Exp $
#
################################################################

BEGIN
{
	push(@INC, '..');
	$ENV{'V6EVAL_WITH_KOI'} = 'TRUE';
}

END {}

use V6evalTool;
use IKEv2v6eval;
use IKEv2;
use strict;



my $remote	= 'common_remote_index';
my $selector	= 'common_selector_index_outbound';

my $session	= undef;
my $ike_sa_init_req_param	= undef;
my $ike_sa_init_resp_param	= undef;
my $ike_auth_req_param	= undef;
my $ike_auth_resp_param	= undef;
my $create_child_sa_req_param_from_tn1	= undef;
my $create_child_sa_req_param_from_nut	= undef;
my $create_child_sa_resp_param_from_tn1	= undef;
my $create_child_sa_resp_param_from_nut	= undef;
my $informational_req_param = undef;
my $informational_resp_param = undef;

my $material_1st	= undef;
my $material_2nd	= undef;
my $material_3rd	= undef;
my $child_sa_material = undef;
my $ret	= undef;
my $str = undef;

my @local_create_child_sa_req = undef;
my @local_create_child_sa_resp	= undef;



kLogHTML('<FONT COLOR="#FF0000" SIZE="+1"><U><B>TEST SETUP</B></U></FONT>');

my $tn = 'SGW';
my $nut = 'SGW';


#------------------------------#
# register IKEv2.pm            #
#------------------------------#
unless(IKEv2initialize($tn, $nut)) {
	IKEv2exitFatal('<FONT COLOR="#ff0000">IKEv2 module initializing failure</FONT>');
}



#------------------------------#
# customize configuration      #
#------------------------------#
my $conf = {
	'kmp_sa_lifetime' => '60',
	'ipsec_sa_lifetime' => '300',
};
unless (IKEv2customize($conf)) {
	IKEv2exitFatal('<FONT COLOR="#ff0000">IKEv2 configuration failure</FONT>');
}



#------------------------------#
# configure TN                 #
#------------------------------#
unless(IKEv2setupTN()) {
	IKEv2exitFatal('<FONT COLOR="#ff0000">TN setup failure</FONT>');
}



#------------------------------#
# configure NUT                #
#------------------------------#
unless(IKEv2setupNUT()) {
	IKEv2exitFatal('<FONT COLOR="#ff0000">NUT setup failure</FONT>');
}



kLogHTML('<FONT COLOR="#FF0000" SIZE="+1"><U><B>TEST PROCEDURE</B></U></FONT>');


#------------------------------#
# prepare session handler      #
#------------------------------#
$session = IKEv2create_session($remote);
unless(defined($session)) {
	IKEv2exitFatal('<FONT COLOR="#ff0000">IKEv2 session creation failure</FONT>');
}



$str  = '<PRE>';
$str .= "    (I)             (R)\n";
$str .= "    NUT             TN1\n";
$str .= "     |               |\n";
$str .= "     |-------------->| IKE_SA_INIT request (HDR, SAi1, KEi, Ni)\n";
$str .= "     |               |\n";
$str .= "     V               V";
$str .= '</PRE>';

kLogHTML($str);



#--------------------------------------#
# invoke IKE_SA_INIT request           #
#--------------------------------------#
unless(IKEv2initiateNUT($selector)) {
	IKEv2exitFatal('<FONT COLOR="#ff0000">NUT initiation failure</FONT>');
}



#--------------------------------------#
# receive IKE_SA_INIT request          #
#--------------------------------------#
$ike_sa_init_req_param = devel_IKEv2receive_IKE_SA_INIT_request($session, $remote);
unless(defined($ike_sa_init_req_param)) {
	kLogHTML(kDump_Common_Error());
	kLogHTML('<FONT COLOR="#ff0000">Can\'t observe IKE_SA_INIT request.</FONT>');
	IKEv2exitFail();
}



#--------------------------------------#
# send IKE_SA_INIT response            #
#--------------------------------------#
$str  = '<PRE>';
$str .= "    (I)             (R)\n";
$str .= "    NUT             TN1\n";
$str .= "     |               |\n";
$str .= "     |<--------------| IKE_SA_INIT response (HDR, SAr1, KEr, Nr)\n";
$str .= "     |               |\n";
$str .= "     V               V";
$str .= '</PRE>';

kLogHTML($str);

$ike_sa_init_resp_param = devel_IKEv2send_IKE_SA_INIT_response($session, $remote, $ike_sa_init_req_param);
unless(defined($ike_sa_init_resp_param)) {
	kLogHTML(kDump_Common_Error());
	IKEv2exitFatal('<FONT COLOR="#ff0000">Can\'t send IKE_SA_INIT response.</FONT>');
}



#--------------------------------------#
# generate keying material             #
#--------------------------------------#
$material_1st = devel_IKEv2gen_keymat(0, $ike_sa_init_req_param, $ike_sa_init_resp_param);
unless(defined($material_1st)) {
	kLogHTML(kDump_Common_Error());
	IKEv2exitFatal('<FONT COLOR="#ff0000">Can\'t generate keying material.</FONT>');
}



#--------------------------------------#
# receive IKE_AUTH request             #
#--------------------------------------#
$str  = '<PRE>';
$str .= "    (I)             (R)\n";
$str .= "    NUT             TN1\n";
$str .= "     |               |\n";
$str .= "     |-------------->| IKE_AUTH request (HDR, SK {IDi, AUTH, N(USE_TRANSPORT_MODE), SAi2, TSi, TSr})\n";
$str .= "     |               |\n";
$str .= "     V               V";
$str .= '</PRE>';

kLogHTML($str);



$ike_auth_req_param = devel_IKEv2receive_IKE_AUTH_request($session,
							  $remote,
							  $ike_sa_init_req_param,
							  $ike_sa_init_resp_param,
							  $material_1st);
unless(defined($ike_auth_req_param)) {
	kLogHTML(kDump_Common_Error());
	kLogHTML('<FONT COLOR="#ff0000">Can\'t observe IKE_AUTH request.</FONT>');
	IKEv2exitFail();
}



#--------------------------------------#
# send IKE_AUTH response               #
#--------------------------------------#
$str  = '<PRE>';
$str .= "    (I)             (R)\n";
$str .= "    NUT             TN1\n";
$str .= "     |               |\n";
$str .= "     |<--------------| IKE_AUTH response (HDR, SK {IDr, AUTH, N(USE_TRANSPORT_MODE), SAr2, TSi, TSr})\n";
$str .= "     |               |\n";
$str .= "     V               V";
$str .= '</PRE>';

kLogHTML($str);



$ike_auth_resp_param = devel_IKEv2send_IKE_AUTH_response($session,
							 $remote,
							 $ike_sa_init_req_param,
							 $ike_sa_init_resp_param,
							 $material_1st);
unless (defined($ike_auth_resp_param)) {
	kLogHTML(kDump_Common_Error());
	IKEv2exitFatal('<FONT COLOR="#ff0000">Can\'t send IKE_AUTH response.</FONT>');
}



#--------------------------------------#
# generate keying material (CHILD_SA)  #
#--------------------------------------#
$child_sa_material = devel_IKEv2gen_child_sa_keymat(1,	# Initial Exchanges
						    $material_1st,
						    $ike_sa_init_req_param,
						    $ike_sa_init_resp_param,
						    $ike_auth_req_param,
						    $ike_auth_resp_param);



#--------------------------------------#
# set Upper Protocol for TN's SPD      #
#--------------------------------------#
IKEv2set_SPD('upperspec', 'icmp6');



#--------------------------------------#
# set keying material                  #
#--------------------------------------#
$ret = IKEv2set_child_sa_keymat(0, $child_sa_material, $ike_auth_req_param, $ike_auth_resp_param);
unless($ret) {
	kLogHTML(kDump_Common_Error());
	IKEv2exitFatal('<FONT COLOR="#ff0000">Can\'t set keying material.</FONT>');
}



#------------------------------------------#
# prepare expected CREATE_CHILD_SA request #
#------------------------------------------#
# get IKE_SA_INIT's transform
my $common_ike_sa_init_req = $exp_ike_sa_init_req->{'common_remote_index'};
my @tmp_ike_sa_init_req = @{$common_ike_sa_init_req};
my @ike_sa_init_transform = undef;
for (my $i = 0; $i < scalar(@tmp_ike_sa_init_req); $i++) {
	my $payload = $tmp_ike_sa_init_req[$i];

	if ($payload->{'self'} eq 'SA') {
		for (my $j = 0; $j < scalar(@{$payload->{'proposals'}}); $j++) {
			my $proposal = @{$payload->{'proposals'}}[$j];

			if (defined($proposal->{'transforms'})) {
				@ike_sa_init_transform = @{$proposal->{'transforms'}};
				last;
			}
		}
	}
}
# generete CREATE_CHILD_SA request for IKE_SA
my $common_create_child_sa_req = $exp_create_child_sa_req->{'common_remote_index'};
@local_create_child_sa_req = @{$common_create_child_sa_req};
for (my $i = 0; $i < scalar(@local_create_child_sa_req); $i++) {
	my $payload = $local_create_child_sa_req[$i];

	if ($payload->{'self'} eq 'E') {
		for (my $j = 0; $j < scalar(@{$payload->{'innerPayloads'}}); $j++) {
			my $inner = @{$payload->{'innerPayloads'}}[$j];

			# delete N, TSi, TSr
			if ( (($inner->{'self'} eq 'N') && ($inner->{'type'} eq 'USE_TRANSPORT_MODE'))
			    || ($inner->{'self'} eq 'TSi') || ($inner->{'self'} eq 'TSr') ) {
				splice(@{$payload->{'innerPayloads'}}, $j, 1);
				redo;
			}
			# change proposal setting
			if ($inner->{'self'} eq 'SA') {
				for (my $k = 0; $k < scalar(@{$inner->{'proposals'}}); $k++) {
					my $proposal = @{$inner->{'proposals'}}[$k];

					$proposal->{'id'} = 'IKE';				# ProtocolID(1=IKE)
					$proposal->{'spiSize'} = '8';				# SPI size
					$proposal->{'proposalLen'} = '48';			# length +8 +4

					@{$proposal->{'transforms'}} = @ike_sa_init_transform;
				}
				$inner->{'length'} = '52';	  # SA payload length
			}
		}
		#set correct nexttype
		$payload->{'innerType'} = @{$payload->{'innerPayloads'}}[0]->{'self'};
		for (my $j = 0; $j < scalar(@{$payload->{'innerPayloads'}}); $j++) {
			my $inner = @{$payload->{'innerPayloads'}}[$j];

			if ($inner->{'self'} eq 'Ni, Nr') {
				my $next = ${$payload->{'innerPayloads'}}[$j+1]; 
				unless (defined($next)) {
					$inner->{'nexttype'} = '0';
					next;
				}
				if ($inner->{'nexttype'} eq $next->{'self'}) {
					next;
				}
				$inner->{'nexttype'} = $next->{'self'};
			}
		}
	}
}
my $index = 'simultaneous_ike_sa_rekeying';
$exp_create_child_sa_req->{$index} = \@local_create_child_sa_req;



#--------------------------------------#
# prepare ICMP session handler         #
#--------------------------------------#
my $icmp_session_th2 = ICMPcreate_session('TH2sendtoTH1');
unless(defined($icmp_session_th2)) {
	IKEv2exitFatal('<FONT COLOR="#ff0000">ICMP session creation failure</FONT>');
}


my $icmp_session_th1 = ICMPcreate_session('TH1sendtoTH2');
unless(defined($icmp_session_th1)) {
        IKEv2exitFatal('<FONT COLOR="#ff0000">ICMP session creation failure</FONT>');
}



#-------------------------------------------------------------#
# repeat Echo exchange until lifetime of NUT's SA is expired  #
#-------------------------------------------------------------#
#---------------------------#
# set lifetime to CHILD_SA  #
#---------------------------#
my $sa_life = $config_pl->{'ikev2_nut_ike_sa_lifetime'};
my $t1 = time;
my $t2 = time;

while (($t2 - $t1) < $sa_life)
{
	#--------------------------------------#
	# send Echo Request                    #
	# receive Echo Reply                   #
	#--------------------------------------#
	$ret = ICMPexchange($tn, $nut, $icmp_session_th2, $icmp_session_th1);
	if ($ret == -1) {
		kLogHTML(kDump_Common_Error());
		IKEv2exitFatal('<FONT COLOR="#ff0000">Can\'t send ICMP packet.</FONT>');
	}
	elsif ($ret == 0) {
		my $strerror = kDump_Common_Error();
		kLogHTML('<FONT COLOR="#ff0000">Can\'t observe ICMP packet.</FONT>');
		IKEv2exitFail();
	}


	#------------------------------------------#
	# receive CREATE_CHILD_SA request by NUT   #
	#------------------------------------------#
	$str  = '<PRE>';
	$str .= "    (I)             (R)\n";
	$str .= "    NUT             TN1\n";
	$str .= "     |               |\n";
	$str .= "     |-------------->| CREATE_CHILD_SA request (HDR, SK {SA, Ni})\n";
	$str .= "     |               |\n";
	$str .= "     V               V";
	$str .= '</PRE>';
	kLogHTML($str);


	$session->timeout(3);
	$create_child_sa_req_param_from_nut = devel_IKEv2receive_CREATE_CHILD_SA_request($session,
											 $index,
											 $ike_sa_init_req_param,
											 $ike_sa_init_resp_param,
											 $ike_auth_req_param,
											 $material_1st);
	$t2 = time;

	if (defined($create_child_sa_req_param_from_nut)) {
		last;
	}
}

if (($t2 - $t1) >= $sa_life)
{
	kLogHTML(kDump_Common_Error());
	kLogHTML('<FONT COLOR="#ff0000">Can\'t observe CREATE_CHILD_SA request.</FONT>');
	IKEv2exitFail();
}



#---------------------------------------------#
# (Step. 10) send CREATE_CHILD_SA request     #
#---------------------------------------------#
#--------------------------------------#
# prepare CREATE_CHILD_SA request      #
#--------------------------------------#
# get IKE_SA_INIT's transform
my $common_ike_sa_init_req = $gen_ike_sa_init_req->{'common_remote_index'};
my @tmp_ike_sa_init_req = @{$common_ike_sa_init_req};
my @ike_sa_init_transform = undef;
my $ike_sa_init_ke = undef;            #********************* for racoon2 ***************
for (my $i = 0; $i < scalar(@tmp_ike_sa_init_req); $i++) {
	my $payload = $tmp_ike_sa_init_req[$i];

	if ($payload->{'self'} eq 'SA') {
		for (my $j = 0; $j < scalar(@{$payload->{'proposals'}}); $j++) {
			my $proposal = @{$payload->{'proposals'}}[$j];

			if (defined($proposal->{'transforms'})) {
				@ike_sa_init_transform = @{$proposal->{'transforms'}};
				last;
			}
		}
	}
	#********************** for racoon2 ***************
	if ($payload->{'self'} eq 'KE') {
		$ike_sa_init_ke = $payload;
	}
}
# generate CREATE_CHILD_SA Request for IKE_SA
my $common_create_child_sa_req = $gen_create_child_sa_req->{'common_remote_index'};
@local_create_child_sa_req = @{$common_create_child_sa_req};
for (my $i = 0; $i < scalar(@local_create_child_sa_req); $i++) {
	my $payload = $local_create_child_sa_req[$i];

	# delete N, TSi, TSr
	if ( (($payload->{'self'} eq 'N') && ($payload->{'type'} eq 'USE_TRANSPORT_MODE'))
	     || ($payload->{'self'} eq 'TSi')
	     || ($payload->{'self'} eq 'TSr') ) {
		splice(@local_create_child_sa_req, $i, 1);
		redo;
	}
	# change proposal setting
	if ($payload->{'self'} eq 'SA') {
		for (my $j = 0; $j < scalar(@{$payload->{'proposals'}}); $j++) {
			my $proposal = @{$payload->{'proposals'}}[$j];

			$proposal->{'id'} = 'IKE';				# ProtocolID(1=IKE)
			$proposal->{'spiSize'} = '8';				# SPI size

			@{$proposal->{'transforms'}} = @ike_sa_init_transform;
		}

		#****** add KE for racoon2.... ******
		splice(@local_create_child_sa_req, $i+1, 0, $ike_sa_init_ke);	 # add KEi ****for racoon2***
	}
}
$index = 'simultaneous_ike_sa_rekeying.10';
$gen_create_child_sa_req->{$index} = \@local_create_child_sa_req;



#--------------------------------------#
# send CREATE_CHILD_SA request to NUT  #
#--------------------------------------#
$str  = '<PRE>';
$str .= "    (R)             (I)\n";
$str .= "    NUT             TN1\n";
$str .= "     |               |\n";
$str .= "     |<--------------| CREATE_CHILD_SA request (HDR, SK {SA, Nir})\n";
$str .= "     |               |\n";
$str .= "     V               V";
$str .= '</PRE>';

kLogHTML($str);



$create_child_sa_req_param_from_tn1 = devel_IKEv2send_CREATE_CHILD_SA_request($session,
								     $index,
								     $ike_sa_init_req_param,
								     $ike_sa_init_resp_param,
								     $ike_auth_req_param,
								     $material_1st);
unless(defined($create_child_sa_req_param_from_tn1)) {
	kLogHTML(kDump_Common_Error());
	IKEv2exitFatal('<FONT COLOR="#ff0000">Can\'t send CREATE_CHILD_SA request.</FONT>');
}



#---------------------------------------------#
# (Step. 11) receive CREATE_CHILD_SA response #
#---------------------------------------------#
#--------------------------------------#
# prepare CREATE_CHILD_SA response     #
#--------------------------------------#
# get IKE_SA_INIT's transform
my $common_ike_sa_init_resp = $exp_ike_sa_init_resp->{'common_remote_index'};
my @tmp_ike_sa_init_resp = @{$common_ike_sa_init_resp};
my @ike_sa_init_transform = undef;
for (my $i = 0; $i < scalar(@tmp_ike_sa_init_resp); $i++) {
	my $payload = $tmp_ike_sa_init_resp[$i];

	if ($payload->{'self'} eq 'SA') {
		for (my $j = 0; $j < scalar(@{$payload->{'proposals'}}); $j++) {
			my $proposal = @{$payload->{'proposals'}}[$j];

			if (defined($proposal->{'transforms'})) {
				@ike_sa_init_transform = @{$proposal->{'transforms'}};
				last;
			}
		}
	}
}
# generete CREATE_CHILD_SA Response for IKE_SA
my $common_create_child_sa_resp = $exp_create_child_sa_resp->{'common_remote_index'};
@local_create_child_sa_resp = @{$common_create_child_sa_resp};
for (my $i = 0; $i < scalar(@local_create_child_sa_resp); $i++) {
	my $payload = $local_create_child_sa_resp[$i];

	if ($payload->{'self'} eq 'E') {
		for (my $j = 0; $j < scalar(@{$payload->{'innerPayloads'}}); $j++) {
			my $inner = @{$payload->{'innerPayloads'}}[$j];

			# delete N, TSi, TSr
			if ( (($inner->{'self'} eq 'N') && ($inner->{'type'} eq 'USE_TRANSPORT_MODE'))
			     || ($inner->{'self'} eq 'TSi') || ($inner->{'self'} eq 'TSr') ) {
				splice(@{$payload->{'innerPayloads'}}, $j, 1);
				redo;
			}
			# change proposal setting
			if ($inner->{'self'} eq 'SA') {
				for (my $k = 0; $k < scalar(@{$inner->{'proposals'}}); $k++) {
					my $proposal = @{$inner->{'proposals'}}[$k];

					$proposal->{'id'} = 'IKE';				# ProtocolID(1=IKE)
					$proposal->{'spiSize'} = '8';				# SPI size
					$proposal->{'proposalLen'} = '48';			# length +8 +4

					@{$proposal->{'transforms'}} = @ike_sa_init_transform;
				}
				$inner->{'length'} = '52';	  # SA payload length
			}
		}
		#set correct nexttype
		$payload->{'innerType'} = @{$payload->{'innerPayloads'}}[0]->{'self'};
		for (my $j = 0; $j < scalar(@{$payload->{'innerPayloads'}}); $j++) {
			my $inner = @{$payload->{'innerPayloads'}}[$j];

			if ($inner->{'self'} eq 'Ni, Nr') {
				my $next = ${$payload->{'innerPayloads'}}[$j+1]; 
				unless (defined($next)) {
					$inner->{'nexttype'} = '0';
					next;
				}
				if ($inner->{'nexttype'} eq $next->{'self'}) {
					next;
				}
				$inner->{'nexttype'} = $next->{'self'};
			}
		}
	}
}
$index = 'simultaneous_ike_sa_rekeying.11';
$exp_create_child_sa_resp->{$index} = \@local_create_child_sa_resp;



#------------------------------------------#
# receive CREATE_CHILD_SA response by NUT  #
#------------------------------------------#
$str  = '<PRE>';
$str .= "    (R)             (I)\n";
$str .= "    NUT             TN1\n";
$str .= "     |               |\n";
$str .= "     |-------------->| CREATE_CHILD_SA response (HDR, SK {SA, Nr})\n";
$str .= "     |               |\n";
$str .= "     V               V";
$str .= '</PRE>';

kLogHTML($str);



$create_child_sa_resp_param_from_nut = devel_IKEv2receive_CREATE_CHILD_SA_response($session,
										   $index,
										   $ike_sa_init_req_param,
										   $ike_sa_init_resp_param,
										   $create_child_sa_req_param_from_tn1,
										   $material_1st);
unless(defined($create_child_sa_resp_param_from_nut)) {
	kLogHTML(kDump_Common_Error());
	kLogHTML('<FONT COLOR="#ff0000">Can\'t observe CREATE_CHILD_SA response.</FONT>');
	IKEv2exitFail();
}



#---------------------------------------------#
# (Step. 12) send CREATE_CHILD_SA response    #
#---------------------------------------------#
#--------------------------------------#
# prepare CREATE_CHILD_SA response     #
#--------------------------------------#
# get IKE_SA_INIT's transform
my $common_ike_sa_init_resp = $gen_ike_sa_init_resp->{'common_remote_index'};
my @tmp_ike_sa_init_resp = @{$common_ike_sa_init_resp};
my @ike_sa_init_transform = undef;
my $ike_sa_init_ke = undef;	#********************** for racoon2 ***************
for (my $i = 0; $i < scalar(@tmp_ike_sa_init_resp); $i++) {
	my $payload = $tmp_ike_sa_init_resp[$i];

	if ($payload->{'self'} eq 'SA') {
		for (my $j = 0; $j < scalar(@{$payload->{'proposals'}}); $j++) {
			my $proposal = @{$payload->{'proposals'}}[$j];

			if (defined($proposal->{'transforms'})) {
				@ike_sa_init_transform = @{$proposal->{'transforms'}};
				last;
			}
		}
	}
	#********************** for racoon2 ***************
	if ($payload->{'self'} eq 'KE') {
		$ike_sa_init_ke = $payload;
	}
}

# generate CREATE_CHILD_SA response for IKE_SA
my $common_create_child_sa_resp = $gen_create_child_sa_resp->{'common_remote_index'};
@local_create_child_sa_resp = @{$common_create_child_sa_resp};
for (my $i = 0; $i < scalar(@local_create_child_sa_resp); $i++) {
	my $payload = $local_create_child_sa_resp[$i];

	# delete N, TSi, TSr
	if ( (($payload->{'self'} eq 'N') && ($payload->{'type'} eq 'USE_TRANSPORT_MODE'))
	     || ($payload->{'self'} eq 'TSi')
	     || ($payload->{'self'} eq 'TSr')) {
		splice(@local_create_child_sa_resp, $i, 1);
		redo;
	}
	# change proposal setting
	if ($payload->{'self'} eq 'SA') {
		for (my $j = 0; $j < scalar(@{$payload->{'proposals'}}); $j++) {
			my $proposal = @{$payload->{'proposals'}}[$j];

			$proposal->{'id'} = 'IKE';				# ProtocolID(1=IKE)
			$proposal->{'spiSize'} = '8';				# SPI size

			@{$proposal->{'transforms'}} = @ike_sa_init_transform;
		}

		#****** add KE for racoon2.... ******
		splice(@local_create_child_sa_resp, $i+1, 0, $ike_sa_init_ke);	 # add KEi ****for racoon2***
	}
	# specify minimum value
	if ($payload->{'self'} eq 'Ni, Nr') {
		$payload->{'nonce'} = '0000000000000000000000000000000000000000000000000000000000000001';
	}
}
$index = 'simultaneous_ike_sa_rekeying.12';
$gen_create_child_sa_resp->{$index} = \@local_create_child_sa_resp;



#--------------------------------------#
# send CREATE_CHILD_SA response        #
#--------------------------------------#
$str  = '<PRE>';
$str .= "    (R)             (I)\n";
$str .= "    NUT             TN1\n";
$str .= "     |               |\n";
$str .= "     |<--------------| CREATE_CHILD_SA response (HDR, SK {SA, Nir})\n";
$str .= "     |               |\n";
$str .= "     V               V";
$str .= '</PRE>';

kLogHTML($str);



$create_child_sa_resp_param_from_tn1 = devel_IKEv2send_CREATE_CHILD_SA_response($session,
										$index,
										$ike_sa_init_req_param,
										$ike_sa_init_resp_param,
										$create_child_sa_req_param_from_nut,
										$material_1st);
unless(defined($create_child_sa_req_param_from_tn1)) {
	kLogHTML(kDump_Common_Error());
	IKEv2exitFatal('<FONT COLOR="#ff0000">Can\'t send CREATE_CHILD_SA request.</FONT>');
}



#--------------------------------------#
# generate keying material             #
#--------------------------------------#
# IKE_SA to be closed, because this IKE_SA has minimum nonce value
$material_2nd = devel_IKEv2gen_keymat(0,
				      $ike_sa_init_req_param,
				      $ike_sa_init_resp_param,
				      $create_child_sa_req_param_from_nut,
				      $create_child_sa_resp_param_from_tn1,
				      $material_1st);
unless(defined($material_2nd)) {
	kLogHTML(kDump_Common_Error());
	IKEv2exitFatal('<FONT COLOR="#ff0000">Can\'t generate keying material.</FONT>');
}

$material_3rd = devel_IKEv2gen_keymat(1,
				      $ike_sa_init_req_param,
				      $ike_sa_init_resp_param,
				      $create_child_sa_req_param_from_tn1,
				      $create_child_sa_resp_param_from_nut,
				      $material_1st);
unless(defined($material_3rd)) {
	kLogHTML(kDump_Common_Error());
	IKEv2exitFatal('<FONT COLOR="#ff0000">Can\'t generate keying material.</FONT>');
}



#----------------------------------------------------------#
# (Step. 13) receive INFORMATIONAL request to close IKE_SA #
#----------------------------------------------------------#
#--------------------------------------------#
# prepare expected packet                    #
# for INFORMATIONAL Request (Delete Payload) #
#--------------------------------------------#
my $delete_payload =
{	# Delete Payload
	'self'		=> 'D',		# *** MUST BE HERE ***
	'nexttype'	=> undef,	# Next Payload
	'critical'	=> undef,	# Critical
	'reserved'	=> undef,	# RESERVED
	'length'	=> '8',		# Payload Length
	'id'		=> 'IKE',	# Protocol ID
	'spiSize'	=> '0',		# SPI Size
	'spiCount'	=> '0',
	'spis'		=> '',
};
my $common_informational_req = $exp_informational_req->{'common_remote_index'};
my @local_informational_req = @{$common_informational_req};

# add Delete payload 
for (my $i = 0; $i < scalar(@local_informational_req); $i++) {
	if ($local_informational_req[$i]->{'self'} eq 'HDR') {
		$local_informational_req[$i]->{'initSPI'} = $create_child_sa_req_param_from_nut->{'spi'}[0];
		$local_informational_req[$i]->{'respSPI'} = $create_child_sa_resp_param_from_tn1->{'spi'};
	}

	if ($local_informational_req[$i]->{'self'} eq 'E') {
		splice(@{$local_informational_req[$i]->{'innerPayloads'}}, 0);
		push(@{$local_informational_req[$i]->{'innerPayloads'}}, $delete_payload);
	}
}

# set correct nexttype
foreach my $payload1 (@local_informational_req) {
	if ($payload1->{'self'} eq 'E') {
		$payload1->{'innerType'} = @{$payload1->{'innerPayloads'}}[0]->{'self'};
		for (my $i = 0; $i < scalar(@{$payload1->{'innerPayloads'}}); $i++) {
			my $inner = ${$payload1->{'innerPayloads'}}[$i];
			my $next = ${$payload1->{'innerPayloads'}}[$i+1];
			if (defined($next)) {
				$inner->{'nexttype'} = $next->{'self'};
			}
			else {
				$inner->{'nexttype'} = '0';
			}
		}
	}
}

$index = 'simultaneous_ike_sa_rekeying.13';
$exp_informational_req->{$index} = \@local_informational_req;



#-----------------------------------------#
# receive INFORMATIONAL Request by NUT    #
#-----------------------------------------#
$str  = '<PRE>';
$str .= "    (I)             (R)\n";
$str .= "    NUT             TN1\n";
$str .= "     |               |\n";
$str .= "     |-------------->| INFORMATIONAL request (HDR, SK {D})\n";
$str .= "     |               |\n";
$str .= "     V               V";
$str .= '</PRE>';

kLogHTML($str);


$informational_req_param = devel_IKEv2receive_INFORMATIONAL_request($session,
								    $index,
								    $ike_sa_init_req_param,
								    $ike_sa_init_resp_param,
								    $create_child_sa_req_param_from_nut,
								    $material_2nd);
unless (defined($informational_req_param)) {
	kLogHTML(kDump_Common_Error());
	kLogHTML('<FONT COLOR="#ff0000">Can\'t observe INFORMATIONAL Request.</FONT>');
	IKEv2exitFail();
}



#---------------------------------------------#
# (Step. 14) send INFORMATIONAL response      #
#---------------------------------------------#
my $common_informational_resp = $gen_informational_resp->{'common_remote_index'};
my @local_informational_resp = @{$common_informational_resp};

for (my $i = 0; $i < scalar(@local_informational_resp); $i++) {
	if ($local_informational_resp[$i]->{'self'} eq 'HDR') {
		$local_informational_resp[$i]->{'initSPI'} = $create_child_sa_req_param_from_nut->{'spi'}[0];
		$local_informational_resp[$i]->{'respSPI'} = $create_child_sa_resp_param_from_tn1->{'spi'};
	}
}
$index = 'simultaneous_ike_sa_rekeying.14';
$gen_informational_resp->{$index} = \@local_informational_resp;


$str  = '<PRE>';
$str .= "    (I)             (R)\n";
$str .= "    NUT             TN1\n";
$str .= "     |               |\n";
$str .= "     |<--------------| INFORMATIONAL response (HDR, SK {})\n";
$str .= "     |               |\n";
$str .= "     V               V";
$str .= '</PRE>';

kLogHTML($str);



$informational_resp_param = devel_IKEv2send_INFORMATIONAL_response($session,
								   $remote,
								   $ike_sa_init_req_param,
								   $ike_sa_init_resp_param,
								   $informational_req_param,
								   $material_2nd);
unless (defined($informational_resp_param)) {
	kLogHTML(kDump_Common_Error());
	IKEv2exitFatal('<FONT COLOR="#ff0000">Can\'t send INFORMATIONAL response.</FONT>');
}



#----------------------------------------------------------#
# (Step. 15) receive INFORMATIONAL request to close IKE_SA #
#----------------------------------------------------------#
#--------------------------------------------#
# prepare expected packet                    #
# for INFORMATIONAL Request (Delete Payload) #
#--------------------------------------------#
my $delete_payload =
{	# Delete Payload
	'self'		=> 'D',		# *** MUST BE HERE ***
	'nexttype'	=> undef,	# Next Payload
	'critical'	=> undef,	# Critical
	'reserved'	=> undef,	# RESERVED
	'length'	=> '8',		# Payload Length
	'id'		=> 'IKE',	# Protocol ID
	'spiSize'	=> '0',		# SPI Size
	'spiCount'	=> '0',
	'spis'		=> '',
};
$common_informational_req = $exp_informational_req->{'common_remote_index'};
@local_informational_req = @{$common_informational_req};

# add Delete payload 
for (my $i = 0; $i < scalar(@local_informational_req); $i++) {
	if ($local_informational_req[$i]->{'self'} eq 'HDR') {
		$local_informational_req[$i]->{'initSPI'} = 'read';
		$local_informational_req[$i]->{'respSPI'} = 'read';
	}

	if ($local_informational_req[$i]->{'self'} eq 'E') {
		splice(@{$local_informational_req[$i]->{'innerPayloads'}}, 0);
		push(@{$local_informational_req[$i]->{'innerPayloads'}}, $delete_payload);
		last;
	}
}

# set correct nexttype
foreach my $payload1 (@local_informational_req) {
	if ($payload1->{'self'} eq 'E') {
		$payload1->{'innerType'} = @{$payload1->{'innerPayloads'}}[0]->{'self'};
		for (my $i = 0; $i < scalar(@{$payload1->{'innerPayloads'}}); $i++) {
			my $inner = ${$payload1->{'innerPayloads'}}[$i];
			my $next = ${$payload1->{'innerPayloads'}}[$i+1];
			if (defined($next)) {
				$inner->{'nexttype'} = $next->{'self'};
			}
			else {
				$inner->{'nexttype'} = '0';
			}
		}
	}
}

$index = 'simultaneous_ike_sa_rekeying.15';
$exp_informational_req->{$index} = \@local_informational_req;


#-----------------------------------------#
# receive INFORMATIONAL Request by NUT    #
#-----------------------------------------#
$str  = '<PRE>';
$str .= "    (I)             (R)\n";
$str .= "    NUT             TN1\n";
$str .= "     |               |\n";
$str .= "     |-------------->| INFORMATIONAL request (HDR, SK {D})\n";
$str .= "     |               |\n";
$str .= "     V               V";
$str .= '</PRE>';

kLogHTML($str);



$informational_req_param = devel_IKEv2receive_INFORMATIONAL_request($session,
								    $index,
								    $ike_sa_init_req_param,
								    $ike_sa_init_resp_param,
								    $create_child_sa_req_param_from_nut,
								    $material_1st);
unless (defined($informational_req_param)) {
	kLogHTML(kDump_Common_Error());
	kLogHTML('<FONT COLOR="#ff0000">Can\'t observe INFORMATIONAL Request.</FONT>');
	IKEv2exitFail();
}



#---------------------------------------------#
# (Step. 16) send INFORMATIONAL response      #
#---------------------------------------------#
$common_informational_resp = $gen_informational_resp->{'common_remote_index'};
@local_informational_resp = @{$common_informational_resp};

for (my $i = 0; $i < scalar(@local_informational_resp); $i++) {
	if ($local_informational_resp[$i]->{'self'} eq 'HDR') {
		$local_informational_resp[$i]->{'initSPI'} = 'read';
		$local_informational_resp[$i]->{'respSPI'} = 'read';
	}
}
$index = 'simultaneous_ike_sa_rekeying.16';
$gen_informational_resp->{$index} = \@local_informational_resp;


$str  = '<PRE>';
$str .= "    (I)             (R)\n";
$str .= "    NUT             TN1\n";
$str .= "     |               |\n";
$str .= "     |<--------------| INFORMATIONAL response (HDR, SK {})\n";
$str .= "     |               |\n";
$str .= "     V               V";
$str .= '</PRE>';

kLogHTML($str);



$informational_resp_param = devel_IKEv2send_INFORMATIONAL_response($session,
								   $remote,
								   $ike_sa_init_req_param,
								   $ike_sa_init_resp_param,
								   $informational_req_param,
								   $material_1st);
unless (defined($informational_resp_param)) {
	kLogHTML(kDump_Common_Error());
	IKEv2exitFatal('<FONT COLOR="#ff0000">Can\'t send INFORMATIONAL response.</FONT>');
}



#----------------------------------------------------------#
# (Step. 17) send INFORMATIONAL request for liveness check #
#----------------------------------------------------------#
$common_informational_req = $exp_informational_req->{'common_remote_index'};
@local_informational_req = @{$common_informational_req};

for (my $i = 0; $i < scalar(@local_informational_req); $i++) {
	if ($local_informational_req[$i]->{'self'} eq 'HDR') {
		$local_informational_req[$i]->{'initSPI'} = $create_child_sa_req_param_from_tn1->{'spi'}[0];
		$local_informational_req[$i]->{'respSPI'} = $create_child_sa_resp_param_from_nut->{'spi'};
	}

	if ($local_informational_req[$i]->{'self'} eq 'E') {
		splice(@{$local_informational_req[$i]->{'innerPayloads'}}, 0);
	}
}

$index = 'simultaneous_ike_sa_rekeying.17';
$gen_informational_req->{$index} = \@local_informational_req;


#-----------------------------------------#
# send INFORMATIONAL Request              #
#-----------------------------------------#
$str  = '<PRE>';
$str .= "    (I)             (R)\n";
$str .= "    NUT             TN1\n";
$str .= "     |               |\n";
$str .= "     |               |\n";
$str .= "     |<--------------| INFORMATIONAL Request (HDR, SK {})\n";
$str .= "     |               |\n";
$str .= "     V               V";
$str .= '</PRE>';

kLogHTML($str);


$informational_req_param = devel_IKEv2send_INFORMATIONAL_request($session,
								 $index,
								 $ike_sa_init_req_param,
								 $ike_sa_init_resp_param,
								 $ike_auth_req_param,
								 $material_3rd);
unless(defined($informational_req_param)) {
	kLogHTML(kDump_Common_Error());
	IKEv2exitFatal('<FONT COLOR="#ff0000">Can\'t send INFORMATIONAL request.</FONT>');
}



#---------------------------------------------#
# (Step. 18) receive INFORMATIONAL response   #
#---------------------------------------------#
my $common_informational_resp = $exp_informational_resp->{'common_remote_index'};
my @local_informational_resp = @{$common_informational_resp};

# add Delete payload 
for (my $i = 0; $i < scalar(@local_informational_resp); $i++) {
	if ($local_informational_resp[$i]->{'self'} eq 'HDR') {
		$local_informational_resp[$i]->{'initSPI'} = $create_child_sa_req_param_from_tn1->{'spi'}[0];
		$local_informational_resp[$i]->{'respSPI'} = $create_child_sa_resp_param_from_nut->{'spi'};
	}

	if ($local_informational_resp[$i]->{'self'} eq 'E') {
#		splice(@{$local_informational_resp[$i]->{'innerPayloads'}}, 0);
	}
}

$index = 'simultaneous_ike_sa_rekeying.18';
$exp_informational_resp->{$index} = \@local_informational_resp;


#-----------------------------------------#
# receive INFORMATIONAL Request by NUT    #
#-----------------------------------------#
$str  = '<PRE>';
$str .= "    (I)             (R)\n";
$str .= "    NUT             TN1\n";
$str .= "     |               |\n";
$str .= "     |-------------->| INFORMATIONAL Response (HDR, SK {})\n";
$str .= "     |               |\n";
$str .= "     V               V";
$str .= '</PRE>';

kLogHTML($str);


$informational_resp_param = devel_IKEv2receive_INFORMATIONAL_response($session,
								      $index,
								      $ike_sa_init_req_param,
								      $ike_sa_init_resp_param,
								      $informational_req_param,
								      $material_3rd);
unless (defined($informational_resp_param)) {
	kLogHTML(kDump_Common_Error());
	kLogHTML('<FONT COLOR="#ff0000">Can\'t observe INFORMATIONAL Response.</FONT>');
	IKEv2exitFail();
}



#--------------------------------------#
# exit with cleanup                    #
#--------------------------------------#
IKEv2exitPass();


#
# perldoc
#
########################################################################
__END__

=head1 Title

  Test IKEv2.SGW.I.1.2.6.5: Simultaneous IKE_SA Rekeying
  Part A: (BASIC)

=head1 Purpose

  To verify an IKEv2 device properly handles a CREATE_CHILD_SA to rekey IKE_SA.

=head1 References

  * [RFC 4718] - Sections 5.11.4

=head1 Test Setup

  * Network Topology
      Connect the devices according to the Common Topology.
  * Configuration
      In each part, configure the devices according to the Common Configuration.
      In addition, set IKE_SA Lifetime to 60 seconds and set CHILD_SA Lifetime to 300
      seconds.
  * Pre-Sequence and Cleanup Sequence
      IKEv2 on the NUT is disabled after each part.

=head1 Procedure

=begin html

<BLOCKQUOTE>
<PRE>

   TH1            NUT           TN1           TH2
 (HOST)          (SGW)         (SGW)         (Host)
    |              |             |             |
    |              |------------>|             | IKE_SA_INIT request (HDR, SAi1, KEi, Ni)
    |              |             |             | (Judgement #1)
    |              |<------------|             | IKE_SA_INIT Response (HDR, SAr1, KEr, Nr)
    |              |             |             | (Packet #1)
    |              |             |             |
    |              |------------>|             | IKE_AUTH request (HDR, SK {IDi, AUTH, SAi2, TSi, TSr})
    |              |             |             | (Judgement #2)
    |              |<------------|             | IKE_AUTH Response (HDR, SK {IDr, AUTH, SAr2, TSi, TSr})
    |              |             |             | (Packet #2)
    |              |             |             |
   ---            ---           ---           ---
    |              |             |             |                             ---
    |<-------------+=============+-------------| IPSec {Echo Request}         | repeat Echo Exchange
    |              |             |             | (Packet #3) (Judgement #3)   | until lifetime of
    |--------------+=============+------------>| IPSec {Echo Reply}           | SA is expired
    |              |             |             | (Packet #4) (Judgement #4)   |
    |              |             |             |                             ---
   ---            ---           ---           ---
    |              |             |             |
    |              |------------>|             | CREATE_CHILD_SA request (HDR, SK {SA, Ni})
    |              |             |             | (Judgement #5)
    |              |             |             |
    |              |<------------|             | CREATE_CHILD_SA request (HDR, SK {SA, Ni})
    |              |             |             | (Packet #5)
    |              |------------>|             | CREATE_CHILD_SA response (HDR, SK {SA, Nr})
    |              |             |             | (Judgement #6)
    |              |             |             |
    |              |<------------|             | CREATE_CHILD_SA response (HDR, SK {SA, Nr})
    |              |             |             | (Packet #6)
    |              |             |             |
    |              |------------>|             | INFORMATIONAL request (HDR, SK {D})
    |              |             |             | (Judgement #7)
    |              |<------------|             | INFORMATIONAL response (HDR, SK {})
    |              |             |             | (Packet #7)
    |              |             |             |
    |              |------------>|             | INFORMATIONAL request (HDR, SK {D})
    |              |             |             | (Judgement #8)
    |              |<------------|             | INFORMATIONAL response (HDR, SK {})
    |              |             |             | (Packet #8)
    |              |             |             |
    |              |<------------|             | INFORMATIONAL request (HDR, SK {})  (new IKE_SA)
    |              |             |             | (Judgement #9)
    |              |------------>|             | INFORMATIONAL response (HDR, SK {}) (new IKE_SA)
    |              |             |             | (Packet #9)
    |              |             |             |
    V              V             V             V<br>

</PRE>
</BLOCKQUOTE>

<BLOCKQUOTE>
<TABLE BORDER>
<TR>
<TD><TT>Packet #1</TT></TD>
<TD><TT>See Common Packet #2</TT></TD>
</TR>
<TR>
<TD><TT>Packet #2</TT></TD>
<TD><TT>See Common Packet #6</TT></TD>
</TR>
<TR>
<TD><TT>Packet #3</TT></TD>
<TD><TT>See Common Packet #21</TT></TD>
</TR>
<TR>
<TD><TT>Packet #4</TT></TD>
<TD><TT>See Common Packet #25</TT></TD>
</TR>
<TR>
<TD><TT>Packet #5</TT></TD>
<TD><TT>See Common Packet #11</TT></TD>
</TR>
<TR>
<TD><TT>Packet #6</TT></TD>
<TD><TT>See Common Packet #12</TT></TD>
</TR>
<TR>
<TD><TT>Packet #7</TT></TD>
<TD><TT>See Common Packet #18</TT></TD>
</TR>
<TR>
<TD><TT>Packet #8</TT></TD>
<TD><TT>See Common Packet #18</TT></TD>
</TR>
<TR>
<TD><TT>Packet #9</TT></TD>
<TD><TT>See Common Packet #17<br>(new IKE_SA)</TT></TD>
</TR>
</TABLE>
</BLOCKQUOTE>

=end html

  Part A: (BASIC)
     1. NUT starts to negotiate with TN1 by sending IKE_SA_INIT request.
     2. Observe the messages transmitted on Link A.
     3. TN1 responds with an IKE_SA_INIT response to the NUT.
     4. Observe the messages transmitted on Link A.
     5. After reception of IKE_AUTH request from the NUT, TN1 responds with an IKE_AUTH
         response to the NUT
     6. TH2 transmits an Echo Request to TH1.
     7. Observe the messages transmitted on Link B.
     8. TH1 transmits an Echo Reply to TH2.
     9. Observe the messages transmitted on Link A.
     10. Repeat Steps 6 and 9 until lifetime of SA is expired.
     11. Observe the messages transmitted on Link A.
     12. TN1 transmits a CREATE_CHILD_SA request to rekey IKE_SA to the NUT.
     13. Observe the messages transmitted on Link A.
     14. TN1 responds with a CREATE_CHILD_SA response to the CREATE_CHILD_SA request
         received at Step 11. The response message includes minimum Nonce Data to make the NUT
         send a message to close duplicated IKE_SA.
     15. Observe the messages transmitted on Link A.
     16. TN1 responds with an INFORMATIONAL response with no payload.
     17. Observe the messages transmitted on Link A.
     18. TN1 responds with an INFORMATIONAL response with no payload.
     19. TN1 transmits an INFORMATIONAL request with no payload to the NUT. The message is
         cryptographically protected by the new IKE_SA initiated by TN1 at Step 12.
     20. Observe the messages transmitted on Link A.

=head1 Observable Result

  Part A
       Step 2: Judgment #1
       The NUT transmits an IKE_SA_INIT request including "ENCR_3DES",
       "PRF_HMAC_SHA1", "AUTH_HMAC_SHA1_96" and "D-H group 2" as proposed
       algorithms.

       Step 4: Judgment #2
       The NUT transmits an IKE_AUTH request including "ENCR_3DES",
       "AUTH_HMAC_SHA1_96" and "No Extended Sequence Numbers" as proposed algorithms.

       Step 7: Judgment #3
       The NUT forwards an Echo Request.

       Step 9: Judgment #4
       The NUT forwards an Echo Reply with IPsec ESP using ENCR_3DES an
       AUTH_HMAC_SHA1_96.

       Step 11: Judgment #5
       The NUT transmits a CREATE_CHILD_SA request to rekey an IKE_SA. The message
       includes "ENCR_3DES", "PRF_HMAC_SHA1", "AUTH_HMAC_SHA1_96" and "D-H
       group 2" as proposed algorithms. And the CREATE_CHILD_SA request has a SA payload
       including 1 (IKE) in the Protocol ID field, 8 in the SPI size field and new IKE_SA's SPI
       value in the SPI field.

       Step 13: Judgment #6
       The NUT responds a CREATE_CHILD_SA response including "ENCR_3DES",
       "AUTH_HMAC_SHA1_96" and "No Extended Sequence Numbers" as proposed algorithms.
       And the proposal in the SA payload Response has a SA payload including 1 (IKE) in the
       Protocol ID field, 8 in the SPI size field and new IKE_SA's responder's SPI value in the SPI
       field.

       Step 15: Judgment #7
       The NUT transmits an INFORMATIONAL request . The message's IKE_SA Initiator's SPI
       value is the IKE_SA Initiator's SPI value of the original IKE_SA, and the message's IKE_SA
       Responder's SPI value is the IKE_SA Responder's SPI value of the original IKE_SA. The
       message also has a Delete Payload including 1 (IKE_SA) as Protocol ID, zero as SPI Size and
       no SPI value.

       Step 17: Judgment #8
       The NUT transmits an INFORMATIONAL request . The message's IKE_SA Initiator's SPI
       value is the IKE_SA Initiator's SPI value of the new IKE_SA initiated by the NUT at Step 9,
       and the message's IKE_SA Responder's SPI value is the IKE_SA Responder's SPI value of
       the new IKE_SA initiated by the NUT at Step 9. The message also has a Delete Payload
       including 1 (IKE_SA) as Protocol ID, zero as SPI Size and no SPI value.

       Step 20: Judgment #9
       The NUT transmits an INFORMATIONAL response with no payload.

=head1 Possible Problems

  * Each NUT has the different lifetime of SA.

=cut


