Updated Android implementation to support new trusted root CA option

This commit is contained in:
Pierre-Eric Pelloux-Prayer 2011-07-22 11:43:05 +02:00
parent 8b19f2314f
commit 970b083c67
4 changed files with 77 additions and 0 deletions

View file

@ -21,8 +21,17 @@ package org.linphone;
import static android.content.Intent.ACTION_MAIN; import static android.content.Intent.ACTION_MAIN;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;
import java.util.Enumeration;
import java.util.List; import java.util.List;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
import org.linphone.LinphoneManager.EcCalibrationListener; import org.linphone.LinphoneManager.EcCalibrationListener;
import org.linphone.core.LinphoneCore; import org.linphone.core.LinphoneCore;
import org.linphone.core.LinphoneCoreException; import org.linphone.core.LinphoneCoreException;
@ -47,6 +56,7 @@ import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.text.Html; import android.text.Html;
import android.util.Base64;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
@ -139,6 +149,49 @@ public class LinphoneActivity extends TabActivity {
if (savedInstanceState !=null && savedInstanceState.getBoolean(SCREEN_IS_HIDDEN,false)) { if (savedInstanceState !=null && savedInstanceState.getBoolean(SCREEN_IS_HIDDEN,false)) {
hideScreen(true); hideScreen(true);
} }
if (false) {
try {
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
Enumeration<String> al = ks.aliases();
while(al.hasMoreElements()) {
Log.i(al.nextElement());
}
Log.i("Enumeration done");
} catch (KeyStoreException e) {
e.printStackTrace();
}
} else if (false) {
try {
String defaultAlg = TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(defaultAlg);
// init is needed for Android to fill the javax.net.ssl.trustStore property
// ref : http://groups.google.com/group/android-developers/browse_thread/thread/366a3c8a6b2a7ad/163ff07c8ac39929?lnk=gst&q=SSL+root
tmf.init((KeyStore)null);
String trustStore = System.getProperty("javax.net.ssl.trustStore");
Log.i(trustStore + "\n");
for(TrustManager tm: tmf.getTrustManagers()) {
X509TrustManager xtm = (X509TrustManager)tm;
Log.i(xtm.getAcceptedIssuers().length);
for(X509Certificate ca : xtm.getAcceptedIssuers()) {
byte[] encoded = ca.getEncoded();
String s = new String(encoded);
byte[] d2 = Base64.decode(encoded, 0);
String s2 = new String(d2);
Log.i(ca.toString());
}
}
} catch (KeyStoreException e) {
} catch (NoSuchAlgorithmException e) {
} catch (Exception e) {
e.printStackTrace();
}
}
} }

View file

@ -119,6 +119,7 @@ public final class LinphoneManager implements LinphoneCoreListener {
basePath = c.getFilesDir().getAbsolutePath(); basePath = c.getFilesDir().getAbsolutePath();
linphoneInitialConfigFile = basePath + "/linphonerc"; linphoneInitialConfigFile = basePath + "/linphonerc";
linphoneConfigFile = basePath + "/.linphonerc"; linphoneConfigFile = basePath + "/.linphonerc";
linphoneRootCaFile = basePath + "/rootca.pem";
ringSoundFile = basePath + "/oldphone_mono.wav"; ringSoundFile = basePath + "/oldphone_mono.wav";
ringbackSoundFile = basePath + "/ringback.wav"; ringbackSoundFile = basePath + "/ringback.wav";
@ -136,6 +137,7 @@ public final class LinphoneManager implements LinphoneCoreListener {
private static final int dbStep = 4; private static final int dbStep = 4;
/** Called when the activity is first created. */ /** Called when the activity is first created. */
private final String linphoneInitialConfigFile; private final String linphoneInitialConfigFile;
private final String linphoneRootCaFile;
private final String linphoneConfigFile; private final String linphoneConfigFile;
private final String ringSoundFile; private final String ringSoundFile;
private final String ringbackSoundFile; private final String ringbackSoundFile;
@ -326,6 +328,8 @@ public final class LinphoneManager implements LinphoneCoreListener {
mLc.setPlaybackGain(3); mLc.setPlaybackGain(3);
mLc.setRing(null); mLc.setRing(null);
mLc.setRootCA(linphoneRootCaFile);
try { try {
initFromConf(context); initFromConf(context);
@ -354,6 +358,7 @@ public final class LinphoneManager implements LinphoneCoreListener {
copyIfNotExist(context, R.raw.oldphone_mono,ringSoundFile); copyIfNotExist(context, R.raw.oldphone_mono,ringSoundFile);
copyIfNotExist(context, R.raw.ringback,ringbackSoundFile); copyIfNotExist(context, R.raw.ringback,ringbackSoundFile);
copyFromPackage(context, R.raw.linphonerc, new File(linphoneInitialConfigFile).getName()); copyFromPackage(context, R.raw.linphonerc, new File(linphoneInitialConfigFile).getName());
copyIfNotExist(context, R.raw.rootca, new File(linphoneRootCaFile).getName());
} }
private void copyIfNotExist(Context context, int ressourceId,String target) throws IOException { private void copyIfNotExist(Context context, int ressourceId,String target) throws IOException {
File lFileToCopy = new File(target); File lFileToCopy = new File(target);

View file

@ -19,7 +19,21 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
package org.linphone.core; package org.linphone.core;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.PKIXParameters;
import java.security.cert.TrustAnchor;
import java.security.cert.X509Certificate;
import java.util.Iterator;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
public class LinphoneCoreFactoryImpl extends LinphoneCoreFactory { public class LinphoneCoreFactoryImpl extends LinphoneCoreFactory {

View file

@ -87,6 +87,7 @@ class LinphoneCoreImpl implements LinphoneCore {
private native int[] getPreferredVideoSize(long nativePtr); private native int[] getPreferredVideoSize(long nativePtr);
private native void setRing(long nativePtr, String path); private native void setRing(long nativePtr, String path);
private native String getRing(long nativePtr); private native String getRing(long nativePtr);
private native void setRootCA(long nativePtr, String path);
private native long[] listVideoPayloadTypes(long nativePtr); private native long[] listVideoPayloadTypes(long nativePtr);
private native long[] listAudioPayloadTypes(long nativePtr); private native long[] listAudioPayloadTypes(long nativePtr);
private native void enableKeepAlive(long nativePtr,boolean enable); private native void enableKeepAlive(long nativePtr,boolean enable);
@ -420,6 +421,10 @@ class LinphoneCoreImpl implements LinphoneCore {
return getRing(nativePtr); return getRing(nativePtr);
} }
public void setRootCA(String path) {
setRootCA(nativePtr, path);
}
public PayloadType[] getVideoCodecs() { public PayloadType[] getVideoCodecs() {
long[] typesPtr = listVideoPayloadTypes(nativePtr); long[] typesPtr = listVideoPayloadTypes(nativePtr);
if (typesPtr == null) return null; if (typesPtr == null) return null;