1 /*
   2  * Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.security.ssl;
  27 
  28 import java.util.ArrayList;
  29 import java.util.List;
  30 
  31 final class ExtensionType {
  32 
  33     final int id;
  34     final String name;
  35 
  36     private ExtensionType(int id, String name) {
  37         this.id = id;
  38         this.name = name;
  39     }
  40 
  41     @Override
  42     public String toString() {
  43         return name;
  44     }
  45 
  46     static List<ExtensionType> knownExtensions =
  47             new ArrayList<ExtensionType>(13);
  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     final static ExtensionType EXT_SERVER_NAME =
  66             e(0x0000, "server_name");            // IANA registry value: 0
  67     final static ExtensionType EXT_MAX_FRAGMENT_LENGTH =
  68             e(0x0001, "max_fragment_length");    // IANA registry value: 1
  69     final static ExtensionType EXT_CLIENT_CERTIFICATE_URL =
  70             e(0x0002, "client_certificate_url"); // IANA registry value: 2
  71     final static ExtensionType EXT_TRUSTED_CA_KEYS =
  72             e(0x0003, "trusted_ca_keys");        // IANA registry value: 3
  73     final static ExtensionType EXT_TRUNCATED_HMAC =
  74             e(0x0004, "truncated_hmac");         // IANA registry value: 4
  75     final static ExtensionType EXT_STATUS_REQUEST =
  76             e(0x0005, "status_request");         // IANA registry value: 5
  77 
  78     // extensions defined in RFC 4681
  79     final static ExtensionType EXT_USER_MAPPING =
  80             e(0x0006, "user_mapping");           // IANA registry value: 6
  81 
  82     // extensions defined in RFC 5081
  83     final static ExtensionType EXT_CERT_TYPE =
  84             e(0x0009, "cert_type");              // IANA registry value: 9
  85 
  86     // extensions defined in RFC 4492 (ECC)
  87     final static ExtensionType EXT_ELLIPTIC_CURVES =
  88             e(0x000A, "elliptic_curves");        // IANA registry value: 10
  89     final static ExtensionType EXT_EC_POINT_FORMATS =
  90             e(0x000B, "ec_point_formats");       // IANA registry value: 11
  91 
  92     // extensions defined in RFC 5054
  93     final static ExtensionType EXT_SRP =
  94             e(0x000C, "srp");                    // IANA registry value: 12
  95 
  96     // extensions defined in RFC 5246
  97     final static ExtensionType EXT_SIGNATURE_ALGORITHMS =
  98             e(0x000D, "signature_algorithms");   // IANA registry value: 13
  99 
 100     // extensions defined in RFC 5746
 101     final static ExtensionType EXT_RENEGOTIATION_INFO =
 102             e(0xff01, "renegotiation_info");     // IANA registry value: 65281
 103 }