1 /*
  2  * Copyright (c) 2020, 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.util;
 27 
 28 import java.util.List;
 29 import java.util.Locale;
 30 import java.util.Objects;
 31 import java.util.concurrent.ConcurrentHashMap;
 32 
 33 /**
 34  * This utility class maps algorithm name to the corresponding oid strings.
 35  * NOTE: for 100% backward compatibility, the standard name for the enum
 36  * is determined by existing usage and may be in lowercase/uppercase in
 37  * order to match existing output.
 38  */
 39 public enum KnownOIDs {
 40 
 41     // X.500 Attributes 2.5.4.*
 42     CommonName("2.5.4.3"),
 43     Surname("2.5.4.4"),
 44     SerialNumber("2.5.4.5"),
 45     CountryName("2.5.4.6"),
 46     LocalityName("2.5.4.7"),
 47     StateName("2.5.4.8"),
 48     StreetAddress("2.5.4.9"),
 49     OrgName("2.5.4.10"),
 50     OrgUnitName("2.5.4.11"),
 51     Title("2.5.4.12"),
 52     GivenName("2.5.4.42"),
 53     Initials("2.5.4.43"),
 54     GenerationQualifier("2.5.4.44"),
 55     DNQualifier("2.5.4.46"),
 56 
 57     // Certificate Extension 2.5.29.*
 58     SubjectDirectoryAttributes("2.5.29.9"),
 59     SubjectKeyID("2.5.29.14"),
 60     KeyUsage("2.5.29.15"),
 61     PrivateKeyUsage("2.5.29.16"),
 62     SubjectAlternativeName("2.5.29.17"),
 63     IssuerAlternativeName("2.5.29.18"),
 64     BasicConstraints("2.5.29.19"),
 65     CRLNumber("2.5.29.20"),
 66     ReasonCode("2.5.29.21"),
 67     HoldInstructionCode("2.5.29.23"),
 68     InvalidityDate("2.5.29.24"),
 69     DeltaCRLIndicator("2.5.29.27"),
 70     IssuingDistributionPoint("2.5.29.28"),
 71     CertificateIssuer("2.5.29.29"),
 72     NameConstraints("2.5.29.30"),
 73     CRLDistributionPoints("2.5.29.31"),
 74     CertificatePolicies("2.5.29.32"),
 75     CE_CERT_POLICIES_ANY("2.5.29.32.0"),
 76     PolicyMappings("2.5.29.33"),
 77     AuthorityKeyID("2.5.29.35"),
 78     PolicyConstraints("2.5.29.36"),
 79     extendedKeyUsage("2.5.29.37"),
 80     anyExtendedKeyUsage("2.5.29.37.0"),
 81     FreshestCRL("2.5.29.46"),
 82     InhibitAnyPolicy("2.5.29.54"),
 83 
 84     // PKIX 1.3.6.1.5.5.7.
 85     AuthInfoAccess("1.3.6.1.5.5.7.1.1"),
 86     SubjectInfoAccess("1.3.6.1.5.5.7.1.11"),
 87     // key usage purposes - PKIX.3.*
 88     serverAuth("1.3.6.1.5.5.7.3.1"),
 89     clientAuth("1.3.6.1.5.5.7.3.2"),
 90     codeSigning("1.3.6.1.5.5.7.3.3"),
 91     emailProtection("1.3.6.1.5.5.7.3.4"),
 92     ipsecEndSystem("1.3.6.1.5.5.7.3.5"),
 93     ipsecTunnel("1.3.6.1.5.5.7.3.6"),
 94     ipsecUser("1.3.6.1.5.5.7.3.7"),
 95     KP_TimeStamping("1.3.6.1.5.5.7.3.8", "timeStamping") {
 96         @Override
 97         boolean registerNames() { return false; }
 98     },
 99     OCSPSigning("1.3.6.1.5.5.7.3.9"),
100     // access descriptors - PKIX.48.*
101     OCSP("1.3.6.1.5.5.7.48.1"),
102     OCSPBasicResponse("1.3.6.1.5.5.7.48.1.1"),
103     OCSPNonceExt("1.3.6.1.5.5.7.48.1.2"),
104     OCSPNoCheck("1.3.6.1.5.5.7.48.1.5"),
105     caIssuers("1.3.6.1.5.5.7.48.2"),
106     AD_TimeStamping("1.3.6.1.5.5.7.48.3", "timeStamping") {
107         @Override
108         boolean registerNames() { return false; }
109     },
110     caRepository("1.3.6.1.5.5.7.48.5", "caRepository"),
111 
112     // NIST --
113     // AES 2.16.840.1.101.3.4.1.*
114     AES("2.16.840.1.101.3.4.1"),
115     AES_128$ECB$NoPadding("2.16.840.1.101.3.4.1.1", "AES_128/ECB/NoPadding"),
116     AES_128$CBC$NoPadding("2.16.840.1.101.3.4.1.2", "AES_128/CBC/NoPadding"),
117     AES_128$OFB$NoPadding("2.16.840.1.101.3.4.1.3", "AES_128/OFB/NoPadding"),
118     AES_128$CFB$NoPadding("2.16.840.1.101.3.4.1.4", "AES_128/CFB/NoPadding"),
119     AESWRAP_128("2.16.840.1.101.3.4.1.5"),
120     AES_128$GCM$NoPadding("2.16.840.1.101.3.4.1.6", "AES_128/GCM/NoPadding"),
121     AES_192$ECB$NoPadding("2.16.840.1.101.3.4.1.21", "AES_192/ECB/NoPadding"),
122     AES_192$CBC$NoPadding("2.16.840.1.101.3.4.1.22", "AES_192/CBC/NoPadding"),
123     AES_192$OFB$NoPadding("2.16.840.1.101.3.4.1.23", "AES_192/OFB/NoPadding"),
124     AES_192$CFB$NoPadding("2.16.840.1.101.3.4.1.24", "AES_192/CFB/NoPadding"),
125     AESWRAP_192("2.16.840.1.101.3.4.1.25"),
126     AES_192$GCM$NoPadding("2.16.840.1.101.3.4.1.26", "AES_192/GCM/NoPadding"),
127     AES_256$ECB$NoPadding("2.16.840.1.101.3.4.1.41", "AES_256/ECB/NoPadding"),
128     AES_256$CBC$NoPadding("2.16.840.1.101.3.4.1.42", "AES_256/CBC/NoPadding"),
129     AES_256$OFB$NoPadding("2.16.840.1.101.3.4.1.43", "AES_256/OFB/NoPadding"),
130     AES_256$CFB$NoPadding("2.16.840.1.101.3.4.1.44", "AES_256/CFB/NoPadding"),
131     AESWRAP_256("2.16.840.1.101.3.4.1.45"),
132     AES_256$GCM$NoPadding("2.16.840.1.101.3.4.1.46", "AES_256/GCM/NoPadding"),
133 
134     // hashAlgs 2.16.840.1.101.3.4.2.*
135     SHA_256("2.16.840.1.101.3.4.2.1", "SHA-256", "SHA256"),
136     SHA_384("2.16.840.1.101.3.4.2.2", "SHA-384", "SHA384"),
137     SHA_512("2.16.840.1.101.3.4.2.3", "SHA-512", "SHA512"),
138     SHA_224("2.16.840.1.101.3.4.2.4", "SHA-224", "SHA224"),
139     SHA_512$224("2.16.840.1.101.3.4.2.5", "SHA-512/224", "SHA512/224"),
140     SHA_512$256("2.16.840.1.101.3.4.2.6", "SHA-512/256", "SHA512/256"),
141     SHA3_224("2.16.840.1.101.3.4.2.7", "SHA3-224"),
142     SHA3_256("2.16.840.1.101.3.4.2.8", "SHA3-256"),
143     SHA3_384("2.16.840.1.101.3.4.2.9", "SHA3-384"),
144     SHA3_512("2.16.840.1.101.3.4.2.10", "SHA3-512"),
145     SHAKE128("2.16.840.1.101.3.4.2.11"),
146     SHAKE256("2.16.840.1.101.3.4.2.12"),
147     HmacSHA3_224("2.16.840.1.101.3.4.2.13", "HmacSHA3-224"),
148     HmacSHA3_256("2.16.840.1.101.3.4.2.14", "HmacSHA3-256"),
149     HmacSHA3_384("2.16.840.1.101.3.4.2.15", "HmacSHA3-384"),
150     HmacSHA3_512("2.16.840.1.101.3.4.2.16", "HmacSHA3-512"),
151 
152     // sigAlgs 2.16.840.1.101.3.4.3.*
153     SHA224withDSA("2.16.840.1.101.3.4.3.1"),
154     SHA256withDSA("2.16.840.1.101.3.4.3.2"),
155     SHA384withDSA("2.16.840.1.101.3.4.3.3"),
156     SHA512withDSA("2.16.840.1.101.3.4.3.4"),
157     SHA3_224withDSA("2.16.840.1.101.3.4.3.5", "SHA3-224withDSA"),
158     SHA3_256withDSA("2.16.840.1.101.3.4.3.6", "SHA3-256withDSA"),
159     SHA3_384withDSA("2.16.840.1.101.3.4.3.7", "SHA3-384withDSA"),
160     SHA3_512withDSA("2.16.840.1.101.3.4.3.8", "SHA3-512withDSA"),
161     SHA3_224withECDSA("2.16.840.1.101.3.4.3.9", "SHA3-224withECDSA"),
162     SHA3_256withECDSA("2.16.840.1.101.3.4.3.10", "SHA3-256withECDSA"),
163     SHA3_384withECDSA("2.16.840.1.101.3.4.3.11", "SHA3-384withECDSA"),
164     SHA3_512withECDSA("2.16.840.1.101.3.4.3.12", "SHA3-512withECDSA"),
165     SHA3_224withRSA("2.16.840.1.101.3.4.3.13", "SHA3-224withRSA"),
166     SHA3_256withRSA("2.16.840.1.101.3.4.3.14", "SHA3-256withRSA"),
167     SHA3_384withRSA("2.16.840.1.101.3.4.3.15", "SHA3-384withRSA"),
168     SHA3_512withRSA("2.16.840.1.101.3.4.3.16", "SHA3-512withRSA"),
169 
170     // RSASecurity
171     // PKCS1 1.2.840.113549.1.1.*
172     PKCS1("1.2.840.113549.1.1", "RSA") { // RSA KeyPairGenerator and KeyFactory
173         @Override
174         boolean registerNames() { return false; }
175     },
176     RSA("1.2.840.113549.1.1.1"), // RSA encryption
177 
178     MD2withRSA("1.2.840.113549.1.1.2"),
179     MD5withRSA("1.2.840.113549.1.1.4"),
180     SHA1withRSA("1.2.840.113549.1.1.5"),
181     OAEP("1.2.840.113549.1.1.7"),
182     MGF1("1.2.840.113549.1.1.8"),
183     PSpecified("1.2.840.113549.1.1.9"),
184     RSASSA_PSS("1.2.840.113549.1.1.10", "RSASSA-PSS"),
185     SHA256withRSA("1.2.840.113549.1.1.11"),
186     SHA384withRSA("1.2.840.113549.1.1.12"),
187     SHA512withRSA("1.2.840.113549.1.1.13"),
188     SHA224withRSA("1.2.840.113549.1.1.14"),
189     SHA512$224withRSA("1.2.840.113549.1.1.15", "SHA512/224withRSA"),
190     SHA512$256withRSA("1.2.840.113549.1.1.16", "SHA512/256withRSA"),
191 
192     // PKCS3 1.2.840.113549.1.3.*
193     DiffieHellman("1.2.840.113549.1.3.1", "DiffieHellman", "DH"),
194 
195     // PKCS5 1.2.840.113549.1.5.*
196     PBEWithMD5AndDES("1.2.840.113549.1.5.3"),
197     PBEWithMD5AndRC2("1.2.840.113549.1.5.6"),
198     PBEWithSHA1AndDES("1.2.840.113549.1.5.10"),
199     PBEWithSHA1AndRC2("1.2.840.113549.1.5.11"),
200     PBKDF2WithHmacSHA1("1.2.840.113549.1.5.12"),
201     PBES2("1.2.840.113549.1.5.13"),
202 
203     // PKCS7 1.2.840.113549.1.7.*
204     PKCS7("1.2.840.113549.1.7"),
205     Data("1.2.840.113549.1.7.1"),
206     SignedData("1.2.840.113549.1.7.2"),
207     JDK_OLD_Data("1.2.840.1113549.1.7.1"), // extra 1 in 4th component
208     JDK_OLD_SignedData("1.2.840.1113549.1.7.2"),
209     EnvelopedData("1.2.840.113549.1.7.3"),
210     SignedAndEnvelopedData("1.2.840.113549.1.7.4"),
211     DigestedData("1.2.840.113549.1.7.5"),
212     EncryptedData("1.2.840.113549.1.7.6"),
213 
214     // PKCS9 1.2.840.113549.1.9.*
215     EmailAddress("1.2.840.113549.1.9.1"),
216     UnstructuredName("1.2.840.113549.1.9.2"),
217     ContentType("1.2.840.113549.1.9.3"),
218     MessageDigest("1.2.840.113549.1.9.4"),
219     SigningTime("1.2.840.113549.1.9.5"),
220     CounterSignature("1.2.840.113549.1.9.6"),
221     ChallengePassword("1.2.840.113549.1.9.7"),
222     UnstructuredAddress("1.2.840.113549.1.9.8"),
223     ExtendedCertificateAttributes("1.2.840.113549.1.9.9"),
224     IssuerAndSerialNumber("1.2.840.113549.1.9.10"),
225     ExtensionRequest("1.2.840.113549.1.9.14"),
226     SMIMECapability("1.2.840.113549.1.9.15"),
227     TimeStampTokenInfo("1.2.840.113549.1.9.16.1.4"),
228     SigningCertificate("1.2.840.113549.1.9.16.2.12"),
229     SignatureTimestampToken("1.2.840.113549.1.9.16.2.14"),
230     CHACHA20_POLY1305("1.2.840.113549.1.9.16.3.18", "CHACHA20-POLY1305"),
231     FriendlyName("1.2.840.113549.1.9.20"),
232     LocalKeyID("1.2.840.113549.1.9.21"),
233     CertTypeX509("1.2.840.113549.1.9.22.1"),
234 
235     // PKCS12 1.2.840.113549.1.12.*
236     PBEWithSHA1AndRC4_128("1.2.840.113549.1.12.1.1"),
237     PBEWithSHA1AndRC4_40("1.2.840.113549.1.12.1.2"),
238     PBEWithSHA1AndDESede("1.2.840.113549.1.12.1.3"),
239     PBEWithSHA1AndRC2_128("1.2.840.113549.1.12.1.5"),
240     PBEWithSHA1AndRC2_40("1.2.840.113549.1.12.1.6"),
241     PKCS8ShroudedKeyBag("1.2.840.113549.1.12.10.1.2"),
242     CertBag("1.2.840.113549.1.12.10.1.3"),
243     SecretBag("1.2.840.113549.1.12.10.1.5"),
244 
245     // digestAlgs 1.2.840.113549.2.*
246     MD2("1.2.840.113549.2.2"),
247     MD5("1.2.840.113549.2.5"),
248     HmacSHA1("1.2.840.113549.2.7"),
249     HmacSHA224("1.2.840.113549.2.8"),
250     HmacSHA256("1.2.840.113549.2.9"),
251     HmacSHA384("1.2.840.113549.2.10"),
252     HmacSHA512("1.2.840.113549.2.11"),
253     HmacSHA512$224("1.2.840.113549.2.12", "HmacSHA512/224"),
254     HmacSHA512$256("1.2.840.113549.2.13", "HmacSHA512/256"),
255 
256     // encryptionAlgs 1.2.840.113549.3.*
257     RC2$CBC$PKCS5Padding("1.2.840.113549.3.2", "RC2/CBC/PKCS5Padding"),
258     ARCFOUR("1.2.840.113549.3.4", "ARCFOUR", "RC4"),
259     DESede$CBC$NoPadding("1.2.840.113549.3.7", "DESede/CBC/NoPadding"),
260     RC5$CBC$PKCS5Padding("1.2.840.113549.3.9", "RC5/CBC/PKCS5Padding"),
261 
262     // ANSI --
263     // X9 1.2.840.10040.4.*
264     DSA("1.2.840.10040.4.1"),
265     SHA1withDSA("1.2.840.10040.4.3", "SHA1withDSA", "DSS"),
266     // X9.62 1.2.840.10045.*
267     EC("1.2.840.10045.2.1"),
268 
269     //c2pnb163v1("1.2.840.10045.3.0.1", "X9.62 c2pnb163v1"),
270     //c2pnb163v2("1.2.840.10045.3.0.2", "X9.62 c2pnb163v2"),
271     //c2pnb163v3("1.2.840.10045.3.0.3", "X9.62 c2pnb163v3"),
272     //c2pnb176w1("1.2.840.10045.3.0.4", "X9.62 c2pnb176w1"),
273     c2tnb191v1("1.2.840.10045.3.0.5", "X9.62 c2tnb191v1"),
274     c2tnb191v2("1.2.840.10045.3.0.6", "X9.62 c2tnb191v2"),
275     c2tnb191v3("1.2.840.10045.3.0.7", "X9.62 c2tnb191v3"),
276     //c2pnb208w1("1.2.840.10045.3.0.10", "X9.62 c2pnb208w1"),
277     c2tnb239v1("1.2.840.10045.3.0.11", "X9.62 c2tnb239v1"),
278     c2tnb239v2("1.2.840.10045.3.0.12", "X9.62 c2tnb239v2"),
279     c2tnb239v3("1.2.840.10045.3.0.13", "X9.62 c2tnb239v3"),
280     //c2pnb272w1("1.2.840.10045.3.0.16", "X9.62 c2pnb272w1"),
281     //c2pnb304w1("1.2.840.10045.3.0.17", "X9.62 c2pnb304w1"),
282     c2tnb359v1("1.2.840.10045.3.0.18", "X9.62 c2tnb359v1"),
283     //c2pnb368w1("1.2.840.10045.3.0.19", "X9.62 c2pnb368w1"),
284     c2tnb431r1("1.2.840.10045.3.0.20", "X9.62 c2tnb431r1"),
285 
286     secp192r1("1.2.840.10045.3.1.1",
287             "secp192r1", "NIST P-192", "X9.62 prime192v1"),
288     prime192v2("1.2.840.10045.3.1.2", "X9.62 prime192v2"),
289     prime192v3("1.2.840.10045.3.1.3", "X9.62 prime192v3"),
290     prime239v1("1.2.840.10045.3.1.4", "X9.62 prime239v1"),
291     prime239v2("1.2.840.10045.3.1.5", "X9.62 prime239v2"),
292     prime239v3("1.2.840.10045.3.1.6", "X9.62 prime239v3"),
293     secp256r1("1.2.840.10045.3.1.7",
294             "secp256r1", "NIST P-256", "X9.62 prime256v1"),
295     SHA1withECDSA("1.2.840.10045.4.1"),
296     SHA224withECDSA("1.2.840.10045.4.3.1"),
297     SHA256withECDSA("1.2.840.10045.4.3.2"),
298     SHA384withECDSA("1.2.840.10045.4.3.3"),
299     SHA512withECDSA("1.2.840.10045.4.3.4"),
300     SpecifiedSHA2withECDSA("1.2.840.10045.4.3"),
301 
302     // X9.42 1.2.840.10046.2.*
303     X942_DH("1.2.840.10046.2.1", "DiffieHellman") { // unused by JDK providers
304         @Override
305         boolean registerNames() { return false; }
306     },
307 
308     // Teletrust 1.3.36.*
309     brainpoolP160r1("1.3.36.3.3.2.8.1.1.1"),
310     brainpoolP192r1("1.3.36.3.3.2.8.1.1.3"),
311     brainpoolP224r1("1.3.36.3.3.2.8.1.1.5"),
312     brainpoolP256r1("1.3.36.3.3.2.8.1.1.7"),
313     brainpoolP320r1("1.3.36.3.3.2.8.1.1.9"),
314     brainpoolP384r1("1.3.36.3.3.2.8.1.1.11"),
315     brainpoolP512r1("1.3.36.3.3.2.8.1.1.13"),
316 
317     // Certicom 1.3.132.*
318     sect163k1("1.3.132.0.1", "sect163k1", "NIST K-163"),
319     sect163r1("1.3.132.0.2"),
320     sect239k1("1.3.132.0.3"),
321     sect113r1("1.3.132.0.4"),
322     sect113r2("1.3.132.0.5"),
323     secp112r1("1.3.132.0.6"),
324     secp112r2("1.3.132.0.7"),
325     secp160r1("1.3.132.0.8"),
326     secp160k1("1.3.132.0.9"),
327     secp256k1("1.3.132.0.10"),
328     sect163r2("1.3.132.0.15", "sect163r2", "NIST B-163"),
329     sect283k1("1.3.132.0.16", "sect283k1", "NIST K-283"),
330     sect283r1("1.3.132.0.17", "sect283r1", "NIST B-283"),
331 
332     sect131r1("1.3.132.0.22"),
333     sect131r2("1.3.132.0.23"),
334     sect193r1("1.3.132.0.24"),
335     sect193r2("1.3.132.0.25"),
336     sect233k1("1.3.132.0.26", "sect233k1", "NIST K-233"),
337     sect233r1("1.3.132.0.27", "sect233r1", "NIST B-233"),
338     secp128r1("1.3.132.0.28"),
339     secp128r2("1.3.132.0.29"),
340     secp160r2("1.3.132.0.30"),
341     secp192k1("1.3.132.0.31"),
342     secp224k1("1.3.132.0.32"),
343     secp224r1("1.3.132.0.33", "secp224r1", "NIST P-224"),
344     secp384r1("1.3.132.0.34", "secp384r1", "NIST P-384"),
345     secp521r1("1.3.132.0.35", "secp521r1", "NIST P-521"),
346     sect409k1("1.3.132.0.36", "sect409k1", "NIST K-409"),
347     sect409r1("1.3.132.0.37", "sect409r1", "NIST B-409"),
348     sect571k1("1.3.132.0.38", "sect571k1", "NIST K-571"),
349     sect571r1("1.3.132.0.39", "sect571r1", "NIST B-571"),
350 
351     ECDH("1.3.132.1.12"),
352 
353     // OIW secsig 1.3.14.3.*
354     OIW_DES_CBC("1.3.14.3.2.7", "DES/CBC"),
355 
356     OIW_DSA("1.3.14.3.2.12", "DSA") {
357         @Override
358         boolean registerNames() { return false; }
359     },
360 
361     OIW_JDK_SHA1withDSA("1.3.14.3.2.13", "SHA1withDSA") {
362         @Override
363         boolean registerNames() { return false; }
364     },
365 
366     OIW_SHA1withRSA_Odd("1.3.14.3.2.15", "SHA1withRSA") {
367         @Override
368         boolean registerNames() { return false; }
369     },
370 
371     SHA_1("1.3.14.3.2.26", "SHA-1", "SHA", "SHA1"),
372 
373     OIW_SHA1withDSA("1.3.14.3.2.27", "SHA1withDSA") {
374         @Override
375         boolean registerNames() { return false; }
376     },
377 
378     OIW_SHA1withRSA("1.3.14.3.2.29", "SHA1withRSA") {
379         @Override
380         boolean registerNames() { return false; }
381     },
382 
383     // Thawte 1.3.101.*
384     X25519("1.3.101.110"),
385     X448("1.3.101.111"),
386     Ed25519("1.3.101.112"),
387     Ed448("1.3.101.113"),
388 
389     // University College London (UCL) 0.9.2342.19200300.*
390     UCL_UserID("0.9.2342.19200300.100.1.1"),
391     UCL_DomainComponent("0.9.2342.19200300.100.1.25"),
392 
393     // Netscape 2.16.840.1.113730.*
394     NETSCAPE_CertType("2.16.840.1.113730.1.1"),
395     NETSCAPE_CertSequence("2.16.840.1.113730.2.5"),
396     NETSCAPE_ExportApproved("2.16.840.1.113730.4.1"),
397 
398     // Oracle 2.16.840.1.113894.*
399     ORACLE_TrustedKeyUsage("2.16.840.1.113894.746875.1.1"),
400 
401     // Miscellaneous oids below which are legacy, and not well known
402     // Consider removing them in future releases when their usage
403     // have died out
404 
405     ITUX509_RSA("2.5.8.1.1", "RSA") { // unused by JDK providers
406                                       // defined in X.509 for RSA keys
407         @Override                     // with modulus length as its parameter
408         boolean registerNames() { return false; }
409     },
410 
411     SkipIPAddress("1.3.6.1.4.1.42.2.11.2.1"),
412     JAVASOFT_JDKKeyProtector("1.3.6.1.4.1.42.2.17.1.1"),
413     JAVASOFT_JCEKeyProtector("1.3.6.1.4.1.42.2.19.1"),
414     MICROSOFT_ExportApproved("1.3.6.1.4.1.311.10.3.3");
415 
416     private String stdName;
417     private String oid;
418     private String[] aliases;
419 
420     // find the matching enum using either name or oid string
421     // return null if no match found
422     public static KnownOIDs findMatch(String s) {
423         s = s.toUpperCase(Locale.ENGLISH);
424         KnownOIDs res = name2enum.get(s);
425         if (res == null && debug != null) {
426             debug.println("No KnownOIDs enum found for " + s);
427         }
428         return res;
429     }
430 
431     private static final Debug debug = Debug.getInstance("jca");
432     //private static final java.io.PrintStream debug = System.out;
433     private static final ConcurrentHashMap<String, KnownOIDs> name2enum =
434             new ConcurrentHashMap<>();
435 
436     static {
437         if (debug != null) {
438             debug.println("Setting up name2enum:");
439         }
440         for (KnownOIDs o : KnownOIDs.values()) {
441             register(o);
442         };
443     }
444 
445     private static void register(KnownOIDs o) {
446         KnownOIDs ov = name2enum.put(o.oid, o);
447         if (ov != null) {
448             throw new RuntimeException("ERROR: Duplicate " + o.oid +
449                     " between " + o + " and " + ov);
450         } else if (debug != null) {
451             debug.println(o.oid + " => " + o.name());
452         }
453         // only register the stdName and aliases if o.registerNames()
454         // returns true
455         if (o.registerNames()) {
456             String stdNameUpper = o.stdName.toUpperCase(Locale.ENGLISH);
457             if (Objects.nonNull(name2enum.put(stdNameUpper, o))) {
458                 throw new RuntimeException("ERROR: Duplicate " +
459                         stdNameUpper + " exists already");
460             }
461             if (debug != null) {
462                 debug.println(stdNameUpper + " => " + o.name());
463             }
464 
465             for (String a :  o.aliases) {
466                 String aliasUpper = a.toUpperCase(Locale.ENGLISH);
467                 if (Objects.nonNull(name2enum.put(aliasUpper, o))) {
468                     throw new RuntimeException("ERROR: Duplicate " +
469                             aliasUpper + " exists already");
470                 }
471                 if (debug != null) {
472                     debug.println(aliasUpper + " => " + o.name());
473                 }
474             }
475         }
476     }
477 
478     private KnownOIDs(String oid) {
479         this.oid = oid;
480         this.stdName = name(); // defaults to enum name
481         this.aliases = new String[0];
482     }
483 
484     private KnownOIDs(String oid, String stdName, String ... aliases) {
485         this.oid = oid;
486         this.stdName = stdName;
487         this.aliases = aliases;
488     }
489 
490     // returns the oid string associated with this enum
491     public String value() {
492         return oid;
493     }
494 
495     // returns the user-friendly standard algorithm name
496     public String stdName() {
497         return stdName;
498     }
499 
500     // return the internal aliases
501     public String[] aliases() {
502         return aliases;
503     }
504 
505     boolean registerNames() {
506         return true;
507     }
508 }