Search in sources :

Example 1 with HCCol

use of com.helger.html.hc.html.tabular.HCCol in project phoss-smp by phax.

the class SMPCommonUI method createCertificateDetailsTable.

@Nonnull
public static BootstrapTable createCertificateDetailsTable(@Nullable final String sAlias, @Nonnull final X509Certificate aX509Cert, @Nonnull final LocalDateTime aNowLDT, @Nonnull final Locale aDisplayLocale) {
    final LocalDateTime aNotBefore = PDTFactory.createLocalDateTime(aX509Cert.getNotBefore());
    final LocalDateTime aNotAfter = PDTFactory.createLocalDateTime(aX509Cert.getNotAfter());
    final PublicKey aPublicKey = aX509Cert.getPublicKey();
    final BootstrapTable aCertDetails = new BootstrapTable(new HCCol().addStyle(CCSSProperties.WIDTH.newValue("12rem")), HCCol.star());
    aCertDetails.setResponsive(true);
    if (StringHelper.hasText(sAlias))
        aCertDetails.addBodyRow().addCell("Alias:").addCell(sAlias);
    aCertDetails.addBodyRow().addCell("Version:").addCell(Integer.toString(aX509Cert.getVersion()));
    aCertDetails.addBodyRow().addCell("Subject:").addCell(aX509Cert.getSubjectX500Principal().getName());
    aCertDetails.addBodyRow().addCell("Issuer:").addCell(aX509Cert.getIssuerX500Principal().getName());
    aCertDetails.addBodyRow().addCell("Serial number:").addCell(aX509Cert.getSerialNumber().toString() + " / 0x" + _inGroupsOf(aX509Cert.getSerialNumber().toString(16), 4));
    aCertDetails.addBodyRow().addCell("Valid from:").addCell(new HCTextNode(PDTToString.getAsString(aNotBefore, aDisplayLocale) + " "), aNowLDT.isBefore(aNotBefore) ? new BootstrapBadge(EBootstrapBadgeType.DANGER).addChild("!!!NOT YET VALID!!!") : null);
    aCertDetails.addBodyRow().addCell("Valid to:").addCell(new HCTextNode(PDTToString.getAsString(aNotAfter, aDisplayLocale) + " "), aNowLDT.isAfter(aNotAfter) ? new BootstrapBadge(EBootstrapBadgeType.DANGER).addChild("!!!NO LONGER VALID!!!") : new HCDiv().addChild("Valid for: " + PDTDisplayHelper.getPeriodTextEN(aNowLDT, aNotAfter)));
    if (aPublicKey instanceof RSAPublicKey) {
        // Special handling for RSA
        aCertDetails.addBodyRow().addCell("Public key:").addCell(aX509Cert.getPublicKey().getAlgorithm() + " (" + ((RSAPublicKey) aPublicKey).getModulus().bitLength() + " bits)");
    } else {
        // Usually EC or DSA key
        aCertDetails.addBodyRow().addCell("Public key:").addCell(aX509Cert.getPublicKey().getAlgorithm());
    }
    aCertDetails.addBodyRow().addCell("Signature algorithm:").addCell(aX509Cert.getSigAlgName() + " (" + aX509Cert.getSigAlgOID() + ")");
    return aCertDetails;
}
Also used : LocalDateTime(java.time.LocalDateTime) HCDiv(com.helger.html.hc.html.grouping.HCDiv) HCCol(com.helger.html.hc.html.tabular.HCCol) BootstrapBadge(com.helger.photon.bootstrap4.badge.BootstrapBadge) BootstrapTable(com.helger.photon.bootstrap4.table.BootstrapTable) RSAPublicKey(java.security.interfaces.RSAPublicKey) RSAPublicKey(java.security.interfaces.RSAPublicKey) PublicKey(java.security.PublicKey) HCTextNode(com.helger.html.hc.impl.HCTextNode) Nonnull(javax.annotation.Nonnull)

Aggregations

HCDiv (com.helger.html.hc.html.grouping.HCDiv)1 HCCol (com.helger.html.hc.html.tabular.HCCol)1 HCTextNode (com.helger.html.hc.impl.HCTextNode)1 BootstrapBadge (com.helger.photon.bootstrap4.badge.BootstrapBadge)1 BootstrapTable (com.helger.photon.bootstrap4.table.BootstrapTable)1 PublicKey (java.security.PublicKey)1 RSAPublicKey (java.security.interfaces.RSAPublicKey)1 LocalDateTime (java.time.LocalDateTime)1 Nonnull (javax.annotation.Nonnull)1