- public static void checkPinnedMismatch(int domainSettingsDatabaseId) {
- if ((pinnedSslCertificate || pinnedIpAddresses) && !ignorePinnedDomainInformation) {
- // Initialize the current SSL certificate variables.
- String currentWebsiteIssuedToCName = "";
- String currentWebsiteIssuedToOName = "";
- String currentWebsiteIssuedToUName = "";
- String currentWebsiteIssuedByCName = "";
- String currentWebsiteIssuedByOName = "";
- String currentWebsiteIssuedByUName = "";
- Date currentWebsiteSslStartDate = null;
- Date currentWebsiteSslEndDate = null;
-
-
- // Extract the individual pieces of information from the current website SSL certificate if it is not null.
- if (sslCertificate != null) {
- currentWebsiteIssuedToCName = sslCertificate.getIssuedTo().getCName();
- currentWebsiteIssuedToOName = sslCertificate.getIssuedTo().getOName();
- currentWebsiteIssuedToUName = sslCertificate.getIssuedTo().getUName();
- currentWebsiteIssuedByCName = sslCertificate.getIssuedBy().getCName();
- currentWebsiteIssuedByOName = sslCertificate.getIssuedBy().getOName();
- currentWebsiteIssuedByUName = sslCertificate.getIssuedBy().getUName();
- currentWebsiteSslStartDate = sslCertificate.getValidNotBeforeDate();
- currentWebsiteSslEndDate = sslCertificate.getValidNotAfterDate();
- }
-
- // Initialize string variables to store the SSL certificate dates. Strings are needed to compare the values below, which doesn't work with `Dates` if they are `null`.
- String currentWebsiteSslStartDateString = "";
- String currentWebsiteSslEndDateString = "";
- String pinnedSslStartDateString = "";
- String pinnedSslEndDateString = "";
-
- // Convert the `Dates` to `Strings` if they are not `null`.
- if (currentWebsiteSslStartDate != null) {
- currentWebsiteSslStartDateString = currentWebsiteSslStartDate.toString();
- }
-
- if (currentWebsiteSslEndDate != null) {
- currentWebsiteSslEndDateString = currentWebsiteSslEndDate.toString();
- }
-
- if (pinnedSslStartDate != null) {
- pinnedSslStartDateString = pinnedSslStartDate.toString();
- }
-
- if (pinnedSslEndDate != null) {
- pinnedSslEndDateString = pinnedSslEndDate.toString();
- }
-
- // Check to see if the pinned information matches the current information.
- if ((pinnedIpAddresses && !currentHostIpAddresses.equals(pinnedHostIpAddresses)) || (pinnedSslCertificate && (!currentWebsiteIssuedToCName.equals(pinnedSslIssuedToCName) ||
- !currentWebsiteIssuedToOName.equals(pinnedSslIssuedToOName) || !currentWebsiteIssuedToUName.equals(pinnedSslIssuedToUName) ||
- !currentWebsiteIssuedByCName.equals(pinnedSslIssuedByCName) || !currentWebsiteIssuedByOName.equals(pinnedSslIssuedByOName) ||
- !currentWebsiteIssuedByUName.equals(pinnedSslIssuedByUName) || !currentWebsiteSslStartDateString.equals(pinnedSslStartDateString) ||
- !currentWebsiteSslEndDateString.equals(pinnedSslEndDateString)))) {
-
- // Get a handle for the pinned mismatch alert dialog.
- DialogFragment pinnedMismatchDialogFragment = PinnedMismatchDialog.displayDialog(domainSettingsDatabaseId, pinnedSslCertificate, pinnedIpAddresses);
-
- // Show the pinned mismatch alert dialog.
- pinnedMismatchDialogFragment.show(fragmentManager, "Pinned Mismatch");
- }
- }
- }
-
- private class WebViewPagerAdapter extends FragmentPagerAdapter {
- // The WebView fragments list contains all the WebViews.
- private LinkedList<WebViewTabFragment> webViewFragmentsList = new LinkedList<>();
-
- // Define the constructor.
- private WebViewPagerAdapter(FragmentManager fragmentManager){
- // Run the default commands.
- super(fragmentManager);
- }
-
- @Override
- public int getCount() {
- // Return the number of pages.
- return webViewFragmentsList.size();
- }
-
- @Override
- public int getItemPosition(@NonNull Object object) {
- //noinspection SuspiciousMethodCalls
- if (webViewFragmentsList.contains(object)) {
- // The tab has not been deleted.
- return POSITION_UNCHANGED;
- } else {
- // The tab has been deleted.
- return POSITION_NONE;
- }
- }
-
- @Override
- public Fragment getItem(int pageNumber) {
- // Get a WebView for a particular page. Page numbers are 0 indexed.
- return webViewFragmentsList.get(pageNumber);
- }
-
- private void addPage() {
- // Add a new page. The pages and tabs are 0 indexed, so the size of the current list equals the number of the next page.
- webViewFragmentsList.add(WebViewTabFragment.createTab(webViewFragmentsList.size()));
-
- // Update the view pager.
- notifyDataSetChanged();
- }
-
- private void deletePage(int pageNumber) {
- // Get a handle for the tab layout.
- TabLayout tabLayout = findViewById(R.id.tablayout);
-
- // TODO always move to the next tab if possible.
- // Select a tab that is not being deleted.
- if (pageNumber == 0) { // The first tab is being deleted.
- // Get a handle for the second tab. The tabs are 0 indexed.
- TabLayout.Tab secondTab = tabLayout.getTabAt(1);
-
- // Remove the incorrect lint warning below that the second tab might be null.
- assert secondTab != null;
-
- // Select the second tab.
- secondTab.select();
- } else { // The first tab is not being deleted.
- // Get a handle for the previous tab.
- TabLayout.Tab previousTab = tabLayout.getTabAt(pageNumber - 1);