Commit 6b886a6f authored by DanmeiChen's avatar DanmeiChen

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

parent 2b3d4ae3
......@@ -38,10 +38,20 @@ BELLE_SIP_INSTANCIATE_VPTR(LinphoneAccountCreatorCbs, belle_sip_object_t,
);
/************************** Start Misc **************************/
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_algo(username, realm, passwd, ha1);
return ha1;
}
else {
return NULL;
}
}
static unsigned int validate_uri(const char* username, const char* domain, const char* display_name) {
......@@ -424,6 +434,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;
......@@ -706,10 +728,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, linphone_proxy_config_get_domain(creator->proxy_cfg), creator->password) : "");
ha1_for_passwd(creator->username ? creator->username : creator->phone_number, linphone_proxy_config_get_domain(creator->proxy_cfg), 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, linphone_proxy_config_get_domain(creator->proxy_cfg));
linphone_xml_rpc_request_add_string_arg(request, creator->language);
linphone_xml_rpc_request_add_string_arg(request, creator->algorithm);
return request;
}
......@@ -727,9 +750,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, linphone_proxy_config_get_domain(creator->proxy_cfg), creator->password));
ha1_for_passwd(creator->username ? creator->username : creator->phone_number, linphone_proxy_config_get_domain(creator->proxy_cfg), 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, linphone_proxy_config_get_domain(creator->proxy_cfg));
linphone_xml_rpc_request_add_string_arg(request, creator->algorithm);
return request;
}
......@@ -793,6 +817,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, 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), _activate_account_cb_custom);
linphone_xml_rpc_session_send_request(creator->xmlrpc_session, request);
......@@ -818,6 +843,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_activate_email_account_lin
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, 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), _activate_account_cb_custom);
linphone_xml_rpc_session_send_request(creator->xmlrpc_session, request);
......@@ -1014,8 +1040,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, linphone_proxy_config_get_domain(creator->proxy_cfg), creator->password));
linphone_xml_rpc_request_add_string_arg(request, creator->ha1 ? creator->ha1 : 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), _activate_phone_number_link_cb_custom);
linphone_xml_rpc_session_send_request(creator->xmlrpc_session, request);
......@@ -1106,8 +1133,8 @@ LinphoneAccountCreatorStatus linphone_account_creator_update_password_linphone(L
}
const char * username = creator->username ? creator->username : creator->phone_number;
const char * ha1 = ms_strdup(creator->ha1 ? creator->ha1 : ha1_for_passwd(username, linphone_proxy_config_get_domain(creator->proxy_cfg), creator->password) );
const char * new_ha1 = ms_strdup(ha1_for_passwd(username, linphone_proxy_config_get_domain(creator->proxy_cfg), new_pwd));
const char * ha1 = ms_strdup(creator->ha1 ? creator->ha1 : ha1_for_passwd(username, linphone_proxy_config_get_domain(creator->proxy_cfg), creator->password, creator->algorithm) );
const char * new_ha1 = ms_strdup(ha1_for_passwd(username, linphone_proxy_config_get_domain(creator->proxy_cfg), new_pwd, creator->algorithm));
ms_debug("Account creator: update_password (username=%s, domain=%s)",
creator->username,
......@@ -1118,6 +1145,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, 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), _password_updated_cb_custom);
linphone_xml_rpc_session_send_request(creator->xmlrpc_session, request);
......
......@@ -944,6 +944,12 @@ void sal_use_dates(Sal *ctx, bool_t enabled){
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");
}
SalCustomHeader *sal_custom_header_ref(SalCustomHeader *ch){
......
......@@ -1517,7 +1517,7 @@ struct _LinphoneAccountCreator {
char *activation_code; /**< Account validation code */
char *domain; /**< Domain */
LinphoneTransportType transport; /**< Transport used */
char *algorithm; /**< User algorithm */
/* Deprecated */
char *route;
};
......
......@@ -236,6 +236,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
......
......@@ -106,6 +106,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
......
......@@ -569,6 +569,7 @@ SalAuthInfo* sal_auth_info_new(void);
SalAuthInfo* sal_auth_info_clone(const SalAuthInfo* auth_info);
void sal_auth_info_delete(SalAuthInfo* auth_info);
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]);
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