Implement IP Address Pinning. https://redmine.stoutner.com/issues/212
[PrivacyBrowser.git] / app / src / main / java / com / stoutner / privacybrowser / dialogs / PinnedMismatchDialog.java
1 /*
2  * Copyright © 2017-2019 Soren Stoutner <soren@stoutner.com>.
3  *
4  * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
5  *
6  * Privacy Browser is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Privacy Browser is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Privacy Browser.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 package com.stoutner.privacybrowser.dialogs;
21
22 import android.annotation.SuppressLint;
23 import android.app.AlertDialog;
24 import android.app.Dialog;
25 import android.content.Context;
26 import android.content.DialogInterface;
27 import android.graphics.drawable.BitmapDrawable;
28 import android.graphics.drawable.Drawable;
29 import android.net.Uri;
30 import android.net.http.SslCertificate;
31 import android.os.Bundle;
32 import android.support.annotation.NonNull;
33 import android.support.design.widget.TabLayout;
34 import android.support.v4.view.PagerAdapter;
35 // `AppCompatDialogFragment` is used instead of `DialogFragment` to avoid an error on API <=22.
36 import android.support.v7.app.AppCompatDialogFragment;
37 import android.text.SpannableStringBuilder;
38 import android.text.Spanned;
39 import android.text.style.ForegroundColorSpan;
40 import android.view.LayoutInflater;
41 import android.view.View;
42 import android.view.ViewGroup;
43 import android.view.WindowManager;
44 import android.widget.TextView;
45
46 import com.stoutner.privacybrowser.R;
47 import com.stoutner.privacybrowser.activities.MainWebViewActivity;
48 import com.stoutner.privacybrowser.definitions.WrapVerticalContentViewPager;
49 import com.stoutner.privacybrowser.helpers.DomainsDatabaseHelper;
50
51 import java.text.DateFormat;
52 import java.util.Date;
53
54 public class PinnedMismatchDialog extends AppCompatDialogFragment {
55     // Instantiate the class variables.
56     private PinnedMismatchListener pinnedMismatchListener;
57     private LayoutInflater layoutInflater;
58     private String currentSslIssuedToCName;
59     private String currentSslIssuedToOName;
60     private String currentSslIssuedToUName;
61     private String currentSslIssuedByCName;
62     private String currentSslIssuedByOName;
63     private String currentSslIssuedByUName;
64     private Date currentSslStartDate;
65     private Date currentSslEndDate;
66     private boolean pinnedSslCertificate;
67     private boolean pinnedIpAddresses;
68
69     // The public interface is used to send information back to the parent activity.
70     public interface PinnedMismatchListener {
71         void onPinnedMismatchBack();
72
73         void onPinnedMismatchProceed();
74     }
75
76     // Check to make sure that the parent activity implements the listener.
77     public void onAttach(Context context) {
78         // Run the default commands.
79         super.onAttach(context);
80
81         // Get a handle for `PinnedSslCertificateMismatchListener` from the launching context.
82         pinnedMismatchListener = (PinnedMismatchListener) context;
83     }
84
85     public static PinnedMismatchDialog displayDialog(boolean pinnedSslCertificate, boolean pinnedIpAddresses) {
86         // Create an arguments bundle.
87         Bundle argumentsBundle = new Bundle();
88
89         // Store the variables in the bundle.
90         argumentsBundle.putBoolean("Pinned_SSL_Certificate", pinnedSslCertificate);
91         argumentsBundle.putBoolean("Pinned_IP_Addresses", pinnedIpAddresses);
92
93         // Add the arguments bundle to this instance of `PinnedMismatchDialog`.
94         PinnedMismatchDialog thisPinnedMismatchDialog = new PinnedMismatchDialog();
95         thisPinnedMismatchDialog.setArguments(argumentsBundle);
96         return thisPinnedMismatchDialog;
97     }
98
99     // `@SuppressLing("InflateParams")` removes the warning about using `null` as the parent view group when inflating the `AlertDialog`.
100     @SuppressLint("InflateParams")
101     @Override
102     @NonNull
103     public Dialog onCreateDialog(Bundle savedInstanceState) {
104         // Remove the incorrect lint warning that `getActivity()` might be null.
105         assert getActivity() != null;
106
107         // Get the activity's layout inflater.
108         layoutInflater = getActivity().getLayoutInflater();
109
110         // Use an alert dialog builder to create the alert dialog.
111         AlertDialog.Builder dialogBuilder;
112
113         // Set the style according to the theme.
114         if (MainWebViewActivity.darkTheme) {
115             // Set the dialog theme.
116             dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogDark);
117         } else {
118             // Set the dialog theme.
119             dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogLight);
120         }
121
122         // Remove the incorrect lint warning below that `.getArguments.getBoolean()` might be null.
123         assert getArguments() != null;
124
125         // Get the variables from the bundle.
126         pinnedSslCertificate = getArguments().getBoolean("Pinned_SSL_Certificate");
127         pinnedIpAddresses = getArguments().getBoolean("Pinned_IP_Addresses");
128
129         if (MainWebViewActivity.favoriteIconBitmap.equals(MainWebViewActivity.favoriteIconDefaultBitmap)) {
130             // Set the icon according to the theme.
131             if (MainWebViewActivity.darkTheme) {
132                 dialogBuilder.setIcon(R.drawable.ssl_certificate_enabled_dark);
133             } else {
134                 dialogBuilder.setIcon(R.drawable.ssl_certificate_enabled_light);
135             }
136         } else {
137             // Create a drawable version of the favorite icon.
138             Drawable favoriteIconDrawable = new BitmapDrawable(getResources(), MainWebViewActivity.favoriteIconBitmap);
139
140             // Set the icon.
141             dialogBuilder.setIcon(favoriteIconDrawable);
142         }
143
144         // Setup the neutral button.
145         dialogBuilder.setNeutralButton(R.string.update, (DialogInterface dialog, int which) -> {
146             // Initialize the long date variables.  If the date is null, a long value of `0` will be stored in the Domains database entry.
147             long currentSslStartDateLong = 0;
148             long currentSslEndDateLong = 0;
149
150             // Convert the `Dates` into `longs`.
151             if (currentSslStartDate != null) {
152                 currentSslStartDateLong = currentSslStartDate.getTime();
153             }
154
155             if (currentSslEndDate != null) {
156                 currentSslEndDateLong = currentSslEndDate.getTime();
157             }
158
159             // Initialize the database handler.  The `0` specifies the database version, but that is ignored and set instead using a constant in `DomainsDatabaseHelper`.
160             DomainsDatabaseHelper domainsDatabaseHelper = new DomainsDatabaseHelper(getContext(), null, null, 0);
161
162             // Update the SSL certificate if it is pinned.
163             if (pinnedSslCertificate) {
164                 // Update the pinned SSL certificate in the domain database.
165                 domainsDatabaseHelper.updatePinnedSslCertificate(MainWebViewActivity.domainSettingsDatabaseId, currentSslIssuedToCName, currentSslIssuedToOName, currentSslIssuedToUName,
166                         currentSslIssuedByCName, currentSslIssuedByOName, currentSslIssuedByUName, currentSslStartDateLong, currentSslEndDateLong);
167
168                 // Update the pinned SSL certificate class variables to match the information that is now in the database.
169                 MainWebViewActivity.pinnedSslIssuedToCName = currentSslIssuedToCName;
170                 MainWebViewActivity.pinnedSslIssuedToOName = currentSslIssuedToOName;
171                 MainWebViewActivity.pinnedSslIssuedToUName = currentSslIssuedToUName;
172                 MainWebViewActivity.pinnedSslIssuedByCName = currentSslIssuedByCName;
173                 MainWebViewActivity.pinnedSslIssuedByOName = currentSslIssuedByOName;
174                 MainWebViewActivity.pinnedSslIssuedByUName = currentSslIssuedByUName;
175                 MainWebViewActivity.pinnedSslStartDate = currentSslStartDate;
176                 MainWebViewActivity.pinnedSslEndDate = currentSslEndDate;
177             }
178
179             // Update the IP addresses if they are pinned.
180             if (pinnedIpAddresses) {
181                 // Update the pinned IP addresses in the domain database.
182                 domainsDatabaseHelper.updatePinnedIpAddresses(MainWebViewActivity.domainSettingsDatabaseId, MainWebViewActivity.currentHostIpAddresses);
183
184                 // Update the pinned IP addresses class variable to match the information that is now in the database.
185                 MainWebViewActivity.pinnedHostIpAddresses = MainWebViewActivity.currentHostIpAddresses;
186             }
187         });
188
189         // Setup the negative button.
190         dialogBuilder.setNegativeButton(R.string.back, (DialogInterface dialog, int which) -> {
191             // Call the `onSslMismatchBack` public interface to send the `WebView` back one page.
192             pinnedMismatchListener.onPinnedMismatchBack();
193         });
194
195         // Setup the positive button.
196         dialogBuilder.setPositiveButton(R.string.proceed, (DialogInterface dialog, int which) -> {
197             // Call the `onSslMismatchProceed` public interface.
198             pinnedMismatchListener.onPinnedMismatchProceed();
199         });
200
201         // Set the title.
202         dialogBuilder.setTitle(R.string.pinned_mismatch);
203
204         // Set the layout.  The parent view is `null` because it will be assigned by `AlertDialog`.
205         dialogBuilder.setView(layoutInflater.inflate(R.layout.pinned_mismatch_linearlayout, null));
206
207         // Create an alert dialog from the alert dialog builder.
208         final AlertDialog alertDialog = dialogBuilder.create();
209
210         // Disable screenshots if not allowed.
211         if (!MainWebViewActivity.allowScreenshots) {
212             // Remove the warning below that `getWindow()` might be null.
213             assert alertDialog.getWindow() != null;
214
215             // Disable screenshots.
216             alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
217         }
218
219         // Show the alert dialog so the items in the layout can be modified.
220         alertDialog.show();
221
222         //  Setup the view pager.
223         WrapVerticalContentViewPager wrapVerticalContentViewPager = alertDialog.findViewById(R.id.pinned_ssl_certificate_mismatch_viewpager);
224         wrapVerticalContentViewPager.setAdapter(new pagerAdapter());
225
226         // Setup the tab layout and connect it to the view pager.
227         TabLayout tabLayout = alertDialog.findViewById(R.id.pinned_ssl_certificate_mismatch_tablayout);
228         tabLayout.setupWithViewPager(wrapVerticalContentViewPager);
229
230         // `onCreateDialog()` requires the return of an `AlertDialog`.
231         return alertDialog;
232     }
233
234     private class pagerAdapter extends PagerAdapter {
235         @Override
236         public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
237             // Check to see if the `View` and the `Object` are the same.
238             return (view == object);
239         }
240
241         @Override
242         public int getCount() {
243             // There are two tabs.
244             return 2;
245         }
246
247         @Override
248         public CharSequence getPageTitle(int position) {
249             // Return the current tab title.
250             if (position == 0) {  // The current SSL certificate tab.
251                 return getString(R.string.current);
252             } else {  // The pinned SSL certificate tab.
253                 return getString(R.string.pinned);
254             }
255         }
256
257         @Override
258         @NonNull
259         public Object instantiateItem(@NonNull ViewGroup container, int position) {
260             // Inflate the scroll view for this tab.
261             ViewGroup tabViewGroup = (ViewGroup) layoutInflater.inflate(R.layout.pinned_mismatch_scrollview, container, false);
262
263             // Get handles for the `TextViews`.
264             TextView domainNameTextView = tabViewGroup.findViewById(R.id.domain_name);
265             TextView ipAddressesTextView = tabViewGroup.findViewById(R.id.ip_addresses);
266             TextView issuedToCNameTextView = tabViewGroup.findViewById(R.id.issued_to_cname);
267             TextView issuedToONameTextView = tabViewGroup.findViewById(R.id.issued_to_oname);
268             TextView issuedToUNameTextView = tabViewGroup.findViewById(R.id.issued_to_uname);
269             TextView issuedByCNameTextView = tabViewGroup.findViewById(R.id.issued_by_cname);
270             TextView issuedByONameTextView = tabViewGroup.findViewById(R.id.issued_by_oname);
271             TextView issuedByUNameTextView = tabViewGroup.findViewById(R.id.issued_by_uname);
272             TextView startDateTextView = tabViewGroup.findViewById(R.id.start_date);
273             TextView endDateTextView = tabViewGroup.findViewById(R.id.end_date);
274
275             // Setup the labels.
276             String domainNameLabel = getString(R.string.domain_label) + "  ";
277             String ipAddressesLabel = getString(R.string.ip_addresses) + "  ";
278             String cNameLabel = getString(R.string.common_name) + "  ";
279             String oNameLabel = getString(R.string.organization) + "  ";
280             String uNameLabel = getString(R.string.organizational_unit) + "  ";
281             String startDateLabel = getString(R.string.start_date) + "  ";
282             String endDateLabel = getString(R.string.end_date) + "  ";
283
284             // Get a URI for the URL.
285             Uri currentUri = Uri.parse(MainWebViewActivity.formattedUrlString);
286
287             // Get the current host from the URI.
288             String domainName = currentUri.getHost();
289
290             // Get the current website SSL certificate.
291             SslCertificate sslCertificate = MainWebViewActivity.sslCertificate;
292
293             // Extract the individual pieces of information from the current website SSL certificate if it is not null.
294             if (sslCertificate != null) {
295                 currentSslIssuedToCName = sslCertificate.getIssuedTo().getCName();
296                 currentSslIssuedToOName = sslCertificate.getIssuedTo().getOName();
297                 currentSslIssuedToUName = sslCertificate.getIssuedTo().getUName();
298                 currentSslIssuedByCName = sslCertificate.getIssuedBy().getCName();
299                 currentSslIssuedByOName = sslCertificate.getIssuedBy().getOName();
300                 currentSslIssuedByUName = sslCertificate.getIssuedBy().getUName();
301                 currentSslStartDate = sslCertificate.getValidNotBeforeDate();
302                 currentSslEndDate = sslCertificate.getValidNotAfterDate();
303             } else {
304                 // Initialize the current website SSL certificate variables with blank information.
305                 currentSslIssuedToCName = "";
306                 currentSslIssuedToOName = "";
307                 currentSslIssuedToUName = "";
308                 currentSslIssuedByCName = "";
309                 currentSslIssuedByOName = "";
310                 currentSslIssuedByUName = "";
311             }
312
313             // Setup the domain name spannable string builder.
314             SpannableStringBuilder domainNameStringBuilder = new SpannableStringBuilder(domainNameLabel + domainName);
315
316             // Initialize the spannable string builders.
317             SpannableStringBuilder ipAddressesStringBuilder;
318             SpannableStringBuilder issuedToCNameStringBuilder;
319             SpannableStringBuilder issuedToONameStringBuilder;
320             SpannableStringBuilder issuedToUNameStringBuilder;
321             SpannableStringBuilder issuedByCNameStringBuilder;
322             SpannableStringBuilder issuedByONameStringBuilder;
323             SpannableStringBuilder issuedByUNameStringBuilder;
324             SpannableStringBuilder startDateStringBuilder;
325             SpannableStringBuilder endDateStringBuilder;
326
327             // Setup the spannable string builders for each tab.
328             if (position == 0) {  // Setup the current settings tab.
329                 // Create the string builders.
330                 ipAddressesStringBuilder = new SpannableStringBuilder(ipAddressesLabel + MainWebViewActivity.currentHostIpAddresses);
331                 issuedToCNameStringBuilder = new SpannableStringBuilder(cNameLabel + currentSslIssuedToCName);
332                 issuedToONameStringBuilder = new SpannableStringBuilder(oNameLabel + currentSslIssuedToOName);
333                 issuedToUNameStringBuilder = new SpannableStringBuilder(uNameLabel + currentSslIssuedToUName);
334                 issuedByCNameStringBuilder = new SpannableStringBuilder(cNameLabel + currentSslIssuedByCName);
335                 issuedByONameStringBuilder = new SpannableStringBuilder(oNameLabel + currentSslIssuedByOName);
336                 issuedByUNameStringBuilder = new SpannableStringBuilder(uNameLabel + currentSslIssuedByUName);
337
338                 // Set the dates if they aren't `null`.
339                 if (currentSslStartDate == null) {
340                     startDateStringBuilder = new SpannableStringBuilder(startDateLabel);
341                 } else {
342                     startDateStringBuilder = new SpannableStringBuilder(startDateLabel + DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG).format(currentSslStartDate));
343                 }
344
345                 if (currentSslEndDate == null) {
346                     endDateStringBuilder = new SpannableStringBuilder(endDateLabel);
347                 } else {
348                     endDateStringBuilder = new SpannableStringBuilder(endDateLabel + DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG).format(currentSslEndDate));
349                 }
350             } else {  // Setup the pinned settings tab.
351                 // Create the string builders.
352                 ipAddressesStringBuilder = new SpannableStringBuilder(ipAddressesLabel + MainWebViewActivity.pinnedHostIpAddresses);
353                 issuedToCNameStringBuilder = new SpannableStringBuilder(cNameLabel + MainWebViewActivity.pinnedSslIssuedToCName);
354                 issuedToONameStringBuilder = new SpannableStringBuilder(oNameLabel + MainWebViewActivity.pinnedSslIssuedToOName);
355                 issuedToUNameStringBuilder = new SpannableStringBuilder(uNameLabel + MainWebViewActivity.pinnedSslIssuedToUName);
356                 issuedByCNameStringBuilder = new SpannableStringBuilder(cNameLabel + MainWebViewActivity.pinnedSslIssuedByCName);
357                 issuedByONameStringBuilder = new SpannableStringBuilder(oNameLabel + MainWebViewActivity.pinnedSslIssuedByOName);
358                 issuedByUNameStringBuilder = new SpannableStringBuilder(uNameLabel + MainWebViewActivity.pinnedSslIssuedByUName);
359
360                 // Set the dates if they aren't `null`.
361                 if (MainWebViewActivity.pinnedSslStartDate == null) {
362                     startDateStringBuilder = new SpannableStringBuilder(startDateLabel);
363                 } else {
364                     startDateStringBuilder = new SpannableStringBuilder(startDateLabel + DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG)
365                             .format(MainWebViewActivity.pinnedSslStartDate));
366                 }
367
368                 if (MainWebViewActivity.pinnedSslEndDate == null) {
369                     endDateStringBuilder = new SpannableStringBuilder(endDateLabel);
370                 } else {
371                     endDateStringBuilder = new SpannableStringBuilder(endDateLabel + DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG).format(MainWebViewActivity.pinnedSslEndDate));
372                 }
373             }
374
375             // Create a red foreground color span.  The deprecated `getResources().getColor` must be used until the minimum API >= 23.
376             @SuppressWarnings("deprecation") ForegroundColorSpan redColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.red_a700));
377
378             // Create a blue foreground color span.
379             ForegroundColorSpan blueColorSpan;
380
381             // Set the blue color span according to the theme.  The deprecated `getResources().getColor` must be used until the minimum API >= 23.
382             if (MainWebViewActivity.darkTheme) {
383                 //noinspection deprecation
384                 blueColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.blue_400));
385             } else {
386                 //noinspection deprecation
387                 blueColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.blue_700));
388             }
389
390             // Set the domain name to be blue.
391             domainNameStringBuilder.setSpan(blueColorSpan, domainNameLabel.length(), domainNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
392
393             // Color coordinate the IP addresses if they are pinned.
394             if (pinnedIpAddresses) {
395                 if (MainWebViewActivity.currentHostIpAddresses.equals(MainWebViewActivity.pinnedHostIpAddresses)) {
396                     ipAddressesStringBuilder.setSpan(blueColorSpan, ipAddressesLabel.length(), ipAddressesStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
397                 } else {
398                     ipAddressesStringBuilder.setSpan(redColorSpan, ipAddressesLabel.length(), ipAddressesStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
399                 }
400             }
401
402             // Color coordinate the SSL certificate fields if they are pinned.
403             if (pinnedSslCertificate) {
404                 if (currentSslIssuedToCName.equals(MainWebViewActivity.pinnedSslIssuedToCName)) {
405                     issuedToCNameStringBuilder.setSpan(blueColorSpan, cNameLabel.length(), issuedToCNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
406                 } else {
407                     issuedToCNameStringBuilder.setSpan(redColorSpan, cNameLabel.length(), issuedToCNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
408                 }
409
410                 if (currentSslIssuedToOName.equals(MainWebViewActivity.pinnedSslIssuedToOName)) {
411                     issuedToONameStringBuilder.setSpan(blueColorSpan, oNameLabel.length(), issuedToONameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
412                 } else {
413                     issuedToONameStringBuilder.setSpan(redColorSpan, oNameLabel.length(), issuedToONameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
414                 }
415
416                 if (currentSslIssuedToUName.equals(MainWebViewActivity.pinnedSslIssuedToUName)) {
417                     issuedToUNameStringBuilder.setSpan(blueColorSpan, uNameLabel.length(), issuedToUNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
418                 } else {
419                     issuedToUNameStringBuilder.setSpan(redColorSpan, uNameLabel.length(), issuedToUNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
420                 }
421
422                 if (currentSslIssuedByCName.equals(MainWebViewActivity.pinnedSslIssuedByCName)) {
423                     issuedByCNameStringBuilder.setSpan(blueColorSpan, cNameLabel.length(), issuedByCNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
424                 } else {
425                     issuedByCNameStringBuilder.setSpan(redColorSpan, cNameLabel.length(), issuedByCNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
426                 }
427
428                 if (currentSslIssuedByOName.equals(MainWebViewActivity.pinnedSslIssuedByOName)) {
429                     issuedByONameStringBuilder.setSpan(blueColorSpan, oNameLabel.length(), issuedByONameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
430                 } else {
431                     issuedByONameStringBuilder.setSpan(redColorSpan, oNameLabel.length(), issuedByONameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
432                 }
433
434                 if (currentSslIssuedByUName.equals(MainWebViewActivity.pinnedSslIssuedByUName)) {
435                     issuedByUNameStringBuilder.setSpan(blueColorSpan, uNameLabel.length(), issuedByUNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
436                 } else {
437                     issuedByUNameStringBuilder.setSpan(redColorSpan, uNameLabel.length(), issuedByUNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
438                 }
439
440                 if ((currentSslStartDate != null) && currentSslStartDate.equals(MainWebViewActivity.pinnedSslStartDate)) {
441                     startDateStringBuilder.setSpan(blueColorSpan, startDateLabel.length(), startDateStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
442                 } else {
443                     startDateStringBuilder.setSpan(redColorSpan, startDateLabel.length(), startDateStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
444                 }
445
446                 if ((currentSslEndDate != null) && currentSslEndDate.equals(MainWebViewActivity.pinnedSslEndDate)) {
447                     endDateStringBuilder.setSpan(blueColorSpan, endDateLabel.length(), endDateStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
448                 } else {
449                     endDateStringBuilder.setSpan(redColorSpan, endDateLabel.length(), endDateStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
450                 }
451             }
452
453             // Display the strings.
454             domainNameTextView.setText(domainNameStringBuilder);
455             ipAddressesTextView.setText(ipAddressesStringBuilder);
456             issuedToCNameTextView.setText(issuedToCNameStringBuilder);
457             issuedToONameTextView.setText(issuedToONameStringBuilder);
458             issuedToUNameTextView.setText(issuedToUNameStringBuilder);
459             issuedByCNameTextView.setText(issuedByCNameStringBuilder);
460             issuedByONameTextView.setText(issuedByONameStringBuilder);
461             issuedByUNameTextView.setText(issuedByUNameStringBuilder);
462             startDateTextView.setText(startDateStringBuilder);
463             endDateTextView.setText(endDateStringBuilder);
464
465             // Display the tab.
466             container.addView(tabViewGroup);
467
468             // Make it so.
469             return tabViewGroup;
470         }
471     }
472 }