2  *   ownCloud Android client application 
   5  *   @author David A. Velasco 
   6  *   Copyright (C) 2015 ownCloud Inc. 
   8  *   This program is free software: you can redistribute it and/or modify 
   9  *   it under the terms of the GNU General Public License version 2, 
  10  *   as published by the Free Software Foundation. 
  12  *   This program is distributed in the hope that it will be useful, 
  13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of 
  14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  15  *   GNU General Public License for more details. 
  17  *   You should have received a copy of the GNU General Public License 
  18  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. 
  21 package com
.owncloud
.android
.ui
.adapter
; 
  23 import java
.text
.DateFormat
; 
  24 import java
.util
.Date
; 
  26 import com
.owncloud
.android
.R
; 
  27 import com
.owncloud
.android
.ui
.dialog
.SslUntrustedCertDialog
; 
  28 import android
.net
.http
.SslCertificate
; 
  29 import android
.view
.View
; 
  30 import android
.widget
.TextView
; 
  35 public class SslCertificateViewAdapter 
implements SslUntrustedCertDialog
.CertificateViewAdapter 
{ 
  37     //private final static String TAG = SslCertificateViewAdapter.class.getSimpleName(); 
  39     private SslCertificate mCertificate
; 
  47     public SslCertificateViewAdapter(SslCertificate certificate
) { 
  48         mCertificate 
= certificate
; 
  52     public void updateCertificateView(View dialogView
) { 
  53         TextView nullCerView 
= (TextView
) dialogView
.findViewById(R
.id
.null_cert
); 
  54         if (mCertificate 
!= null
) { 
  55             nullCerView
.setVisibility(View
.GONE
); 
  56             showSubject(mCertificate
.getIssuedTo(), dialogView
); 
  57             showIssuer(mCertificate
.getIssuedBy(), dialogView
); 
  58             showValidity(mCertificate
.getValidNotBeforeDate(), mCertificate
.getValidNotAfterDate(), dialogView
); 
  59             hideSignature(dialogView
); 
  62             nullCerView
.setVisibility(View
.VISIBLE
); 
  66     private void showValidity(Date notBefore
, Date notAfter
, View dialogView
) { 
  67         TextView fromView 
= ((TextView
)dialogView
.findViewById(R
.id
.value_validity_from
)); 
  68         TextView toView 
= ((TextView
)dialogView
.findViewById(R
.id
.value_validity_to
)); 
  69         DateFormat dateFormat 
= DateFormat
.getDateInstance(); 
  70         fromView
.setText(dateFormat
.format(notBefore
)); 
  71         toView
.setText(dateFormat
.format(notAfter
)); 
  75     private void showSubject(SslCertificate
.DName subject
, View dialogView
) { 
  76         TextView cnView 
= ((TextView
)dialogView
.findViewById(R
.id
.value_subject_CN
)); 
  77         cnView
.setText(subject
.getCName()); 
  78         cnView
.setVisibility(View
.VISIBLE
); 
  80         TextView oView 
= ((TextView
)dialogView
.findViewById(R
.id
.value_subject_O
)); 
  81         oView
.setText(subject
.getOName()); 
  82         oView
.setVisibility(View
.VISIBLE
); 
  84         TextView ouView 
= ((TextView
)dialogView
.findViewById(R
.id
.value_subject_OU
)); 
  85         ouView
.setText(subject
.getUName()); 
  86         ouView
.setVisibility(View
.VISIBLE
); 
  88         // SslCertificates don't offer this information 
  89         ((TextView
)dialogView
.findViewById(R
.id
.value_subject_C
)).setVisibility(View
.GONE
); 
  90         ((TextView
)dialogView
.findViewById(R
.id
.value_subject_ST
)).setVisibility(View
.GONE
); 
  91         ((TextView
)dialogView
.findViewById(R
.id
.value_subject_L
)).setVisibility(View
.GONE
); 
  92         ((TextView
)dialogView
.findViewById(R
.id
.label_subject_C
)).setVisibility(View
.GONE
); 
  93         ((TextView
)dialogView
.findViewById(R
.id
.label_subject_ST
)).setVisibility(View
.GONE
); 
  94         ((TextView
)dialogView
.findViewById(R
.id
.label_subject_L
)).setVisibility(View
.GONE
); 
  98     private void showIssuer(SslCertificate
.DName issuer
, View dialogView
) { 
  99         TextView cnView 
= ((TextView
)dialogView
.findViewById(R
.id
.value_issuer_CN
)); 
 100         cnView
.setText(issuer
.getCName()); 
 101         cnView
.setVisibility(View
.VISIBLE
); 
 103         TextView oView 
= ((TextView
)dialogView
.findViewById(R
.id
.value_issuer_O
)); 
 104         oView
.setText(issuer
.getOName()); 
 105         oView
.setVisibility(View
.VISIBLE
); 
 107         TextView ouView 
= ((TextView
)dialogView
.findViewById(R
.id
.value_issuer_OU
)); 
 108         ouView
.setText(issuer
.getUName()); 
 109         ouView
.setVisibility(View
.VISIBLE
); 
 111         // SslCertificates don't offer this information 
 112         ((TextView
)dialogView
.findViewById(R
.id
.value_issuer_C
)).setVisibility(View
.GONE
); 
 113         ((TextView
)dialogView
.findViewById(R
.id
.value_issuer_ST
)).setVisibility(View
.GONE
); 
 114         ((TextView
)dialogView
.findViewById(R
.id
.value_issuer_L
)).setVisibility(View
.GONE
); 
 115         ((TextView
)dialogView
.findViewById(R
.id
.label_issuer_C
)).setVisibility(View
.GONE
); 
 116         ((TextView
)dialogView
.findViewById(R
.id
.label_issuer_ST
)).setVisibility(View
.GONE
); 
 117         ((TextView
)dialogView
.findViewById(R
.id
.label_issuer_L
)).setVisibility(View
.GONE
); 
 120     private void hideSignature(View dialogView
) { 
 121         ((TextView
)dialogView
.findViewById(R
.id
.label_signature
)).setVisibility(View
.GONE
); 
 122         ((TextView
)dialogView
.findViewById(R
.id
.label_signature_algorithm
)).setVisibility(View
.GONE
); 
 123         ((TextView
)dialogView
.findViewById(R
.id
.value_signature_algorithm
)).setVisibility(View
.GONE
); 
 124         ((TextView
)dialogView
.findViewById(R
.id
.value_signature
)).setVisibility(View
.GONE
);