From: masensio Date: Fri, 7 Mar 2014 14:11:59 +0000 (+0100) Subject: Merge branch 'add_ssl_warning_dialog_for_devices_without_access_to_X509Certificte_in_... X-Git-Tag: oc-android-1.5.5~15^2~7 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/9cac3b60a574f2b82cb3b33b45d3a4ba9a2f4d3e?ds=inline Merge branch 'add_ssl_warning_dialog_for_devices_without_access_to_X509Certificte_in_WebView_SSL_errors' into check_server_certificates_in_SSO_webview --- 9cac3b60a574f2b82cb3b33b45d3a4ba9a2f4d3e diff --cc res/layout/ssl_untrusted_cert_layout.xml index e6817111,debb3318..ef57de63 --- a/res/layout/ssl_untrusted_cert_layout.xml +++ b/res/layout/ssl_untrusted_cert_layout.xml @@@ -24,64 -24,37 +24,68 @@@ android:orientation="vertical" > + + + + + + + + android:layout_width="match_parent" + android:layout_height="0dp" + android:layout_weight="1" + > . + * + */ + package com.owncloud.android.ui.dialog; + + import java.text.DateFormat; + import java.util.Date; + + import com.owncloud.android.R; + import com.owncloud.android.authentication.AuthenticatorActivity; + + import android.app.Activity; + import android.app.Dialog; + import android.net.http.SslCertificate; + import android.net.http.SslError; + import android.os.Bundle; + import android.view.LayoutInflater; + import android.view.View; + import android.view.View.OnClickListener; + import android.view.ViewGroup; + import android.view.Window; + import android.webkit.SslErrorHandler; + import android.webkit.WebView; + import android.widget.Button; + import android.widget.TextView; + + /** + * Dialog to show an Untrusted Certificate + * + * @author masensio + * @author David A. Velasco + */ + public class SslUntrustedCertDialogForEmptySslError extends SslUntrustedCertDialogABSTRACT { + + //private final static String TAG = SslUntrustedCertDialogForEmptySslError.class.getSimpleName(); + + private SslError mError; + private SslErrorHandler mHandler; + private View mView; + + + /** + * Factory method. + * + * @param error Error occurred; details about it will be shown in the dialog. + * @param handler Handler to indicate to the {@link WebView} where the error was found what to do next. + * @return New dialog. + */ + public static SslUntrustedCertDialogForEmptySslError newInstance(SslError error, SslErrorHandler handler) { + return new SslUntrustedCertDialogForEmptySslError(error, handler); + } + + + /** + * Empty constructor. + * + * Required by Android framework. Never used, since the state is retained; see {@link #onCreate(Bundle)} + */ + public SslUntrustedCertDialogForEmptySslError() {} + + + /** + * Private constructor. + * + * Used by the factory method {@link #newInstance(SslError, SslErrorHandler)}. + * + * @param error Error occurred; details about it will be shown in the dialog. + * @param handler Handler to indicate to the {@link WebView} where the error was found what to do next. + */ + private SslUntrustedCertDialogForEmptySslError(SslError error, SslErrorHandler handler) { + mError = error; + mHandler = handler; + } + + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + /*if (!(activity instanceof OnSslUntrustedCertListener)) { + throw new IllegalArgumentException("Trying to attach to an Activity not implementing " + OnSslUntrustedCertListener.class.getCanonicalName()); + }*/ + } + + + // TODO try to move to the parent class ? + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setRetainInstance(true); // force to keep the state of the fragment on configuration changes (such as device rotations) + setCancelable(false); + mView = null; + } + + // try to move to the parent class ? + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + // Create a view by inflating desired layout + if (mView == null) { + mView = inflater.inflate(R.layout.ssl_untrusted_cert_layout, container, false); + } else { + ((ViewGroup)mView.getParent()).removeView(mView); + } + - Button ok = (Button) mView.findViewById(R.id.untrusted_ok); ++ Button ok = (Button) mView.findViewById(R.id.ok); + ok.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + //AuthenticatorActivity act = ((AuthenticatorActivity)getSherlockActivity()); + mHandler.proceed(); + dismiss(); + } + }); + - Button cancel = (Button) mView.findViewById(R.id.untrusted_cancel); ++ Button cancel = (Button) mView.findViewById(R.id.cancel); + cancel.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + AuthenticatorActivity act = ((AuthenticatorActivity)getSherlockActivity()); + getDialog().cancel(); + mHandler.cancel(); + act.cancelWebView(); + } + }); + - Button details = (Button) mView.findViewById(R.id.untrusted_details_btn); ++ Button details = (Button) mView.findViewById(R.id.details_btn); + details.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { - View detailsScroll = mView.findViewById(R.id.untrusted_details_scroll); ++ View detailsScroll = mView.findViewById(R.id.details_scroll); + if (detailsScroll.getVisibility() == View.VISIBLE) { + detailsScroll.setVisibility(View.GONE); + ((Button) v).setText(R.string.ssl_validator_btn_details_see); + + } else { + detailsScroll.setVisibility(View.VISIBLE); + ((Button) v).setText(R.string.ssl_validator_btn_details_hide); + showCertificateData(); + } + } + }); + + return mView; + } + + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + final Dialog dialog = super.onCreateDialog(savedInstanceState); + dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); + return dialog; + } + + @Override + public void onDestroyView() { + if (getDialog() != null && getRetainInstance()) + getDialog().setDismissMessage(null); + super.onDestroyView(); + } + + private void showCertificateData() { - TextView nullCerView = (TextView) mView.findViewById(R.id.untrusted_null_cert); ++ TextView nullCerView = (TextView) mView.findViewById(R.id.null_cert); + SslCertificate cert = mError.getCertificate(); + if (cert != null) { + nullCerView.setVisibility(View.GONE); + showSubject(cert.getIssuedTo()); + showIssuer(cert.getIssuedBy()); + showValidity(cert.getValidNotBeforeDate(), cert.getValidNotAfterDate()); + hideSignature(); + + } else { + nullCerView.setVisibility(View.VISIBLE); + } + } + + 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)); ++ TextView fromView = ((TextView)mView.findViewById(R.id.value_validity_from)); ++ TextView toView = ((TextView)mView.findViewById(R.id.value_validity_to)); + DateFormat dateFormat = DateFormat.getDateInstance(); + fromView.setText(dateFormat.format(notBefore)); + toView.setText(dateFormat.format(notAfter)); + } + + + private void showSubject(SslCertificate.DName subject) { - TextView cnView = ((TextView)mView.findViewById(R.id.untrusted_value_subject_CN)); ++ TextView cnView = ((TextView)mView.findViewById(R.id.value_subject_CN)); + cnView.setText(subject.getCName()); + cnView.setVisibility(View.VISIBLE); + - TextView oView = ((TextView)mView.findViewById(R.id.untrusted_value_subject_O)); ++ TextView oView = ((TextView)mView.findViewById(R.id.value_subject_O)); + oView.setText(subject.getOName()); + oView.setVisibility(View.VISIBLE); + - TextView ouView = ((TextView)mView.findViewById(R.id.untrusted_value_subject_OU)); ++ TextView ouView = ((TextView)mView.findViewById(R.id.value_subject_OU)); + ouView.setText(subject.getUName()); + ouView.setVisibility(View.VISIBLE); + + // SslCertificates don't offer this information - ((TextView)mView.findViewById(R.id.untrusted_value_subject_C)).setVisibility(View.GONE); - ((TextView)mView.findViewById(R.id.untrusted_value_subject_ST)).setVisibility(View.GONE); - ((TextView)mView.findViewById(R.id.untrusted_value_subject_L)).setVisibility(View.GONE); - ((TextView)mView.findViewById(R.id.untrusted_label_subject_C)).setVisibility(View.GONE); - ((TextView)mView.findViewById(R.id.untrusted_label_subject_ST)).setVisibility(View.GONE); - ((TextView)mView.findViewById(R.id.untrusted_label_subject_L)).setVisibility(View.GONE); ++ ((TextView)mView.findViewById(R.id.value_subject_C)).setVisibility(View.GONE); ++ ((TextView)mView.findViewById(R.id.value_subject_ST)).setVisibility(View.GONE); ++ ((TextView)mView.findViewById(R.id.value_subject_L)).setVisibility(View.GONE); ++ ((TextView)mView.findViewById(R.id.label_subject_C)).setVisibility(View.GONE); ++ ((TextView)mView.findViewById(R.id.label_subject_ST)).setVisibility(View.GONE); ++ ((TextView)mView.findViewById(R.id.label_subject_L)).setVisibility(View.GONE); + } + + + private void showIssuer(SslCertificate.DName issuer) { - TextView cnView = ((TextView)mView.findViewById(R.id.untrusted_value_issuer_CN)); ++ TextView cnView = ((TextView)mView.findViewById(R.id.value_issuer_CN)); + cnView.setText(issuer.getCName()); + cnView.setVisibility(View.VISIBLE); + - TextView oView = ((TextView)mView.findViewById(R.id.untrusted_value_issuer_O)); ++ TextView oView = ((TextView)mView.findViewById(R.id.value_issuer_O)); + oView.setText(issuer.getOName()); + oView.setVisibility(View.VISIBLE); + - TextView ouView = ((TextView)mView.findViewById(R.id.untrusted_value_issuer_OU)); ++ TextView ouView = ((TextView)mView.findViewById(R.id.value_issuer_OU)); + ouView.setText(issuer.getUName()); + ouView.setVisibility(View.VISIBLE); + + // SslCertificates don't offer this information - ((TextView)mView.findViewById(R.id.untrusted_value_issuer_C)).setVisibility(View.GONE); - ((TextView)mView.findViewById(R.id.untrusted_value_issuer_ST)).setVisibility(View.GONE); - ((TextView)mView.findViewById(R.id.untrusted_value_issuer_L)).setVisibility(View.GONE); - ((TextView)mView.findViewById(R.id.untrusted_label_issuer_C)).setVisibility(View.GONE); - ((TextView)mView.findViewById(R.id.untrusted_label_issuer_ST)).setVisibility(View.GONE); - ((TextView)mView.findViewById(R.id.untrusted_label_issuer_L)).setVisibility(View.GONE); ++ ((TextView)mView.findViewById(R.id.value_issuer_C)).setVisibility(View.GONE); ++ ((TextView)mView.findViewById(R.id.value_issuer_ST)).setVisibility(View.GONE); ++ ((TextView)mView.findViewById(R.id.value_issuer_L)).setVisibility(View.GONE); ++ ((TextView)mView.findViewById(R.id.label_issuer_C)).setVisibility(View.GONE); ++ ((TextView)mView.findViewById(R.id.label_issuer_ST)).setVisibility(View.GONE); ++ ((TextView)mView.findViewById(R.id.label_issuer_L)).setVisibility(View.GONE); + } + + private void hideSignature() { - ((TextView)mView.findViewById(R.id.untrusted_label_signature)).setVisibility(View.GONE); - ((TextView)mView.findViewById(R.id.untrusted_label_signature_algorithm)).setVisibility(View.GONE); - ((TextView)mView.findViewById(R.id.untrusted_value_signature_algorithm)).setVisibility(View.GONE); - ((TextView)mView.findViewById(R.id.untrusted_value_signature)).setVisibility(View.GONE); ++ ((TextView)mView.findViewById(R.id.label_signature)).setVisibility(View.GONE); ++ ((TextView)mView.findViewById(R.id.label_signature_algorithm)).setVisibility(View.GONE); ++ ((TextView)mView.findViewById(R.id.value_signature_algorithm)).setVisibility(View.GONE); ++ ((TextView)mView.findViewById(R.id.value_signature)).setVisibility(View.GONE); + } + + }