ExtensionType.java revision 12745:f068a4ffddd2
1178476Sjb/*
2178476Sjb * Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.
3178476Sjb * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4178476Sjb *
5178476Sjb * This code is free software; you can redistribute it and/or modify it
6178476Sjb * under the terms of the GNU General Public License version 2 only, as
7178476Sjb * published by the Free Software Foundation.  Oracle designates this
8178476Sjb * particular file as subject to the "Classpath" exception as provided
9178476Sjb * by Oracle in the LICENSE file that accompanied this code.
10178476Sjb *
11178476Sjb * This code is distributed in the hope that it will be useful, but WITHOUT
12178476Sjb * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13178476Sjb * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14178476Sjb * version 2 for more details (a copy is included in the LICENSE file that
15178476Sjb * accompanied this code).
16178476Sjb *
17178476Sjb * You should have received a copy of the GNU General Public License version
18178476Sjb * 2 along with this work; if not, write to the Free Software Foundation,
19178476Sjb * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20178476Sjb *
21178476Sjb * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22178476Sjb * or visit www.oracle.com if you need additional information or have any
23178476Sjb * questions.
24178476Sjb */
25178476Sjb
26178476Sjbpackage sun.security.ssl;
27178476Sjb
28178476Sjbimport java.util.ArrayList;
29178476Sjbimport java.util.List;
30178476Sjb
31178476Sjbfinal class ExtensionType {
32178476Sjb
33178476Sjb    final int id;
34178476Sjb    final String name;
35178476Sjb
36178476Sjb    private ExtensionType(int id, String name) {
37178476Sjb        this.id = id;
38178476Sjb        this.name = name;
39178476Sjb    }
40178476Sjb
41178476Sjb    @Override
42178476Sjb    public String toString() {
43178476Sjb        return name;
44178476Sjb    }
45
46    static List<ExtensionType> knownExtensions =
47            new ArrayList<ExtensionType>(14);
48
49    static ExtensionType get(int id) {
50        for (ExtensionType ext : knownExtensions) {
51            if (ext.id == id) {
52                return ext;
53            }
54        }
55        return new ExtensionType(id, "type_" + id);
56    }
57
58    private static ExtensionType e(int id, String name) {
59        ExtensionType ext = new ExtensionType(id, name);
60        knownExtensions.add(ext);
61        return ext;
62    }
63
64    // extensions defined in RFC 3546
65    static final ExtensionType EXT_SERVER_NAME =
66            e(0x0000, "server_name");            // IANA registry value: 0
67    static final ExtensionType EXT_MAX_FRAGMENT_LENGTH =
68            e(0x0001, "max_fragment_length");    // IANA registry value: 1
69    static final ExtensionType EXT_CLIENT_CERTIFICATE_URL =
70            e(0x0002, "client_certificate_url"); // IANA registry value: 2
71    static final ExtensionType EXT_TRUSTED_CA_KEYS =
72            e(0x0003, "trusted_ca_keys");        // IANA registry value: 3
73    static final ExtensionType EXT_TRUNCATED_HMAC =
74            e(0x0004, "truncated_hmac");         // IANA registry value: 4
75    static final ExtensionType EXT_STATUS_REQUEST =
76            e(0x0005, "status_request");         // IANA registry value: 5
77
78    // extensions defined in RFC 4681
79    static final ExtensionType EXT_USER_MAPPING =
80            e(0x0006, "user_mapping");           // IANA registry value: 6
81
82    // extensions defined in RFC 5081
83    static final ExtensionType EXT_CERT_TYPE =
84            e(0x0009, "cert_type");              // IANA registry value: 9
85
86    // extensions defined in RFC 4492 (ECC)
87    static final ExtensionType EXT_ELLIPTIC_CURVES =
88            e(0x000A, "elliptic_curves");        // IANA registry value: 10
89    static final ExtensionType EXT_EC_POINT_FORMATS =
90            e(0x000B, "ec_point_formats");       // IANA registry value: 11
91
92    // extensions defined in RFC 5054
93    static final ExtensionType EXT_SRP =
94            e(0x000C, "srp");                    // IANA registry value: 12
95
96    // extensions defined in RFC 5246
97    static final ExtensionType EXT_SIGNATURE_ALGORITHMS =
98            e(0x000D, "signature_algorithms");   // IANA registry value: 13
99
100    // extensions defined in RFC 6961
101    static final ExtensionType EXT_STATUS_REQUEST_V2 =
102            e(0x0011, "status_request_v2");      // IANA registry value: 17
103
104    // extensions defined in RFC 5746
105    static final ExtensionType EXT_RENEGOTIATION_INFO =
106            e(0xff01, "renegotiation_info");     // IANA registry value: 65281
107}
108