From 2a9037c749d3395ac65105604ab4936c4af0fc56 Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Mon, 20 May 2013 09:55:50 +0200 Subject: Add certificate CN print Need to fix string for email and order --HG-- extra : rebase_source : c3d5858d53d2f8f340b0d4a07434021f194a247a --- res/layout/file_select.xml | 14 +++- src/de/blinkt/openvpn/FileSelectLayout.java | 33 +++++---- src/de/blinkt/openvpn/VpnProfile.java | 21 ++---- src/de/blinkt/openvpn/core/X509Utils.java | 78 ++++++++++++++++++++ .../blinkt/openvpn/fragments/Settings_Basic.java | 8 +-- src/org/spongycastle/util/io/pem/PemReader.java | 84 ++++++++++++++++++++++ 6 files changed, 205 insertions(+), 33 deletions(-) create mode 100644 src/de/blinkt/openvpn/core/X509Utils.java create mode 100644 src/org/spongycastle/util/io/pem/PemReader.java diff --git a/res/layout/file_select.xml b/res/layout/file_select.xml index 0dd1abba..8c9e4da6 100644 --- a/res/layout/file_select.xml +++ b/res/layout/file_select.xml @@ -51,5 +51,17 @@ android:ellipsize="end" android:singleLine="true" android:text="@string/file_nothing_selected" /> - + + + \ No newline at end of file diff --git a/src/de/blinkt/openvpn/FileSelectLayout.java b/src/de/blinkt/openvpn/FileSelectLayout.java index b7e28b5c..d7bcc475 100644 --- a/src/de/blinkt/openvpn/FileSelectLayout.java +++ b/src/de/blinkt/openvpn/FileSelectLayout.java @@ -1,5 +1,6 @@ package de.blinkt.openvpn; +import de.blinkt.openvpn.core.X509Utils; import android.app.Fragment; import android.content.Context; import android.content.Intent; @@ -22,19 +23,21 @@ public class FileSelectLayout extends LinearLayout implements OnClickListener { private boolean mBase64Encode; private String mTitle; private boolean mShowClear; + private TextView mDataDetails; public FileSelectLayout( Context context,AttributeSet attrset) { super(context,attrset); inflate(getContext(), R.layout.file_select, this); - + TypedArray ta = context.obtainStyledAttributes(attrset,R.styleable.FileSelectLayout); - + mTitle = ta.getString(R.styleable.FileSelectLayout_title); - + TextView tview = (TextView) findViewById(R.id.file_title); tview.setText(mTitle); - + mDataView = (TextView) findViewById(R.id.file_selected_item); + mDataDetails = (TextView) findViewById(R.id.file_selected_description); mSelectButton = (Button) findViewById(R.id.file_select_button); mSelectButton.setOnClickListener(this); @@ -46,7 +49,7 @@ public class FileSelectLayout extends LinearLayout implements OnClickListener { mTaskId = i; mFragment = fragment; } - + public void getCertificateFileDialog() { Intent startFC = new Intent(getContext(),FileSelect.class); startFC.putExtra(FileSelect.START_DATA, mData); @@ -58,20 +61,24 @@ public class FileSelectLayout extends LinearLayout implements OnClickListener { mFragment.startActivityForResult(startFC,mTaskId); } - + public String getData() { return mData; } public void setData(String data) { mData = data; - if(data==null) + if(data==null) { mDataView.setText(mFragment.getString(R.string.no_data)); - else if(mData.startsWith(VpnProfile.INLINE_TAG)) - mDataView.setText(R.string.inline_file_data); - else - mDataView.setText(data); - + mDataDetails.setText(""); + }else { + if(mData.startsWith(VpnProfile.INLINE_TAG)) + mDataView.setText(R.string.inline_file_data); + else + mDataView.setText(data); + mDataDetails.setText(X509Utils.getCertificateFriendlyName(data)); + } + } @Override @@ -88,5 +95,5 @@ public class FileSelectLayout extends LinearLayout implements OnClickListener { public void setShowClear() { mShowClear=true; } - + } diff --git a/src/de/blinkt/openvpn/VpnProfile.java b/src/de/blinkt/openvpn/VpnProfile.java index 9d183897..03fcbc1b 100644 --- a/src/de/blinkt/openvpn/VpnProfile.java +++ b/src/de/blinkt/openvpn/VpnProfile.java @@ -45,6 +45,7 @@ import de.blinkt.openvpn.R; import de.blinkt.openvpn.core.NativeUtils; import de.blinkt.openvpn.core.OpenVPN; import de.blinkt.openvpn.core.OpenVpnService; +import de.blinkt.openvpn.core.X509Utils; public class VpnProfile implements Serializable{ // Note that this class cannot be moved to core where it belongs since @@ -52,7 +53,7 @@ public class VpnProfile implements Serializable{ // The Serializable documentation mentions that class name change are possible // but the how is unclear // - + private static final long serialVersionUID = 7085688938959334563L; public static final int TYPE_CERTIFICATES=0; public static final int TYPE_PKCS12=1; @@ -79,7 +80,7 @@ public class VpnProfile implements Serializable{ public transient String mTransientPW=null; public transient String mTransientPCKS12PW=null; private transient PrivateKey mPrivateKey; - + // variable named wrong and should haven beeen transient // but needs to keep wrong name to guarante loading of old // profiles @@ -590,7 +591,7 @@ public class VpnProfile implements Serializable{ if(nonNull(mCaFilename)) { try { - Certificate cacert = getCacertFromFile(); + Certificate cacert = X509Utils.getCertificateFromFile(mCaFilename); X509Certificate[] newcachain = new X509Certificate[cachain.length+1]; for(int i=0;i 0) + { + return loadObject(type); + } + } + + return null; + } + + private PemObject loadObject(String type) + throws IOException + { + String line; + String endMarker = END + type; + StringBuffer buf = new StringBuffer(); + List headers = new ArrayList(); + + while ((line = readLine()) != null) + { + if (line.indexOf(":") >= 0) + { + int index = line.indexOf(':'); + String hdr = line.substring(0, index); + String value = line.substring(index + 1).trim(); + + headers.add(new PemHeader(hdr, value)); + + continue; + } + + if (line.indexOf(endMarker) != -1) + { + break; + } + + buf.append(line.trim()); + } + + if (line == null) + { + throw new IOException(endMarker + " not found"); + } + + return new PemObject(type, headers, Base64.decode(buf.toString())); + } + +} -- cgit v1.2.3