Commit d3b6da9d authored by jehan's avatar jehan

fix for http proxy support

parent 42d9dc06
......@@ -69,7 +69,7 @@ BELLESIP_EXPORT int belle_sip_tls_listening_point_set_verify_exceptions(belle_si
BELLESIP_EXPORT int belle_sip_tls_listening_point_set_verify_policy(belle_sip_tls_listening_point_t *s, belle_tls_verify_policy_t *pol);
BELLESIP_EXPORT void belle_sip_tls_listening_point_set_http_proxy_addr(belle_sip_tls_listening_point_t *s, const char* proxy_addr);
BELLESIP_EXPORT void belle_sip_tls_listening_point_set_http_proxy_host(belle_sip_tls_listening_point_t *s, const char* proxy_addr);
BELLESIP_EXPORT void belle_sip_tls_listening_point_set_http_proxy_port(belle_sip_tls_listening_point_t *s, int port);
BELLESIP_EXPORT const char *belle_sip_tls_listening_point_get_http_proxy_addr(const belle_sip_tls_listening_point_t *s);
BELLESIP_EXPORT int belle_sip_tls_listening_point_get_http_proxy_port(const belle_sip_tls_listening_point_t *s);
......
......@@ -92,7 +92,7 @@ belle_sip_listening_point_t * belle_sip_stream_listening_point_new(belle_sip_sta
struct belle_sip_tls_listening_point{
belle_sip_stream_listening_point_t base;
belle_tls_verify_policy_t *verify_ctx;
char *http_proxy_addr;
char *http_proxy_host;
int http_proxy_port;
char *http_proxy_username; /*for futur use*/
char *http_proxy_passwd; /*for futur use*/
......
......@@ -197,6 +197,7 @@ static void http_proxy_res_done(void *data, const char *name, struct addrinfo *a
}
if (ai_list){
tls_channel_connect_to((belle_sip_channel_t *)obj,ai_list);
belle_sip_freeaddrinfo(ai_list);
}else{
belle_sip_error("%s: DNS resolution failed for %s", __FUNCTION__, name);
channel_set_state((belle_sip_channel_t*)obj,BELLE_SIP_CHANNEL_ERROR);
......@@ -206,10 +207,10 @@ static void http_proxy_res_done(void *data, const char *name, struct addrinfo *a
static int tls_channel_connect(belle_sip_channel_t *obj, const struct addrinfo *ai){
belle_sip_tls_listening_point_t * lp = (belle_sip_tls_listening_point_t * )obj->lp;
belle_sip_tls_channel_t *channel=(belle_sip_tls_channel_t*)obj;
if (lp->http_proxy_addr) {
belle_sip_message("Resolving http proxy addr [%s] for channel [%p]",lp->http_proxy_addr,obj);
if (lp->http_proxy_host) {
belle_sip_message("Resolving http proxy addr [%s] for channel [%p]",lp->http_proxy_host,obj);
/*assume ai family is the same*/
channel->http_proxy_resolver_ctx = belle_sip_stack_resolve_a(obj->stack, lp->http_proxy_addr, lp->http_proxy_port, obj->ai_family, http_proxy_res_done, obj);
channel->http_proxy_resolver_ctx = belle_sip_stack_resolve_a(obj->stack, lp->http_proxy_host, lp->http_proxy_port, obj->ai_family, http_proxy_res_done, obj);
if (channel->http_proxy_resolver_ctx) belle_sip_object_ref(channel->http_proxy_resolver_ctx);
return 0;
} else {
......@@ -322,17 +323,17 @@ static int tls_process_http_connect(belle_sip_tls_channel_t *obj) {
size_t encoded_username_paswd_length = username_passwd_length*2;
unsigned char *encoded_username_paswd = belle_sip_malloc(2*username_passwd_length);
base64_encode(encoded_username_paswd,&encoded_username_paswd_length,(const unsigned char *)username_passwd,username_passwd_length);
belle_sip_strcat_printf(request, "Proxy-Authorization: Basic %s\r\n",encoded_username_paswd);
request = belle_sip_strcat_printf(request, "Proxy-Authorization: Basic %s\r\n",encoded_username_paswd);
belle_sip_free(username_passwd);
belle_sip_free(encoded_username_paswd);
}
belle_sip_strcat_printf(request,"\r\n");
request = belle_sip_strcat_printf(request,"\r\n");
err = send(belle_sip_source_get_socket((belle_sip_source_t*)obj),request,strlen(request),0);
belle_sip_free(request);
if (err <= 0) {
belle_sip_error("tls_process_http_connect: fail to send connect request to http proxy [%s:%i] status [%s]"
,lp->http_proxy_addr
,lp->http_proxy_host
,lp->http_proxy_port
,strerror(errno));
return -1;
......@@ -355,40 +356,40 @@ static int tls_process_data(belle_sip_channel_t *obj,unsigned int revents){
belle_sip_source_set_events((belle_sip_source_t*)channel,BELLE_SIP_EVENT_READ|BELLE_SIP_EVENT_ERROR);
belle_sip_source_set_timeout((belle_sip_source_t*)obj,belle_sip_stack_get_transport_timeout(obj->stack));
if (lp->http_proxy_addr) {
if (lp->http_proxy_host) {
belle_sip_message("Channel [%p]: Connected at TCP level, now doing http proxy connect",obj);
if (tls_process_http_connect(channel)) goto process_error;
} else {
belle_sip_message("Channel [%p]: Connected at TCP level, now doing TLS handshake",obj);
if (tls_process_handshake(obj)==-1) goto process_error;
}
} else if (lp->http_proxy_addr && !channel->http_proxy_connected) {
} else if (lp->http_proxy_host && !channel->http_proxy_connected) {
char response[256];
err = stream_channel_recv((belle_sip_stream_channel_t*)obj,response,sizeof(response));
if (err<0 ){
belle_sip_error("Channel [%p]: connection refused by http proxy [%s:%i] status [%s]"
,channel
,lp->http_proxy_addr
,lp->http_proxy_host
,lp->http_proxy_port
,strerror(errno));
goto process_error;
} else if (strstr(response,"407")) {
belle_sip_error("Channel [%p]: auth requested, provide user/passwd by http proxy [%s:%i]"
,channel
,lp->http_proxy_addr
,lp->http_proxy_host
,lp->http_proxy_port);
goto process_error;
} else if (strstr(response,"200")) {
belle_sip_message("Channel [%p]: connected to http proxy, doing TLS handshake [%s:%i] "
,channel
,lp->http_proxy_addr
,lp->http_proxy_host
,lp->http_proxy_port);
channel->http_proxy_connected = 1;
if (tls_process_handshake(obj)==-1) goto process_error;
} else {
belle_sip_error("Channel [%p]: connection refused by http proxy [%s:%i]"
,channel
,lp->http_proxy_addr
,lp->http_proxy_host
,lp->http_proxy_port);
goto process_error;
}
......@@ -1099,7 +1100,7 @@ BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sip_signing_key_t);
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_signing_key_t,belle_sip_object_t,belle_sip_signing_key_destroy,belle_sip_signing_key_clone,NULL,TRUE);
GET_SET_STRING(belle_sip_tls_listening_point,http_proxy_addr)
GET_SET_STRING(belle_sip_tls_listening_point,http_proxy_host)
GET_SET_INT(belle_sip_tls_listening_point,http_proxy_port, int)
......
......@@ -24,9 +24,9 @@
static void belle_sip_tls_listening_point_uninit(belle_sip_tls_listening_point_t *lp){
belle_sip_object_unref(lp->verify_ctx);
if (lp->http_proxy_addr) belle_sip_object_unref(lp->http_proxy_addr);
if (lp->http_proxy_passwd) belle_sip_object_unref(lp->http_proxy_passwd);
if (lp->http_proxy_username) belle_sip_object_unref(lp->http_proxy_username);
if (lp->http_proxy_host) belle_sip_free(lp->http_proxy_host);
if (lp->http_proxy_passwd) belle_sip_free(lp->http_proxy_passwd);
if (lp->http_proxy_username) belle_sip_free(lp->http_proxy_username);
}
static belle_sip_channel_t *tls_create_channel(belle_sip_listening_point_t *lp, const belle_sip_hop_t *hop){
......
......@@ -421,10 +421,10 @@ static void stateful_register_tls_with_http_proxy(void) {
belle_sip_error("No TLS support, test skipped.");
return;
}
belle_sip_tls_listening_point_set_http_proxy_addr(lp, test_http_proxy_addr);
belle_sip_tls_listening_point_set_http_proxy_host(lp, test_http_proxy_addr);
belle_sip_tls_listening_point_set_http_proxy_port(lp, test_http_proxy_port);
register_test("tls",1);
belle_sip_tls_listening_point_set_http_proxy_addr(lp, NULL);
belle_sip_tls_listening_point_set_http_proxy_host(lp, NULL);
belle_sip_tls_listening_point_set_http_proxy_port(lp, 0);
}
......@@ -436,10 +436,10 @@ static void stateful_register_tls_with_wrong_http_proxy(void){
belle_sip_error("No TLS support, test skipped.");
return;
}
belle_sip_tls_listening_point_set_http_proxy_addr(lp, "mauvaisproxy.linphone.org");
belle_sip_tls_listening_point_set_http_proxy_host(lp, "mauvaisproxy.linphone.org");
belle_sip_tls_listening_point_set_http_proxy_port(lp, test_http_proxy_port);
try_register_user_at_domain(stack,prov,"tls",1,"tester",test_domain,NULL,0);
belle_sip_tls_listening_point_set_http_proxy_addr(lp, NULL);
belle_sip_tls_listening_point_set_http_proxy_host(lp, NULL);
belle_sip_tls_listening_point_set_http_proxy_port(lp, 0);
}
......@@ -615,10 +615,10 @@ static void register_dns_srv_tls_with_http_proxy(void){
return;
}
io_error_count=0;
belle_sip_tls_listening_point_set_http_proxy_addr(lp, test_http_proxy_addr);
belle_sip_tls_listening_point_set_http_proxy_host(lp, test_http_proxy_addr);
belle_sip_tls_listening_point_set_http_proxy_port(lp, test_http_proxy_port);
req=try_register_user_at_domain(stack, prov, "TLS",1,"tester",client_auth_domain,"sip:linphone.net;transport=tls",1);
belle_sip_tls_listening_point_set_http_proxy_addr(lp, NULL);
belle_sip_tls_listening_point_set_http_proxy_host(lp, NULL);
belle_sip_tls_listening_point_set_http_proxy_port(lp, 0);
BC_ASSERT_EQUAL(io_error_count, 0, int, "%d");
if (req) belle_sip_object_unref(req);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment