diff --git a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/security/CertificateListTabUi.java b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/security/CertificateListTabUi.java index 4480dcc7732..f7de50b8ad0 100644 --- a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/security/CertificateListTabUi.java +++ b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/security/CertificateListTabUi.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2020, 2021 Eurotech and/or its affiliates and others + * Copyright (c) 2020, 2023 Eurotech and/or its affiliates and others * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -177,6 +177,15 @@ public String getValue(GwtKeystoreEntry object) { this.certificatesGrid.addColumn(col1, MSGS.certificateAlias()); col1.setSortable(true); + TextColumn col1bis = new TextColumn() { + + @Override + public String getValue(GwtKeystoreEntry object) { + return String.join(" ", object.getDistinguishedNames()); + } + }; + this.certificatesGrid.addColumn(col1bis, MSGS.certificateDNs()); + TextColumn col2 = new TextColumn() { @Override diff --git a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/server/GwtCertificatesServiceImpl.java b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/server/GwtCertificatesServiceImpl.java index b2a0a02cf18..7f0a1b1516c 100644 --- a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/server/GwtCertificatesServiceImpl.java +++ b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/server/GwtCertificatesServiceImpl.java @@ -32,6 +32,7 @@ import org.eclipse.kura.KuraException; import org.eclipse.kura.certificate.CertificatesService; import org.eclipse.kura.certificate.KuraCertificateEntry; +import org.eclipse.kura.core.keystore.util.CertificateUtil; import org.eclipse.kura.core.keystore.util.KeystoreRemoteService; import org.eclipse.kura.security.keystore.KeystoreService; import org.eclipse.kura.web.server.util.ServiceLocator; @@ -153,6 +154,8 @@ public List listEntries() throws GwtKuraException { Date validityStartDate = null; Date validityEndDate = null; + List distinguishedNames = new ArrayList<>(); + if (e.getValue() instanceof PrivateKeyEntry) { kind = Kind.KEY_PAIR; @@ -166,6 +169,18 @@ public List listEntries() throws GwtKuraException { validityStartDate = ((X509Certificate) leaf).getNotBefore(); validityEndDate = ((X509Certificate) leaf).getNotAfter(); } + + for (int i = 0; i < chain.length; i++) { + String index = String.format("[%d]: ", i); + if (chain.length == 1) { + index = ""; + } + Certificate cert = chain[i]; + if (cert instanceof X509Certificate) { + X509Certificate x509Cert = CertificateUtil.toJavaX509Certificate(cert); + distinguishedNames.add(index + x509Cert.getSubjectX500Principal().getName()); + } + } } } else if (e.getValue() instanceof TrustedCertificateEntry) { kind = Kind.TRUSTED_CERT; @@ -175,6 +190,9 @@ public List listEntries() throws GwtKuraException { if (cert instanceof X509Certificate) { validityStartDate = ((X509Certificate) cert).getNotBefore(); validityEndDate = ((X509Certificate) cert).getNotAfter(); + + X509Certificate x509Cert = CertificateUtil.toJavaX509Certificate(cert); + distinguishedNames.add(x509Cert.getSubjectX500Principal().getName()); } } else if (e.getValue() instanceof SecretKeyEntry) { kind = Kind.SECRET_KEY; @@ -182,11 +200,11 @@ public List listEntries() throws GwtKuraException { continue; } - result.add(new GwtKeystoreEntry(e.getKey(), (String) kuraServicePid, kind, validityStartDate, + result.add(new GwtKeystoreEntry(e.getKey(), distinguishedNames, (String) kuraServicePid, kind, validityStartDate, validityEndDate)); } } catch (KuraException keystoreException) { - logger.error("Error while accessing keystore file of Keystore Service {}: {}", (String) kuraServicePid, + logger.error("Error while accessing keystore file of Keystore Service {}: {}", kuraServicePid, keystoreException.getMessage(), keystoreException); } finally { context.ungetService(ref); diff --git a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/shared/model/GwtKeystoreEntry.java b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/shared/model/GwtKeystoreEntry.java index 5e679a45ac1..e83a55b91ea 100644 --- a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/shared/model/GwtKeystoreEntry.java +++ b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/shared/model/GwtKeystoreEntry.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2020, 2021 Eurotech and/or its affiliates and others + * Copyright (c) 2020, 2023 Eurotech and/or its affiliates and others * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -14,6 +14,7 @@ import java.io.Serializable; import java.util.Date; +import java.util.List; import com.google.gwt.user.client.rpc.IsSerializable; @@ -30,8 +31,10 @@ public enum Kind { public GwtKeystoreEntry() { } - public GwtKeystoreEntry(final String alias, final String keystoreName, final Kind kind, final Date validityStart, final Date validityEnd) { + public GwtKeystoreEntry(final String alias, final List distinguishedNames, String keystoreName, + final Kind kind, final Date validityStart, final Date validityEnd) { set("alias", alias); + set("DNs", distinguishedNames); set("keystoreName", keystoreName); set("kind", kind.toString()); set("validityStart", validityStart); @@ -42,16 +45,20 @@ public String getAlias() { return get("alias"); } + public List getDistinguishedNames() { + return get("DNs"); + } + public String getKeystoreName() { return get("keystoreName"); } - + public Date getValidityStartDate() { - return get("validityStart"); + return get("validityStart"); } - + public Date getValidityEndDate() { - return get("validityEnd"); + return get("validityEnd"); } public Kind getKind() { diff --git a/kura/org.eclipse.kura.web2/src/main/resources/org/eclipse/kura/web/client/messages/Messages.properties b/kura/org.eclipse.kura.web2/src/main/resources/org/eclipse/kura/web/client/messages/Messages.properties index b67d7794fe4..05443ad3718 100644 --- a/kura/org.eclipse.kura.web2/src/main/resources/org/eclipse/kura/web/client/messages/Messages.properties +++ b/kura/org.eclipse.kura.web2/src/main/resources/org/eclipse/kura/web/client/messages/Messages.properties @@ -287,6 +287,7 @@ settingsReloadStartupFingerprintDescription=Allows to change the startup command certificateAlias=Alias +certificateDNs=Distinguished Names certificateAliasUsed=Certificate Alias already used. certificateAliasMaxLength=Alias must be at most {0} characters certificateKeystoreName=Keystore Service Name