diff options
author | Alexandre Oliveira <rockytvbr@gmail.com> | 2017-11-26 16:42:40 -0200 |
---|---|---|
committer | Luca Stefani <luca.stefani.ge1@gmail.com> | 2018-01-22 19:23:31 +0000 |
commit | 71ff34ea61a57a62ecc6fc5b0ef3029641710864 (patch) | |
tree | 7a5afc33bf251b8e03503a74a8a630b3c61cd92a | |
parent | a80ca961e9b25d202d3232df4de2371be73a0836 (diff) | |
download | android_packages_apps_Jelly-71ff34ea61a57a62ecc6fc5b0ef3029641710864.tar.gz android_packages_apps_Jelly-71ff34ea61a57a62ecc6fc5b0ef3029641710864.tar.bz2 android_packages_apps_Jelly-71ff34ea61a57a62ecc6fc5b0ef3029641710864.zip |
Jelly: add dialog to show SSL certificate info
* Based off the same functionality from Soren Stoutner's Privacy Browser
(https://git.stoutner.com/?p=PrivacyBrowser.git)
* Preview: https://goo.gl/DPYfUQ
Change-Id: I46d568ed794183f94f41dc5e5a4543df7917eb37
(cherry picked from commit 77b808bdcd817d6ce60374af8d1ba82f45b61f23)
6 files changed, 297 insertions, 2 deletions
diff --git a/app/src/main/java/org/lineageos/jelly/ui/KeyValueView.java b/app/src/main/java/org/lineageos/jelly/ui/KeyValueView.java new file mode 100644 index 0000000..1a86360 --- /dev/null +++ b/app/src/main/java/org/lineageos/jelly/ui/KeyValueView.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2017 The LineageOS Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.lineageos.jelly.ui; + +import android.content.Context; +import android.support.annotation.Nullable; +import android.support.annotation.StringRes; +import android.util.AttributeSet; +import android.view.View; +import android.widget.LinearLayout; +import android.widget.TextView; + +import org.lineageos.jelly.R; + +public class KeyValueView extends LinearLayout { + private TextView mKeyView; + private TextView mValueView; + + public KeyValueView(Context context) { + super(context); + init(); + } + + public KeyValueView(Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + init(); + } + + public KeyValueView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + init(); + } + + private void init() { + inflate(getContext(), R.layout.key_value_view, this); + + mKeyView = (TextView) findViewById(R.id.key); + mValueView = (TextView) findViewById(R.id.value); + } + + public void setText(@StringRes int attributeTextResId, String value) { + if (!value.isEmpty()) { + this.mKeyView.setText(attributeTextResId); + this.mValueView.setText(value); + } else { + setVisibility(View.GONE); + } + } +} diff --git a/app/src/main/java/org/lineageos/jelly/ui/UrlBarController.java b/app/src/main/java/org/lineageos/jelly/ui/UrlBarController.java index a0e0a74..6422b46 100644 --- a/app/src/main/java/org/lineageos/jelly/ui/UrlBarController.java +++ b/app/src/main/java/org/lineageos/jelly/ui/UrlBarController.java @@ -15,9 +15,21 @@ */ package org.lineageos.jelly.ui; +import android.app.AlertDialog; +import android.content.Context; +import android.net.Uri; +import android.net.http.SslCertificate; +import android.view.LayoutInflater; import android.view.View; import android.widget.EditText; import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; + +import org.lineageos.jelly.R; + +import java.text.DateFormat; +import java.util.Date; public class UrlBarController implements View.OnFocusChangeListener { private EditText mEditor; @@ -44,12 +56,13 @@ public class UrlBarController implements View.OnFocusChangeListener { updateSecureIconVisibility(); } - public void onPageLoadFinished() { + public void onPageLoadFinished(Context context, SslCertificate certificate) { mLoading = false; if (!mUrlBarHasFocus) { updateUrlBarText(); } updateSecureIconVisibility(); + updateSSLCertificateDialog(context, certificate); } public void onTitleReceived(String title) { @@ -79,4 +92,59 @@ public class UrlBarController implements View.OnFocusChangeListener { private boolean isSecure() { return mUrl != null && mUrl.startsWith("https"); } + + private void updateSSLCertificateDialog(Context context, SslCertificate certificate) { + if (certificate == null) return; + + // Show the dialog if you tap the lock icon and the cert is valid + mSecureIcon.setOnClickListener((v) -> { + View view = LayoutInflater.from(context). + inflate(R.layout.dialog_ssl_certificate_info, new LinearLayout(context)); + + // Get the text views + TextView domainView = (TextView) view.findViewById(R.id.domain); + KeyValueView issuedToCNView = (KeyValueView) view.findViewById(R.id.issued_to_cn); + KeyValueView issuedToOView = (KeyValueView) view.findViewById(R.id.issued_to_o); + KeyValueView issuedToUNView = (KeyValueView) view.findViewById(R.id.issued_to_un); + KeyValueView issuedByCNView = (KeyValueView) view.findViewById(R.id.issued_by_cn); + KeyValueView issuedByOView = (KeyValueView) view.findViewById(R.id.issued_by_o); + KeyValueView issuedByUNView = (KeyValueView) view.findViewById(R.id.issued_by_un); + KeyValueView issuedOnView = (KeyValueView) view.findViewById(R.id.issued_on); + KeyValueView expiresOnView = (KeyValueView) view.findViewById(R.id.expires_on); + + // Get the domain name + String domainString = Uri.parse(mUrl).getHost(); + + // Get the validity dates + Date startDate = certificate.getValidNotBeforeDate(); + Date endDate = certificate.getValidNotAfterDate(); + + // Update TextViews + domainView.setText(domainString); + issuedToCNView.setText(R.string.ssl_cert_dialog_common_name, + certificate.getIssuedTo().getCName()); + issuedToOView.setText(R.string.ssl_cert_dialog_organization, + certificate.getIssuedTo().getOName()); + issuedToUNView.setText(R.string.ssl_cert_dialog_organizational_unit, + certificate.getIssuedTo().getUName()); + issuedByCNView.setText(R.string.ssl_cert_dialog_common_name, + certificate.getIssuedBy().getCName()); + issuedByOView.setText(R.string.ssl_cert_dialog_organization, + certificate.getIssuedBy().getOName()); + issuedByUNView.setText(R.string.ssl_cert_dialog_organizational_unit, + certificate.getIssuedBy().getUName()); + issuedOnView.setText(R.string.ssl_cert_dialog_issued_on, + DateFormat.getDateTimeInstance().format(startDate)); + expiresOnView.setText(R.string.ssl_cert_dialog_expires_on, + DateFormat.getDateTimeInstance().format(endDate)); + + // Build and show the dialog + new AlertDialog.Builder(context) + .setTitle(R.string.ssl_cert_dialog_title) + .setView(view) + .setNegativeButton(R.string.ssl_cert_dialog_dismiss, null) + .create() + .show(); + }); + } } diff --git a/app/src/main/java/org/lineageos/jelly/webview/WebClient.java b/app/src/main/java/org/lineageos/jelly/webview/WebClient.java index b477412..74969d4 100644 --- a/app/src/main/java/org/lineageos/jelly/webview/WebClient.java +++ b/app/src/main/java/org/lineageos/jelly/webview/WebClient.java @@ -67,7 +67,7 @@ class WebClient extends WebViewClient { @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); - mUrlBarController.onPageLoadFinished(); + mUrlBarController.onPageLoadFinished(view.getContext(), view.getCertificate()); } @Override diff --git a/app/src/main/res/layout/dialog_ssl_certificate_info.xml b/app/src/main/res/layout/dialog_ssl_certificate_info.xml new file mode 100644 index 0000000..413a0c1 --- /dev/null +++ b/app/src/main/res/layout/dialog_ssl_certificate_info.xml @@ -0,0 +1,120 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (c) 2017 The LineageOS Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical" + android:paddingBottom="8dp" + android:paddingEnd="24dp" + android:paddingStart="24dp" + android:paddingTop="8dp"> + + <!-- Domain Name --> + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="8dp" + android:text="@string/ssl_cert_dialog_domain" + android:textAllCaps="true" + android:textStyle="bold" /> + + <TextView + android:id="@+id/domain" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:textColor="@color/colorAccent" /> + + <!-- Issued To --> + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="16dp" + android:text="@string/ssl_cert_dialog_issued_to" + android:textAllCaps="true" + android:textStyle="bold" /> + + <org.lineageos.jelly.ui.KeyValueView + android:id="@+id/issued_to_cn" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="5dp" /> + + <org.lineageos.jelly.ui.KeyValueView + android:id="@+id/issued_to_o" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="5dp" /> + + <org.lineageos.jelly.ui.KeyValueView + android:id="@+id/issued_to_un" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="5dp" /> + + <!-- Issued By --> + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="16dp" + android:text="@string/ssl_cert_dialog_issued_by" + android:textAllCaps="true" + android:textStyle="bold" /> + + <org.lineageos.jelly.ui.KeyValueView + android:id="@+id/issued_by_cn" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="5dp" /> + + <org.lineageos.jelly.ui.KeyValueView + android:id="@+id/issued_by_o" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="5dp" /> + + <org.lineageos.jelly.ui.KeyValueView + android:id="@+id/issued_by_un" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="5dp" /> + + <!-- Period of Validity --> + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="16dp" + android:text="@string/ssl_cert_dialog_validity" + android:textAllCaps="true" + android:textStyle="bold" /> + + <org.lineageos.jelly.ui.KeyValueView + android:id="@+id/issued_on" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="5dp" /> + + <org.lineageos.jelly.ui.KeyValueView + android:id="@+id/expires_on" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="5dp" /> + + </LinearLayout> +</ScrollView>
\ No newline at end of file diff --git a/app/src/main/res/layout/key_value_view.xml b/app/src/main/res/layout/key_value_view.xml new file mode 100644 index 0000000..6a8ba62 --- /dev/null +++ b/app/src/main/res/layout/key_value_view.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (c) 2017 The LineageOS Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> + + <TextView + android:id="@+id/key" + android:layout_width="wrap_content" + android:layout_height="wrap_content" /> + + <TextView + android:id="@+id/value" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:textColor="@color/colorAccent" /> + +</LinearLayout>
\ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 00f273f..f8b2198 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -174,4 +174,17 @@ <!-- Search in page: search hint --> <string name="search_bar_hint">Search</string> + + <!-- SSL Certificate Details dialog --> + <string name="ssl_cert_dialog_title">SSL Certificate Details</string> + <string name="ssl_cert_dialog_domain">Domain</string> + <string name="ssl_cert_dialog_issued_to">Issued to</string> + <string name="ssl_cert_dialog_issued_by">Issued by</string> + <string name="ssl_cert_dialog_validity">Validity Period</string> + <string name="ssl_cert_dialog_common_name">Common Name (CN)</string> + <string name="ssl_cert_dialog_organization">Organization (O)</string> + <string name="ssl_cert_dialog_organizational_unit">Organizational Unit (UN)</string> + <string name="ssl_cert_dialog_issued_on">Issued On</string> + <string name="ssl_cert_dialog_expires_on">Expires On</string> + <string name="ssl_cert_dialog_dismiss">Dismiss</string> </resources> |