- if (cert != null) {
- nullCerView.setVisibility(View.GONE);
- showSubject(cert.getSubjectX500Principal());
- showIssuer(cert.getIssuerX500Principal());
- showValidity(cert.getNotBefore(), cert.getNotAfter());
- showSignature(cert);
-
- } else {
- nullCerView.setVisibility(View.VISIBLE);
- }
- }
-
- private void showSignature(X509Certificate cert) {
- TextView sigView = ((TextView)mView.findViewById(R.id.untrusted_value_signature));
- TextView algorithmView = ((TextView)mView.findViewById(R.id.untrusted_value_signature_algorithm));
- sigView.setText(getHex(cert.getSignature()));
- algorithmView.setText(cert.getSigAlgName());
- }
-
- public String getHex(final byte [] raw) {
- if (raw == null) {
- return null;
- }
- final StringBuilder hex = new StringBuilder(2 * raw.length);
- for (final byte b : raw) {
- final int hiVal = (b & 0xF0) >> 4;
- final int loVal = b & 0x0F;
- hex.append((char) ('0' + (hiVal + (hiVal / 10 * 7))));
- hex.append((char) ('0' + (loVal + (loVal / 10 * 7))));
- }
- return hex.toString();
- }
-
- @SuppressWarnings("deprecation")
- private void showValidity(Date notBefore, Date notAfter) {
- TextView fromView = ((TextView)mView.findViewById(R.id.untrusted_value_validity_from));
- TextView toView = ((TextView)mView.findViewById(R.id.untrusted_value_validity_to));
- fromView.setText(notBefore.toLocaleString());
- toView.setText(notAfter.toLocaleString());
- }
-
- private void showSubject(X500Principal subject) {
- Map<String, String> s = parsePrincipal(subject);
- TextView cnView = ((TextView)mView.findViewById(R.id.untrusted_value_subject_CN));
- TextView oView = ((TextView)mView.findViewById(R.id.untrusted_value_subject_O));
- TextView ouView = ((TextView)mView.findViewById(R.id.untrusted_value_subject_OU));
- TextView cView = ((TextView)mView.findViewById(R.id.untrusted_value_subject_C));
- TextView stView = ((TextView)mView.findViewById(R.id.untrusted_value_subject_ST));
- TextView lView = ((TextView)mView.findViewById(R.id.untrusted_value_subject_L));
-
- if (s.get("CN") != null) {
- cnView.setText(s.get("CN"));
- cnView.setVisibility(View.VISIBLE);
- } else {
- cnView.setVisibility(View.GONE);
- }
- if (s.get("O") != null) {
- oView.setText(s.get("O"));
- oView.setVisibility(View.VISIBLE);
- } else {
- oView.setVisibility(View.GONE);
- }
- if (s.get("OU") != null) {
- ouView.setText(s.get("OU"));
- ouView.setVisibility(View.VISIBLE);
- } else {
- ouView.setVisibility(View.GONE);
- }
- if (s.get("C") != null) {
- cView.setText(s.get("C"));
- cView.setVisibility(View.VISIBLE);
- } else {
- cView.setVisibility(View.GONE);
- }
- if (s.get("ST") != null) {
- stView.setText(s.get("ST"));
- stView.setVisibility(View.VISIBLE);
- } else {
- stView.setVisibility(View.GONE);
- }
- if (s.get("L") != null) {
- lView.setText(s.get("L"));
- lView.setVisibility(View.VISIBLE);
- } else {
- lView.setVisibility(View.GONE);