diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/de/blinkt/openvpn/LogWindow.java | 9 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/NetworkSateReceiver.java | 12 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/OpenVPN.java | 85 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/VpnProfile.java | 8 |
4 files changed, 94 insertions, 20 deletions
diff --git a/src/de/blinkt/openvpn/LogWindow.java b/src/de/blinkt/openvpn/LogWindow.java index b38951df..6060e7ad 100644 --- a/src/de/blinkt/openvpn/LogWindow.java +++ b/src/de/blinkt/openvpn/LogWindow.java @@ -27,6 +27,7 @@ import android.widget.ListAdapter; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; +import de.blinkt.openvpn.OpenVPN.LogItem; import de.blinkt.openvpn.OpenVPN.LogListener; import de.blinkt.openvpn.OpenVPN.StateListener; @@ -59,8 +60,8 @@ public class LogWindow extends ListActivity implements StateListener { private void initLogBuffer() { myEntries.clear(); - for (String litem : OpenVPN.getlogbuffer()) { - myEntries.add(litem); + for (LogItem litem : OpenVPN.getlogbuffer()) { + myEntries.add(litem.getString(getBaseContext())); } } @@ -149,11 +150,11 @@ public class LogWindow extends ListActivity implements StateListener { } @Override - public void newLog(String logmessage) { + public void newLog(LogItem logmessage) { Message msg = Message.obtain(); msg.what=MESSAGE_NEWLOG; Bundle mbundle=new Bundle(); - mbundle.putString("logmessage", logmessage); + mbundle.putString("logmessage", logmessage.getString(getBaseContext())); msg.setData(mbundle); mHandler.sendMessage(msg); } diff --git a/src/de/blinkt/openvpn/NetworkSateReceiver.java b/src/de/blinkt/openvpn/NetworkSateReceiver.java index 77e25acf..a8d69896 100644 --- a/src/de/blinkt/openvpn/NetworkSateReceiver.java +++ b/src/de/blinkt/openvpn/NetworkSateReceiver.java @@ -29,10 +29,14 @@ public class NetworkSateReceiver extends BroadcastReceiver { String netstatestring;
if(networkInfo==null)
- netstatestring = "null";
- else
+ netstatestring = "not connected";
+ else {
+ String subtype = networkInfo.getSubtypeName();
+ if(subtype==null)
+ subtype = "";
netstatestring = String.format("%2$s %4$s to %1$s %3$s",networkInfo.getTypeName(),
- networkInfo.getDetailedState(),networkInfo.getExtraInfo(), networkInfo.getSubtypeName());
+ networkInfo.getDetailedState(),networkInfo.getExtraInfo(),subtype );
+ }
if(networkInfo!=null && networkInfo.getState() == State.CONNECTED) {
int newnet = networkInfo.getType();
@@ -43,7 +47,7 @@ public class NetworkSateReceiver extends BroadcastReceiver { lastNetwork = newnet;
}
if(!netstatestring.equals(lastStateMsg))
- OpenVPN.logMessage(0, "Network:", netstatestring);
+ OpenVPN.logInfo(R.string.netstatus, netstatestring);
lastStateMsg=netstatestring;
}
diff --git a/src/de/blinkt/openvpn/OpenVPN.java b/src/de/blinkt/openvpn/OpenVPN.java index 55e15abc..39533db3 100644 --- a/src/de/blinkt/openvpn/OpenVPN.java +++ b/src/de/blinkt/openvpn/OpenVPN.java @@ -3,21 +3,67 @@ package de.blinkt.openvpn; import java.util.LinkedList; import java.util.Vector; +import android.content.Context; + public class OpenVPN { + + static class LogItem { + public static final int ERROR = 1; + public static final int INFO = 2; + public static final int VERBOSE = 3; + + private Object [] mArgs = null; + private String mMessage = null; + private int mRessourceId; + // Default log priority + int mLevel = INFO; + + public LogItem(int ressourceId, Object[] args) { + mRessourceId = ressourceId; + mArgs = args; + } + + + public LogItem(int loglevel,int ressourceId, Object[] args) { + mRessourceId = ressourceId; + mArgs = args; + mLevel = loglevel; + } + + + public LogItem(String message) { + mMessage = message; + } + + String getString(Context c) { + if(mMessage !=null) { + return mMessage; + } else { + if(mArgs == null) + return c.getString(mRessourceId); + else + return c.getString(mRessourceId,mArgs); + } + } + } + private static final int MAXLOGENTRIES = 200; public static final String MANAGMENT_PREFIX = "M:"; - public static LinkedList<String> logbuffer = new LinkedList<String>(); + + + + public static LinkedList<LogItem> logbuffer = new LinkedList<LogItem>(); private static Vector<LogListener> logListener=new Vector<OpenVPN.LogListener>(); private static Vector<StateListener> stateListener=new Vector<OpenVPN.StateListener>(); private static String[] mBconfig; public interface LogListener { - void newLog(String logmessage); + void newLog(LogItem logItem); } public interface StateListener { @@ -26,13 +72,7 @@ public class OpenVPN { synchronized static void logMessage(int level,String prefix, String message) { - logbuffer.addLast(prefix + message); - if(logbuffer.size()>MAXLOGENTRIES) - logbuffer.removeFirst(); - - for (LogListener ll : logListener) { - ll.newLog(prefix + message); - } + newlogItem(new LogItem(prefix + message)); } @@ -59,15 +99,15 @@ public class OpenVPN { - synchronized public static String[] getlogbuffer() { + synchronized public static LogItem[] getlogbuffer() { // The stoned way of java to return an array from a vector // brought to you by eclipse auto complete - return (String[]) logbuffer.toArray(new String[logbuffer.size()]); + return (LogItem[]) logbuffer.toArray(new LogItem[logbuffer.size()]); } public static void logBuilderConfig(String[] bconfig) { - mBconfig =bconfig; + mBconfig = bconfig; } public static void triggerLogBuilderConfig() { if(mBconfig==null) { @@ -85,4 +125,25 @@ public class OpenVPN { sl.updateState(msg); } } + + public static void logInfo(String message) { + + } + + public static void logInfo(int ressourceId, Object... args) { + newlogItem(new LogItem(LogItem.INFO, ressourceId, args)); + } + + private static void newlogItem(LogItem logItem) { + logbuffer.addLast(logItem); + if(logbuffer.size()>MAXLOGENTRIES) + logbuffer.removeFirst(); + + for (LogListener ll : logListener) { + ll.newLog(logItem); + } + } + + + } diff --git a/src/de/blinkt/openvpn/VpnProfile.java b/src/de/blinkt/openvpn/VpnProfile.java index d74701f5..e9cb994a 100644 --- a/src/de/blinkt/openvpn/VpnProfile.java +++ b/src/de/blinkt/openvpn/VpnProfile.java @@ -23,6 +23,7 @@ import android.content.Intent; import android.content.pm.ApplicationInfo; import android.security.KeyChain; import android.security.KeyChainException; +import android.util.Log; public class VpnProfile implements Serializable{ // Parcable @@ -473,7 +474,14 @@ public class VpnProfile implements Serializable{ try { privateKey = KeyChain.getPrivateKey(context,mAlias); cachain = KeyChain.getCertificateChain(context, mAlias); + if(cachain.length <= 1) + OpenVPN.logMessage(0, "", context.getString(R.string.keychain_nocacert)); + + for(X509Certificate cert:cachain) { + OpenVPN.logInfo(R.string.cert_from_keystore,cert.getSubjectDN()); + } + KeyStore ks = KeyStore.getInstance("PKCS12"); ks.load(null, null); ks.setKeyEntry("usercert", privateKey, null, cachain); |