Skip to content

Commit

Permalink
Introduce column 'Certificate Validity' in main window (#249)
Browse files Browse the repository at this point in the history
* GUI improvment #249

* Introduce column 'Certificate Validity' in main window

* Amendments

* Amendments #2

* Renaming to validity start
  • Loading branch information
bjmi authored Oct 29, 2023
1 parent eb612d5 commit d607d1b
Show file tree
Hide file tree
Showing 10 changed files with 270 additions and 226 deletions.
177 changes: 85 additions & 92 deletions kse/src/org/kse/gui/KeyStoreTableColumns.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
package org.kse.gui;

import java.util.stream.Stream;

/**
* POJO class to configure the cells shown in the KeyStore table of KeyStore Explorer.
*/
Expand All @@ -27,6 +29,7 @@ public class KeyStoreTableColumns {
private boolean bEnableEntryName;
private boolean bEnableAlgorithm;
private boolean bEnableKeySize;
private boolean bEnableCertificateValidityStart;
private boolean bEnableCertificateExpiry;
private boolean bEnableLastModified;
private boolean bEnableSKI;
Expand All @@ -47,6 +50,7 @@ public class KeyStoreTableColumns {
private int iAlgorithmColumn = -1;
private int iKeySizeColumn = -1;
private int iCurveColumn = -1;
private int iCertValidityStartColumn = -1;
private int iCertExpiryColumn = -1;
private int iLastModifiedColumn = -1;
private int iAKIColumn = -1;
Expand All @@ -66,6 +70,7 @@ public KeyStoreTableColumns() {
bEnableEntryName = true;
bEnableAlgorithm = true;
bEnableKeySize = true;
bEnableCertificateValidityStart = false;
bEnableCertificateExpiry = true;
bEnableLastModified = true;
bEnableSKI = false;
Expand All @@ -82,15 +87,17 @@ public KeyStoreTableColumns() {
}

public KeyStoreTableColumns(boolean bEnableEntryName, boolean bEnableAlgorithm, boolean bEnableKeySize,
boolean bEnableCertificateExpiry, boolean bEnableLastModified, boolean bEnableSKI,
boolean bEnableAKI, boolean bEnableIssuerDN, boolean bEnableSubjectDN,
boolean bEnableIssuerCN, boolean bEnableSubjectCN, boolean bEnableIssuerO,
boolean bEnableSubjectO, boolean bEnableCurve, int expiryWarnDays,
boolean bEnableSerialNumberHex, boolean bEnableSerialNumberDec) {
boolean bEnableCertificateValidityStart, boolean bEnableCertificateExpiry,
boolean bEnableLastModified, boolean bEnableSKI, boolean bEnableAKI,
boolean bEnableIssuerDN, boolean bEnableSubjectDN, boolean bEnableIssuerCN,
boolean bEnableSubjectCN, boolean bEnableIssuerO, boolean bEnableSubjectO,
boolean bEnableCurve, int expiryWarnDays, boolean bEnableSerialNumberHex,
boolean bEnableSerialNumberDec) {
super();
this.bEnableEntryName = bEnableEntryName;
this.bEnableAlgorithm = bEnableAlgorithm;
this.bEnableKeySize = bEnableKeySize;
this.bEnableCertificateValidityStart = bEnableCertificateValidityStart;
this.bEnableCertificateExpiry = bEnableCertificateExpiry;
this.bEnableLastModified = bEnableLastModified;
this.bEnableSKI = bEnableSKI;
Expand All @@ -114,6 +121,7 @@ private void sortCol() {
iAlgorithmColumn = -1;
iKeySizeColumn = -1;
iCurveColumn = -1;
iCertValidityStartColumn = -1;
iCertExpiryColumn = -1;
iLastModifiedColumn = -1;
iAKIColumn = -1;
Expand All @@ -139,6 +147,9 @@ private void sortCol() {
if (bEnableCurve) {
iCurveColumn = ++col;
}
if (bEnableCertificateValidityStart) {
iCertValidityStartColumn = ++col;
}
if (bEnableCertificateExpiry) {
iCertExpiryColumn = ++col;
}
Expand Down Expand Up @@ -178,14 +189,15 @@ private void sortCol() {
}

public void setColumns(boolean bEnableEntryName, boolean bEnableAlgorithm, boolean bEnableKeySize,
boolean bEnableCertificateExpiry, boolean bEnableLastModified, boolean bEnableSKI,
boolean bEnableAKI, boolean bEnableIssuerDN, boolean bEnableSubjectDN,
boolean bEnableIssuerCN, boolean bEnableSubjectCN, boolean bEnableIssuerO,
boolean bEnableSubjectO, boolean bEnableCurve, boolean bEnableSerialNumberHex,
boolean bEnableSerialNumberDec, int expiryWarnDays) {
boolean bEnableCertificateValidityStart, boolean bEnableCertificateExpiry,
boolean bEnableLastModified, boolean bEnableSKI, boolean bEnableAKI, boolean bEnableIssuerDN,
boolean bEnableSubjectDN, boolean bEnableIssuerCN, boolean bEnableSubjectCN,
boolean bEnableIssuerO, boolean bEnableSubjectO, boolean bEnableCurve,
boolean bEnableSerialNumberHex, boolean bEnableSerialNumberDec, int expiryWarnDays) {
this.bEnableEntryName = bEnableEntryName;
this.bEnableAlgorithm = bEnableAlgorithm;
this.bEnableKeySize = bEnableKeySize;
this.bEnableCertificateValidityStart = bEnableCertificateValidityStart;
this.bEnableCertificateExpiry = bEnableCertificateExpiry;
this.bEnableLastModified = bEnableLastModified;
this.bEnableSKI = bEnableSKI;
Expand All @@ -210,22 +222,23 @@ public void setColumns(boolean bEnableEntryName, boolean bEnableAlgorithm, boole
*/
public void setColumns(int col) {

bEnableEntryName = ((col & 1) != 0);
bEnableAlgorithm = ((col & 2) != 0);
bEnableKeySize = ((col & 4) != 0);
bEnableCertificateExpiry = ((col & 8) != 0);
bEnableLastModified = ((col & 0x10) != 0);
bEnableSKI = ((col & 0x20) != 0);
bEnableAKI = ((col & 0x40) != 0);
bEnableIssuerDN = ((col & 0x80) != 0);
bEnableSubjectDN = ((col & 0x100) != 0);
bEnableCurve = ((col & 0x200) != 0);
bEnableIssuerCN = ((col & 0x400) != 0);
bEnableSubjectCN = ((col & 0x800) != 0);
bEnableIssuerO = ((col & 0x1000) != 0);
bEnableSubjectO = ((col & 0x2000) != 0);
bEnableSerialNumberHex = ((col & 0x4000) != 0);
bEnableSerialNumberDec = ((col & 0x8000) != 0);
bEnableEntryName = ((col & 1 << 0) != 0);
bEnableAlgorithm = ((col & 1 << 1) != 0);
bEnableKeySize = ((col & 1 << 2) != 0);
bEnableCertificateExpiry = ((col & 1 << 3) != 0);
bEnableLastModified = ((col & 1 << 4) != 0);
bEnableSKI = ((col & 1 << 5) != 0);
bEnableAKI = ((col & 1 << 6) != 0);
bEnableIssuerDN = ((col & 1 << 7) != 0);
bEnableSubjectDN = ((col & 1 << 8) != 0);
bEnableCurve = ((col & 1 << 9) != 0);
bEnableIssuerCN = ((col & 1 << 10) != 0);
bEnableSubjectCN = ((col & 1 << 11) != 0);
bEnableIssuerO = ((col & 1 << 12) != 0);
bEnableSubjectO = ((col & 1 << 13) != 0);
bEnableSerialNumberHex = ((col & 1 << 14) != 0);
bEnableSerialNumberDec = ((col & 1 << 15) != 0);
bEnableCertificateValidityStart = ((col & 1 << 16) != 0);
sortCol();
}

Expand All @@ -237,52 +250,55 @@ public void setColumns(int col) {
public int getColumns() {
int col = 0;
if (bEnableEntryName) {
col += 1;
col += 1 << 0;
}
if (bEnableAlgorithm) {
col += 2;
col += 1 << 1;
}
if (bEnableKeySize) {
col += 4;
col += 1 << 2;
}
if (bEnableCertificateExpiry) {
col += 8;
col += 1 << 3;
}
if (bEnableLastModified) {
col += 0x10;
col += 1 << 4;
}
if (bEnableSKI) {
col += 0x20;
col += 1 << 5;
}
if (bEnableAKI) {
col += 0x40;
col += 1 << 6;
}
if (bEnableIssuerDN) {
col += 0x80;
col += 1 << 7;
}
if (bEnableSubjectDN) {
col += 0x100;
col += 1 << 8;
}
if (bEnableCurve) {
col += 0x200;
col += 1 << 9;
}
if (bEnableIssuerCN) {
col += 0x400;
col += 1 << 10;
}
if (bEnableSubjectCN) {
col += 0x800;
col += 1 << 11;
}
if (bEnableIssuerO) {
col += 0x1000;
col += 1 << 12;
}
if (bEnableSubjectO) {
col += 0x2000;
col += 1 << 13;
}
if (bEnableSerialNumberHex) {
col += 0x4000;
col += 1 << 14;
}
if (bEnableSerialNumberDec) {
col += 0x8000;
col += 1 << 15;
}
if (bEnableCertificateValidityStart) {
col += 1 << 16;
}
return col;
}
Expand All @@ -293,56 +309,25 @@ public int getColumns() {
* @return number of columns selected
*/
public int getNofColumns() {
int col = 0;
if (bEnableEntryName) {
col++;
}
if (bEnableAlgorithm) {
col++;
}
if (bEnableKeySize) {
col++;
}
if (bEnableCertificateExpiry) {
col++;
}
if (bEnableLastModified) {
col++;
}
if (bEnableSKI) {
col++;
}
if (bEnableAKI) {
col++;
}
if (bEnableIssuerDN) {
col++;
}
if (bEnableSubjectDN) {
col++;
}
if (bEnableCurve) {
col++;
}
if (bEnableIssuerCN) {
col++;
}
if (bEnableSubjectCN) {
col++;
}
if (bEnableIssuerO) {
col++;
}
if (bEnableSubjectO) {
col++;
}
if (bEnableSerialNumberHex) {
col++;
}
if (bEnableSerialNumberDec) {
col++;
}
return col;
return Stream.of(
bEnableEntryName,
bEnableAlgorithm,
bEnableKeySize,
bEnableCertificateValidityStart,
bEnableCertificateExpiry,
bEnableLastModified,
bEnableSKI,
bEnableAKI,
bEnableIssuerDN,
bEnableSubjectDN,
bEnableCurve,
bEnableIssuerCN,
bEnableSubjectCN,
bEnableIssuerO,
bEnableSubjectO,
bEnableSerialNumberHex,
bEnableSerialNumberDec
).mapToInt(b -> b ? 1 : 0).sum();
}

public boolean getEnableEntryName() {
Expand All @@ -357,6 +342,10 @@ public boolean getEnableKeySize() {
return bEnableKeySize;
}

public boolean getEnableCertificateValidityStart() {
return bEnableCertificateValidityStart;
}

public boolean getEnableCertificateExpiry() {
return bEnableCertificateExpiry;
}
Expand Down Expand Up @@ -429,6 +418,10 @@ public int colKeySize() {
return iKeySizeColumn;
}

public int colCertificateValidityStart() {
return iCertValidityStartColumn;
}

public int colCertificateExpiry() {
return iCertExpiryColumn;
}
Expand Down
2 changes: 2 additions & 0 deletions kse/src/org/kse/gui/KeyStoreTableHeadRend.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ else if (col == 2) {
header.setToolTipText(res.getString("KeyStoreTableHeadRend.AlgorithmColumn.tooltip"));
} else if (col == keyStoreTableColumns.colKeySize()) {
header.setToolTipText(res.getString("KeyStoreTableHeadRend.KeySizeColumn.tooltip"));
} else if (col == keyStoreTableColumns.colCertificateValidityStart()) {
header.setToolTipText(res.getString("KeyStoreTableHeadRend.CertValidityStartColumn.tooltip"));
} else if (col == keyStoreTableColumns.colCertificateExpiry()) {
header.setToolTipText(res.getString("KeyStoreTableHeadRend.CertExpiryColumn.tooltip"));
} else if (col == keyStoreTableColumns.colLastModified()) {
Expand Down
33 changes: 33 additions & 0 deletions kse/src/org/kse/gui/KeyStoreTableModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public class KeyStoreTableModel extends AbstractTableModel {
private int iAlgorithmColumn = -1;
private int iKeySizeColumn = -1;
private int iCurveColumn = -1;
private int iCertValidityStartColumn = -1;
private int iCertExpiryColumn = -1;
private int iLastModifiedColumn = -1;
private int iAKIColumn = -1;
Expand Down Expand Up @@ -232,6 +233,15 @@ public void load(KeyStoreHistory history) throws GeneralSecurityException, Crypt
}
}
}
if (iCertValidityStartColumn > 0) {
Date validityStart = getCertificateValidityStart(alias, keyStore);
// Validity start date column
if (validityStart != null) {
data[i][iCertValidityStartColumn] = validityStart;
} else {
data[i][iCertValidityStartColumn] = null; // No validity start date - must be a key entry
}
}
if (iCertExpiryColumn > 0) {
// Expiry date column
if (expiry != null) {
Expand Down Expand Up @@ -356,6 +366,22 @@ public void load(KeyStoreHistory history) throws GeneralSecurityException, Crypt
fireTableDataChanged();
}

private Date getCertificateValidityStart(String alias, KeyStore keyStore) throws CryptoException, KeyStoreException {
if (KeyStoreUtil.isTrustedCertificateEntry(alias, keyStore)) {
return X509CertUtil.convertCertificate(keyStore.getCertificate(alias)).getNotBefore();
} else {
Certificate[] chain = keyStore.getCertificateChain(alias);

if (chain == null) {
return null; // Key entry - no validity start date
}

// Key pair - first certificate in chain will be for the private key
X509Certificate[] x509Chain = X509CertUtil.orderX509CertChain(X509CertUtil.convertCertificates(chain));
return x509Chain[0].getNotBefore();
}
}

private Date getCertificateExpiry(String alias, KeyStore keyStore) throws CryptoException, KeyStoreException {
if (KeyStoreUtil.isTrustedCertificateEntry(alias, keyStore)) {
return X509CertUtil.convertCertificate(keyStore.getCertificate(alias)).getNotAfter();
Expand Down Expand Up @@ -529,6 +555,7 @@ private void adjustColumns(KeyStoreTableColumns keyStoreTableColumnsParm) {
iAlgorithmColumn = -1;
iKeySizeColumn = -1;
iCurveColumn = -1;
iCertValidityStartColumn = -1;
iCertExpiryColumn = -1;
iLastModifiedColumn = -1;
iAKIColumn = -1;
Expand Down Expand Up @@ -575,6 +602,12 @@ private void adjustColumns(KeyStoreTableColumns keyStoreTableColumnsParm) {
columnTypes[col] = String.class;
iCurveColumn = col;
}
if (col == keyStoreTableColumns.colCertificateValidityStart()) {
columnNames[col] = res.getString("KeyStoreTableModel.CertValidityStartColumn");
columnTypes[col] = Date.class;
iCertValidityStartColumn = col;
iColWidth[col] = " 20.00.2000 00:00:00 MESZ ".length();
}
if (col == keyStoreTableColumns.colCertificateExpiry()) {
columnNames[col] = res.getString("KeyStoreTableModel.CertExpiryColumn");
columnTypes[col] = Date.class;
Expand Down
Loading

0 comments on commit d607d1b

Please sign in to comment.