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_224withRSA("2.16.840.1.101.3.4.3.13", "SHA3-224withRSA"),
158 SHA3_256withRSA("2.16.840.1.101.3.4.3.14", "SHA3-256withRSA"),
159 SHA3_384withRSA("2.16.840.1.101.3.4.3.15", "SHA3-384withRSA"),
160 SHA3_512withRSA("2.16.840.1.101.3.4.3.16", "SHA3-512withRSA"),
161
162 // RSASecurity
163 // PKCS1 1.2.840.113549.1.1.*
164 PKCS1("1.2.840.113549.1.1", "RSA") { // RSA KeyPairGenerator and KeyFactory
165 @Override
166 boolean registerNames() { return false; }
167 },
168 RSA("1.2.840.113549.1.1.1"), // RSA encryption
169
170 MD2withRSA("1.2.840.113549.1.1.2"),
171 MD5withRSA("1.2.840.113549.1.1.4"),
172 SHA1withRSA("1.2.840.113549.1.1.5"),
173 OAEP("1.2.840.113549.1.1.7"),
174 MGF1("1.2.840.113549.1.1.8"),
175 PSpecified("1.2.840.113549.1.1.9"),
176 RSASSA_PSS("1.2.840.113549.1.1.10", "RSASSA-PSS"),
412 // find the matching enum using either name or oid string
413 // return null if no match found
414 public static KnownOIDs findMatch(String s) {
415 s = s.toUpperCase(Locale.ENGLISH);
416 KnownOIDs res = name2enum.get(s);
417 if (res == null && debug != null) {
418 debug.println("No KnownOIDs enum found for " + s);
419 }
420 return res;
421 }
422
423 private static final Debug debug = Debug.getInstance("jca");
424 //private static final java.io.PrintStream debug = System.out;
425 private static final ConcurrentHashMap<String, KnownOIDs> name2enum =
426 new ConcurrentHashMap<>();
427
428 static {
429 if (debug != null) {
430 debug.println("Setting up name2enum:");
431 }
432 List.of(KnownOIDs.values()).forEach(o -> {
433 register(o);
434 });
435 }
436
437 private static void register(KnownOIDs o) {
438 KnownOIDs ov = name2enum.put(o.oid, o);
439 if (ov != null) {
440 throw new RuntimeException("ERROR: Duplicate " + o.oid +
441 " between " + o + " and " + ov);
442 } else if (debug != null) {
443 debug.println(o.oid + " => " + o.name());
444 }
445 // only register the stdName and aliases if o.registerNames()
446 // returns true
447 if (o.registerNames()) {
448 String stdNameUpper = o.stdName.toUpperCase(Locale.ENGLISH);
449 if (Objects.nonNull(name2enum.put(stdNameUpper, o))) {
450 throw new RuntimeException("ERROR: Duplicate " +
451 stdNameUpper + " exists already");
452 }
453 if (debug != null) {
454 debug.println(stdNameUpper + " => " + o.name());
|
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"),
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());
|