summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2013-06-06 23:38:45 +0200
committerArne Schwabe <arne@rfc2549.org>2013-06-06 23:38:45 +0200
commite3cfe6d24e7b0a05780ef8a8351d2f53df7f6f87 (patch)
tree69741e320ef20c0070d89cd30191edab0fe0cf27
parent4c01d6e43ab355c39ed4c66b54d85115bbeaaa2e (diff)
Fix printing of certificate DN Namesv0.5.37
-rw-r--r--res/layout/file_select.xml75
-rw-r--r--src/de/blinkt/openvpn/core/X509Utils.java69
2 files changed, 82 insertions, 62 deletions
diff --git a/res/layout/file_select.xml b/res/layout/file_select.xml
index 8c9e4da6..5e40b3a8 100644
--- a/res/layout/file_select.xml
+++ b/res/layout/file_select.xml
@@ -17,51 +17,50 @@
<!-- A layout to select a certificate, akin to a file selector on web pages. -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_margin="8dip"
- android:gravity="center_vertical" >
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_margin="8dip"
+ android:gravity="center_vertical" >
<Button
- android:id="@+id/file_select_button"
- style="@style/accountSetupButton"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentRight="true"
- android:text="@string/file_select" />
+ android:id="@+id/file_select_button"
+ style="@style/accountSetupButton"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentRight="true"
+ android:text="@string/file_select" />
<TextView
- android:id="@+id/file_title"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:layout_alignParentTop="true"
- android:layout_toLeftOf="@+id/file_select_button"
- android:text="@string/client_certificate_title"
- android:textStyle="bold" />
+ android:id="@+id/file_title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentLeft="true"
+ android:layout_alignParentTop="true"
+ android:layout_toLeftOf="@+id/file_select_button"
+ android:text="@string/client_certificate_title"
+ android:textStyle="bold" />
<TextView
- android:id="@+id/file_selected_item"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:layout_below="@+id/file_title"
- android:layout_marginLeft="16dip"
- android:layout_toLeftOf="@+id/file_select_button"
- android:ellipsize="end"
- android:singleLine="true"
- android:text="@string/file_nothing_selected" />
+ android:id="@+id/file_selected_item"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentLeft="true"
+ android:layout_below="@+id/file_title"
+ android:layout_marginLeft="16dip"
+ android:layout_toLeftOf="@+id/file_select_button"
+ android:ellipsize="end"
+ android:singleLine="true"
+ android:text="@string/file_nothing_selected" />
<TextView
- android:id="@+id/file_selected_description"
- android:layout_width="wrap_content"
- android:textIsSelectable="true"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:layout_below="@+id/file_selected_item"
- android:layout_marginLeft="16dip"
- android:layout_toLeftOf="@+id/file_select_button"
- android:ellipsize="end"
- android:singleLine="true" />
+ android:id="@+id/file_selected_description"
+ android:layout_width="wrap_content"
+ android:textIsSelectable="true"
+ android:layout_height="wrap_content"
+ android:layout_alignParentLeft="true"
+ android:layout_below="@+id/file_selected_item"
+ android:layout_marginLeft="16dip"
+ android:layout_toLeftOf="@+id/file_select_button"
+ android:ellipsize="end" />
</RelativeLayout> \ No newline at end of file
diff --git a/src/de/blinkt/openvpn/core/X509Utils.java b/src/de/blinkt/openvpn/core/X509Utils.java
index e50343f4..0969069f 100644
--- a/src/de/blinkt/openvpn/core/X509Utils.java
+++ b/src/de/blinkt/openvpn/core/X509Utils.java
@@ -1,31 +1,17 @@
package de.blinkt.openvpn.core;
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-import java.io.StringReader;
-import java.security.KeyFactory;
-import java.security.KeyPair;
-import java.security.Principal;
+import android.text.TextUtils;
+import de.blinkt.openvpn.VpnProfile;
+import org.spongycastle.util.io.pem.PemObject;
+import org.spongycastle.util.io.pem.PemReader;
+
+import javax.security.auth.x500.X500Principal;
+import java.io.*;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
-import javax.security.auth.x500.X500Principal;
-
-import org.spongycastle.util.io.pem.PemObject;
-import org.spongycastle.util.io.pem.PemReader;
-
-import android.text.TextUtils;
-
-import de.blinkt.openvpn.VpnProfile;
-
public class X509Utils {
public static Certificate getCertificateFromFile(String certfilename) throws FileNotFoundException, CertificateException {
CertificateFactory certFact = CertificateFactory.getInstance("X.509");
@@ -63,9 +49,21 @@ public class X509Utils {
try {
X509Certificate cert = (X509Certificate) getCertificateFromFile(filename);
- String friendly = cert.getSubjectDN().getName();
-
- return friendly;
+ X500Principal principal = (X500Principal) cert.getSubjectDN();
+
+ String friendlyname = principal.getName();
+ System.out.println(friendlyname);
+ // Really evil hack to decode email address
+
+ String[] parts = friendlyname.split(",");
+ for (int i=0;i<parts.length;i++){
+ String part = parts[i];
+ if (part.startsWith("1.2.840.113549.1.9.1=#16")) {
+ parts[i] = "email=" + ia5decode(part.replace("1.2.840.113549.1.9.1=#16", ""));
+ }
+ }
+ friendlyname = TextUtils.join(",",parts);
+ return friendlyname;
} catch (Exception e) {
OpenVPN.logError("Could not read certificate" + e.getLocalizedMessage());
@@ -74,5 +72,28 @@ public class X509Utils {
return "Could not read/parse certificate";
}
+ public static boolean isPrintableChar(char c) {
+ Character.UnicodeBlock block = Character.UnicodeBlock.of( c );
+ return (!Character.isISOControl(c)) &&
+ block != null &&
+ block != Character.UnicodeBlock.SPECIALS;
+ }
+
+ private static String ia5decode(String ia5string) {
+ String d = "";
+ for (int i=1;i<ia5string.length();i=i+2) {
+ String hexstr = ia5string.substring(i-1,i+1);
+ char c = (char) Integer.parseInt(hexstr,16);
+ if (isPrintableChar(c)) {
+ d+=c;
+ } else if (i==1 && c==0x12) {
+ ; // ignore
+ } else {
+ d += "\\x" + hexstr;
+ }
+ }
+ return d;
+ }
+
}