Exemplo n.º 1
0
int belle_sip_auth_helper_compute_ha1(const char* userid,const char* realm,const char* password, char ha1[33]) {
	md5_byte_t out[16];
	md5_state_t state;
	int di;
	if (!userid) {
		 belle_sip_error("belle_sip_fill_authorization_header, username not found ");
		 return -1;
	}
	if (!password) {
		 belle_sip_error("belle_sip_fill_authorization_header, password not found ");
		 return -1;
	}
	if (!realm) {
		 belle_sip_error("belle_sip_fill_authorization_header, password not found ");
		 return -1;
	}

	belle_sip_md5_init(&state);
	belle_sip_md5_append(&state,(const md5_byte_t *)userid,strlen(userid));
	belle_sip_md5_append(&state,(const md5_byte_t *)":",1);
	belle_sip_md5_append(&state,(const md5_byte_t *)realm,strlen(realm));
	belle_sip_md5_append(&state,(const md5_byte_t *)":",1);
	belle_sip_md5_append(&state,(const md5_byte_t *)password,strlen(password));
	belle_sip_md5_finish(&state,out);
	for (di = 0; di < 16; ++di)
			    sprintf(ha1 + di * 2, "%02x", out[di]);
	ha1[32]='\0';
	return 0;
}
Exemplo n.º 2
0
int belle_sip_auth_helper_compute_ha2(const char* method,const char* uri, char ha2[33]) {
	md5_byte_t out[16];
	md5_state_t state;
	int di;
	ha2[32]='\0';
	/*HA2=MD5(method:uri)*/
	belle_sip_md5_init(&state);
	belle_sip_md5_append(&state,(const md5_byte_t *)method,strlen(method));
	belle_sip_md5_append(&state,(const md5_byte_t *)":",1);
	belle_sip_md5_append(&state,(const md5_byte_t *)uri,strlen(uri));
	belle_sip_md5_finish(&state,out);
	for (di = 0; di < 16; ++di)
				    sprintf(ha2 + di * 2, "%02x", out[di]);
	return 0;
}
Exemplo n.º 3
0
int belle_sip_auth_helper_compute_response_qop_auth(const char* ha1
													, const char* nonce
													, unsigned int nonce_count
													, const char* cnonce
													, const char* qop
													, const char* ha2, char response[33]) {
	md5_byte_t out[16];
	md5_state_t state;
	char nounce_count_as_string[9];
	int di;

	response[32]='\0';

	snprintf(nounce_count_as_string,sizeof(nounce_count_as_string),"%08x",nonce_count);
	/*response=MD5(HA1:nonce:nonce_count:cnonce:qop:HA2)*/

	belle_sip_md5_init(&state);
	belle_sip_md5_append(&state,(const md5_byte_t *)ha1,strlen(ha1));
	belle_sip_md5_append(&state,(const md5_byte_t *)":",1);
	belle_sip_md5_append(&state
			,(const md5_byte_t *)nonce
			,strlen(nonce));
	belle_sip_md5_append(&state,(const md5_byte_t *)":",1);
	belle_sip_md5_append(&state
				,(const md5_byte_t *)nounce_count_as_string
				,strlen(nounce_count_as_string));
	belle_sip_md5_append(&state,(const md5_byte_t *)":",1);
	belle_sip_md5_append(&state
				,(const md5_byte_t *)cnonce
				,strlen(cnonce));
	belle_sip_md5_append(&state,(const md5_byte_t *)":",1);
	belle_sip_md5_append(&state
				,(const md5_byte_t *)qop
				,strlen(qop));
	belle_sip_md5_append(&state,(const md5_byte_t *)":",1);

	belle_sip_md5_append(&state,(const md5_byte_t *)ha2,strlen(ha2));
	belle_sip_md5_finish(&state,out);
	/*copy values*/
	for (di = 0; di < 16; ++di)
		    sprintf(response + di * 2, "%02x", out[di]);

	return 0;
}
Exemplo n.º 4
0
int belle_sip_auth_helper_compute_response(const char* ha1,const char* nonce, const char* ha2, char response[33]) {
	md5_byte_t out[16];
	md5_state_t state;
	int di;
	response[32]='\0';

	belle_sip_md5_init(&state);
	belle_sip_md5_append(&state,(const md5_byte_t *)ha1,strlen(ha1));
	belle_sip_md5_append(&state,(const md5_byte_t *)":",1);
	belle_sip_md5_append(&state
			,(const md5_byte_t *)nonce
			,strlen(nonce));
	belle_sip_md5_append(&state,(const md5_byte_t *)":",1);
	belle_sip_md5_append(&state,(const md5_byte_t *)ha2,strlen(ha2));
		belle_sip_md5_finish(&state,out);
		/*copy values*/
		for (di = 0; di < 16; ++di)
			    sprintf(response + di * 2, "%02x", out[di]);
	return 0;

}