Skip to content

Commit

Permalink
Improved layout of DViewCrl; changed more dialogs to use X509CertUtil…
Browse files Browse the repository at this point in the history
….getSerialNumberAsHex()
  • Loading branch information
kaikramer committed Oct 28, 2023
1 parent 0e0507a commit eb612d5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 54 deletions.
3 changes: 1 addition & 2 deletions kse/src/org/kse/gui/dialogs/DCompareCertificates.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,7 @@ private String getIssuer(X509Certificate certificate) {

private String getSerialNumber(X509Certificate certificate) {
String serialNumber = MessageFormat.format(res.getString("DProperties.properties.SerialNumber"),
new BigInteger(certificate.getSerialNumber().toByteArray()).toString(
16).toUpperCase());
X509CertUtil.getSerialNumberAsHex(certificate));
return serialNumber;
}

Expand Down
4 changes: 1 addition & 3 deletions kse/src/org/kse/gui/dialogs/DProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,7 @@ private void populateCertificateNode(DefaultMutableTreeNode certificateNode, X50
certificateNode.add(new DefaultMutableTreeNode(issuer));

String serialNumber = MessageFormat.format(res.getString("DProperties.properties.SerialNumber"),
new BigInteger(
certificate.getSerialNumber().toByteArray()).toString(16)
.toUpperCase());
X509CertUtil.getSerialNumberAsHex(certificate));
certificateNode.add(new DefaultMutableTreeNode(serialNumber));

Date validFromDate = certificate.getNotBefore();
Expand Down
40 changes: 11 additions & 29 deletions kse/src/org/kse/gui/dialogs/DViewCrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
package org.kse.gui.dialogs;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dialog;
Expand All @@ -43,17 +42,14 @@
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.RowSorter;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingUtilities;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.table.TableColumn;
import javax.swing.table.TableRowSorter;

Expand All @@ -62,7 +58,6 @@
import org.kse.crypto.x509.X509CertUtil;
import org.kse.gui.CursorUtil;
import org.kse.gui.JEscDialog;
import org.kse.gui.JKseTable;
import org.kse.gui.PlatformUtil;
import org.kse.gui.crypto.JDistinguishedName;
import org.kse.gui.dialogs.extensions.DViewExtensions;
Expand All @@ -81,9 +76,7 @@ public class DViewCrl extends JEscDialog {

private static ResourceBundle res = ResourceBundle.getBundle("org/kse/gui/dialogs/resources");

private JPanel jpOK;
private JButton jbOK;
private JPanel jpCRL;
private JLabel jlVersion;
private JTextField jtfVersion;
private JLabel jlIssuer;
Expand All @@ -94,14 +87,11 @@ public class DViewCrl extends JEscDialog {
private JTextField jtfNextUpdate;
private JLabel jlSignatureAlgorithm;
private JTextField jtfSignatureAlgorithm;
private JPanel jpCrlButtons;
private JButton jbCrlExtensions;
private JButton jbCrlAsn1;
private JPanel jpRevokedCertsTable;
private JLabel jlRevokedCerts;
private JScrollPane jspRevokedCertsTable;
private JKseTable jtRevokedCerts;
private JPanel jpCrlEntryExtensions;
private JTable jtRevokedCerts;
private JButton jbCrlEntryExtensions;

private X509CRL crl;
Expand Down Expand Up @@ -136,7 +126,7 @@ public DViewCrl(JDialog parent, String title, Dialog.ModalityType modality, X509
private void initComponents() {
jlVersion = new JLabel(res.getString("DViewCrl.jlVersion.text"));

jtfVersion = new JTextField(3);
jtfVersion = new JTextField(30);
jtfVersion.setEditable(false);
jtfVersion.setToolTipText(res.getString("DViewCrl.jtfVersion.tooltip"));

Expand All @@ -159,7 +149,7 @@ private void initComponents() {

jlSignatureAlgorithm = new JLabel(res.getString("DViewCrl.jlSignatureAlgorithm.text"));

jtfSignatureAlgorithm = new JTextField(15);
jtfSignatureAlgorithm = new JTextField(30);
jtfSignatureAlgorithm.setEditable(false);
jtfSignatureAlgorithm.setToolTipText(res.getString("DViewCrl.jtfSignatureAlgorithm.tooltip"));

Expand Down Expand Up @@ -194,7 +184,7 @@ private void initComponents() {

RevokedCertsTableModel rcModel = new RevokedCertsTableModel();

jtRevokedCerts = new JKseTable(rcModel);
jtRevokedCerts = new JTable(rcModel);

RowSorter<RevokedCertsTableModel> sorter = new TableRowSorter<>(rcModel);
jtRevokedCerts.setRowSorter(sorter);
Expand All @@ -203,13 +193,13 @@ private void initComponents() {
jtRevokedCerts.setRowMargin(0);
jtRevokedCerts.getColumnModel().setColumnMargin(0);
jtRevokedCerts.getTableHeader().setReorderingAllowed(false);
jtRevokedCerts.setAutoResizeMode(JKseTable.AUTO_RESIZE_ALL_COLUMNS);
jtRevokedCerts.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);

for (int i = 0; i < jtRevokedCerts.getColumnCount(); i++) {
TableColumn column = jtRevokedCerts.getColumnModel().getColumn(i);

if (i == 0) {
column.setPreferredWidth(100);
column.setPreferredWidth(150);
}

column.setHeaderRenderer(
Expand Down Expand Up @@ -240,12 +230,7 @@ public void mouseClicked(MouseEvent evt) {
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
jspRevokedCertsTable.getViewport().setBackground(jtRevokedCerts.getBackground());

jpRevokedCertsTable = new JPanel(new BorderLayout(10, 10));
jpRevokedCertsTable.setPreferredSize(new Dimension(100, 200));
jpRevokedCertsTable.add(jlRevokedCerts, BorderLayout.NORTH);
jpRevokedCertsTable.add(jspRevokedCertsTable, BorderLayout.CENTER);
jpRevokedCertsTable.setBorder(new CompoundBorder(new EtchedBorder(), new EmptyBorder(5, 5, 5, 5)));
jspRevokedCertsTable.setPreferredSize(new Dimension(300, 200));

jbCrlEntryExtensions = new JButton(res.getString("DViewCrl.jbCrlEntryExtensions.text"));

Expand Down Expand Up @@ -282,7 +267,7 @@ public void mouseClicked(MouseEvent evt) {
pane.add(jbCrlAsn1, "wrap unrel");
pane.add(new JSeparator(), "spanx, growx, wrap");
pane.add(jlRevokedCerts, "split, wrap");
pane.add(jpRevokedCertsTable, "split, spanx, growx, wrap");
pane.add(jspRevokedCertsTable, "split, spanx, growx, wrap");
pane.add(jbCrlEntryExtensions, "split, spanx, right, wrap");
pane.add(new JSeparator(), "spanx, growx, wrap");
pane.add(jbOK, "split, spanx, right, tag ok");
Expand Down Expand Up @@ -367,11 +352,8 @@ private void populateDialog() {
Set<?> critExts = crl.getCriticalExtensionOIDs();
Set<?> nonCritExts = crl.getNonCriticalExtensionOIDs();

if ((critExts != null && !critExts.isEmpty()) || (nonCritExts != null && !nonCritExts.isEmpty())) {
jbCrlExtensions.setEnabled(true);
} else {
jbCrlExtensions.setEnabled(false);
}
jbCrlExtensions.setEnabled(
(critExts != null && !critExts.isEmpty()) || (nonCritExts != null && !nonCritExts.isEmpty()));

Set<? extends X509CRLEntry> revokedCertsSet = crl.getRevokedCertificates();
if (revokedCertsSet == null) {
Expand Down
22 changes: 2 additions & 20 deletions kse/src/org/kse/gui/dialogs/RevokedCertsTableCellRend.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import javax.swing.table.DefaultTableCellRenderer;

import org.kse.utilities.StringUtils;
import org.kse.utilities.io.HexUtil;

/**
* Custom cell renderer for the cells of the RevokedCerts table of DViewCrl.
Expand All @@ -55,7 +56,7 @@ public Component getTableCellRendererComponent(JTable jtRevokedCerts, Object val
col);

if (col == 0) {
cell.setText(formatSerialNumberAsHexString((BigInteger) value));
cell.setText(HexUtil.getHexString((BigInteger) value, "0x", 4, 0));
} else {
cell.setText(StringUtils.formatDate((Date) value));
}
Expand All @@ -64,23 +65,4 @@ public Component getTableCellRendererComponent(JTable jtRevokedCerts, Object val

return cell;
}

private String formatSerialNumberAsHexString(BigInteger serialNumber) {
// The string is divided by spaces into groups of four hex characters.
String hexSerialNumber = serialNumber.toString(16).toUpperCase();

StringBuilder strBuff = new StringBuilder();

strBuff.append("0x");

for (int i = 0; i < hexSerialNumber.length(); i++) {
strBuff.append(hexSerialNumber.charAt(i));

if ((i + 1) % 4 == 0 && i + 1 != hexSerialNumber.length()) {
strBuff.append(' ');
}
}

return strBuff.toString();
}
}

0 comments on commit eb612d5

Please sign in to comment.