Commit 61b0790d authored by DanmeiChen's avatar DanmeiChen

Feature/update linphone auth info for algorithm

parent 5a3a49b8
......@@ -58,16 +58,17 @@ LinphoneAuthInfo *linphone_auth_info_new_for_algorithm(const char *username, con
if (realm!=NULL && (strlen(realm)>0)) obj->realm=ms_strdup(realm);
if (domain!=NULL && (strlen(domain)>0)) obj->domain=ms_strdup(domain);
if (!algorithm)
if (!algorithm) {
obj->algorithm = ms_strdup("MD5");
return obj;
}
if(algorithm && strcasecmp(algorithm, "MD5") && strcasecmp(algorithm, "SHA-256")){
ms_error("Given algorithm %s is not correct.", algorithm);
return NULL;
}
if(algorithm)
obj->algorithm=ms_strdup(algorithm);
obj->algorithm=ms_strdup(algorithm);
return obj;
}
......@@ -101,6 +102,10 @@ const char *linphone_auth_info_get_username(const LinphoneAuthInfo *i) {
return i->username;
}
const char *linphone_auth_info_get_algorithm(const LinphoneAuthInfo *i) {
return i->algorithm;
}
const char *linphone_auth_info_get_passwd(const LinphoneAuthInfo *i) {
return linphone_auth_info_get_password(i);
}
......@@ -161,6 +166,24 @@ void linphone_auth_info_set_username(LinphoneAuthInfo *info, const char *usernam
if (username && strlen(username) > 0) info->username = ms_strdup(username);
}
void linphone_auth_info_set_algorithm(LinphoneAuthInfo *info, const char *algorithm) {
if (info->algorithm) {
ms_free(info->algorithm);
info->algorithm = NULL;
}
if (!algorithm) {
info->algorithm = ms_strdup("MD5");
return;
}
if(algorithm && strcasecmp(algorithm, "MD5") && strcasecmp(algorithm, "SHA-256")){
ms_error("Given algorithm %s is not correct. Set algorithm failed", algorithm);
return;
}
info->algorithm = ms_strdup(algorithm);
}
void linphone_auth_info_set_userid(LinphoneAuthInfo *info, const char *userid) {
if (info->userid) {
ms_free(info->userid);
......
......@@ -246,6 +246,10 @@ LinphoneAuthInfo *linphone_factory_create_auth_info(const LinphoneFactory *facto
return linphone_auth_info_new(username, userid, passwd, ha1, realm, domain);
}
LinphoneAuthInfo *linphone_factory_create_auth_info_2(const LinphoneFactory *factory, const char *username, const char *userid, const char *passwd, const char *ha1, const char *realm, const char *domain, const char *algorithm) {
return linphone_auth_info_new_for_algorithm(username, userid, passwd, ha1, realm, domain, algorithm);
}
LinphoneCallCbs * linphone_factory_create_call_cbs(const LinphoneFactory *factory) {
return _linphone_call_cbs_new();
}
......
......@@ -3009,11 +3009,11 @@ extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_pauseRegister(JN
}
//Auth Info
extern "C" jlong Java_org_linphone_core_LinphoneAuthInfoImpl_newLinphoneAuthInfo(JNIEnv* env
, jobject thiz ) {
return (jlong)linphone_auth_info_new(NULL,NULL,NULL,NULL,NULL,NULL);
return (jlong)linphone_auth_info_new_for_algorithm(NULL,NULL,NULL,NULL,NULL,NULL,NULL);
}
extern "C" void Java_org_linphone_core_LinphoneAuthInfoImpl_delete(JNIEnv* env
, jobject thiz
, jlong ptr) {
......@@ -3078,6 +3078,21 @@ extern "C" jstring Java_org_linphone_core_LinphoneAuthInfoImpl_getUsername
}
}
/*
* Class: org_linphone_core_LinphoneAuthInfoImpl
* Method: getAlgoorithm
* Signature: (J)Ljava/lang/String;
*/
extern "C" jstring Java_org_linphone_core_LinphoneAuthInfoImpl_getAlgorithm
(JNIEnv *env , jobject, jlong auth_info) {
const char* algorithm = linphone_auth_info_get_algorithm((LinphoneAuthInfo*)auth_info);
if (algorithm) {
return env->NewStringUTF(algorithm);
} else {
return NULL;
}
}
/*
* Class: org_linphone_core_LinphoneAuthInfoImpl
* Method: setPassword
......@@ -3126,6 +3141,18 @@ extern "C" void Java_org_linphone_core_LinphoneAuthInfoImpl_setUsername
ReleaseStringUTFChars(env, jusername, username);
}
/*
* Class: org_linphone_core_LinphoneAuthInfoImpl
* Method: setAlgorithm
* Signature: (JLjava/lang/String;)V
*/
extern "C" void Java_org_linphone_core_LinphoneAuthInfoImpl_setAlgorithm
(JNIEnv *env, jobject, jlong auth_info, jstring jalgorithm) {
const char* username = GetStringUTFChars(env, jalgorithm);
linphone_auth_info_set_algorithm((LinphoneAuthInfo*)auth_info,algorithm);
ReleaseStringUTFChars(env, jalgorithm, algorithm);
}
/*
* Class: org_linphone_core_LinphoneAuthInfoImpl
* Method: setAuthUserId
......
......@@ -109,6 +109,13 @@ LINPHONE_PUBLIC void linphone_auth_info_set_password(LinphoneAuthInfo *info, con
**/
LINPHONE_PUBLIC void linphone_auth_info_set_username(LinphoneAuthInfo *info, const char *username);
/**
* Sets the algorithm.
* @param[in] info The #LinphoneAuthInfo object
* @param[in] algorithm The algorithm.
**/
LINPHONE_PUBLIC void linphone_auth_info_set_algorithm(LinphoneAuthInfo *info, const char *algorithm);
/**
* Sets the userid.
* @param[in] info The #LinphoneAuthInfo object
......@@ -174,6 +181,13 @@ LINPHONE_PUBLIC void linphone_auth_info_set_tls_key_path(LinphoneAuthInfo *info,
*/
LINPHONE_PUBLIC const char *linphone_auth_info_get_username(const LinphoneAuthInfo *info);
/**
* Gets the algorithm.
* @param[in] info The #LinphoneAuthInfo object
* @return The algorithm.
*/
LINPHONE_PUBLIC const char *linphone_auth_info_get_algorithm(const LinphoneAuthInfo *info);
/**
* Gets the password.
* @param[in] info The #LinphoneAuthInfo object
......
......@@ -2201,6 +2201,7 @@ LINPHONE_PUBLIC void linphone_core_set_default_proxy_config(LinphoneCore *lc, Li
* @param[in] domain String containing the SIP domain for which this authentication information is valid, if it has to be restricted for a single SIP domain.
* @return #LinphoneAuthInfo with default values set
* @ingroup authentication
* @deprecated use linphone_factory_create_auth_info() instead.
*/
LINPHONE_PUBLIC LinphoneAuthInfo * linphone_core_create_auth_info(LinphoneCore *lc, const char *username, const char *userid, const char *passwd, const char *ha1, const char *realm, const char *domain);
......
......@@ -230,6 +230,24 @@ LINPHONE_PUBLIC LinphoneParticipantDeviceIdentity *linphone_factory_create_parti
*/
LINPHONE_PUBLIC LinphoneAuthInfo *linphone_factory_create_auth_info(const LinphoneFactory *factory, const char *username, const char *userid, const char *passwd, const char *ha1, const char *realm, const char *domain);
/**
* Creates a #LinphoneAuthInfo object.
* The object can be created empty, that is with all arguments set to NULL.
* Username, userid, password, realm and domain can be set later using specific methods.
* At the end, username and passwd (or ha1) are required.
* @param factory The #LinphoneFactory singleton.
* @param username The username that needs to be authenticated
* @param userid The userid used for authenticating (use NULL if you don't know what it is)
* @param passwd The password in clear text
* @param ha1 The ha1-encrypted password if password is not given in clear text.
* @param realm The authentication domain (which can be larger than the sip domain. Unfortunately many SIP servers don't use this parameter.
* @param domain The SIP domain for which this authentication information is valid, if it has to be restricted for a single SIP domain.
* @param algorithm The algorithm for encrypting password.
* @return A #LinphoneAuthInfo object. linphone_auth_info_destroy() must be used to destroy it when no longer needed. The #LinphoneCore makes a copy of #LinphoneAuthInfo
* passed through linphone_core_add_auth_info().
*/
LINPHONE_PUBLIC LinphoneAuthInfo *linphone_factory_create_auth_info_2(const LinphoneFactory *factory, const char *username, const char *userid, const char *passwd, const char *ha1, const char *realm, const char *domain, const char *algorithm);
/**
* Create a #LinphoneCallCbs object that holds callbacks for events happening on a call.
* @param[in] factory #LinphoneFactory singletion object
......
......@@ -93,6 +93,18 @@ public interface LinphoneAuthInfo {
* @return the domain
*/
String getDomain();
/**
* Sets the algorithm
* @param algorithm
*/
void setAlgorithm(String algorithm);
/**
* Gets the algorithm
* @return the algorithm
*/
String getAlgorithm();
/**
* Clones a current auth info
......
......@@ -70,6 +70,17 @@ abstract public class LinphoneCoreFactory {
* */
abstract public LinphoneAuthInfo createAuthInfo(String username, String userid, String passwd, String ha1, String realm, String domain);
/**
* create {@link LinphoneAuthInfo}
* @param username
* @param userid user id as set in auth header
* @param passwd
* @param ha1
* @param realm
* @param algorithm
* */
abstract public LinphoneAuthInfo createAuthInfo(String username, String userid, String passwd, String ha1, String realm, String domain, String algorithm);
/**
* Create a LinphoneCore object. The LinphoneCore is the root for all liblinphone operations. You need only one per application.
* @param listener listener to receive notifications from the core
......
......@@ -25,9 +25,11 @@ class LinphoneAuthInfoImpl implements LinphoneAuthInfo {
private native String getPassword(long ptr);
private native String getRealm(long ptr);
private native String getUsername(long ptr);
private native String getAlgorithm(long ptr);
private native void setPassword(long ptr, String password);
private native void setRealm(long ptr, String realm);
private native void setUsername(long ptr, String username);
private native void setAlgorithm(long ptr, String algorithm);
private native void setUserId(long ptr, String username);
private native void setHa1(long ptr, String ha1);
private native void setDomain(long ptr, String domain);
......@@ -48,6 +50,9 @@ class LinphoneAuthInfoImpl implements LinphoneAuthInfo {
this(username, null, password, null, realm, domain);
}
protected LinphoneAuthInfoImpl(String username, String userid, String passwd, String ha1, String realm, String domain) {
this(username, userid, passwd, ha1, realm, domain, null);
}
protected LinphoneAuthInfoImpl(String username, String userid, String passwd, String ha1, String realm, String domain, String algorithm) {
nativePtr = newLinphoneAuthInfo();
this.setUsername(username);
this.setUserId(userid);
......@@ -55,6 +60,7 @@ class LinphoneAuthInfoImpl implements LinphoneAuthInfo {
this.setHa1(ha1);
this.setDomain(domain);
this.setRealm(realm);
this.setAlgorithm(algorithm);
ownPtr = true;
}
protected LinphoneAuthInfoImpl(long aNativePtr) {
......@@ -73,6 +79,7 @@ class LinphoneAuthInfoImpl implements LinphoneAuthInfo {
public String getUsername() {
return getUsername (nativePtr);
}
public String getAlgorithm() { return getAlgorithm (nativePtr); }
public void setPassword(String password) {
setPassword(nativePtr,password);
}
......@@ -82,6 +89,7 @@ class LinphoneAuthInfoImpl implements LinphoneAuthInfo {
public void setUsername(String username) {
setUsername(nativePtr,username);
}
public void setAlgorithm(String algorithm) { setAlgorithm(nativePtr,algorithm); }
@Override
public String getUserId() {
return getUserId(nativePtr);
......@@ -116,7 +124,8 @@ class LinphoneAuthInfoImpl implements LinphoneAuthInfo {
getPassword(),
getHa1(),
getRealm(),
getDomain());
getDomain(),
getAlgorithm());
return clone;
}
......
......@@ -185,6 +185,13 @@ public class LinphoneCoreFactoryImpl extends LinphoneCoreFactory {
return new LinphoneAuthInfoImpl(username, userid, passwd, ha1, realm, domain);
}
@Override
public LinphoneAuthInfo createAuthInfo(String username, String userid,
String passwd, String ha1, String realm, String domain,
String algorithm) {
return new LinphoneAuthInfoImpl(username, userid, passwd, ha1, realm, domain, algorithm);
}
@Override
public LinphoneContent createLinphoneContent(String type, String subType,
byte [] data, String encoding) {
......
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