Browse code

misc: update ims pcscf register example

- Updated ims pcscf register script file
with removing of ck/ik in 401 Challenge reply.

Aleksandar Yosifov authored on 22/11/2021 16:28:28 • Daniel-Constantin Mierla committed on 22/11/2021 18:32:49
Showing 1 changed files
... ...
@@ -3,9 +3,9 @@
3 3
 ######################################################################
4 4
 route[REGISTER] {
5 5
 	# Provide some statistics
6
-        if ($sht(a=>$ci::start_time) == $null || $sht(a=>$ci::start_time) == 0) {
7
-            $sht(a=>$ci::start_time) = $TV(Sn);
8
-        } 
6
+		if ($sht(a=>$ci::start_time) == $null || $sht(a=>$ci::start_time) == 0) {
7
+			$sht(a=>$ci::start_time) = $TV(Sn);
8
+		} 
9 9
 
10 10
 	# Strip Transport from RURI:
11 11
 	$ru = $(ru{re.subst,/;transport=[A-Za-z]*//g});
... ...
@@ -146,23 +146,31 @@ onreply_route[REGISTER_reply]
146 146
 #!endif
147 147
 #!endif
148 148
 		#update stats for register reply on success
149
-        	$var(start_secs) = $(sht(a=>$ci::start_time){s.select,0,.});
150
-        	$var(start_usecs) = $(sht(a=>$ci::start_time){s.select,1,.});
151
-        	$var(diff_secs) = $TV(s) - $var(start_secs);
152
-        	$var(diff_usecs) = $TV(u) - $var(start_usecs);
153
-        	$var(diff_ms) = $var(diff_secs)*1000 + ($var(diff_usecs)/1000);
154
-        	$sht(a=>$ci::start_time)=0;
155
-        	$var(stat_add) = "+" + $var(diff_ms);
156
-        	xlog("L_DBG", "REGISTER SUCCESS[$ci] took $var(stat_add)ms\n"); 
157
-        	update_stat("register_success", "+1");
158
-        	update_stat("register_time", "$var(stat_add)");
149
+		$var(start_secs) = $(sht(a=>$ci::start_time){s.select,0,.});
150
+		$var(start_usecs) = $(sht(a=>$ci::start_time){s.select,1,.});
151
+		$var(diff_secs) = $TV(s) - $var(start_secs);
152
+		$var(diff_usecs) = $TV(u) - $var(start_usecs);
153
+		$var(diff_ms) = $var(diff_secs)*1000 + ($var(diff_usecs)/1000);
154
+		$sht(a=>$ci::start_time)=0;
155
+		$var(stat_add) = "+" + $var(diff_ms);
156
+		xlog("L_DBG", "REGISTER SUCCESS[$ci] took $var(stat_add)ms\n"); 
157
+		update_stat("register_success", "+1");
158
+		update_stat("register_time", "$var(stat_add)");
159 159
 #!ifdef WITH_IPSEC
160
-            ipsec_forward("location");
161
-   	}
162
-	else {  
160
+		ipsec_forward("location");
161
+	}
162
+	else {
163 163
 		if (t_check_status("401")) {
164
-			ipsec_create("location");
165
-        }
164
+			#Remove ck and ik from Authentication header
165
+			$var(rem_ck) = $(hdr(WWW-Authenticate){re.subst,/ck="[a-zA-Z0-9]*", //g});
166
+			$var(rem_ik) = $(var(rem_ck){re.subst,/ik="[a-zA-Z0-9]*", //g});
167
+			remove_hf("WWW-Authenticate");
168
+			append_hf("WWW-Authenticate: $var(rem_ik)\r\n");
169
+
170
+			if(ipsec_create("location")!=1) {
171
+				send_reply("503", "Service Unavailable (Create ipsec failed)");
172
+			}
173
+		}
166 174
 #!endif
167 175
     }
168 176
 	exit;
... ...
@@ -183,12 +191,12 @@ failure_route[REGISTER_failure]
183 191
 			xlog("Blocking traffic from $si\n");
184 192
 			$sht(ipban=>$si) = 1;
185 193
 		}
186
-                update_stat("register_failed", "+1");
194
+		update_stat("register_failed", "+1");
187 195
 	}
188 196
 #!endif
189 197
 	if (t_check_status("408")) {
190 198
 		send_reply("504","Server Time-Out");
191
-                update_stat("register_failed", "+1");
199
+		update_stat("register_failed", "+1");
192 200
 		exit;
193 201
 	}
194 202
 }