导航菜单

页面标题

页面副标题

AdaModal v1.4.0 - DomainPinningPolicy.java 源代码

正在查看: AdaModal v1.4.0 应用的 DomainPinningPolicy.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.datatheorem.android.trustkit.config;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public final class DomainPinningPolicy {
    private static final URL DEFAULT_REPORTING_URL;
    private final Date expirationDate;
    private final String hostname;
    private final Set<PublicKeyPin> publicKeyPins;
    private final Set<URL> reportUris;
    private final boolean shouldEnforcePinning;
    private final boolean shouldIncludeSubdomains;

    static {
        try {
            DEFAULT_REPORTING_URL = new URL("https://overmind.datatheorem.com/trustkit/report");
        } catch (MalformedURLException unused) {
            throw new IllegalStateException("Bad DEFAULT_REPORTING_URL");
        }
    }

    DomainPinningPolicy(String str, Boolean bool, Set<String> set, Boolean bool2, Date date, Set<String> set2, Boolean bool3) throws MalformedURLException {
        if (!DomainValidator.getInstance().isValid(str)) {
            throw new ConfigurationException("Tried to pin an invalid domain: " + str);
        }
        String trim = str.trim();
        this.hostname = trim;
        set = set == null ? new HashSet<>() : set;
        if (bool2 == null) {
            this.shouldEnforcePinning = false;
        } else {
            this.shouldEnforcePinning = bool2.booleanValue();
        }
        if (bool == null) {
            this.shouldIncludeSubdomains = false;
        } else {
            this.shouldIncludeSubdomains = bool.booleanValue();
        }
        if (set.isEmpty() && this.shouldEnforcePinning) {
            throw new ConfigurationException("An empty pin-set was supplied for domain " + trim + " with the enforcePinning set to true. An empty pin-set disables pinning and can't be use with enforcePinning set to true.");
        }
        if (set.size() < 2 && this.shouldEnforcePinning) {
            throw new ConfigurationException("Less than two pins were supplied for domain " + trim + ". This might brick your App; please review the Getting Started guide in ./docs/getting-started.md");
        }
        this.publicKeyPins = new HashSet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            this.publicKeyPins.add(new PublicKeyPin(it.next()));
        }
        this.reportUris = new HashSet();
        if (set2 != null) {
            Iterator<String> it2 = set2.iterator();
            while (it2.hasNext()) {
                this.reportUris.add(new URL(it2.next()));
            }
        }
        if (bool3 == null || !bool3.booleanValue()) {
            this.reportUris.add(DEFAULT_REPORTING_URL);
        }
        this.expirationDate = date;
    }

    public String getHostname() {
        return this.hostname;
    }

    public Set<PublicKeyPin> getPublicKeyPins() {
        return this.publicKeyPins;
    }

    public boolean shouldEnforcePinning() {
        return this.shouldEnforcePinning;
    }

    public Set<URL> getReportUris() {
        return this.reportUris;
    }

    public boolean shouldIncludeSubdomains() {
        return this.shouldIncludeSubdomains;
    }

    public Date getExpirationDate() {
        return this.expirationDate;
    }

    public String toString() {
        return "DomainPinningPolicy{hostname = " + this.hostname + "\nknownPins = " + Arrays.toString(this.publicKeyPins.toArray()) + "\nshouldEnforcePinning = " + this.shouldEnforcePinning + "\nreportUris = " + this.reportUris + "\nshouldIncludeSubdomains = " + this.shouldIncludeSubdomains + "\n}";
    }

    public static final class Builder {
        private Date expirationDate;
        private String hostname;
        private Builder parentBuilder = null;
        private Set<String> publicKeyHashes;
        private Set<String> reportUris;
        private Boolean shouldDisableDefaultReportUri;
        private Boolean shouldEnforcePinning;
        private Boolean shouldIncludeSubdomains;

        public DomainPinningPolicy build() throws MalformedURLException {
            Builder builder = this.parentBuilder;
            if (builder != null) {
                if (this.shouldIncludeSubdomains == null) {
                    this.shouldIncludeSubdomains = builder.getShouldIncludeSubdomains();
                }
                if (this.publicKeyHashes == null) {
                    this.publicKeyHashes = this.parentBuilder.getPublicKeyHashes();
                }
                if (this.expirationDate == null) {
                    this.expirationDate = this.parentBuilder.getExpirationDate();
                }
                if (this.shouldEnforcePinning == null) {
                    this.shouldEnforcePinning = this.parentBuilder.getShouldEnforcePinning();
                }
                if (this.reportUris == null) {
                    this.reportUris = this.parentBuilder.getReportUris();
                }
                if (this.shouldDisableDefaultReportUri == null) {
                    this.shouldDisableDefaultReportUri = this.parentBuilder.getShouldDisableDefaultReportUri();
                }
            }
            if (this.publicKeyHashes == null) {
                return null;
            }
            return new DomainPinningPolicy(this.hostname, this.shouldIncludeSubdomains, this.publicKeyHashes, this.shouldEnforcePinning, this.expirationDate, this.reportUris, this.shouldDisableDefaultReportUri);
        }

        public Builder setParent(Builder builder) {
            for (Builder builder2 = builder; builder2 != null; builder2 = builder2.parentBuilder) {
                if (builder2 == this) {
                    throw new IllegalArgumentException("Loops are not allowed in Builder parents");
                }
            }
            this.parentBuilder = builder;
            return this;
        }

        public Builder setHostname(String str) {
            this.hostname = str;
            return this;
        }

        Boolean getShouldIncludeSubdomains() {
            return this.shouldIncludeSubdomains;
        }

        public Builder setShouldIncludeSubdomains(Boolean bool) {
            this.shouldIncludeSubdomains = bool;
            return this;
        }

        Set<String> getPublicKeyHashes() {
            return this.publicKeyHashes;
        }

        public Builder setPublicKeyHashes(Set<String> set) {
            this.publicKeyHashes = set;
            return this;
        }

        Date getExpirationDate() {
            return this.expirationDate;
        }

        public Builder setExpirationDate(Date date) {
            this.expirationDate = date;
            return this;
        }

        Boolean getShouldEnforcePinning() {
            return this.shouldEnforcePinning;
        }

        public Builder setShouldEnforcePinning(Boolean bool) {
            this.shouldEnforcePinning = bool;
            return this;
        }

        Set<String> getReportUris() {
            return this.reportUris;
        }

        public Builder setReportUris(Set<String> set) {
            this.reportUris = set;
            return this;
        }

        Boolean getShouldDisableDefaultReportUri() {
            return this.shouldDisableDefaultReportUri;
        }

        public Builder setShouldDisableDefaultReportUri(Boolean bool) {
            this.shouldDisableDefaultReportUri = bool;
            return this;
        }
    }
}