src/java.base/share/classes/sun/security/util/RegisteredDomain.java
author weijun
Tue, 26 Jun 2018 18:55:48 +0800
changeset 50788 6274aee1f692
parent 47216 71c04702a3d5
permissions -rw-r--r--
8201815: Use Mozilla Public Suffix List Reviewed-by: michaelm, erikj, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44760
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
     1
/*
50788
6274aee1f692 8201815: Use Mozilla Public Suffix List
weijun
parents: 47216
diff changeset
     2
 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
44760
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
     4
 *
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    10
 *
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    15
 * accompanied this code).
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    16
 *
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    20
 *
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    23
 * questions.
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    24
 */
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    25
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    26
package sun.security.util;
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    27
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    28
import java.util.Optional;
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    29
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    30
/**
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    31
 * A domain that is registered under a "public suffix". The public suffix is
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    32
 * a top-level domain under which names can be registered. For example,
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    33
 * "com" and "co.uk" are public suffixes, and "example.com" and "example.co.uk"
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    34
 * are registered domains.
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    35
 * <p>
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    36
 * The primary purpose of this class is to determine if domains are safe to
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    37
 * use in various use-cases.
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    38
 */
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    39
public interface RegisteredDomain {
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    40
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    41
    public enum Type {
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    42
        /**
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    43
         * An ICANN registered domain.
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    44
         */
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    45
        ICANN,
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    46
        /**
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    47
         * A private registered domain.
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    48
         */
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    49
        PRIVATE
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    50
    }
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    51
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    52
    /**
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    53
     * Returns the name of the registered domain.
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    54
     *
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    55
     * @return the name of the registered domain
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    56
     */
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    57
    String name();
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    58
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    59
    /**
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    60
     * Returns the type of the registered domain.
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    61
     *
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    62
     * @return the type of the registered domain
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    63
     */
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    64
    Type type();
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    65
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    66
    /**
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    67
     * Returns the public suffix of the registered domain.
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    68
     *
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    69
     * @return the public suffix of the registered domain
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    70
     */
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    71
    String publicSuffix();
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    72
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    73
    /**
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    74
     * Returns an {@code Optional<RegisteredDomain>} representing the
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    75
     * registered part of the specified domain.
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    76
     *
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    77
     * @param domain the domain name
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    78
     * @return an {@code Optional<RegisteredDomain>}; the {@code Optional} is
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    79
     *    empty if the domain is unknown or not registerable
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    80
     * @throws NullPointerException if domain is null
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    81
     */
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    82
    public static Optional<RegisteredDomain> from(String domain) {
50788
6274aee1f692 8201815: Use Mozilla Public Suffix List
weijun
parents: 47216
diff changeset
    83
        return Optional.ofNullable(DomainName.registeredDomain(domain));
44760
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    84
    }
61b03b960583 8038893: Recertify certificate matching
mullan
parents:
diff changeset
    85
}