From 74d19c0493d7bf464d466b2dff2305021d911c27 Mon Sep 17 00:00:00 2001 From: CGantert345 <57003061+CGantert345@users.noreply.github.com> Date: Wed, 17 May 2023 13:57:03 +0200 Subject: SSB tests --- .../java/org/uic/barcode/utils/SecurityUtils.java | 41 ++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'src/main/java/org/uic/barcode/utils/SecurityUtils.java') diff --git a/src/main/java/org/uic/barcode/utils/SecurityUtils.java b/src/main/java/org/uic/barcode/utils/SecurityUtils.java index 8c981af..8f19e4b 100644 --- a/src/main/java/org/uic/barcode/utils/SecurityUtils.java +++ b/src/main/java/org/uic/barcode/utils/SecurityUtils.java @@ -15,6 +15,8 @@ import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.X509EncodedKeySpec; import java.util.Arrays; +import org.uic.barcode.dynamicFrame.Constants; + /** * The Class SecurityUtils. */ @@ -23,8 +25,8 @@ public class SecurityUtils { /** * Find provider by public key. * - * @param algorithmOid the algorithm oid used to generate the key - * @param keyBytes the encoded bytes of the public key + * @param keyAlgorithmOid the key algorithm oid + * @param keyBytes the encoded bytes of the public key * @return the provider */ public static Provider findPublicKeyProvider(String keyAlgorithmOid, byte[] keyBytes) { @@ -263,6 +265,13 @@ public class SecurityUtils { return out.toByteArray(); } + /** + * Recombine dsa signature. + * + * @param sealdata the sealdata + * @return the byte[] + * @throws IOException Signals that an I/O exception has occurred. + */ public static byte[] recombineDsaSignature(byte[] sealdata) throws IOException { //check whether the encoding is wrong and the sealdata contain a signature @@ -311,4 +320,32 @@ public class SecurityUtils { return out.toByteArray(); } + + /** + * Gets the dsa algorithm allowed for ssb or static frame. + * + * @param bs the size of the signature + * @return the dsa algorithm OID + */ + public static String getDsaAlgorithm(byte[] bs) { + + BigInteger[] bInts = null; + int size = 0; + try { + bInts = decodeSignatureIntegerSequence(bs); + int sizeR = bInts[0].bitLength(); + int sizeS = bInts[1].bitLength(); + size = Math.max(sizeR,sizeS); + } catch (Exception e) { + return null; + } + + if (size > 224) { + return Constants.DSA_SHA256; + } else if (size > 160) { + return Constants.DSA_SHA224; + } else { + return Constants.DSA_SHA1; + } + } } -- cgit v1.2.3