Commit 70d4acc6 authored by DanmeiChen's avatar DanmeiChen Committed by Matthieu Tanon

Add algo in account creater for supporting SHA-256 and add tests for this

parent 1a0d5bad
......@@ -52,10 +52,20 @@ static const char *_get_domain(LinphoneAccountCreator *creator) {
return linphone_proxy_config_get_domain(creator->proxy_cfg);
}
static const char* ha1_for_passwd(const char* username, const char* realm, const char* passwd) {
static char ha1[33];
sal_auth_compute_ha1(username, realm, passwd, ha1);
return ha1;
static const char* ha1_for_passwd(const char* username, const char* realm, const char* passwd, const char* algo) {
if(algo==NULL || strcmp(algo, "MD5")==0) {
static char ha1[33];
sal_auth_compute_ha1(username, realm, passwd, ha1);
return ha1;
}
else if(strcmp(algo, "SHA-256")==0) {
static char ha1[65];
sal_auth_compute_ha1_for_algorithm(username, realm, passwd, ha1, 65, algo);
return ha1;
}
else {
return NULL;
}
}
static unsigned int validate_uri(const char* username, const char* domain, const char* display_name) {
......@@ -492,6 +502,18 @@ const char * linphone_account_creator_get_password(const LinphoneAccountCreator
return creator->password;
}
LinphoneAccountCreatorAlgoStatus linphone_account_creator_set_algorithm(LinphoneAccountCreator *creator, const char *algorithm) {
set_string(&creator->algorithm, algorithm, FALSE);
if(algorithm && strcmp(algorithm,"MD5") && strcmp(algorithm, "SHA-256")) {
return LinphoneAccountCreatorAlgoStatusNotSupported;
}
return LinphoneAccountCreatorAlgoStatusOk;
}
const char * linphone_account_creator_get_algorithm(const LinphoneAccountCreator *creator) {
return creator->algorithm;
}
LinphoneAccountCreatorPasswordStatus linphone_account_creator_set_ha1(LinphoneAccountCreator *creator, const char *ha1){
set_string(&creator->ha1, ha1, FALSE);
return LinphoneAccountCreatorPasswordStatusOk;
......@@ -795,10 +817,11 @@ static LinphoneXmlRpcRequest * _create_account_with_phone_custom(LinphoneAccount
linphone_xml_rpc_request_add_string_arg(request, creator->phone_number);
linphone_xml_rpc_request_add_string_arg(request, creator->username ? creator->username : creator->phone_number);
linphone_xml_rpc_request_add_string_arg(request, creator->password ?
ha1_for_passwd(creator->username ? creator->username : creator->phone_number, _get_domain(creator), creator->password) : "");
ha1_for_passwd(creator->username ? creator->username : creator->phone_number, _get_domain(creator), creator->password, creator->algorithm) : "");
linphone_xml_rpc_request_add_string_arg(request, linphone_core_get_user_agent(creator->core));
linphone_xml_rpc_request_add_string_arg(request, _get_domain(creator));
linphone_xml_rpc_request_add_string_arg(request, creator->language);
linphone_xml_rpc_request_add_string_arg(request, creator->algorithm);
return request;
}
......@@ -816,9 +839,10 @@ static LinphoneXmlRpcRequest * _create_account_with_email_custom(LinphoneAccount
linphone_xml_rpc_request_add_string_arg(request, creator->username);
linphone_xml_rpc_request_add_string_arg(request, creator->email);
linphone_xml_rpc_request_add_string_arg(request,
ha1_for_passwd(creator->username ? creator->username : creator->phone_number, _get_domain(creator), creator->password));
ha1_for_passwd(creator->username ? creator->username : creator->phone_number, _get_domain(creator), creator->password, creator->algorithm));
linphone_xml_rpc_request_add_string_arg(request, linphone_core_get_user_agent(creator->core));
linphone_xml_rpc_request_add_string_arg(request, _get_domain(creator));
linphone_xml_rpc_request_add_string_arg(request, creator->algorithm);
return request;
}
......@@ -928,6 +952,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_activate_account_linphone(
linphone_xml_rpc_request_add_string_arg(request, creator->username ? creator->username : creator->phone_number);
linphone_xml_rpc_request_add_string_arg(request, creator->activation_code);
linphone_xml_rpc_request_add_string_arg(request, _get_domain(creator));
linphone_xml_rpc_request_add_string_arg(request, creator->algorithm);
linphone_xml_rpc_request_set_user_data(request, creator);
linphone_xml_rpc_request_cbs_set_response(linphone_xml_rpc_request_get_callbacks(request), _activate_account_cb_custom);
linphone_xml_rpc_session_send_request(creator->xmlrpc_session, request);
......@@ -1004,8 +1029,9 @@ LinphoneAccountCreatorStatus linphone_account_creator_get_confirmation_key_linph
request = linphone_xml_rpc_request_new(LinphoneXmlRpcArgString, "get_confirmation_key");
linphone_xml_rpc_request_add_string_arg(request, creator->username);
linphone_xml_rpc_request_add_string_arg(request, ha1_for_passwd(creator->username, linphone_proxy_config_get_domain(creator->proxy_cfg), creator->password));
linphone_xml_rpc_request_add_string_arg(request, ha1_for_passwd(creator->username, linphone_proxy_config_get_domain(creator->proxy_cfg), creator->password, creator->algorithm));
linphone_xml_rpc_request_add_string_arg(request, linphone_proxy_config_get_domain(creator->proxy_cfg));
linphone_xml_rpc_request_add_string_arg(request, creator->algorithm);
linphone_xml_rpc_request_set_user_data(request, creator);
linphone_xml_rpc_request_cbs_set_response(linphone_xml_rpc_request_get_callbacks(request), _get_confirmation_key_cb_custom);
linphone_xml_rpc_session_send_request(creator->xmlrpc_session, request);
......@@ -1218,8 +1244,9 @@ LinphoneAccountCreatorStatus linphone_account_creator_activate_phone_number_link
linphone_xml_rpc_request_add_string_arg(request, creator->phone_number);
linphone_xml_rpc_request_add_string_arg(request, creator->username);
linphone_xml_rpc_request_add_string_arg(request, creator->activation_code);
linphone_xml_rpc_request_add_string_arg(request, creator->ha1 ? creator->ha1 : ha1_for_passwd(creator->username, _get_domain(creator), creator->password));
linphone_xml_rpc_request_add_string_arg(request, creator->ha1 ? creator->ha1 : ha1_for_passwd(creator->username, _get_domain(creator), creator->password, creator->algorithm));
linphone_xml_rpc_request_add_string_arg(request, _get_domain(creator));
linphone_xml_rpc_request_add_string_arg(request, creator->algorithm);
linphone_xml_rpc_request_set_user_data(request, creator);
linphone_xml_rpc_request_cbs_set_response(linphone_xml_rpc_request_get_callbacks(request), _activate_phone_number_link_cb_custom);
linphone_xml_rpc_session_send_request(creator->xmlrpc_session, request);
......@@ -1316,8 +1343,8 @@ LinphoneAccountCreatorStatus linphone_account_creator_update_password_linphone(L
if (creator->xmlrpc_session) {
const char *username = creator->username ? creator->username : creator->phone_number;
char *ha1 = bctbx_strdup(creator->ha1 ? creator->ha1 : ha1_for_passwd(username, _get_domain(creator), creator->password) );
char *new_ha1 = bctbx_strdup(ha1_for_passwd(username, _get_domain(creator), new_pwd));
char *ha1 = bctbx_strdup(creator->ha1 ? creator->ha1 : ha1_for_passwd(username, _get_domain(creator), creator->password, creator->algorithm) );
char *new_ha1 = bctbx_strdup(ha1_for_passwd(username, _get_domain(creator), new_pwd, creator->algorithm));
ms_debug("Account creator: update_password (username=%s, domain=%s)",
creator->username,
......@@ -1328,6 +1355,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_update_password_linphone(L
linphone_xml_rpc_request_add_string_arg(request, ha1);
linphone_xml_rpc_request_add_string_arg(request, new_ha1);
linphone_xml_rpc_request_add_string_arg(request, _get_domain(creator));
linphone_xml_rpc_request_add_string_arg(request, creator->algorithm);
linphone_xml_rpc_request_set_user_data(request, creator);
linphone_xml_rpc_request_cbs_set_response(linphone_xml_rpc_request_get_callbacks(request), _password_updated_cb_custom);
linphone_xml_rpc_session_send_request(creator->xmlrpc_session, request);
......
......@@ -100,6 +100,7 @@ struct _LinphoneAccountCreator {
char *language; /**< User language */
char *activation_code; /**< Account validation code */
char *domain; /**< Domain */
char *algorithm; /**< Digest authentication algorithm */
LinphoneTransportType transport; /**< Transport used */
// test
......
......@@ -82,6 +82,12 @@ void sal_signing_key_delete(belle_sip_signing_key_t *key) {
int sal_auth_compute_ha1(const char* userid,const char* realm,const char* password, char ha1[33]) {
return belle_sip_auth_helper_compute_ha1(userid, realm, password, ha1);
}
int sal_auth_compute_ha1_for_algo(const char* userid,const char* realm,const char* password, char ha1[65]) {
return belle_sip_auth_helper_compute_ha1_for_algorithm(userid, realm, password, ha1, 65, "SHA-256");
}
int sal_auth_compute_ha1_for_algorithm(
......
......@@ -257,6 +257,14 @@ LINPHONE_PUBLIC const char * linphone_account_creator_get_activation_code(const
**/
LINPHONE_PUBLIC LinphoneAccountCreatorLanguageStatus linphone_account_creator_set_language(LinphoneAccountCreator *creator, const char *lang);
/**
* Set the algorithm supported.
* @param[in] creator LinphoneAccountCreator object
* @param[in] lang The algorithm to use
* @return LinphoneAccountCreatorAlgoStatusOk if everything is OK, or a specific error otherwise.
**/
LINPHONE_PUBLIC LinphoneAccountCreatorAlgoStatus linphone_account_creator_set_algorithm(LinphoneAccountCreator *creator, const char *algorithm);
/**
* Get the language use in email of SMS.
* @param[in] creator #LinphoneAccountCreator object
......
......@@ -108,6 +108,16 @@ typedef enum _LinphoneAccountCreatorLanguageStatus {
LinphoneAccountCreatorLanguageStatusOk /**< Language ok */
} LinphoneAccountCreatorLanguageStatus;
/**
* Enum algorithm checking.
* @ingroup account_creator
**/
typedef enum _LinphoneAccountCreatorAlgoStatus {
LinphoneAccountCreatorAlgoStatusOk, /**< Algorithm ok */
LinphoneAccountCreatorAlgoStatusNotSupported /**< Algorithm not supported */
} LinphoneAccountCreatorAlgoStatus;
/**
* Enum describing Activation code checking.
* @ingroup account_creator
......
......@@ -488,8 +488,13 @@ extern "C" {
SalAuthInfo* sal_auth_info_new(void);
SalAuthInfo* sal_auth_info_clone(const SalAuthInfo* auth_info);
void sal_auth_info_delete(SalAuthInfo* auth_info);
// <<<<<<< HEAD:src/c-wrapper/internal/c-sal.h
LINPHONE_PUBLIC int sal_auth_compute_ha1(const char *userid, const char *realm, const char *password, char ha1[33]);
LINPHONE_PUBLIC int sal_auth_compute_ha1_for_algorithm(const char *userid, const char *realm, const char *password, char *ha1, size_t size, const char *algo);
// =======
// LINPHONE_PUBLIC int sal_auth_compute_ha1(const char* userid,const char* realm,const char* password, char ha1[33]);
// LINPHONE_PUBLIC int sal_auth_compute_ha1_for_algo(const char* userid,const char* realm,const char* password, char ha1[65]);
// >>>>>>> 6b886a6f0... Add algo in account creater for supporting SHA-256 and add tests for this:include/sal/sal.h
SalAuthMode sal_auth_info_get_mode(const SalAuthInfo* auth_info);
belle_sip_signing_key_t *sal_auth_info_get_signing_key(const SalAuthInfo* auth_info);
belle_sip_certificates_chain_t *sal_auth_info_get_certificates_chain(const SalAuthInfo* auth_info);
......
This diff is collapsed.
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