From 1f54ef67f54face4de2647b90e2552d9a1aca54a Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Tue, 9 Jul 2019 16:50:26 +0200 Subject: fix bug in BPKBuilder.java and make methods static --- .../core/impl/idp/auth/builder/BPKBuilder.java | 54 +++++++++++----------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/builder/BPKBuilder.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/builder/BPKBuilder.java index dfafea6f..6defefdd 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/builder/BPKBuilder.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/builder/BPKBuilder.java @@ -82,10 +82,10 @@ public class BPKBuilder { * * @param baseID baseId from user but never null * @param targetIdentifier target identifier for area specific identifier calculation but never null - * @return Pair but never null + * @return Pair consists of (unique person identifier for this target, targetArea) but never null * @throws EAAFBuilderException if some input data are not valid */ - public Pair generateAreaSpecificPersonIdentifier(String baseID, String targetIdentifier) throws EAAFBuilderException { + public static Pair generateAreaSpecificPersonIdentifier(String baseID, String targetIdentifier) throws EAAFBuilderException { return generateAreaSpecificPersonIdentifier(baseID, EAAFConstants.URN_PREFIX_BASEID, targetIdentifier); } @@ -96,10 +96,10 @@ public class BPKBuilder { * @param baseID baseId from user but never null * @param baseIdType Type of the baseID but never null * @param targetIdentifier target identifier for area specific identifier calculation but never null - * @return Pair but never null + * @return Pair consists of (unique person identifier for this target, targetArea) but never null * @throws EAAFBuilderException if some input data are not valid */ - public Pair generateAreaSpecificPersonIdentifier(String baseID, String baseIdType, String targetIdentifier) throws EAAFBuilderException{ + public static Pair generateAreaSpecificPersonIdentifier(String baseID, String baseIdType, String targetIdentifier) throws EAAFBuilderException{ if (StringUtils.isEmpty(baseID)) throw new EAAFBuilderException("builder.00", new Object[]{"baseID is empty or null"}, "BaseId is empty or null"); @@ -122,9 +122,9 @@ public class BPKBuilder { } else if (targetIdentifier.startsWith(EAAFConstants.URN_PREFIX_EIDAS)) { log.trace("Calculate eIDAS identifier for target: " + targetIdentifier); - String[] splittedTarget = targetIdentifier.split("\\+"); - String cititzenCountryCode = splittedTarget[1]; - String eIDASOutboundCountry = splittedTarget[2]; + final String[] splittedTarget = targetIdentifier.split("\\+"); + final String cititzenCountryCode = splittedTarget[1]; + final String eIDASOutboundCountry = splittedTarget[2]; if (cititzenCountryCode.equalsIgnoreCase(eIDASOutboundCountry)) { log.warn("Suspect configuration FOUND!!! CitizenCountry equals DestinationCountry"); @@ -166,7 +166,7 @@ public class BPKBuilder { * @return Pair in a BASE64 encoding * @throws EAAFBuilderException if some input data are not valid */ - private Pair buildeIDASIdentifer(String baseID, String baseIDType, String sourceCountry, String destinationCountry) + private static Pair buildeIDASIdentifer(String baseID, String baseIDType, String sourceCountry, String destinationCountry) throws EAAFBuilderException { String bPK = null; String bPKType = null; @@ -193,29 +193,29 @@ public class BPKBuilder { } log.trace("eIDAS pseudonym generation finished. "); - String eIdentifier = sourceCountry + "/" + destinationCountry + "/" + bPK; + final String eIdentifier = sourceCountry + "/" + destinationCountry + "/" + bPK; return Pair.newInstance(eIdentifier, bPKType); } public static String encryptBPK(String bpk, String target, PublicKey publicKey) throws EAAFBuilderException { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); - if (target.startsWith(EAAFConstants.URN_PREFIX_CDID + "+")) - target = target.substring((EAAFConstants.URN_PREFIX_CDID + "+").length()); + final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); + if (target.startsWith(EAAFConstants.URN_PREFIX_CDID)) + target = target.substring((EAAFConstants.URN_PREFIX_CDID).length()); - String input = "V1::urn:publicid:gv.at:cdid+" + target + "::" + final String input = "V1::urn:publicid:gv.at:cdid+" + target + "::" + bpk + "::" + sdf.format(new Date()); System.out.println(input); byte[] result; try { - byte[] inputBytes = input.getBytes("ISO-8859-1"); + final byte[] inputBytes = input.getBytes("ISO-8859-1"); result = encrypt(inputBytes, publicKey); return new String(Base64Utils.encode(result), "ISO-8859-1").replaceAll("\r\n", ""); //return new String(Base64Utils.encode(result, "ISO-8859-1")).replaceAll("\r\n", ""); - } catch (Exception e) { + } catch (final Exception e) { throw new EAAFBuilderException("bPK encryption FAILED", null, e.getMessage(), e); @@ -226,20 +226,20 @@ public class BPKBuilder { String decryptedString; try { //byte[] encryptedBytes = Base64Utils.decode(encryptedBpk, false, "ISO-8859-1"); - byte[] encryptedBytes = Base64Utils.decode(encryptedBpk.getBytes("ISO-8859-1")); - byte[] decryptedBytes = decrypt(encryptedBytes, privateKey); + final byte[] encryptedBytes = Base64Utils.decode(encryptedBpk.getBytes("ISO-8859-1")); + final byte[] decryptedBytes = decrypt(encryptedBytes, privateKey); decryptedString = new String(decryptedBytes, "ISO-8859-1"); - } catch (Exception e) { + } catch (final Exception e) { throw new EAAFBuilderException("bPK decryption FAILED", null, e.getMessage(), e); } String tmp = decryptedString.substring(decryptedString.indexOf('+') + 1); - String sector = tmp.substring(0, tmp.indexOf("::")); + final String sector = tmp.substring(0, tmp.indexOf("::")); tmp = tmp.substring(tmp.indexOf("::") + 2); - String bPK = tmp.substring(0, tmp.indexOf("::")); + final String bPK = tmp.substring(0, tmp.indexOf("::")); if (target.startsWith(EAAFConstants.URN_PREFIX_CDID + "+")) target = target.substring((EAAFConstants.URN_PREFIX_CDID + "+").length()); @@ -253,14 +253,14 @@ public class BPKBuilder { } } - private String calculatebPKwbPK(String basisbegriff) throws EAAFBuilderException { + private static String calculatebPKwbPK(String basisbegriff) throws EAAFBuilderException { try { - MessageDigest md = MessageDigest.getInstance("SHA-1"); - byte[] hash = md.digest(basisbegriff.getBytes("ISO-8859-1")); - String hashBase64 = new String(Base64Utils.encode(hash), "ISO-8859-1").replaceAll("\r\n", ""); //Base64Utils.encode(hash); + final MessageDigest md = MessageDigest.getInstance("SHA-1"); + final byte[] hash = md.digest(basisbegriff.getBytes("ISO-8859-1")); + final String hashBase64 = new String(Base64Utils.encode(hash), "ISO-8859-1").replaceAll("\r\n", ""); //Base64Utils.encode(hash); return hashBase64; - } catch (Exception ex) { + } catch (final Exception ex) { throw new EAAFBuilderException("builder.00", new Object[]{"bPK/wbPK", ex.toString()}, ex.getMessage(), ex); @@ -274,7 +274,7 @@ public class BPKBuilder { try { cipher = Cipher.getInstance("RSA/ECB/OAEPPadding"); // try with bouncycastle - } catch(NoSuchAlgorithmException e) { + } catch(final NoSuchAlgorithmException e) { cipher = Cipher.getInstance("RSA/ECB/OAEP"); // try with iaik provider } cipher.init(Cipher.ENCRYPT_MODE, publicKey); @@ -290,7 +290,7 @@ public class BPKBuilder { try { cipher = Cipher.getInstance("RSA/ECB/OAEPPadding"); // try with bouncycastle - } catch(NoSuchAlgorithmException e) { + } catch(final NoSuchAlgorithmException e) { cipher = Cipher.getInstance("RSA/ECB/OAEP"); // try with iaik provider } -- cgit v1.2.3