tsip_header_Authorization_t *tsip_header_Authorization_parse(const char *data, tsk_size_t size)
{
	tsip_header_Authorization_t *hdr_sip = 0;
	thttp_header_Authorization_t* hdr_http;

	if((hdr_http = thttp_header_Authorization_parse(data, size))){
		hdr_sip = tsip_header_Authorization_create();
		
		hdr_sip->scheme = tsk_strdup(hdr_http->scheme);
		hdr_sip->username = tsk_strdup(hdr_http->username);
		hdr_sip->realm =  tsk_strdup(hdr_http->realm);
		hdr_sip->nonce =  tsk_strdup(hdr_http->nonce);
		hdr_sip->uri =  tsk_strdup(hdr_http->uri);
		hdr_sip->response =  tsk_strdup(hdr_http->response);
		hdr_sip->algorithm =  tsk_strdup(hdr_http->algorithm);
		hdr_sip->cnonce =  tsk_strdup(hdr_http->cnonce);
		hdr_sip->opaque =  tsk_strdup(hdr_http->opaque);
		hdr_sip->qop =  tsk_strdup(hdr_http->qop);
		hdr_sip->nc =  tsk_strdup(hdr_http->nc);

		TSIP_HEADER(hdr_sip)->params = tsk_object_ref(THTTP_HEADER(hdr_http)->params);

		TSK_OBJECT_SAFE_FREE(hdr_http);
	}
	
	return hdr_sip;
}
tsip_header_Proxy_Authenticate_t *tsip_header_Proxy_Authenticate_parse(const char *data, tsk_size_t size)
{
	tsip_header_Proxy_Authenticate_t *sip_hdr = 0;
	thttp_header_Proxy_Authenticate_t* http_hdr;

	if((http_hdr = thttp_header_Proxy_Authenticate_parse(data, size))){
		sip_hdr = tsip_header_Proxy_Authenticate_create();

		sip_hdr->scheme = tsk_strdup(http_hdr->scheme);
		sip_hdr->realm = tsk_strdup(http_hdr->realm);
		sip_hdr->domain = tsk_strdup(http_hdr->domain);
		sip_hdr->nonce = tsk_strdup(http_hdr->nonce);
		sip_hdr->opaque = tsk_strdup(http_hdr->opaque);
		sip_hdr->algorithm = tsk_strdup(http_hdr->algorithm);
		sip_hdr->qop = tsk_strdup(http_hdr->qop);
		sip_hdr->stale = http_hdr->stale;
		
		TSIP_HEADER(sip_hdr)->params = tsk_object_ref(THTTP_HEADER(http_hdr)->params);

		TSK_OBJECT_SAFE_FREE(http_hdr);
	}
	
	return sip_hdr;
}
示例#3
0
thttp_header_t *thttp_challenge_create_header_authorization(thttp_challenge_t *self, const char* username, const char* password, const thttp_request_t *request)
{
	char* response = tsk_null;
	tsk_size_t response_size = 0;
	nonce_count_t nc;
	char *uristring = tsk_null;
	thttp_header_t *header = 0;

	if (!self || !request || !request->line.request.url){
		goto bail;
	}

	/* Sets URI: hpath do not start with / ==> append a '/'*/
	tsk_sprintf(&uristring, "/%s", request->line.request.url->hpath ? request->line.request.url->hpath : "");

	/* We compute the nc here because @ref thttp_challenge_get_response function will increment it's value. */
	if (self->nc){
		THTTP_NCOUNT_2_STRING(self->nc, nc);
	}

	/* Computes the response (Basic and Digest)*/
	if (THTTP_CHALLENGE_IS_DIGEST(self)){
		if (thttp_challenge_get_digest_response(self, username, password, request->line.request.method, uristring, request->Content, &response)){
			goto bail;
		}
		response_size = (TSK_MD5_DIGEST_SIZE * 2);
	}
	else if (THTTP_CHALLENGE_IS_BASIC(self)){
		response_size = thttp_auth_basic_response(username, password, &response);
	}
	else{
		TSK_DEBUG_ERROR("%s not supported as scheme.", self->scheme);
		goto bail;
	}


#define THTTP_AUTH_COPY_VALUES(hdr)															\
		hdr->username = tsk_strdup(username);												\
		hdr->scheme = tsk_strdup(self->scheme);												\
		hdr->realm = tsk_strdup(self->realm);												\
		hdr->nonce = tsk_strdup(self->nonce);												\
		hdr->qop = tsk_strdup(self->qop);													\
		hdr->opaque = tsk_strdup(self->opaque);												\
		hdr->algorithm = self->algorithm ? tsk_strdup(self->algorithm) : tsk_strdup("MD5");	\
		hdr->cnonce = self->nc? tsk_strdup(self->cnonce) : 0;								\
		hdr->uri = tsk_strdup(uristring);													\
		hdr->nc = self->nc? tsk_strdup(nc) : 0;												\
		hdr->response = tsk_strndup(response, response_size);								\

	if (self->isproxy){
		thttp_header_Proxy_Authorization_t *proxy_auth = thttp_header_authorization_create(); // Very bad way to create Proxy_auth header.
		THTTP_HEADER(proxy_auth)->type = thttp_htype_Proxy_Authorization;

		THTTP_AUTH_COPY_VALUES(proxy_auth);
		header = THTTP_HEADER(proxy_auth);
	}
	else{
		thttp_header_Authorization_t *auth = thttp_header_authorization_create();
		THTTP_AUTH_COPY_VALUES(auth);
		header = THTTP_HEADER(auth);
	}

bail:
	TSK_FREE(uristring);
	TSK_FREE(response);

	return header;

#undef THTTP_AUTH_COPY_VALUES
}
示例#4
0
thttp_header_t *thttp_challenge_create_header_authorization_2(thttp_challenge_t *self, const char* username, const char* password, const char* method, const char *uristring, const tsk_buffer_t* entity_body)
{
    char* response = tsk_null;
    tsk_size_t response_size = 0;
    nonce_count_t nc;
    thttp_header_t *header = tsk_null;

    if (!self || tsk_strnullORempty(uristring)) {
        TSK_DEBUG_ERROR("Invalid parameter");
        goto bail;
    }

    /* We compute the nc here because @ref thttp_challenge_get_response function will increment it's value. */
    if (self->nc) {
        THTTP_NCOUNT_2_STRING(self->nc, nc);
    }

    /* Computes the response (Basic and Digest)*/
    if (THTTP_CHALLENGE_IS_DIGEST(self)) {
        if (thttp_challenge_get_digest_response(self, username, password, method, uristring, entity_body, &response)) {
            goto bail;
        }
        response_size = (TSK_MD5_DIGEST_SIZE * 2);
    }
    else if (THTTP_CHALLENGE_IS_BASIC(self)) {
        response_size = thttp_auth_basic_response(username, password, &response);
    }
    else {
        TSK_DEBUG_ERROR("%s not supported as scheme.", self->scheme);
        goto bail;
    }


#define THTTP_AUTH_COPY_VALUES(hdr)															\
hdr->username = tsk_strdup(username);												\
hdr->scheme = tsk_strdup(self->scheme);												\
hdr->realm = tsk_strdup(self->realm);												\
hdr->nonce = tsk_strdup(self->nonce);												\
hdr->qop = tsk_strdup(self->qop);													\
hdr->opaque = tsk_strdup(self->opaque);												\
hdr->algorithm = self->algorithm ? tsk_strdup(self->algorithm) : tsk_strdup("MD5");	\
hdr->cnonce = self->nc? tsk_strdup(self->cnonce) : 0;								\
hdr->uri = tsk_strdup(uristring);													\
hdr->nc = self->nc? tsk_strdup(nc) : 0;												\
hdr->response = tsk_strndup(response, response_size);								\
 
    if (self->isproxy) {
        thttp_header_Proxy_Authorization_t *proxy_auth = thttp_header_authorization_create(); // Very bad way to create Proxy_auth header.
        THTTP_HEADER(proxy_auth)->type = thttp_htype_Proxy_Authorization;

        THTTP_AUTH_COPY_VALUES(proxy_auth);
        header = THTTP_HEADER(proxy_auth);
    }
    else {
        thttp_header_Authorization_t *auth = thttp_header_authorization_create();
        THTTP_AUTH_COPY_VALUES(auth);
        header = THTTP_HEADER(auth);
    }

bail:
    TSK_FREE(response);

    return header;

#undef THTTP_AUTH_COPY_VALUES
}