001/*
002 * Copyright 2016 The AppAuth for Android Authors. All Rights Reserved.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
005 * in compliance with the License. You may obtain a copy of the License at
006 *
007 * http://www.apache.org/licenses/LICENSE-2.0
008 *
009 * Unless required by applicable law or agreed to in writing, software distributed under the
010 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
011 * express or implied. See the License for the specific language governing permissions and
012 * limitations under the License.
013 */
014
015package net.openid.appauth.browser;
016
017import androidx.annotation.NonNull;
018
019import java.util.Collections;
020import java.util.Set;
021
022/**
023 * Defines the attributes of some commonly-used browsers on Android, for use in browser matchers.
024 */
025public final class Browsers {
026
027    /**
028     * Constants related to Google Chrome.
029     */
030    public static final class Chrome {
031
032        /**
033         * The package name for Chrome.
034         */
035        public static final String PACKAGE_NAME = "com.android.chrome";
036
037        /**
038         * The SHA-512 hash (Base64 url-safe encoded) of the public key for Chrome.
039         */
040        public static final String SIGNATURE =
041                "7fmduHKTdHHrlMvldlEqAIlSfii1tl35bxj1OXN5Ve8c4lU6URVu4xtSHc3BVZxS"
042                        + "6WWJnxMDhIfQN0N0K2NDJg==";
043
044        /**
045         * The set of signature hashes for Chrome.
046         */
047        public static final Set<String> SIGNATURE_SET =
048                Collections.singleton(SIGNATURE);
049
050        /**
051         * The version in which Custom Tabs were introduced in Chrome.
052         */
053        public static final DelimitedVersion MINIMUM_VERSION_FOR_CUSTOM_TAB =
054                DelimitedVersion.parse("45");
055
056        /**
057         * Creates a browser descriptor for the specified version of Chrome, when used as a
058         * standalone browser.
059         */
060        public static BrowserDescriptor standaloneBrowser(@NonNull String version) {
061            return new BrowserDescriptor(PACKAGE_NAME, SIGNATURE_SET, version, false);
062        }
063
064        /**
065         * Creates a browser descriptor for the specified version of Chrome, when used as
066         * a custom tab.
067         */
068        public static BrowserDescriptor customTab(@NonNull String version) {
069            return new BrowserDescriptor(PACKAGE_NAME, SIGNATURE_SET, version, true);
070        }
071
072        private Chrome() {
073            // no need to construct this class
074        }
075    }
076
077    /**
078     * Constants related to Mozilla Firefox.
079     */
080    public static final class Firefox {
081
082        /**
083         * The package name for Firefox.
084         */
085        public static final String PACKAGE_NAME = "org.mozilla.firefox";
086
087        /**
088         * The SHA-512 hash (Base64 url-safe encoded) of the public key for Firefox.
089         */
090        public static final String SIGNATURE_HASH =
091                "2gCe6pR_AO_Q2Vu8Iep-4AsiKNnUHQxu0FaDHO_qa178GByKybdT_BuE8_dYk99G"
092                        + "5Uvx_gdONXAOO2EaXidpVQ==";
093
094        /**
095         * The set of signature hashes for Firefox.
096         */
097        public static final Set<String> SIGNATURE_SET =
098                Collections.singleton(SIGNATURE_HASH);
099
100        /**
101         * The version in which Custom Tabs were introduced in Firefox.
102         */
103        public static final DelimitedVersion MINIMUM_VERSION_FOR_CUSTOM_TAB =
104                DelimitedVersion.parse("57");
105
106        /**
107         * Creates a browser descriptor for the specified version of Firefox, when used
108         * as a standalone browser.
109         */
110        public static BrowserDescriptor standaloneBrowser(@NonNull String version) {
111            return new BrowserDescriptor(PACKAGE_NAME, SIGNATURE_SET, version, false);
112        }
113
114        /**
115         * Creates a browser descriptor for the specified version of Firefox, when used as
116         * a custom tab.
117         */
118        public static BrowserDescriptor customTab(@NonNull String version) {
119            return new BrowserDescriptor(PACKAGE_NAME, SIGNATURE_SET, version, true);
120        }
121
122        private Firefox() {
123            // no need to construct this class
124        }
125    }
126
127    /**
128     * Constants related to
129     * [SBrowser](https://play.google.com/store/apps/details?id=com.sec.android.app.sbrowser),
130     * the default browser on Samsung devices.
131     */
132    public static final class SBrowser {
133
134        /**
135         * The package name for SBrowser.
136         */
137        public static final String PACKAGE_NAME = "com.sec.android.app.sbrowser";
138
139        /**
140         * The SHA-512 hash (Base64 url-safe encoded) of the public key for SBrowser.
141         */
142        public static final String SIGNATURE_HASH =
143                "ABi2fbt8vkzj7SJ8aD5jc4xJFTDFntdkMrYXL3itsvqY1QIw-dZozdop5rgKNxjb"
144                        + "rQAd5nntAGpgh9w84O1Xgg==";
145
146        /**
147         * The set of signature hashes for SBrowser.
148         */
149        public static final Set<String> SIGNATURE_SET =
150                Collections.singleton(SIGNATURE_HASH);
151
152        /**
153         * The version in which Custom Tabs were introduced in Samsung Internet.
154         */
155        public static final DelimitedVersion MINIMUM_VERSION_FOR_CUSTOM_TAB =
156                DelimitedVersion.parse("4.0");
157
158        /**
159         * Creates a browser descriptor for the specified version of SBrowser, when
160         * used as a standalone browser.
161         */
162        public static BrowserDescriptor standaloneBrowser(@NonNull String version) {
163            return new BrowserDescriptor(PACKAGE_NAME, SIGNATURE_SET, version, false);
164        }
165
166        /**
167         * Creates a browser descriptor for the specified version of SBrowser, when
168         * used as a custom tab.
169         */
170        public static BrowserDescriptor customTab(@NonNull String version) {
171            return new BrowserDescriptor(PACKAGE_NAME, SIGNATURE_SET, version, true);
172        }
173
174        private SBrowser() {
175            // no need to construct this class
176        }
177    }
178
179    private Browsers() {
180        // no need to construct this class
181    }
182}