Skip to content

Commit

Permalink
feat(web2): Added Distinguished Names to the certificate table (#5079)
Browse files Browse the repository at this point in the history
* Added Distinguished Name to certificate table

* Update kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/server/GwtCertificatesServiceImpl.java

Co-authored-by: Matteo Maiero <[email protected]>

* Renamed dNs into distinguisedNames.

---------

Co-authored-by: Matteo Maiero <[email protected]>
  • Loading branch information
salvatore-coppola and MMaiero authored Jan 5, 2024
1 parent 57f0cd9 commit f4994ee
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -177,6 +177,15 @@ public String getValue(GwtKeystoreEntry object) {
this.certificatesGrid.addColumn(col1, MSGS.certificateAlias());
col1.setSortable(true);

TextColumn<GwtKeystoreEntry> col1bis = new TextColumn<GwtKeystoreEntry>() {

@Override
public String getValue(GwtKeystoreEntry object) {
return String.join(" ", object.getDistinguishedNames());
}
};
this.certificatesGrid.addColumn(col1bis, MSGS.certificateDNs());

TextColumn<GwtKeystoreEntry> col2 = new TextColumn<GwtKeystoreEntry>() {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -153,6 +154,8 @@ public List<GwtKeystoreEntry> listEntries() throws GwtKuraException {
Date validityStartDate = null;
Date validityEndDate = null;

List<String> distinguishedNames = new ArrayList<>();

if (e.getValue() instanceof PrivateKeyEntry) {
kind = Kind.KEY_PAIR;

Expand All @@ -166,6 +169,18 @@ public List<GwtKeystoreEntry> 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;
Expand All @@ -175,18 +190,21 @@ public List<GwtKeystoreEntry> 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;
} else {
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -14,6 +14,7 @@

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import com.google.gwt.user.client.rpc.IsSerializable;

Expand All @@ -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<String> 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);
Expand All @@ -42,16 +45,20 @@ public String getAlias() {
return get("alias");
}

public List<String> 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f4994ee

Please sign in to comment.