History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/sun/security/x509/OIDMap.java (1 of 18352 files). Show all

Unified · Split

java/pkg/sun/security/x509/OIDMap.java+297−0
@@ -0,0 +1,297 @@
1+/*
2+ * Copyright (c) 1997, 2009, 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.x509;
27+
28+import java.util.*;
29+import java.io.IOException;
30+
31+import java.security.cert.CertificateException;
32+import java.security.cert.CertificateParsingException;
33+
34+import sun.security.util.*;
35+
36+/**
37+ * This class defines the mapping from OID & name to classes and vice
38+ * versa. Used by CertificateExtensions & PKCS10 to get the java
39+ * classes associated with a particular OID/name.
40+ *
41+ * @author Amit Kapoor
42+ * @author Hemma Prafullchandra
43+ * @author Andreas Sterbenz
44+ *
45+ */
46+public class OIDMap {
47+
48+ private OIDMap() {
49+ // empty
50+ }
51+
52+ // "user-friendly" names
53+ private static final String ROOT = X509CertImpl.NAME + "." +
54+ X509CertInfo.NAME + "." +
55+ X509CertInfo.EXTENSIONS;
56+ private static final String AUTH_KEY_IDENTIFIER = ROOT + "." +
57+ AuthorityKeyIdentifierExtension.NAME;
58+ private static final String SUB_KEY_IDENTIFIER = ROOT + "." +
59+ SubjectKeyIdentifierExtension.NAME;
60+ private static final String KEY_USAGE = ROOT + "." +
61+ KeyUsageExtension.NAME;
62+ private static final String PRIVATE_KEY_USAGE = ROOT + "." +
63+ PrivateKeyUsageExtension.NAME;
64+ private static final String POLICY_MAPPINGS = ROOT + "." +
65+ PolicyMappingsExtension.NAME;
66+ private static final String SUB_ALT_NAME = ROOT + "." +
67+ SubjectAlternativeNameExtension.NAME;
68+ private static final String ISSUER_ALT_NAME = ROOT + "." +
69+ IssuerAlternativeNameExtension.NAME;
70+ private static final String BASIC_CONSTRAINTS = ROOT + "." +
71+ BasicConstraintsExtension.NAME;
72+ private static final String NAME_CONSTRAINTS = ROOT + "." +
73+ NameConstraintsExtension.NAME;
74+ private static final String POLICY_CONSTRAINTS = ROOT + "." +
75+ PolicyConstraintsExtension.NAME;
76+ private static final String CRL_NUMBER = ROOT + "." +
77+ CRLNumberExtension.NAME;
78+ private static final String CRL_REASON = ROOT + "." +
79+ CRLReasonCodeExtension.NAME;
80+ private static final String NETSCAPE_CERT = ROOT + "." +
81+ NetscapeCertTypeExtension.NAME;
82+ private static final String CERT_POLICIES = ROOT + "." +
83+ CertificatePoliciesExtension.NAME;
84+ private static final String EXT_KEY_USAGE = ROOT + "." +
85+ ExtendedKeyUsageExtension.NAME;
86+ private static final String INHIBIT_ANY_POLICY = ROOT + "." +
87+ InhibitAnyPolicyExtension.NAME;
88+ private static final String CRL_DIST_POINTS = ROOT + "." +
89+ CRLDistributionPointsExtension.NAME;
90+
91+ private static final String CERT_ISSUER = ROOT + "." +
92+ CertificateIssuerExtension.NAME;
93+ private static final String SUBJECT_INFO_ACCESS = ROOT + "." +
94+ SubjectInfoAccessExtension.NAME;
95+ private static final String AUTH_INFO_ACCESS = ROOT + "." +
96+ AuthorityInfoAccessExtension.NAME;
97+ private static final String ISSUING_DIST_POINT = ROOT + "." +
98+ IssuingDistributionPointExtension.NAME;
99+ private static final String DELTA_CRL_INDICATOR = ROOT + "." +
100+ DeltaCRLIndicatorExtension.NAME;
101+ private static final String FRESHEST_CRL = ROOT + "." +
102+ FreshestCRLExtension.NAME;
103+ private static final String OCSPNOCHECK = ROOT + "." +
104+ OCSPNoCheckExtension.NAME;
105+
106+ private static final int NetscapeCertType_data[] =
107+ { 2, 16, 840, 1, 113730, 1, 1 };
108+
109+ /** Map ObjectIdentifier(oid) -> OIDInfo(info) */
110+ private final static Map<ObjectIdentifier,OIDInfo> oidMap;
111+
112+ /** Map String(friendly name) -> OIDInfo(info) */
113+ private final static Map<String,OIDInfo> nameMap;
114+
115+ static {
116+ oidMap = new HashMap<ObjectIdentifier,OIDInfo>();
117+ nameMap = new HashMap<String,OIDInfo>();
118+ addInternal(SUB_KEY_IDENTIFIER, PKIXExtensions.SubjectKey_Id,
119+ "sun.security.x509.SubjectKeyIdentifierExtension");
120+ addInternal(KEY_USAGE, PKIXExtensions.KeyUsage_Id,
121+ "sun.security.x509.KeyUsageExtension");
122+ addInternal(PRIVATE_KEY_USAGE, PKIXExtensions.PrivateKeyUsage_Id,
123+ "sun.security.x509.PrivateKeyUsageExtension");
124+ addInternal(SUB_ALT_NAME, PKIXExtensions.SubjectAlternativeName_Id,
125+ "sun.security.x509.SubjectAlternativeNameExtension");
126+ addInternal(ISSUER_ALT_NAME, PKIXExtensions.IssuerAlternativeName_Id,
127+ "sun.security.x509.IssuerAlternativeNameExtension");
128+ addInternal(BASIC_CONSTRAINTS, PKIXExtensions.BasicConstraints_Id,
129+ "sun.security.x509.BasicConstraintsExtension");
130+ addInternal(CRL_NUMBER, PKIXExtensions.CRLNumber_Id,
131+ "sun.security.x509.CRLNumberExtension");
132+ addInternal(CRL_REASON, PKIXExtensions.ReasonCode_Id,
133+ "sun.security.x509.CRLReasonCodeExtension");
134+ addInternal(NAME_CONSTRAINTS, PKIXExtensions.NameConstraints_Id,
135+ "sun.security.x509.NameConstraintsExtension");
136+ addInternal(POLICY_MAPPINGS, PKIXExtensions.PolicyMappings_Id,
137+ "sun.security.x509.PolicyMappingsExtension");
138+ addInternal(AUTH_KEY_IDENTIFIER, PKIXExtensions.AuthorityKey_Id,
139+ "sun.security.x509.AuthorityKeyIdentifierExtension");
140+ addInternal(POLICY_CONSTRAINTS, PKIXExtensions.PolicyConstraints_Id,
141+ "sun.security.x509.PolicyConstraintsExtension");
142+ addInternal(NETSCAPE_CERT, ObjectIdentifier.newInternal
143+ (new int[] {2,16,840,1,113730,1,1}),
144+ "sun.security.x509.NetscapeCertTypeExtension");
145+ addInternal(CERT_POLICIES, PKIXExtensions.CertificatePolicies_Id,
146+ "sun.security.x509.CertificatePoliciesExtension");
147+ addInternal(EXT_KEY_USAGE, PKIXExtensions.ExtendedKeyUsage_Id,
148+ "sun.security.x509.ExtendedKeyUsageExtension");
149+ addInternal(INHIBIT_ANY_POLICY, PKIXExtensions.InhibitAnyPolicy_Id,
150+ "sun.security.x509.InhibitAnyPolicyExtension");
151+ addInternal(CRL_DIST_POINTS, PKIXExtensions.CRLDistributionPoints_Id,
152+ "sun.security.x509.CRLDistributionPointsExtension");
153+ addInternal(CERT_ISSUER, PKIXExtensions.CertificateIssuer_Id,
154+ "sun.security.x509.CertificateIssuerExtension");
155+ addInternal(SUBJECT_INFO_ACCESS, PKIXExtensions.SubjectInfoAccess_Id,
156+ "sun.security.x509.SubjectInfoAccessExtension");
157+ addInternal(AUTH_INFO_ACCESS, PKIXExtensions.AuthInfoAccess_Id,
158+ "sun.security.x509.AuthorityInfoAccessExtension");
159+ addInternal(ISSUING_DIST_POINT,
160+ PKIXExtensions.IssuingDistributionPoint_Id,
161+ "sun.security.x509.IssuingDistributionPointExtension");
162+ addInternal(DELTA_CRL_INDICATOR, PKIXExtensions.DeltaCRLIndicator_Id,
163+ "sun.security.x509.DeltaCRLIndicatorExtension");
164+ addInternal(FRESHEST_CRL, PKIXExtensions.FreshestCRL_Id,
165+ "sun.security.x509.FreshestCRLExtension");
166+ addInternal(OCSPNOCHECK, PKIXExtensions.OCSPNoCheck_Id,
167+ "sun.security.x509.OCSPNoCheckExtension");
168+ }
169+
170+ /**
171+ * Add attributes to the table. For internal use in the static
172+ * initializer.
173+ */
174+ private static void addInternal(String name, ObjectIdentifier oid,
175+ String className) {
176+ OIDInfo info = new OIDInfo(name, oid, className);
177+ oidMap.put(oid, info);
178+ nameMap.put(name, info);
179+ }
180+
181+ /**
182+ * Inner class encapsulating the mapping info and Class loading.
183+ */
184+ private static class OIDInfo {
185+
186+ final ObjectIdentifier oid;
187+ final String name;
188+ final String className;
189+ private volatile Class clazz;
190+
191+ OIDInfo(String name, ObjectIdentifier oid, String className) {
192+ this.name = name;
193+ this.oid = oid;
194+ this.className = className;
195+ }
196+
197+ OIDInfo(String name, ObjectIdentifier oid, Class clazz) {
198+ this.name = name;
199+ this.oid = oid;
200+ this.className = clazz.getName();
201+ this.clazz = clazz;
202+ }
203+
204+ /**
205+ * Return the Class object associated with this attribute.
206+ */
207+ Class getClazz() throws CertificateException {
208+ try {
209+ Class c = clazz;
210+ if (c == null) {
211+ c = Class.forName(className);
212+ clazz = c;
213+ }
214+ return c;
215+ } catch (ClassNotFoundException e) {
216+ throw (CertificateException)new CertificateException
217+ ("Could not load class: " + e).initCause(e);
218+ }
219+ }
220+ }
221+
222+ /**
223+ * Add a name to lookup table.
224+ *
225+ * @param name the name of the attr
226+ * @param oid the string representation of the object identifier for
227+ * the class.
228+ * @param clazz the Class object associated with this attribute
229+ * @exception CertificateException on errors.
230+ */
231+ public static void addAttribute(String name, String oid, Class clazz)
232+ throws CertificateException {
233+ ObjectIdentifier objId;
234+ try {
235+ objId = new ObjectIdentifier(oid);
236+ } catch (IOException ioe) {
237+ throw new CertificateException
238+ ("Invalid Object identifier: " + oid);
239+ }
240+ OIDInfo info = new OIDInfo(name, objId, clazz);
241+ if (oidMap.put(objId, info) != null) {
242+ throw new CertificateException
243+ ("Object identifier already exists: " + oid);
244+ }
245+ if (nameMap.put(name, info) != null) {
246+ throw new CertificateException("Name already exists: " + name);
247+ }
248+ }
249+
250+ /**
251+ * Return user friendly name associated with the OID.
252+ *
253+ * @param oid the name of the object identifier to be returned.
254+ * @return the user friendly name or null if no name
255+ * is registered for this oid.
256+ */
257+ public static String getName(ObjectIdentifier oid) {
258+ OIDInfo info = oidMap.get(oid);
259+ return (info == null) ? null : info.name;
260+ }
261+
262+ /**
263+ * Return Object identifier for user friendly name.
264+ *
265+ * @param name the user friendly name.
266+ * @return the Object Identifier or null if no oid
267+ * is registered for this name.
268+ */
269+ public static ObjectIdentifier getOID(String name) {
270+ OIDInfo info = nameMap.get(name);
271+ return (info == null) ? null : info.oid;
272+ }
273+
274+ /**
275+ * Return the java class object associated with the user friendly name.
276+ *
277+ * @param name the user friendly name.
278+ * @exception CertificateException if class cannot be instantiated.
279+ */
280+ public static Class getClass(String name) throws CertificateException {
281+ OIDInfo info = nameMap.get(name);
282+ return (info == null) ? null : info.getClazz();
283+ }
284+
285+ /**
286+ * Return the java class object associated with the object identifier.
287+ *
288+ * @param oid the name of the object identifier to be returned.
289+ * @exception CertificateException if class cannot be instatiated.
290+ */
291+ public static Class getClass(ObjectIdentifier oid)
292+ throws CertificateException {
293+ OIDInfo info = oidMap.get(oid);
294+ return (info == null) ? null : info.getClazz();
295+ }
296+
297+}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t