From e3cfe6d24e7b0a05780ef8a8351d2f53df7f6f87 Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Thu, 6 Jun 2013 23:38:45 +0200 Subject: Fix printing of certificate DN Names --- src/de/blinkt/openvpn/core/X509Utils.java | 69 ++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 24 deletions(-) (limited to 'src') 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