From 6eebf3f29b9658a4e74ab1d1f90146c8e029c736 Mon Sep 17 00:00:00 2001 From: CGantert345 <57003061+CGantert345@users.noreply.github.com> Date: Mon, 28 Jun 2021 17:28:50 +0200 Subject: - option to use a dedicated security provider implementation --- .../uic/barcode/utils/AlgorithmNameResolver.java | 48 +++++++++++++++------- 1 file changed, 33 insertions(+), 15 deletions(-) (limited to 'src/main/java/org/uic/barcode/utils') diff --git a/src/main/java/org/uic/barcode/utils/AlgorithmNameResolver.java b/src/main/java/org/uic/barcode/utils/AlgorithmNameResolver.java index e3918b0..1671ba9 100644 --- a/src/main/java/org/uic/barcode/utils/AlgorithmNameResolver.java +++ b/src/main/java/org/uic/barcode/utils/AlgorithmNameResolver.java @@ -39,24 +39,40 @@ public class AlgorithmNameResolver { Provider[] provs = Security.getProviders(); for (Provider prov : provs) { + + String name = getName(type, oid, prov); + if (name != null) return name; - SortedSet typeAndOID = getTypeAndOIDStrings(prov); - - for (String entry : typeAndOID) { - String[] typeAndOIDArray = entry.split("-"); - String ptype = typeAndOIDArray[0]; - if (ptype.equalsIgnoreCase(type)) { - String poid = typeAndOIDArray[1]; - Service pservice = prov.getService(ptype, poid); - String palgo = pservice.getAlgorithm(); - - if (poid != null && ptype.equalsIgnoreCase(type) && poid.equals(oid)) { - return palgo; - } - } - } } + if (oid.startsWith("1.2.840.10045")) { + return "ECDSA"; + } else if (oid.startsWith("1.2.840.10040")) { + return "DSA"; + } + + return null; + + } + + public static String getName(String type, String oid, Provider prov) throws Exception { + + SortedSet typeAndOID = getTypeAndOIDStrings(prov); + + for (String entry : typeAndOID) { + String[] typeAndOIDArray = entry.split("-"); + String ptype = typeAndOIDArray[0]; + if (ptype.equalsIgnoreCase(type)) { + String poid = typeAndOIDArray[1]; + Service pservice = prov.getService(ptype, poid); + String palgo = pservice.getAlgorithm(); + + if (poid != null && ptype.equalsIgnoreCase(type) && poid.equals(oid)) { + return palgo; + } + } + } + if (oid.startsWith("1.2.840.10045")) { return "ECDSA"; @@ -104,6 +120,8 @@ public class AlgorithmNameResolver { return null; } + + private static SortedSet getTypeAndOIDStrings(Provider prov) { -- cgit v1.2.3