pki-bot / pki-issues-final

0 stars 0 forks source link

Unable to remove user cert via console #181

Open pki-bot opened 4 years ago

pki-bot commented 4 years ago

This issue was migrated from Pagure Issue #181. Originally filed by edewata (@edewata) on 2012-05-22 17:36:55:


Console generates the following exception when removing a user certificate:

Exception in thread "AWT-EventQueue-0" java.lang.StringIndexOutOfBoundsException: String index out of range: -4
    at java.lang.String.substring(String.java:1958)
    at com.netscape.admin.certsrv.ug.CertManagementDialog.toServerFormat(CertManagementDialog.java:334)
    at com.netscape.admin.certsrv.ug.CertManagementDialog.deleteCert(CertManagementDialog.java:423)
    at com.netscape.admin.certsrv.ug.CertManagementDialog.actionPerformed(CertManagementDialog.java:130)
    ...

It looks like in CertManagementDialog.java:334 the code is trying to get the serial number from a string but the string doesn't have it.

pki-bot commented 4 years ago

Comment from edewata (@edewata) at 2012-05-22 18:44:22

The problem only happens with large serial number such as "12512514865863765114". In CertManagementDialog?.java:368 the console tries to parse the serial number that it receives from the server as an integer:

try {
    if (serial != null) {
        String hexserial = Integer.toHexString(Integer.parseInt(serial));
        name = name + "Serial:0x"+hexserial;
    }
} catch (Exception e) {}

If the serial number is outside the integer range the parseInt() throws a number format exception, so the serial number is not added to the string that's going to be read by line 334 above, causing the original problem. Also, the exception is swallowed by the code, so the problem is undetected until you try to remove a certificate.

So the integer parsing should be replaced with BigInteger (or SerialNumber class) and the exception should be handled properly (e.g. generating error dialog).

pki-bot commented 4 years ago

Comment from edewata (@edewata) at 2017-02-27 14:10:06

Metadata Update from @edewata: