Added proper certificate names.
This commit is contained in:
parent
287c6462ff
commit
37ac4d2801
3 changed files with 74 additions and 1 deletions
|
@ -2,6 +2,7 @@ package com.nutomic.zertman;
|
|||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Pair;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -37,8 +38,12 @@ public class CertificateAdapter extends ArrayAdapter<Certificate> implements
|
|||
}
|
||||
|
||||
final Certificate cert = getItem(position);
|
||||
// NOTE: This should be called asynchronously.
|
||||
Pair<String, String> desc = CertificateManager.getDescription(cert);
|
||||
TextView title = (TextView) convertView.findViewById(R.id.title);
|
||||
title.setText(cert.getFile().getName());
|
||||
title.setText(desc.first);
|
||||
TextView summary = (TextView) convertView.findViewById(R.id.summary);
|
||||
summary.setText(desc.second);
|
||||
Button button = (Button) convertView.findViewById(R.id.button);
|
||||
int colorRes;
|
||||
if (cert.isSystemCertificate()) {
|
||||
|
|
|
@ -1,8 +1,17 @@
|
|||
package com.nutomic.zertman;
|
||||
|
||||
import android.net.http.SslCertificate;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -111,4 +120,55 @@ public class CertificateManager {
|
|||
return result != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns strings for certificate naming, copied from AOSP 4.4.4,
|
||||
* packages/apps/Settings/src/com/android/settings/TrustedCredentialsSettings.java:310.
|
||||
*/
|
||||
public static Pair<String, String> getDescription(Certificate cert) {
|
||||
InputStream is = null;
|
||||
X509Certificate cert2;
|
||||
try {
|
||||
CertificateFactory factory = CertificateFactory.getInstance("X509");
|
||||
is = new BufferedInputStream(new FileInputStream(cert.getFile()));
|
||||
cert2 = (X509Certificate) factory.generateCertificate(is);
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
} catch (CertificateException e) {
|
||||
return null;
|
||||
} finally {
|
||||
try {
|
||||
is.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
Log.w(TAG, "Failed to close stream", e);
|
||||
}
|
||||
}
|
||||
|
||||
String primary;
|
||||
String secondary;
|
||||
|
||||
SslCertificate c2 = new SslCertificate(cert2);
|
||||
String cn = c2.getIssuedTo().getCName();
|
||||
String o = c2.getIssuedTo().getOName();
|
||||
String ou = c2.getIssuedTo().getUName();
|
||||
if (!o.isEmpty()) {
|
||||
if (!cn.isEmpty()) {
|
||||
primary = o;
|
||||
secondary = cn;
|
||||
} else {
|
||||
primary = o;
|
||||
secondary = ou;
|
||||
}
|
||||
} else {
|
||||
if (!cn.isEmpty()) {
|
||||
primary = cn;
|
||||
secondary = "";
|
||||
} else {
|
||||
primary = c2.getIssuedTo().getDName();
|
||||
secondary = "";
|
||||
}
|
||||
}
|
||||
return new Pair<String, String>(primary, secondary);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,4 +23,12 @@
|
|||
android:layout_alignParentRight="true"
|
||||
style="?android:attr/buttonStyleSmall"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/summary"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/title"
|
||||
android:layout_alignStart="@id/title"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
|
Reference in a new issue