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