@Test public void testZeusCertFile() throws X509PathBuildException, PemException { StringBuilder stackMsg = new StringBuilder(); StringBuilder sb = new StringBuilder(); Set<X509CertificateHolder> roots = new HashSet<X509CertificateHolder>(); String rootCaStr = PemUtils.toPemString(rootCA); roots.add(rootCA); String userKeyStr = PemUtils.toPemString(userKey); String userCrtStr = PemUtils.toPemString(userCrt); List<X509CertificateHolder> imdCrtsReversed = new ArrayList(imdCrts); Collections.reverse(imdCrtsReversed); for (X509CertificateHolder x509obj : imdCrtsReversed) { sb.append(PemUtils.toPemString(x509obj)); } String imdsString = sb.toString(); ZeusUtils zu = new ZeusUtils(roots); ZeusCrtFile zcf = zu.buildZeusCrtFileLbassValidation(userKeyStr, userCrtStr, imdsString); for (ErrorEntry errors : zcf.getErrors()) { Throwable ex = errors.getException(); if (ex != null) { stackMsg.append(StringUtils.getEST(ex)); } } Assert.assertTrue(zcf.getErrors().isEmpty()); List<PemBlock> parsedImds = PemUtils.parseMultiPem(imdsString); Assert.assertTrue(parsedImds.size() == 7); for (PemBlock block : parsedImds) { Assert.assertTrue(block.getDecodedObject() instanceof X509CertificateHolder); } }
public ZeusCrtFile buildZeusCrtFileLbassValidation(String userKeyStr, String userCrtStr, String intermediates) { ZeusCrtFile zcf = new ZeusCrtFile(); List<ErrorEntry> errors = zcf.getErrors(); Map<X509CertificateHolder, Integer> lineMap = new HashMap<X509CertificateHolder, Integer>(); String zkey = ""; String zcrt = ""; String msg; KeyPair userKey = parseKey(userKeyStr, zcf.getErrors()); X509CertificateHolder userCrt = decodeCrt(userCrtStr, zcf); List<X509CertificateHolder> imdCrts = decodeImd(lineMap, intermediates, zcf); if (!zcf.containsErrorTypes(ErrorType.UNREADABLE_CERT, ErrorType.UNREADABLE_KEY)) { List<ErrorEntry> keyMatchErrors; keyMatchErrors = CertUtils.validateKeyMatchesCrt(userKey, userCrt); errors.addAll(keyMatchErrors); } Date now = new Date(System.currentTimeMillis()); if (userCrt != null && CertUtils.isCertExpired(userCrt, now)) { Date after = userCrt.getNotAfter(); String errorMsg = invalidDateMessage("User cert expired on", after); errors.add(new ErrorEntry(ErrorType.EXPIRED_CERT, errorMsg, false, null)); } if (userCrt != null && CertUtils.isCertPremature(userCrt, now)) { Date before = userCrt.getNotBefore(); String errorMsg = invalidDateMessage("User cert isn't valid till", before); errors.add(new ErrorEntry(ErrorType.PREMATURE_CERT, errorMsg, false, null)); } if (!ErrorEntry.hasFatal(errors)) { StringBuilder sb = new StringBuilder(4096); try { zkey = PemUtils.toPemString(userKey); } catch (PemException ex) { errors.add(new ErrorEntry(ErrorType.COULDENT_ENCODE_KEY, "Error encodeing users key", true, ex)); } try { sb.append(PemUtils.toPemString(userCrt)); } catch (PemException ex) { errors.add(new ErrorEntry(ErrorType.COULDENT_ENCODE_CERT, "Error encodeing users Crt", true, ex)); } for (X509CertificateHolder x509obj : imdCrts) { try { String x509Str = PemUtils.toPemString(x509obj); sb.append(x509Str); } catch (PemException ex) { if (lineMap.containsKey(x509obj)) { int x509lineNum = lineMap.get(x509obj).intValue(); msg = String.format("Error encodeing chain crt at line %d", x509lineNum); errors.add(new ErrorEntry(ErrorType.COULDENT_ENCODE_CERT, msg, true, ex)); } else { errors.add(new ErrorEntry(ErrorType.COULDENT_ENCODE_CERT, "Error encodeing chain crt", true, ex)); } } } if (!ErrorEntry.hasFatal(errors)) { zcrt = sb.toString(); zcf.setPrivate_key(zkey); zcf.setPublic_cert(zcrt); } } return zcf; }
ZeusUtils { public ZeusCrtFile buildZeusCrtFileLbassValidation(String userKeyStr, String userCrtStr, String intermediates) { ZeusCrtFile zcf = new ZeusCrtFile(); List<ErrorEntry> errors = zcf.getErrors(); Map<X509CertificateHolder, Integer> lineMap = new HashMap<X509CertificateHolder, Integer>(); String zkey = ""; String zcrt = ""; String msg; KeyPair userKey = parseKey(userKeyStr, zcf.getErrors()); X509CertificateHolder userCrt = decodeCrt(userCrtStr, zcf); List<X509CertificateHolder> imdCrts = decodeImd(lineMap, intermediates, zcf); if (!zcf.containsErrorTypes(ErrorType.UNREADABLE_CERT, ErrorType.UNREADABLE_KEY)) { List<ErrorEntry> keyMatchErrors; keyMatchErrors = CertUtils.validateKeyMatchesCrt(userKey, userCrt); errors.addAll(keyMatchErrors); } Date now = new Date(System.currentTimeMillis()); if (userCrt != null && CertUtils.isCertExpired(userCrt, now)) { Date after = userCrt.getNotAfter(); String errorMsg = invalidDateMessage("User cert expired on", after); errors.add(new ErrorEntry(ErrorType.EXPIRED_CERT, errorMsg, false, null)); } if (userCrt != null && CertUtils.isCertPremature(userCrt, now)) { Date before = userCrt.getNotBefore(); String errorMsg = invalidDateMessage("User cert isn't valid till", before); errors.add(new ErrorEntry(ErrorType.PREMATURE_CERT, errorMsg, false, null)); } if (!ErrorEntry.hasFatal(errors)) { StringBuilder sb = new StringBuilder(4096); try { zkey = PemUtils.toPemString(userKey); } catch (PemException ex) { errors.add(new ErrorEntry(ErrorType.COULDENT_ENCODE_KEY, "Error encodeing users key", true, ex)); } try { sb.append(PemUtils.toPemString(userCrt)); } catch (PemException ex) { errors.add(new ErrorEntry(ErrorType.COULDENT_ENCODE_CERT, "Error encodeing users Crt", true, ex)); } for (X509CertificateHolder x509obj : imdCrts) { try { String x509Str = PemUtils.toPemString(x509obj); sb.append(x509Str); } catch (PemException ex) { if (lineMap.containsKey(x509obj)) { int x509lineNum = lineMap.get(x509obj).intValue(); msg = String.format("Error encodeing chain crt at line %d", x509lineNum); errors.add(new ErrorEntry(ErrorType.COULDENT_ENCODE_CERT, msg, true, ex)); } else { errors.add(new ErrorEntry(ErrorType.COULDENT_ENCODE_CERT, "Error encodeing chain crt", true, ex)); } } } if (!ErrorEntry.hasFatal(errors)) { zcrt = sb.toString(); zcf.setPrivate_key(zkey); zcf.setPublic_cert(zcrt); } } return zcf; } }
ZeusUtils { public ZeusCrtFile buildZeusCrtFileLbassValidation(String userKeyStr, String userCrtStr, String intermediates) { ZeusCrtFile zcf = new ZeusCrtFile(); List<ErrorEntry> errors = zcf.getErrors(); Map<X509CertificateHolder, Integer> lineMap = new HashMap<X509CertificateHolder, Integer>(); String zkey = ""; String zcrt = ""; String msg; KeyPair userKey = parseKey(userKeyStr, zcf.getErrors()); X509CertificateHolder userCrt = decodeCrt(userCrtStr, zcf); List<X509CertificateHolder> imdCrts = decodeImd(lineMap, intermediates, zcf); if (!zcf.containsErrorTypes(ErrorType.UNREADABLE_CERT, ErrorType.UNREADABLE_KEY)) { List<ErrorEntry> keyMatchErrors; keyMatchErrors = CertUtils.validateKeyMatchesCrt(userKey, userCrt); errors.addAll(keyMatchErrors); } Date now = new Date(System.currentTimeMillis()); if (userCrt != null && CertUtils.isCertExpired(userCrt, now)) { Date after = userCrt.getNotAfter(); String errorMsg = invalidDateMessage("User cert expired on", after); errors.add(new ErrorEntry(ErrorType.EXPIRED_CERT, errorMsg, false, null)); } if (userCrt != null && CertUtils.isCertPremature(userCrt, now)) { Date before = userCrt.getNotBefore(); String errorMsg = invalidDateMessage("User cert isn't valid till", before); errors.add(new ErrorEntry(ErrorType.PREMATURE_CERT, errorMsg, false, null)); } if (!ErrorEntry.hasFatal(errors)) { StringBuilder sb = new StringBuilder(4096); try { zkey = PemUtils.toPemString(userKey); } catch (PemException ex) { errors.add(new ErrorEntry(ErrorType.COULDENT_ENCODE_KEY, "Error encodeing users key", true, ex)); } try { sb.append(PemUtils.toPemString(userCrt)); } catch (PemException ex) { errors.add(new ErrorEntry(ErrorType.COULDENT_ENCODE_CERT, "Error encodeing users Crt", true, ex)); } for (X509CertificateHolder x509obj : imdCrts) { try { String x509Str = PemUtils.toPemString(x509obj); sb.append(x509Str); } catch (PemException ex) { if (lineMap.containsKey(x509obj)) { int x509lineNum = lineMap.get(x509obj).intValue(); msg = String.format("Error encodeing chain crt at line %d", x509lineNum); errors.add(new ErrorEntry(ErrorType.COULDENT_ENCODE_CERT, msg, true, ex)); } else { errors.add(new ErrorEntry(ErrorType.COULDENT_ENCODE_CERT, "Error encodeing chain crt", true, ex)); } } } if (!ErrorEntry.hasFatal(errors)) { zcrt = sb.toString(); zcf.setPrivate_key(zkey); zcf.setPublic_cert(zcrt); } } return zcf; } ZeusUtils();  ZeusUtils(Set<X509CertificateHolder> roots); }
ZeusUtils { public ZeusCrtFile buildZeusCrtFileLbassValidation(String userKeyStr, String userCrtStr, String intermediates) { ZeusCrtFile zcf = new ZeusCrtFile(); List<ErrorEntry> errors = zcf.getErrors(); Map<X509CertificateHolder, Integer> lineMap = new HashMap<X509CertificateHolder, Integer>(); String zkey = ""; String zcrt = ""; String msg; KeyPair userKey = parseKey(userKeyStr, zcf.getErrors()); X509CertificateHolder userCrt = decodeCrt(userCrtStr, zcf); List<X509CertificateHolder> imdCrts = decodeImd(lineMap, intermediates, zcf); if (!zcf.containsErrorTypes(ErrorType.UNREADABLE_CERT, ErrorType.UNREADABLE_KEY)) { List<ErrorEntry> keyMatchErrors; keyMatchErrors = CertUtils.validateKeyMatchesCrt(userKey, userCrt); errors.addAll(keyMatchErrors); } Date now = new Date(System.currentTimeMillis()); if (userCrt != null && CertUtils.isCertExpired(userCrt, now)) { Date after = userCrt.getNotAfter(); String errorMsg = invalidDateMessage("User cert expired on", after); errors.add(new ErrorEntry(ErrorType.EXPIRED_CERT, errorMsg, false, null)); } if (userCrt != null && CertUtils.isCertPremature(userCrt, now)) { Date before = userCrt.getNotBefore(); String errorMsg = invalidDateMessage("User cert isn't valid till", before); errors.add(new ErrorEntry(ErrorType.PREMATURE_CERT, errorMsg, false, null)); } if (!ErrorEntry.hasFatal(errors)) { StringBuilder sb = new StringBuilder(4096); try { zkey = PemUtils.toPemString(userKey); } catch (PemException ex) { errors.add(new ErrorEntry(ErrorType.COULDENT_ENCODE_KEY, "Error encodeing users key", true, ex)); } try { sb.append(PemUtils.toPemString(userCrt)); } catch (PemException ex) { errors.add(new ErrorEntry(ErrorType.COULDENT_ENCODE_CERT, "Error encodeing users Crt", true, ex)); } for (X509CertificateHolder x509obj : imdCrts) { try { String x509Str = PemUtils.toPemString(x509obj); sb.append(x509Str); } catch (PemException ex) { if (lineMap.containsKey(x509obj)) { int x509lineNum = lineMap.get(x509obj).intValue(); msg = String.format("Error encodeing chain crt at line %d", x509lineNum); errors.add(new ErrorEntry(ErrorType.COULDENT_ENCODE_CERT, msg, true, ex)); } else { errors.add(new ErrorEntry(ErrorType.COULDENT_ENCODE_CERT, "Error encodeing chain crt", true, ex)); } } } if (!ErrorEntry.hasFatal(errors)) { zcrt = sb.toString(); zcf.setPrivate_key(zkey); zcf.setPublic_cert(zcrt); } } return zcf; } ZeusUtils();  ZeusUtils(Set<X509CertificateHolder> roots); ZeusCrtFile buildZeusCrtFileLbassValidation(String userKeyStr, String userCrtStr, String intermediates); Set<X509CertificateHolder> getRoots(); void setRoots(Set<X509CertificateHolder> roots); static KeyPair parseKey(String keyIn, List<ErrorEntry> errors); static X509CertificateHolder parseCert(String certIn, List<ErrorEntry> errors); static Set<X509CertificateHolder> parseIntermediateCerts(String intermediates, List<ErrorEntry> errors); static List<X509CertificateHolder> decodeImd(Map<X509CertificateHolder, Integer> lineMap, String imdStr, ZeusCrtFile zcf); }
ZeusUtils { public ZeusCrtFile buildZeusCrtFileLbassValidation(String userKeyStr, String userCrtStr, String intermediates) { ZeusCrtFile zcf = new ZeusCrtFile(); List<ErrorEntry> errors = zcf.getErrors(); Map<X509CertificateHolder, Integer> lineMap = new HashMap<X509CertificateHolder, Integer>(); String zkey = ""; String zcrt = ""; String msg; KeyPair userKey = parseKey(userKeyStr, zcf.getErrors()); X509CertificateHolder userCrt = decodeCrt(userCrtStr, zcf); List<X509CertificateHolder> imdCrts = decodeImd(lineMap, intermediates, zcf); if (!zcf.containsErrorTypes(ErrorType.UNREADABLE_CERT, ErrorType.UNREADABLE_KEY)) { List<ErrorEntry> keyMatchErrors; keyMatchErrors = CertUtils.validateKeyMatchesCrt(userKey, userCrt); errors.addAll(keyMatchErrors); } Date now = new Date(System.currentTimeMillis()); if (userCrt != null && CertUtils.isCertExpired(userCrt, now)) { Date after = userCrt.getNotAfter(); String errorMsg = invalidDateMessage("User cert expired on", after); errors.add(new ErrorEntry(ErrorType.EXPIRED_CERT, errorMsg, false, null)); } if (userCrt != null && CertUtils.isCertPremature(userCrt, now)) { Date before = userCrt.getNotBefore(); String errorMsg = invalidDateMessage("User cert isn't valid till", before); errors.add(new ErrorEntry(ErrorType.PREMATURE_CERT, errorMsg, false, null)); } if (!ErrorEntry.hasFatal(errors)) { StringBuilder sb = new StringBuilder(4096); try { zkey = PemUtils.toPemString(userKey); } catch (PemException ex) { errors.add(new ErrorEntry(ErrorType.COULDENT_ENCODE_KEY, "Error encodeing users key", true, ex)); } try { sb.append(PemUtils.toPemString(userCrt)); } catch (PemException ex) { errors.add(new ErrorEntry(ErrorType.COULDENT_ENCODE_CERT, "Error encodeing users Crt", true, ex)); } for (X509CertificateHolder x509obj : imdCrts) { try { String x509Str = PemUtils.toPemString(x509obj); sb.append(x509Str); } catch (PemException ex) { if (lineMap.containsKey(x509obj)) { int x509lineNum = lineMap.get(x509obj).intValue(); msg = String.format("Error encodeing chain crt at line %d", x509lineNum); errors.add(new ErrorEntry(ErrorType.COULDENT_ENCODE_CERT, msg, true, ex)); } else { errors.add(new ErrorEntry(ErrorType.COULDENT_ENCODE_CERT, "Error encodeing chain crt", true, ex)); } } } if (!ErrorEntry.hasFatal(errors)) { zcrt = sb.toString(); zcf.setPrivate_key(zkey); zcf.setPublic_cert(zcrt); } } return zcf; } ZeusUtils();  ZeusUtils(Set<X509CertificateHolder> roots); ZeusCrtFile buildZeusCrtFileLbassValidation(String userKeyStr, String userCrtStr, String intermediates); Set<X509CertificateHolder> getRoots(); void setRoots(Set<X509CertificateHolder> roots); static KeyPair parseKey(String keyIn, List<ErrorEntry> errors); static X509CertificateHolder parseCert(String certIn, List<ErrorEntry> errors); static Set<X509CertificateHolder> parseIntermediateCerts(String intermediates, List<ErrorEntry> errors); static List<X509CertificateHolder> decodeImd(Map<X509CertificateHolder, Integer> lineMap, String imdStr, ZeusCrtFile zcf);  }