0N/A/*
2362N/A * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.security.x509;
0N/A
0N/Aimport java.util.*;
0N/Aimport java.io.IOException;
0N/A
0N/Aimport java.security.cert.CertificateException;
0N/Aimport java.security.cert.CertificateParsingException;
0N/A
0N/Aimport sun.security.util.*;
0N/A
0N/A/**
0N/A * This class defines the mapping from OID & name to classes and vice
0N/A * versa. Used by CertificateExtensions & PKCS10 to get the java
0N/A * classes associated with a particular OID/name.
0N/A *
0N/A * @author Amit Kapoor
0N/A * @author Hemma Prafullchandra
0N/A * @author Andreas Sterbenz
0N/A *
0N/A */
0N/Apublic class OIDMap {
0N/A
0N/A private OIDMap() {
0N/A // empty
0N/A }
0N/A
0N/A // "user-friendly" names
0N/A private static final String ROOT = X509CertImpl.NAME + "." +
0N/A X509CertInfo.NAME + "." +
0N/A X509CertInfo.EXTENSIONS;
0N/A private static final String AUTH_KEY_IDENTIFIER = ROOT + "." +
0N/A AuthorityKeyIdentifierExtension.NAME;
0N/A private static final String SUB_KEY_IDENTIFIER = ROOT + "." +
0N/A SubjectKeyIdentifierExtension.NAME;
0N/A private static final String KEY_USAGE = ROOT + "." +
0N/A KeyUsageExtension.NAME;
0N/A private static final String PRIVATE_KEY_USAGE = ROOT + "." +
0N/A PrivateKeyUsageExtension.NAME;
0N/A private static final String POLICY_MAPPINGS = ROOT + "." +
0N/A PolicyMappingsExtension.NAME;
0N/A private static final String SUB_ALT_NAME = ROOT + "." +
0N/A SubjectAlternativeNameExtension.NAME;
0N/A private static final String ISSUER_ALT_NAME = ROOT + "." +
0N/A IssuerAlternativeNameExtension.NAME;
0N/A private static final String BASIC_CONSTRAINTS = ROOT + "." +
0N/A BasicConstraintsExtension.NAME;
0N/A private static final String NAME_CONSTRAINTS = ROOT + "." +
0N/A NameConstraintsExtension.NAME;
0N/A private static final String POLICY_CONSTRAINTS = ROOT + "." +
0N/A PolicyConstraintsExtension.NAME;
0N/A private static final String CRL_NUMBER = ROOT + "." +
0N/A CRLNumberExtension.NAME;
0N/A private static final String CRL_REASON = ROOT + "." +
0N/A CRLReasonCodeExtension.NAME;
0N/A private static final String NETSCAPE_CERT = ROOT + "." +
0N/A NetscapeCertTypeExtension.NAME;
0N/A private static final String CERT_POLICIES = ROOT + "." +
0N/A CertificatePoliciesExtension.NAME;
0N/A private static final String EXT_KEY_USAGE = ROOT + "." +
0N/A ExtendedKeyUsageExtension.NAME;
0N/A private static final String INHIBIT_ANY_POLICY = ROOT + "." +
0N/A InhibitAnyPolicyExtension.NAME;
0N/A private static final String CRL_DIST_POINTS = ROOT + "." +
0N/A CRLDistributionPointsExtension.NAME;
0N/A
0N/A private static final String CERT_ISSUER = ROOT + "." +
0N/A CertificateIssuerExtension.NAME;
903N/A private static final String SUBJECT_INFO_ACCESS = ROOT + "." +
903N/A SubjectInfoAccessExtension.NAME;
0N/A private static final String AUTH_INFO_ACCESS = ROOT + "." +
0N/A AuthorityInfoAccessExtension.NAME;
0N/A private static final String ISSUING_DIST_POINT = ROOT + "." +
0N/A IssuingDistributionPointExtension.NAME;
0N/A private static final String DELTA_CRL_INDICATOR = ROOT + "." +
0N/A DeltaCRLIndicatorExtension.NAME;
0N/A private static final String FRESHEST_CRL = ROOT + "." +
0N/A FreshestCRLExtension.NAME;
951N/A private static final String OCSPNOCHECK = ROOT + "." +
951N/A OCSPNoCheckExtension.NAME;
0N/A
0N/A private static final int NetscapeCertType_data[] =
0N/A { 2, 16, 840, 1, 113730, 1, 1 };
0N/A
0N/A /** Map ObjectIdentifier(oid) -> OIDInfo(info) */
0N/A private final static Map<ObjectIdentifier,OIDInfo> oidMap;
0N/A
0N/A /** Map String(friendly name) -> OIDInfo(info) */
0N/A private final static Map<String,OIDInfo> nameMap;
0N/A
0N/A static {
0N/A oidMap = new HashMap<ObjectIdentifier,OIDInfo>();
0N/A nameMap = new HashMap<String,OIDInfo>();
0N/A addInternal(SUB_KEY_IDENTIFIER, PKIXExtensions.SubjectKey_Id,
0N/A "sun.security.x509.SubjectKeyIdentifierExtension");
0N/A addInternal(KEY_USAGE, PKIXExtensions.KeyUsage_Id,
0N/A "sun.security.x509.KeyUsageExtension");
0N/A addInternal(PRIVATE_KEY_USAGE, PKIXExtensions.PrivateKeyUsage_Id,
0N/A "sun.security.x509.PrivateKeyUsageExtension");
0N/A addInternal(SUB_ALT_NAME, PKIXExtensions.SubjectAlternativeName_Id,
0N/A "sun.security.x509.SubjectAlternativeNameExtension");
0N/A addInternal(ISSUER_ALT_NAME, PKIXExtensions.IssuerAlternativeName_Id,
0N/A "sun.security.x509.IssuerAlternativeNameExtension");
0N/A addInternal(BASIC_CONSTRAINTS, PKIXExtensions.BasicConstraints_Id,
0N/A "sun.security.x509.BasicConstraintsExtension");
0N/A addInternal(CRL_NUMBER, PKIXExtensions.CRLNumber_Id,
0N/A "sun.security.x509.CRLNumberExtension");
0N/A addInternal(CRL_REASON, PKIXExtensions.ReasonCode_Id,
0N/A "sun.security.x509.CRLReasonCodeExtension");
0N/A addInternal(NAME_CONSTRAINTS, PKIXExtensions.NameConstraints_Id,
0N/A "sun.security.x509.NameConstraintsExtension");
0N/A addInternal(POLICY_MAPPINGS, PKIXExtensions.PolicyMappings_Id,
0N/A "sun.security.x509.PolicyMappingsExtension");
0N/A addInternal(AUTH_KEY_IDENTIFIER, PKIXExtensions.AuthorityKey_Id,
0N/A "sun.security.x509.AuthorityKeyIdentifierExtension");
0N/A addInternal(POLICY_CONSTRAINTS, PKIXExtensions.PolicyConstraints_Id,
0N/A "sun.security.x509.PolicyConstraintsExtension");
0N/A addInternal(NETSCAPE_CERT, ObjectIdentifier.newInternal
0N/A (new int[] {2,16,840,1,113730,1,1}),
0N/A "sun.security.x509.NetscapeCertTypeExtension");
0N/A addInternal(CERT_POLICIES, PKIXExtensions.CertificatePolicies_Id,
0N/A "sun.security.x509.CertificatePoliciesExtension");
0N/A addInternal(EXT_KEY_USAGE, PKIXExtensions.ExtendedKeyUsage_Id,
0N/A "sun.security.x509.ExtendedKeyUsageExtension");
0N/A addInternal(INHIBIT_ANY_POLICY, PKIXExtensions.InhibitAnyPolicy_Id,
0N/A "sun.security.x509.InhibitAnyPolicyExtension");
0N/A addInternal(CRL_DIST_POINTS, PKIXExtensions.CRLDistributionPoints_Id,
0N/A "sun.security.x509.CRLDistributionPointsExtension");
0N/A addInternal(CERT_ISSUER, PKIXExtensions.CertificateIssuer_Id,
0N/A "sun.security.x509.CertificateIssuerExtension");
903N/A addInternal(SUBJECT_INFO_ACCESS, PKIXExtensions.SubjectInfoAccess_Id,
903N/A "sun.security.x509.SubjectInfoAccessExtension");
0N/A addInternal(AUTH_INFO_ACCESS, PKIXExtensions.AuthInfoAccess_Id,
0N/A "sun.security.x509.AuthorityInfoAccessExtension");
0N/A addInternal(ISSUING_DIST_POINT,
0N/A PKIXExtensions.IssuingDistributionPoint_Id,
0N/A "sun.security.x509.IssuingDistributionPointExtension");
0N/A addInternal(DELTA_CRL_INDICATOR, PKIXExtensions.DeltaCRLIndicator_Id,
0N/A "sun.security.x509.DeltaCRLIndicatorExtension");
0N/A addInternal(FRESHEST_CRL, PKIXExtensions.FreshestCRL_Id,
0N/A "sun.security.x509.FreshestCRLExtension");
951N/A addInternal(OCSPNOCHECK, PKIXExtensions.OCSPNoCheck_Id,
951N/A "sun.security.x509.OCSPNoCheckExtension");
0N/A }
0N/A
0N/A /**
0N/A * Add attributes to the table. For internal use in the static
0N/A * initializer.
0N/A */
0N/A private static void addInternal(String name, ObjectIdentifier oid,
0N/A String className) {
0N/A OIDInfo info = new OIDInfo(name, oid, className);
0N/A oidMap.put(oid, info);
0N/A nameMap.put(name, info);
0N/A }
0N/A
0N/A /**
0N/A * Inner class encapsulating the mapping info and Class loading.
0N/A */
0N/A private static class OIDInfo {
0N/A
0N/A final ObjectIdentifier oid;
0N/A final String name;
0N/A final String className;
0N/A private volatile Class clazz;
0N/A
0N/A OIDInfo(String name, ObjectIdentifier oid, String className) {
0N/A this.name = name;
0N/A this.oid = oid;
0N/A this.className = className;
0N/A }
0N/A
0N/A OIDInfo(String name, ObjectIdentifier oid, Class clazz) {
0N/A this.name = name;
0N/A this.oid = oid;
0N/A this.className = clazz.getName();
0N/A this.clazz = clazz;
0N/A }
0N/A
0N/A /**
0N/A * Return the Class object associated with this attribute.
0N/A */
0N/A Class getClazz() throws CertificateException {
0N/A try {
0N/A Class c = clazz;
0N/A if (c == null) {
0N/A c = Class.forName(className);
0N/A clazz = c;
0N/A }
0N/A return c;
0N/A } catch (ClassNotFoundException e) {
0N/A throw (CertificateException)new CertificateException
0N/A ("Could not load class: " + e).initCause(e);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Add a name to lookup table.
0N/A *
0N/A * @param name the name of the attr
0N/A * @param oid the string representation of the object identifier for
0N/A * the class.
0N/A * @param clazz the Class object associated with this attribute
0N/A * @exception CertificateException on errors.
0N/A */
0N/A public static void addAttribute(String name, String oid, Class clazz)
0N/A throws CertificateException {
0N/A ObjectIdentifier objId;
0N/A try {
0N/A objId = new ObjectIdentifier(oid);
0N/A } catch (IOException ioe) {
0N/A throw new CertificateException
0N/A ("Invalid Object identifier: " + oid);
0N/A }
0N/A OIDInfo info = new OIDInfo(name, objId, clazz);
0N/A if (oidMap.put(objId, info) != null) {
0N/A throw new CertificateException
0N/A ("Object identifier already exists: " + oid);
0N/A }
0N/A if (nameMap.put(name, info) != null) {
0N/A throw new CertificateException("Name already exists: " + name);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Return user friendly name associated with the OID.
0N/A *
0N/A * @param oid the name of the object identifier to be returned.
0N/A * @return the user friendly name or null if no name
0N/A * is registered for this oid.
0N/A */
0N/A public static String getName(ObjectIdentifier oid) {
0N/A OIDInfo info = oidMap.get(oid);
0N/A return (info == null) ? null : info.name;
0N/A }
0N/A
0N/A /**
0N/A * Return Object identifier for user friendly name.
0N/A *
0N/A * @param name the user friendly name.
0N/A * @return the Object Identifier or null if no oid
0N/A * is registered for this name.
0N/A */
0N/A public static ObjectIdentifier getOID(String name) {
0N/A OIDInfo info = nameMap.get(name);
0N/A return (info == null) ? null : info.oid;
0N/A }
0N/A
0N/A /**
0N/A * Return the java class object associated with the user friendly name.
0N/A *
0N/A * @param name the user friendly name.
0N/A * @exception CertificateException if class cannot be instantiated.
0N/A */
0N/A public static Class getClass(String name) throws CertificateException {
0N/A OIDInfo info = nameMap.get(name);
0N/A return (info == null) ? null : info.getClazz();
0N/A }
0N/A
0N/A /**
0N/A * Return the java class object associated with the object identifier.
0N/A *
0N/A * @param oid the name of the object identifier to be returned.
0N/A * @exception CertificateException if class cannot be instatiated.
0N/A */
0N/A public static Class getClass(ObjectIdentifier oid)
0N/A throws CertificateException {
0N/A OIDInfo info = oidMap.get(oid);
0N/A return (info == null) ? null : info.getClazz();
0N/A }
0N/A
0N/A}