Newer
Older
1
2
3
4
5
6
7
8
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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
192
193
194
195
196
197
198
199
200
/**
* @author STF 346, STF366, STF368, STF369, STF450, STF471
* @version $Id: LibSip_Steps.ttcn 645 2016-12-01 13:50:32Z pintar $
* @desc This module provides the functions, altsteps and external functions used
* for SIP-IMS tests.
* This module is part of LibSipV3.
*/
module LibSip_Steps {
// 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;
import from LibSip_Common all;
group externalfunctions {
/**
* @desc External function to return random charstring
*/
external function fx_rndStr(
) return charstring;
/**
* @desc External function to return the equivalent string in lower case
*/
external function fx_putInLowercase(
charstring p_string
) return charstring;
/**
* @desc External function to get IP address.
*/
external function fx_getIpAddr(
charstring p_host_name
) return charstring;
/**
* @desc External function to generate a digest response.
* @reference 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 p_nonce,
charstring p_cnonce,
charstring p_user,
charstring p_realm,
charstring p_passwd,
charstring p_alg,
charstring p_nonceCount,
charstring p_method,
charstring p_qop,
charstring p_URI,
charstring p_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 v_tag_value;
// tag_value is initialized with a random value with at least 32 bits of randomness
// 4294967296 is a 32 bits integer
v_tag_value := fx_rndStr() & fx_rndStr();
return (v_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
* @param p_algorithm Algorthm to be used. Default: omit
* @return Credentials field
*/
function f_calculatecCredentials_empty(
in SipUserProfile p_userprofile,
in boolean p_algorithm := false
) return Credentials {
var Credentials v_result;
// 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 CommaParam_List v_digestResponse := {};
// Construct credentials for an Authorization field of a request.
v_digestResponse := f_addCommaParameter(v_digestResponse, {
id := "username",
paramValue := { quotedString := v_username }
});
v_digestResponse := f_addCommaParameter(v_digestResponse, {
id := "realm",
paramValue := { quotedString := v_realm }
});
v_digestResponse := f_addCommaParameter(v_digestResponse, {
id := "uri",
paramValue := { quotedString := v_uri }
});
v_digestResponse := f_addCommaParameter(v_digestResponse, {
id := "nonce",
paramValue := { quotedString := "" }
}); // already enclosed to " characters
v_digestResponse := f_addCommaParameter(v_digestResponse, {
id := "response",
paramValue := { quotedString := "" }
}); // already enclosed to " characters
if (p_algorithm) {
v_digestResponse := f_addCommaParameter(v_digestResponse, {
id := "algorithm",
paramValue := { tokenOrHost := PX_AUTH_ALGORITHM }
}); // already enclosed to " characters
}
v_result := {digestResponse := v_digestResponse};
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 := "";
var charstring v_cnonce := int2str(float2int(int2float(13172657659 - 1317266) * rnd()) + 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;
// a new pseudo-random cnonce value is used every time
// that assumes it is only used once
const charstring cl_nonceCount := "00000001";
var charstring v_qop := p_userprofile.qop;
var charstring v_uri := c_sipScheme & ":" & p_userprofile.registrarDomain;
// MD5 hash of empty entity body.
const charstring cl_hEntity := "d41d8cd98f00b204e9800998ecf8427e";
var charstring v_response;
var charstring v_opaque;
var CommaParam_List v_digestResponse := {};
// 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, cl_nonceCount, p_method, v_qop, v_uri, cl_hEntity);
// Construct credentials for an Authorization field of a request.
v_digestResponse := f_addCommaParameter(v_digestResponse, {
id := "username",
paramValue := { quotedString := v_username }
});
v_digestResponse := f_addCommaParameter(v_digestResponse, {
id := "realm",
paramValue := { quotedString := v_realm }
});
v_digestResponse := f_addCommaParameter(v_digestResponse, {
id := "nonce",
paramValue := { quotedString := v_nonce }
});
v_digestResponse := f_addCommaParameter(v_digestResponse, {
id := "uri",
paramValue := { quotedString := v_uri }
});
v_digestResponse := f_addCommaParameter(v_digestResponse, {
id := "response",
Loading
Loading full blame…