Commit cd133b15 authored by seb's avatar seb
Browse files

Lib_InterfaceFns/TYpes/Templates created

LibIpv6/LibSec deleted
parent c2de9c50
Loading
Loading
Loading
Loading
+1 −6
Original line number Diff line number Diff line
@@ -13,15 +13,10 @@
	import from LibCommon_VerdictControl { type FncRetCode };
	//LibIpv6
	import from LibIpv6_ExternalFunctions all;
	import from LibIpv6_Interface all ;
	import from LibIpv6_Interface_TypesAndValues all ;
	import from LibIpv6_ModuleParameters all ;
	import from LibIpv6_CommonRfcs_TypesAndValues all;
	import from LibIpv6_CommonRfcs_Templates all;
	import from LibIpv6_Rfc2460Root_TypesAndValues { type all; const all };
	//import from LibIpv6_Rfc2460Root_Templates all;
	



	group calcPrefixFns {
		
+0 −12
Original line number Diff line number Diff line
@@ -410,18 +410,6 @@ module LibIpv6_CommonRfcs_TypesAndValues {
			octetstring icv optional	
		}

		/*
		 * @desc PDU type to be used when building ESP payload for encryption
		*/
		//TODO as well possibe to delete this type and make Ipv6Packet.ipv6Hdr optional
		type record ModularIpv6Packet {
			Ipv6Header			ipv6Hdr optional,
			ExtensionHeaderList extHdrList optional,
			Ipv6Payload			ipv6Payload optional
	    }
		with {
			encode "TODO";
		}

		} // end security

+9 −8
Original line number Diff line number Diff line
@@ -12,13 +12,14 @@
	//LibCommon
	import from LibCommon_BasicTypesAndValues all;
	import from LibCommon_DataStrings all;
	import from LibCommon_VerdictControl all;
	//LibIpv6
	import from LibIpv6_CommonRfcs_TypesAndValues { type all };
	import from LibIpv6_Interface all;
	import from LibIpv6_Rfc2460Root_TypesAndValues {type all};
	import from LibIpv6_Interface_TypesAndValues all;
	

	import from LibIpv6_Rfc3775Mipv6_ExtHdrTypesAndValues all;
	import from LibIpv6_Rfc4303Esp_ExtHdrTypesAndValues all;
	


	/* @desc    This external function calculates the payload length
@@ -107,9 +108,10 @@
	 * @param  p_message Octetstring message
	 * @return Message HMAC
	*/
//	external function fx_integrity( IntegrityAlgo p_integrityAlgo, in octetstring p_key, in octetstring p_message) 
//	return octetstring;
	external function fx_integrity( IntegrityAlgo p_integrityAlgo, in octetstring p_key, in octetstring p_message) 
	return octetstring;

	//TODO comment
	external function fx_integrityEspHdr( 	in IntegrityAlgo p_integrityAlgo,
											in octetstring p_key,
											in EspHeader p_espHeader,
@@ -129,9 +131,8 @@
	external function fx_bindingAuthenticator(in Ipv6Address p_careOfAddr, 
											  in Ipv6Address p_cnAddr,
											  in Ipv6Packet p_ipv6Packet,
											  in Oct20 p_kbm,
											  out octetstring p_result)
	return FncRetCode; 
											  in Oct20 p_kbm)
	return octetstring; 
	
	/* @desc 	This external function computes Integrity Check Value
	 * @param 	p_ipv6Packet Ipv6 Packet
+0 −169
Original line number Diff line number Diff line
/*
 *	@author 	STF 276
 *  @version 	$Id$
 *	@desc		This module defines the interface for any function
 *              part of the IPv6 library.
 *				Further on, this module defines a meta type over all IPv6
 *              packets supported by the IPv6 library as well as
 *              templates for it. Also it includes the raw Ipv6
 *              message type which can be used for sending encoded
 *              Ipv6 packets.
 *
 */
module LibIpv6_Interface {

	//LibCommon
	import from LibCommon_Time all ;
	import from LibCommon_DataStrings all;
	//LibIpv6
	import from LibIpv6_Rfc2460Root_TypesAndValues {type all};
	import from LibIpv6_Rfc2463Icmpv6_TypesAndValues {type all};
	import from LibIpv6_Rfc2461NeighborDiscovery_TypesAndValues {type all};
	import from LibIpv6_Rfc2894RouterRenumbering_TypesAndValues {type all};
	import from LibIpv6_Rfc3775Mipv6_TypesAndValues {type all};
	import from LibIpv6_Rfc0768Udp_TypesAndValues all ;
	import from LibIpv6_CommonRfcs_TypesAndValues all;

	/*
	 * @desc	This type is used to define behavior within the IPv6 library
	 *			which can be executed on  both, host as well as router,
	 *			components. It may also be used to specify behavior outside of
	 *			the IPv6 library. In order to call IPv6 library functions
	 *			defined based on this type the caller function must
	 *			be defined based on a type compatible component type.
	*/
	type component LibIpv6Node {
		port Ipv6Port ipPort;
		timer tc_ac:= PX_TAC;
		timer tc_noAc:= PX_TNOAC;
		timer tc_wait:= PX_TWAIT;
		//var Sad vc_sad;
		var MipSec vc_mipSec;
		var Sad vc_sad;
	}

	type port Ipv6Port message {
		inout
		//Imported from Rfc 2463
		DestinationUnreachable,
		PacketTooBig,
		TimeExceeded,
		ParameterProblem,
		EchoRequest,
		EchoReply,
		//Imported from Rfc 2461
		RouterAdvertisement,
		RouterSolicitation,
		NeighborSolicitation,
		NeighborAdvertisement,
		Redirect,
		//Imported from Rfc 2894
		RouterRenumbering,
		//Imported from Rfc XXXX Mipv6
		HomeAgentAddressDiscoveryRequest,
		HomeAgentAddressDiscoveryReply,
		MobilePrefixSolicitation,
		MobilePrefixAdvertisement,
		MipRouterAdvertisement,
		OtherIcmpv6,
		//hand encoded IPv6 packets
		RawIpv6Packet,
		//UDP
		UdpPacket,
		//MetaPdu
		Ipv6Packet
		//General IPv6 packet
		//GeneralIpv6
	}//end type port Ipv6Port

	/*
	 * @desc PDU type derived from RFC2463 clause 4.1
	*/
	type record Ipv6Packet {
		Ipv6Header			ipv6Hdr,
		ExtensionHeaderList extHdrList optional,
		Ipv6Payload			ipv6Payload optional
	}
	with {
		encode "TODO";
	}
	
	//Alias
	//Imported from Rfc 2463
	type Ipv6Packet DestinationUnreachable;
	type Ipv6Packet PacketTooBig;
	type Ipv6Packet TimeExceeded;
	type Ipv6Packet ParameterProblem;
	type Ipv6Packet EchoRequest;
	type Ipv6Packet EchoReply;
	//Imported from Rfc 2461
	type Ipv6Packet RouterAdvertisement;
	type Ipv6Packet RouterSolicitation;
	type Ipv6Packet NeighborSolicitation;
	type Ipv6Packet NeighborAdvertisement;
	type Ipv6Packet Redirect;
	//Imported from Rfc 2894
	type Ipv6Packet RouterRenumbering;
	//Imported from Rfc XXXX Mipv6
	type Ipv6Packet HomeAgentAddressDiscoveryRequest;
	type Ipv6Packet HomeAgentAddressDiscoveryReply;
	type Ipv6Packet MobilePrefixSolicitation;
	type Ipv6Packet MobilePrefixAdvertisement;
	type Ipv6Packet MipRouterAdvertisement;
	//Default value
	type Ipv6Packet OtherIcmpv6;
	//Udp
	type Ipv6Packet UdpPacket;
  	//General IPv6 packet
//  	type octetstring Ipv6Packet;//TODO check this


	/*
	 * @desc This meta packet type contains any Ipv6 packets.
	 *		 This type is used mainly for checksum calculation
	*/
    type union Ipv6Payload  { //type union Ipv6Packet  {
		//Imported from Rfc 2463
		DestinationUnreachableMsg 				destinationUnreachableMsg,
		PacketTooBigMsg							packetTooBigMsg,
		TimeExceededMsg							timeExceededMsg,
		ParameterProblemMsg						parameterProblemMsg,
		EchoRequestMsg							echoRequestMsg,
		EchoReplyMsg							echoReplyMsg,
		//Imported from Rfc 2461
		RouterAdvertisementMsg					routerAdvMsg,
		RouterSolicitationMsg      				routerSolMsg,
		NeighborSolicitationMsg					nbrSolMsg,
		NeighborAdvertisementMsg				nbrAdvMsg,
		RedirectMsg								redirectMsg,
		//Imported from Rfc 2894
		RouterRenumberingMsg					routerRenumberingMsg,
		//Imported from Rfc XXXX Mipv6
		HomeAgentAddressDiscoveryRequestMsg		homeAgentAddrDiscRequestMsg,
		HomeAgentAddressDiscoveryReplyMsg		homeAgentAddrDiscReplyMsg,
		MobilePrefixSolicitationMsg				mobilePrefixSolMsg,
		MobilePrefixAdvertisementMsg			mobilePrefixAdvMsg,
		MobileRouterAdvertisementMsg			mobileRouterAdvMsg,//TODO check this
		//Default value
		OtherIcmpv6Msg							otherIcmpv6Msg,
		//Udp
		UdpMsg									udpMsg,
	  	//General IPv6 packet
	  	//GeneralIpv6                         	generalIpv6
		octetstring								octetstringMsg
	}
	with {
		//DTE TODO
		encode "isPDU=LibIpv6_Interface;"
	}

	template Ipv6Packet mw_ipPkt := ? ;

	/*
	*  @desc This type is intended to be used to send "hand encoded"
	*        IPv6 packets. It can also be used to create incorrect
	*        IPv6 messages.
    */
	type octetstring RawIpv6Packet;

} // end module LibIpv6_Interface
+250 −0
Original line number Diff line number Diff line
@@ -5,21 +5,27 @@
 *              based on the IPv6 meta message type.  
 *  
 */
 module LibIpv6_Rfc2460Root_Functions {
 module LibIpv6_Interface_Functions {

	//LibCommon
	import from LibCommon_BasicTypesAndValues all;
	import from LibCommon_DataStrings all;
	import from LibCommon_VerdictControl { type FncRetCode };
	//LibIpv6
	import from LibIpv6_Rfc2460Root_Templates all;
	import from LibIpv6_Rfc2460Root_TypesAndValues all;
	import from LibIpv6_Interface all;
	
	
	import from LibIpv6_Interface_TypesAndValues all;
	import from LibIpv6_ExternalFunctions all;
	import from LibIpv6_CommonRfcs_Functions all;
	import from LibIpv6_CommonRfcs_TypesAndValues all;
	import from LibIpv6_Rfc3775Mipv6_ExtHdrFunctions all;

	import from LibIpv6_ModuleParameters all;
	import from LibIpv6_ExternalFunctions all;
	import from LibIpv6_Interface_Templates all;

group rfc2460Root_Functions {
	
		group ipv6Packets {	

	/*
@@ -111,8 +117,134 @@
	}//end group extHdrFns



    } //end group ipv6Packets
	
}//end group rfc2460Root_Functions


group rfc4303Esp_ExtHdrFunctions {
	
	function f_initParams()
	runs on LibIpv6Node {
		
		vc_sad[0] := {
			securityParametersIndex := f_createSpi(),
			sequenceNumber := c_uInt32Zero,
			// AH Integrity
			ahIntegrityAlgo := PX_INTEGRITY_ALGO,
			ahIntegrityKey := f_createSecretKey(),
			// ESP encryption
			espEncryptionAlgo := PX_ENCRYPTION_ALGO,
			espEncryptionKey := f_createSecretKey(),
			// ESP integrity
			espIntegrityAlgo := PX_INTEGRITY_ALGO,
			espIntegrityKey := f_createSecretKey(),
			// Combined mode
			espCombinedModeAlgo := PX_COMBINED_MODE_ALGO,
			espCombinedModeKey := f_createSecretKey(),
			// Protocol mode
			ipSecProtocolMode := PX_IP_SEC_PROTOCOL_MODE
		}
		
	}//end f_initParams


	/*
	 * @desc 	This generates Security Parameters Index
	 * @return 	Security Parameters Index
	*/
	function f_createSpi()
	runs on LibIpv6Node
	return UInt32 {
		var Oct4 v_spi := int2oct(float2int(int2float(20000-5000)*rnd())+5000, 4);

		return oct2int(v_spi);
	}//end f_createSpi

	/*
	 * @desc 	This generates a secret key
	 * @return 	Secret key
	*/
	function f_createSecretKey()
	runs on LibIpv6Node
	return octetstring {
		var Oct20 v_key := int2oct(float2int(int2float(20000-5000)*rnd())+5000, 20);

		return v_key;
	}//end f_createSecretKey

	function f_buildEspExtHdr(	
			in Sa p_sa,
			in template Ipv6Header p_ipv6Header,
			in template ExtensionHeaderList p_extensionHeaderList,
			in template Ipv6Payload p_ipv6Payload,
			out ExtensionHeader p_extensionHeader)
	runs on LibIpv6Node
	return FncRetCode {
		// Variables
		var EncryptResult v_encryptResult;
		var IntegrityResult v_integrityResult;
		var FncRetCode v_ret := e_error;
		var octetstring v_padding := c_1ZeroByte;

		// Build espPayloadData
		var ModularIpv6Packet v_modularIpv6Packet := {
			ipv6Hdr := valueof(p_ipv6Header),
			extHdrList  := valueof(p_extensionHeaderList),
			ipv6Payload := valueof(p_ipv6Payload)
		}

		// Encrypt espPayloadData
		v_ret := fx_encryptModularIpPacket(	p_sa.ipSecProtocolMode,
										p_sa.espEncryptionAlgo,
										p_sa.espEncryptionKey,
										v_modularIpv6Packet,
										v_encryptResult);
		if ( v_ret != e_success ) {return v_ret;}
	
		// Fill EspExtHdr
		var EspHeader v_espHdr := valueof(m_espHdr_dummy);
		// Header
		v_espHdr.securityParametersIndex := p_sa.securityParametersIndex;
		v_espHdr.sequenceNumber := p_sa.sequenceNumber;
		// Payload
		if (ispresent(v_encryptResult.iv)) {
			v_espHdr.iv := v_encryptResult.iv;
		}
		// Encrypted payload is assigend for integrity calculation.
		// Afterwards plaintext will be assigned
		v_espHdr.espPayloadData.encryptedData := v_encryptResult.encryptedData;
		if (ispresent(v_encryptResult.tfcPadding)) {
			v_espHdr.tfcPadding := v_encryptResult.tfcPadding;
		}
		// Byte Align
		v_ret := fx_byteAlignEspHeader(4, v_espHdr, v_padding);
		if ( v_ret != e_success ) {return v_ret;}

		if (v_padding != c_1ZeroByte) {
			v_espHdr.padding := v_padding;
			v_espHdr.padLength := lengthof(v_padding);
		}

		// Integrity
		v_ret := fx_integrityEspHdr(	p_sa.espIntegrityAlgo,
									p_sa.espIntegrityKey,
									v_espHdr,
									v_integrityResult);
		if ( v_ret != e_success ) {return v_ret;}
		if (ispresent(v_integrityResult.icv)) {
			v_espHdr.icv := v_integrityResult.icv;
		}

		// Assign Plaintext EspPayload
		v_espHdr.espPayloadData.plaintextData := v_modularIpv6Packet;
		p_extensionHeader := {espHeader := v_espHdr};

		return e_success;

	}//end function f_buildEspExtHdr	
	
}//end group rfc4303Esp_ExtHdrFunctions

	
} // end module LibIpv6_Rfc2460Root_Functions
} // end module LibIpv6_Interface_Functions
Loading