Browse Source

- more tls add-ons (via parser, srv lookup, forward_tls a.s.o)
- fixed inivite1.sip content-length

Andrei Pelinescu-Onciul 22 years ago
parent
commit
8e807134f6
10 changed files with 64 additions and 10 deletions
  1. 3 0
      action.c
  2. 1 0
      config.h
  3. 6 0
      modules/tm/ut.h
  4. 5 1
      msg_translator.c
  5. 38 3
      parser/parse_via.c
  6. 5 0
      resolve.c
  7. 1 0
      route.c
  8. 1 2
      tcp_main.c
  9. 2 2
      tcp_read.c
  10. 2 2
      test/invite1.sip

+ 3 - 0
action.c

@@ -105,6 +105,9 @@ int do_action(struct action* a, struct sip_msg* msg)
 		case FORWARD_T:
 		case FORWARD_T:
 #ifdef USE_TCP
 #ifdef USE_TCP
 		case FORWARD_TCP_T:
 		case FORWARD_TCP_T:
+#endif
+#ifdef USE_TLS
+		case FORWARD_TLS_T:
 #endif
 #endif
 		case FORWARD_UDP_T:
 		case FORWARD_UDP_T:
 
 

+ 1 - 0
config.h

@@ -106,6 +106,7 @@
 
 
 #define SRV_UDP_PREFIX "_sip._udp."
 #define SRV_UDP_PREFIX "_sip._udp."
 #define SRV_TCP_PREFIX "_sip._tcp."
 #define SRV_TCP_PREFIX "_sip._tcp."
+#define SRV_TLS_PREFIX "_sip._tls."
 #define SRV_PREFIX_LEN 10
 #define SRV_PREFIX_LEN 10
 
 
 /*used only if PKG_MALLOC is defined*/
 /*used only if PKG_MALLOC is defined*/

+ 6 - 0
modules/tm/ut.h

@@ -63,6 +63,9 @@ inline static enum sip_protos get_proto(enum sip_protos force_proto,
                                case PROTO_UDP: /* transport specified explicitely */
                                case PROTO_UDP: /* transport specified explicitely */
 #ifdef USE_TCP
 #ifdef USE_TCP
                                case PROTO_TCP:
                                case PROTO_TCP:
+#endif
+#ifdef USE_TLS
+                               case PROTO_TLS:
 #endif
 #endif
                                        return u->proto;
                                        return u->proto;
                                default:
                                default:
@@ -73,6 +76,9 @@ inline static enum sip_protos get_proto(enum sip_protos force_proto,
                case PROTO_UDP: /* some protocol has been forced -- take it */
                case PROTO_UDP: /* some protocol has been forced -- take it */
 #ifdef USE_TCP
 #ifdef USE_TCP
                case PROTO_TCP:
                case PROTO_TCP:
+#endif
+#ifdef USE_TLS
+               case PROTO_TLS:
 #endif
 #endif
                        return force_proto;
                        return force_proto;
                default:
                default:

+ 5 - 1
msg_translator.c

@@ -1174,6 +1174,8 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
 							" id_builder failed\n");
 							" id_builder failed\n");
 			goto error01; /* free everything */
 			goto error01; /* free everything */
 		}
 		}
+		DBG("build_req_from_req: id added: <%.*s>, rcv proto=%d\n",
+				id_len, id_buf, msg->rcv.proto);
 		extra_params.s=id_buf;
 		extra_params.s=id_buf;
 		extra_params.len=id_len;
 		extra_params.len=id_len;
 	}
 	}
@@ -1183,6 +1185,8 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
 			|| proto==PROTO_TLS
 			|| proto==PROTO_TLS
 #endif
 #endif
 			){
 			){
+		DBG("build_req_from_req: checking for clen; proto=%d, rcv->proto=%d\n",
+				proto, msg->rcv.proto);
 		/* first of all parse content-length */
 		/* first of all parse content-length */
 		if (parse_headers(msg, HDR_CONTENTLENGTH, 0)==-1){
 		if (parse_headers(msg, HDR_CONTENTLENGTH, 0)==-1){
 			LOG(L_ERR, "build_req_buf_from_sip_req:"
 			LOG(L_ERR, "build_req_buf_from_sip_req:"
@@ -1885,7 +1889,7 @@ char* via_builder( unsigned int *len,
 	}else if (proto==PROTO_TCP){
 	}else if (proto==PROTO_TCP){
 		memcpy(line_buf+MY_VIA_LEN-4, "TCP ", 4);
 		memcpy(line_buf+MY_VIA_LEN-4, "TCP ", 4);
 	}else if (proto==PROTO_TLS){
 	}else if (proto==PROTO_TLS){
-		memcpy(line_buf+MY_VIA_LEN-4, "TLS", 4);
+		memcpy(line_buf+MY_VIA_LEN-4, "TLS ", 4);
 	}else{
 	}else{
 		LOG(L_CRIT, "BUG: via_builder: unknown proto %d\n", proto);
 		LOG(L_CRIT, "BUG: via_builder: unknown proto %d\n", proto);
 		return 0;
 		return 0;

+ 38 - 3
parser/parse_via.c

@@ -43,6 +43,7 @@
  *  2003-02-28  scratchpad compatibility abandoned (jiri)
  *  2003-02-28  scratchpad compatibility abandoned (jiri)
  *  2003-04-26  ZSW (jiri)
  *  2003-04-26  ZSW (jiri)
  *  2003-06-23  fixed  parse_via_param [op].* param. parsing bug (andrei)
  *  2003-06-23  fixed  parse_via_param [op].* param. parsing bug (andrei)
+ *  2003-07-02  added support for TLS parsing in via (andrei)
  */
  */
 
 
 
 
@@ -81,7 +82,8 @@ enum {
 	L_VER, F_VER,
 	L_VER, F_VER,
 	VER1, VER2, FIN_VER,
 	VER1, VER2, FIN_VER,
 	UDP1, UDP2, FIN_UDP,
 	UDP1, UDP2, FIN_UDP,
-	TCP1, TCP2, FIN_TCP,
+	TCP_TLS1, TCP2, FIN_TCP,
+	          TLS2, FIN_TLS,
 	L_PROTO, F_PROTO
 	L_PROTO, F_PROTO
 };
 };
 
 
@@ -985,6 +987,12 @@ parse_again:
 						vb->proto=PROTO_TCP;
 						vb->proto=PROTO_TCP;
 						state=F_HOST; /* start looking for host*/
 						state=F_HOST; /* start looking for host*/
 						goto main_via;
 						goto main_via;
+					case FIN_TLS:
+						/* finished proto parsing */
+						vb->transport.len=tmp-vb->transport.s;
+						vb->proto=PROTO_TLS;
+						state=F_HOST; /* start looking for host*/
+						goto main_via;
 					case FIN_SIP:
 					case FIN_SIP:
 						vb->name.len=tmp-vb->name.s;
 						vb->name.len=tmp-vb->name.s;
 						state=L_VER;
 						state=L_VER;
@@ -1026,6 +1034,12 @@ parse_again:
 						state=F_LF;
 						state=F_LF;
 						saved_state=F_HOST; /* start looking for host*/
 						saved_state=F_HOST; /* start looking for host*/
 						goto main_via;
 						goto main_via;
+					case FIN_TLS:
+						vb->transport.len=tmp-vb->transport.s;
+						vb->proto=PROTO_TLS;
+						state=F_LF;
+						saved_state=F_HOST; /* start looking for host*/
+						goto main_via;
 					case FIN_SIP:
 					case FIN_SIP:
 						vb->name.len=tmp-vb->name.s;
 						vb->name.len=tmp-vb->name.s;
 						state=F_LF;
 						state=F_LF;
@@ -1071,6 +1085,12 @@ parse_again:
 						state=F_CR;
 						state=F_CR;
 						saved_state=F_HOST;
 						saved_state=F_HOST;
 						goto main_via;
 						goto main_via;
+					case FIN_TLS:
+						vb->transport.len=tmp-vb->transport.s;
+						vb->proto=PROTO_TLS;
+						state=F_CR;
+						saved_state=F_HOST;
+						goto main_via;
 					case FIN_SIP:
 					case FIN_SIP:
 						vb->name.len=tmp-vb->name.s;
 						vb->name.len=tmp-vb->name.s;
 						state=F_CR;
 						state=F_CR;
@@ -1123,6 +1143,9 @@ parse_again:
 						state=SIP1;
 						state=SIP1;
 						vb->name.s=tmp;
 						vb->name.s=tmp;
 						break;
 						break;
+					case TLS2:
+						state=FIN_TLS;
+						break;
 					default:
 					default:
 						LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
 						LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
 								" state %d\n", *tmp, state);
 								" state %d\n", *tmp, state);
@@ -1189,7 +1212,7 @@ parse_again:
 			case 't':
 			case 't':
 				switch(state){
 				switch(state){
 					case F_PROTO:
 					case F_PROTO:
-						state=TCP1;
+						state=TCP_TLS1;
 						vb->transport.s=tmp;
 						vb->transport.s=tmp;
 						break;
 						break;
 					default:
 					default:
@@ -1201,7 +1224,7 @@ parse_again:
 			case 'C':
 			case 'C':
 			case 'c':
 			case 'c':
 				switch(state){
 				switch(state){
-					case TCP1:
+					case TCP_TLS1:
 						state=TCP2;
 						state=TCP2;
 						break;
 						break;
 					default:
 					default:
@@ -1210,6 +1233,18 @@ parse_again:
 						goto error;
 						goto error;
 				}
 				}
 				break;
 				break;
+			case 'L':
+			case 'l':
+				switch(state){
+					case TCP_TLS1:
+						state=TLS2;
+						break;
+					default:
+						LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
+								" state %d\n", *tmp, state);
+						goto error;
+				}
+				break;
 			/*match 2.0*/
 			/*match 2.0*/
 			case '2':
 			case '2':
 				switch(state){
 				switch(state){

+ 5 - 0
resolve.c

@@ -497,6 +497,11 @@ struct hostent* sip_resolvehost(str* name, unsigned short* port, int proto)
 					memcpy(tmp+SRV_PREFIX_LEN, name->s, name->len);
 					memcpy(tmp+SRV_PREFIX_LEN, name->s, name->len);
 					tmp[SRV_PREFIX_LEN + name->len] = '\0';
 					tmp[SRV_PREFIX_LEN + name->len] = '\0';
 					break;
 					break;
+				case PROTO_TLS:
+					memcpy(tmp, SRV_TLS_PREFIX, SRV_PREFIX_LEN);
+					memcpy(tmp+SRV_PREFIX_LEN, name->s, name->len);
+					tmp[SRV_PREFIX_LEN + name->len] = '\0';
+					break;
 				default:
 				default:
 					LOG(L_CRIT, "BUG: sip_resolvehost: unknown proto %d\n",
 					LOG(L_CRIT, "BUG: sip_resolvehost: unknown proto %d\n",
 							proto);
 							proto);

+ 1 - 0
route.c

@@ -158,6 +158,7 @@ static int fix_actions(struct action* a)
 	for(t=a; t!=0; t=t->next){
 	for(t=a; t!=0; t=t->next){
 		switch(t->type){
 		switch(t->type){
 			case FORWARD_T:
 			case FORWARD_T:
+			case FORWARD_TLS_T:
 			case FORWARD_TCP_T:
 			case FORWARD_TCP_T:
 			case FORWARD_UDP_T:
 			case FORWARD_UDP_T:
 			case SEND_T:
 			case SEND_T:

+ 1 - 2
tcp_main.c

@@ -141,7 +141,6 @@ struct tcp_connection* tcpconn_new(int sock, union sockaddr_union* su,
 	c->refcnt=0;
 	c->refcnt=0;
 	su2ip_addr(&c->rcv.src_ip, su);
 	su2ip_addr(&c->rcv.src_ip, su);
 	c->rcv.src_port=su_getport(su);
 	c->rcv.src_port=su_getport(su);
-	c->rcv.proto=PROTO_TCP;
 	c->rcv.bind_address=ba;
 	c->rcv.bind_address=ba;
 	if (ba){
 	if (ba){
 		c->rcv.dst_ip=ba->address;
 		c->rcv.dst_ip=ba->address;
@@ -793,7 +792,7 @@ void tcp_main_loop()
 		/* start from 1, the "main" process does not transmit anything*/
 		/* start from 1, the "main" process does not transmit anything*/
 		for (r=1; r<process_no && n; r++){
 		for (r=1; r<process_no && n; r++){
 			if ( (pt[r].unix_sock>0) && FD_ISSET(pt[r].unix_sock, &sel_set)){
 			if ( (pt[r].unix_sock>0) && FD_ISSET(pt[r].unix_sock, &sel_set)){
-				/* (we can't have a fd==0, 0 i s never closed )*/
+				/* (we can't have a fd==0, 0 is never closed )*/
 				n--;
 				n--;
 				/* errno==EINTR !!! TODO*/
 				/* errno==EINTR !!! TODO*/
 read_again:
 read_again:

+ 2 - 2
tcp_read.c

@@ -399,14 +399,14 @@ int tcp_read_req(struct tcp_connection* con)
 #ifdef USE_TLS
 #ifdef USE_TLS
 		if (con->type==PROTO_TLS){
 		if (con->type==PROTO_TLS){
 			if (con->state==S_CONN_ACCEPT){
 			if (con->state==S_CONN_ACCEPT){
-				if (tls_accept(con)!=0){
+				if (tls_accept(con, 0)!=0){
 					resp=CONN_ERROR;
 					resp=CONN_ERROR;
 					goto end_req;
 					goto end_req;
 				}
 				}
 				if(con->state!=S_CONN_OK) goto end_req; /* not enough data */
 				if(con->state!=S_CONN_OK) goto end_req; /* not enough data */
 			}
 			}
 			if(con->state==S_CONN_CONNECT){
 			if(con->state==S_CONN_CONNECT){
-				if (tls_connect(con)!=0){
+				if (tls_connect(con, 0)!=0){
 					resp=CONN_ERROR;
 					resp=CONN_ERROR;
 					goto end_req;
 					goto end_req;
 				}
 				}

+ 2 - 2
test/invite1.sip

@@ -1,4 +1,4 @@
-INVITE sip:p2@195.37.78.126 SIP/2.0
+INVITE sip:p2@iptel.org SIP/2.0
 Via: SIP/2.0/UDP 192.168.99.100:5040
 Via: SIP/2.0/UDP 192.168.99.100:5040
 From: "GMD FOKUS iptlab" <sip:[email protected]>;tag=b96b0300ed30f1286-2f5d
 From: "GMD FOKUS iptlab" <sip:[email protected]>;tag=b96b0300ed30f1286-2f5d
 Call-ID: [email protected]
 Call-ID: [email protected]
@@ -9,7 +9,7 @@ User-Agent: Cisco-SIP-IP-Phone/2
 Accept: application/sdp
 Accept: application/sdp
 Contact: sip:[email protected]:5060
 Contact: sip:[email protected]:5060
 Content-Type: application/sdp
 Content-Type: application/sdp
-Content-Length: 225
+Content-Length: 218
 
 
 
 
 v=0
 v=0