Skip to content
LibSip_Steps.ttcn 110 KiB
Newer Older
/*
 *	@author 	STF 346
 *  @version    $Id$
 *	@desc		This module provides the types used by the test component 
 *              for SIP-IMS tests.
 */

module LibSip_Steps language "TTCN-3:2005"//MRO
{	
	//LibCommon
	import from LibCommon_Sync all ;
	import from LibCommon_VerdictControl all ;
	//LibSip
	import from LibSip_SIPTypesAndValues all;
	import from LibSip_SDPTypes all;
	import from LibSip_Templates all;
	import from LibSip_Interface all;
	import from LibSip_PIXITS all;
	import from LibSip_XMLTypes all;

group externalfunctions {
	
	//Return random charstring
	external function fx_rndStr() return charstring;
	// Return the equivalent string in lower case
	external function fx_putInLowercase(charstring par_string) return charstring;
	
	external function fx_getIpAddr(charstring host_name) return charstring;

	// External function to generate a digest response.
	// References:
	//   * RFC 2617 HTTP Authentication: Basic and Digest Access
	//     Authentication, and
	//   * RFC 1321 The MD5 Message-Digest Algorithm
	// See RFC 2617, chapter 5 Sample implementation, for example usage, as
	// the signature of calculateDigestResponse is according to the example
	// given in the RFC.
	//
	external function fx_calculateDigestResponse(
	  charstring nonce,
	  charstring cnonce,
	  charstring user,
	  charstring realm,
	  charstring passwd,
	  charstring alg,
	  charstring nonceCount,
	  charstring method,
	  charstring qop,
	  charstring URI,
	  charstring HEntity) return charstring;

}

group ParameterOperations {

	/**
	 * 
	 * @desc function to generate a 32 bits random number as a charstring for tag field
	 * (used as e.g.: tag in from-header field, or branch parameter in via header)
	 * @return random value with at least 32 bits of randomness
	 * 
	 */
	 function f_getRndTag() return charstring
	{
	  var charstring tag_value;
	  //tag_value is initialized with a random value with at least 32 bits of randomness
	  // 4294967296 is a 32 bits integer
	  tag_value := fx_rndStr()&fx_rndStr();
	  return(tag_value);
	}

	/**
	 * 
	 * @desc  Function to prepare credentials for request that has an empty
	 * entity body such as a REGISTER message.
	 * @param p_userprofile to get important parameters
	 * @return Credentials field
	 */
	function f_calculatecCredentials_empty(in SipUserProfile p_userprofile) return Credentials
	{
	  var Credentials v_result;
	      
	  var charstring v_nonce := "";
	      
	  // RFC 2617 3.2.2 username:
	  // The name of user in the specified realm.
	  var charstring v_username := p_userprofile.privUsername;
	      
	  var charstring v_realm := p_userprofile.registrarDomain;
	      
	  var charstring v_uri := c_sipScheme & ":" & p_userprofile.registrarDomain;
	           
	  var charstring v_response := "";
	 
	  // Construct credentials for an Authorization field of a request.
	  v_result :=
	  {
		digestResponse :=
		{
		  { id := "Digest username", paramValue := v_username },
		  { id := "realm", paramValue := v_realm },
		  { id := "uri", paramValue := v_uri },
		  { id := "nonce=""""", paramValue := omit }, // already enclosed to " characters
		  { id := "response=""""", paramValue := omit } // already enclosed to " characters
		}
	  };
	      
	  return v_result;
	}


	/**
	 * 
	 * @desc  Function to calculate credentials for request that has an empty
	 * entity body such as a REGISTER message.
	 * @param p_userprofile to get important parameters
	 * @param p_method (can be "REGISTER", "INVITE",....)
	 * @param p_challenge parameter from 4xx response
	 * @return Credentials field
	 * @verdict 
	 */
	function f_calculatecCredentials(in SipUserProfile p_userprofile, in charstring p_method, 
		in CommaParam_List p_challenge) return Credentials
	{
	  var Credentials v_result;
      
	  var charstring v_nonce := "";
      
	  // Use a fixed client nonce.
	  var charstring v_cnonce := "1317265";
      
	  // RFC 2617 3.2.2 username:
	  // The name of user in the specified realm.
	  var charstring v_username := p_userprofile.privUsername;
      
	  var charstring v_realm;
      
	  // RFC 2617 3.2.2.2 passwd:
	  // A known shared secret, the password of user of the specified
	  // username.
	  var charstring v_passwd := p_userprofile.passwd;
      
	  var charstring v_algorithm;
      
	  // Use a fixed nonce count.
	  const charstring c_nonceCount := "00000002";

	  var charstring v_qop := p_userprofile.qop;
      
	  var charstring v_uri := c_sipScheme & ":" & p_userprofile.registrarDomain;
      
	  // MD5 hash of empty entity body.
	  const charstring c_hEntity := "d41d8cd98f00b204e9800998ecf8427e";
      
	  var charstring v_response;
	  var charstring v_opaque;
      
      
	  // extract nonce, realm, algorithm, and opaque from challenge
      
	  v_nonce := f_extractParamValueFromChallenge(p_challenge, "nonce"); 
	  v_realm := f_extractParamValueFromChallenge(p_challenge, "realm"); 
	  v_algorithm := f_extractParamValueFromChallenge(p_challenge, "algorithm");
	  v_opaque := f_extractParamValueFromChallenge(p_challenge, "opaque");
      
	  // calculate a digest response for the Authorize header
	  v_response := fx_calculateDigestResponse(
		v_nonce,
		v_cnonce,
		v_username,
		v_realm,
		v_passwd,
		v_algorithm,
		c_nonceCount,
		p_method,
		v_qop,
		v_uri,
		c_hEntity);
      
	  // Construct credentials for an Authorization field of a request.
	  v_result :=
	  {
		digestResponse :=
		{
		  { id := "Digest username", paramValue := v_username },
		  { id := "realm", paramValue := v_realm },
		  { id := "nonce", paramValue := v_nonce },
		  { id := "uri", paramValue := v_uri },
		  { id := "response", paramValue := v_response },
		  { id := "algorithm=md5", paramValue := omit }, // algorithm is not enclosed to " characters
		  { id := "cnonce", paramValue := v_cnonce },
		  { id := "opaque=""""", paramValue := omit }, // already enclosed to " characters
		  { id := "qop="&v_qop, paramValue := omit },//qop
		  { id := "nc="&c_nonceCount, paramValue := omit }//nonceCount
		}
	  };
      
	  return v_result;
	}

Loading full blame...