Newer
Older
* @author STF 346, STF366, STF368, STF369
* @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
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
{
//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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
* @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 := v_opaque }, // already enclosed to " characters
Loading full blame...