diff options
Diffstat (limited to 'base/util/src')
9 files changed, 596 insertions, 635 deletions
diff --git a/base/util/src/com/netscape/cmsutil/ocsp/BasicOCSPResponse.java b/base/util/src/com/netscape/cmsutil/ocsp/BasicOCSPResponse.java index 52535d3d0..1b8273eda 100644 --- a/base/util/src/com/netscape/cmsutil/ocsp/BasicOCSPResponse.java +++ b/base/util/src/com/netscape/cmsutil/ocsp/BasicOCSPResponse.java @@ -61,23 +61,19 @@ public class BasicOCSPResponse implements Response { _certs = certs; } - public BasicOCSPResponse(OCTET_STRING os) { + public BasicOCSPResponse(OCTET_STRING os) throws InvalidBERException, IOException { this(os.toByteArray()); } - public BasicOCSPResponse(byte data[]) { + public BasicOCSPResponse(byte data[]) throws InvalidBERException, IOException { mData = data; // extract _rd, _signAlg, _signature and _certs - try { - BasicOCSPResponse resp = (BasicOCSPResponse) getTemplate().decode(new ByteArrayInputStream(data)); - _rd = resp.getResponseData(); - _signAlg = resp.getSignatureAlgorithm(); - _signature = resp.getSignature(); - _certs = resp.getCerts(); - } catch (Exception e) { - // exception in decoding byte data - } + BasicOCSPResponse resp = (BasicOCSPResponse) getTemplate().decode(new ByteArrayInputStream(data)); + _rd = resp.getResponseData(); + _signAlg = resp.getSignatureAlgorithm(); + _signature = resp.getSignature(); + _certs = resp.getCerts(); } private static final Tag TAG = SEQUENCE.TAG; diff --git a/base/util/src/com/netscape/cmsutil/scep/CRSPKIMessage.java b/base/util/src/com/netscape/cmsutil/scep/CRSPKIMessage.java index de6cb20aa..afde8b6c1 100644 --- a/base/util/src/com/netscape/cmsutil/scep/CRSPKIMessage.java +++ b/base/util/src/com/netscape/cmsutil/scep/CRSPKIMessage.java @@ -484,9 +484,12 @@ public class CRSPKIMessage { return baos.toByteArray(); // return crsd.getEncodedContents(); - } catch (Exception e) { - return null; + } catch (InvalidBERException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); } + return null; } public String toString() { diff --git a/base/util/src/com/netscape/cmsutil/util/Utils.java b/base/util/src/com/netscape/cmsutil/util/Utils.java index c8d6b438d..98becdc4c 100644 --- a/base/util/src/com/netscape/cmsutil/util/Utils.java +++ b/base/util/src/com/netscape/cmsutil/util/Utils.java @@ -87,9 +87,12 @@ public class Utils { **/ return false; } - } catch (Exception e) { - return false; + } catch (IOException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); } + return false; } public static String SpecialURLDecode(String s) { diff --git a/base/util/src/netscape/security/util/CertPrettyPrint.java b/base/util/src/netscape/security/util/CertPrettyPrint.java index a72f0d4fb..34dda33b6 100644 --- a/base/util/src/netscape/security/util/CertPrettyPrint.java +++ b/base/util/src/netscape/security/util/CertPrettyPrint.java @@ -336,6 +336,7 @@ public class CertPrettyPrint { sb.append(certFingerprints.toString()); } catch (Exception e) { + e.printStackTrace(); } return sb.toString(); diff --git a/base/util/src/netscape/security/util/ExtPrettyPrint.java b/base/util/src/netscape/security/util/ExtPrettyPrint.java index d40379e7d..0788e1905 100644 --- a/base/util/src/netscape/security/util/ExtPrettyPrint.java +++ b/base/util/src/netscape/security/util/ExtPrettyPrint.java @@ -17,7 +17,9 @@ // --- END COPYRIGHT BLOCK --- package netscape.security.util; +import java.io.IOException; import java.math.BigInteger; +import java.security.cert.CertificateException; import java.text.DateFormat; import java.util.Enumeration; import java.util.ResourceBundle; @@ -218,34 +220,31 @@ public class ExtPrettyPrint { } //unknown cert extension - try { - String extName = OIDMap.getName(mExt.getExtensionId()); + String extName = OIDMap.getName(mExt.getExtensionId()); - if (extName == null) - sb.append(pp.indent(mIndentSize) + mResource.getString( - PrettyPrintResources.TOKEN_IDENTIFIER) + - mExt.getExtensionId().toString() + "\n"); - else - sb.append(pp.indent(mIndentSize) + mResource.getString( - PrettyPrintResources.TOKEN_IDENTIFIER) + " " + extName + " - " + - mExt.getExtensionId().toString() + "\n"); + if (extName == null) + sb.append(pp.indent(mIndentSize) + mResource.getString( + PrettyPrintResources.TOKEN_IDENTIFIER) + + mExt.getExtensionId().toString() + "\n"); + else + sb.append(pp.indent(mIndentSize) + mResource.getString( + PrettyPrintResources.TOKEN_IDENTIFIER) + " " + extName + " - " + + mExt.getExtensionId().toString() + "\n"); - sb.append(pp.indent(mIndentSize + 4) + mResource.getString( - PrettyPrintResources.TOKEN_CRITICAL)); - if (mExt.isCritical()) { - sb.append(mResource.getString( - PrettyPrintResources.TOKEN_YES) + "\n"); - } else { - sb.append(mResource.getString( - PrettyPrintResources.TOKEN_NO) + "\n"); - } - sb.append(pp.indent(mIndentSize + 4) + mResource.getString( - PrettyPrintResources.TOKEN_VALUE) + "\n"); - sb.append(pp.toHexString(mExt.getExtensionValue(), mIndentSize + 8, 16)); - return sb.toString(); - } catch (Exception e) { - return ""; + sb.append(pp.indent(mIndentSize + 4) + mResource.getString( + PrettyPrintResources.TOKEN_CRITICAL)); + if (mExt.isCritical()) { + sb.append(mResource.getString( + PrettyPrintResources.TOKEN_YES) + "\n"); + } else { + sb.append(mResource.getString( + PrettyPrintResources.TOKEN_NO) + "\n"); } + sb.append(pp.indent(mIndentSize + 4) + mResource.getString( + PrettyPrintResources.TOKEN_VALUE) + "\n"); + sb.append(pp.toHexString(mExt.getExtensionValue(), mIndentSize + 8, 16)); + + return sb.toString(); } @@ -256,268 +255,235 @@ public class ExtPrettyPrint { private String getNSCCommentExtension() { StringBuffer sb = new StringBuffer(); - try { - sb.append(pp.indent(mIndentSize) + mResource.getString( - PrettyPrintResources.TOKEN_IDENTIFIER)); - sb.append(mResource.getString(PrettyPrintResources.TOKEN_NSC_COMMENT) + - "- " + mExt.getExtensionId().toString() + "\n"); - sb.append(pp.indent(mIndentSize + 4) + mResource.getString( - PrettyPrintResources.TOKEN_CRITICAL)); - if (mExt.isCritical()) { - sb.append(mResource.getString( - PrettyPrintResources.TOKEN_YES) + "\n"); - } else { - sb.append(mResource.getString( - PrettyPrintResources.TOKEN_NO) + "\n"); - } - sb.append(pp.indent(mIndentSize + 4) + ((NSCCommentExtension) mExt).toPrint(mIndentSize) + "\n"); - return sb.toString(); - } catch (Exception e) { - return sb.toString(); + sb.append(pp.indent(mIndentSize) + mResource.getString( + PrettyPrintResources.TOKEN_IDENTIFIER)); + sb.append(mResource.getString(PrettyPrintResources.TOKEN_NSC_COMMENT) + + "- " + mExt.getExtensionId().toString() + "\n"); + sb.append(pp.indent(mIndentSize + 4) + mResource.getString( + PrettyPrintResources.TOKEN_CRITICAL)); + if (mExt.isCritical()) { + sb.append(mResource.getString( + PrettyPrintResources.TOKEN_YES) + "\n"); + } else { + sb.append(mResource.getString( + PrettyPrintResources.TOKEN_NO) + "\n"); } + sb.append(pp.indent(mIndentSize + 4) + ((NSCCommentExtension) mExt).toPrint(mIndentSize) + "\n"); + return sb.toString(); } private String getNameConstraintsExtension() { StringBuffer sb = new StringBuffer(); - try { - sb.append(pp.indent(mIndentSize) + mResource.getString( - PrettyPrintResources.TOKEN_IDENTIFIER)); - sb.append(mResource.getString(PrettyPrintResources.TOKEN_NAME_CONSTRAINTS) + - "- " + mExt.getExtensionId().toString() + "\n"); - sb.append(pp.indent(mIndentSize + 4) + mResource.getString( - PrettyPrintResources.TOKEN_CRITICAL)); - if (mExt.isCritical()) { - sb.append(mResource.getString( - PrettyPrintResources.TOKEN_YES) + "\n"); - } else { - sb.append(mResource.getString( - PrettyPrintResources.TOKEN_NO) + "\n"); - } + sb.append(pp.indent(mIndentSize) + mResource.getString( + PrettyPrintResources.TOKEN_IDENTIFIER)); + sb.append(mResource.getString(PrettyPrintResources.TOKEN_NAME_CONSTRAINTS) + + "- " + mExt.getExtensionId().toString() + "\n"); + sb.append(pp.indent(mIndentSize + 4) + mResource.getString( + PrettyPrintResources.TOKEN_CRITICAL)); + if (mExt.isCritical()) { + sb.append(mResource.getString( + PrettyPrintResources.TOKEN_YES) + "\n"); + } else { + sb.append(mResource.getString( + PrettyPrintResources.TOKEN_NO) + "\n"); + } - sb.append(pp.indent(mIndentSize + 4) + ((NameConstraintsExtension) mExt).toPrint(mIndentSize + 4)); + sb.append(pp.indent(mIndentSize + 4) + ((NameConstraintsExtension) mExt).toPrint(mIndentSize + 4)); - return sb.toString(); - } catch (Exception e) { - return sb.toString(); - } + return sb.toString(); } private String getOCSPNoCheckExtension() { StringBuffer sb = new StringBuffer(); - try { - sb.append(pp.indent(mIndentSize) + mResource.getString( - PrettyPrintResources.TOKEN_IDENTIFIER)); - sb.append(mResource.getString(PrettyPrintResources.TOKEN_OCSP_NOCHECK) + - "- " + mExt.getExtensionId().toString() + "\n"); - sb.append(pp.indent(mIndentSize + 4) + mResource.getString( - PrettyPrintResources.TOKEN_CRITICAL)); - if (mExt.isCritical()) { - sb.append(mResource.getString( - PrettyPrintResources.TOKEN_YES) + "\n"); - } else { - sb.append(mResource.getString( - PrettyPrintResources.TOKEN_NO) + "\n"); - } - return sb.toString(); - } catch (Exception e) { - return sb.toString(); + sb.append(pp.indent(mIndentSize) + mResource.getString( + PrettyPrintResources.TOKEN_IDENTIFIER)); + sb.append(mResource.getString(PrettyPrintResources.TOKEN_OCSP_NOCHECK) + + "- " + mExt.getExtensionId().toString() + "\n"); + sb.append(pp.indent(mIndentSize + 4) + mResource.getString( + PrettyPrintResources.TOKEN_CRITICAL)); + if (mExt.isCritical()) { + sb.append(mResource.getString( + PrettyPrintResources.TOKEN_YES) + "\n"); + } else { + sb.append(mResource.getString( + PrettyPrintResources.TOKEN_NO) + "\n"); } + return sb.toString(); } private String getSubjectInfoAccessExtension() { StringBuffer sb = new StringBuffer(); - try { - sb.append(pp.indent(mIndentSize) + mResource.getString( - PrettyPrintResources.TOKEN_IDENTIFIER)); - sb.append(mResource.getString(PrettyPrintResources.TOKEN_SIA) + - "- " + mExt.getExtensionId().toString() + "\n"); - sb.append(pp.indent(mIndentSize + 4) + mResource.getString( - PrettyPrintResources.TOKEN_CRITICAL)); - if (mExt.isCritical()) { - sb.append(mResource.getString( - PrettyPrintResources.TOKEN_YES) + "\n"); - } else { - sb.append(mResource.getString( - PrettyPrintResources.TOKEN_NO) + "\n"); - } - sb.append(pp.indent(mIndentSize + 4) + mResource.getString( - PrettyPrintResources.TOKEN_ACCESS_DESC) + "\n"); - SubjectInfoAccessExtension aia = (SubjectInfoAccessExtension) mExt; + sb.append(pp.indent(mIndentSize) + mResource.getString( + PrettyPrintResources.TOKEN_IDENTIFIER)); + sb.append(mResource.getString(PrettyPrintResources.TOKEN_SIA) + + "- " + mExt.getExtensionId().toString() + "\n"); + sb.append(pp.indent(mIndentSize + 4) + mResource.getString( + PrettyPrintResources.TOKEN_CRITICAL)); + if (mExt.isCritical()) { + sb.append(mResource.getString( + PrettyPrintResources.TOKEN_YES) + "\n"); + } else { + sb.append(mResource.getString( + PrettyPrintResources.TOKEN_NO) + "\n"); + } + sb.append(pp.indent(mIndentSize + 4) + mResource.getString( + PrettyPrintResources.TOKEN_ACCESS_DESC) + "\n"); + SubjectInfoAccessExtension aia = (SubjectInfoAccessExtension) mExt; - for (int i = 0; i < aia.numberOfAccessDescription(); i++) { - AccessDescription ad = aia.getAccessDescription(i); - ObjectIdentifier method = ad.getMethod(); + for (int i = 0; i < aia.numberOfAccessDescription(); i++) { + AccessDescription ad = aia.getAccessDescription(i); + ObjectIdentifier method = ad.getMethod(); - if (method.equals(SubjectInfoAccessExtension.METHOD_OCSP)) { - sb.append(pp.indent(mIndentSize + 8) + "Method #" + i + ": " + - "ocsp" + "\n"); - } else { - sb.append(pp.indent(mIndentSize + 8) + "Method #" + i + ": " + - method.toString() + "\n"); - } - sb.append(pp.indent(mIndentSize + 8) + "Location #" + i + ": " + - ad.getLocation().toString() + "\n"); + if (method.equals(SubjectInfoAccessExtension.METHOD_OCSP)) { + sb.append(pp.indent(mIndentSize + 8) + "Method #" + i + ": " + + "ocsp" + "\n"); + } else { + sb.append(pp.indent(mIndentSize + 8) + "Method #" + i + ": " + + method.toString() + "\n"); } - return sb.toString(); - } catch (Exception e) { - return sb.toString(); + sb.append(pp.indent(mIndentSize + 8) + "Location #" + i + ": " + + ad.getLocation().toString() + "\n"); } + return sb.toString(); } private String getAuthInfoAccessExtension() { StringBuffer sb = new StringBuffer(); - try { - sb.append(pp.indent(mIndentSize) + mResource.getString( - PrettyPrintResources.TOKEN_IDENTIFIER)); - sb.append(mResource.getString(PrettyPrintResources.TOKEN_AIA) + - "- " + mExt.getExtensionId().toString() + "\n"); - sb.append(pp.indent(mIndentSize + 4) + mResource.getString( - PrettyPrintResources.TOKEN_CRITICAL)); - if (mExt.isCritical()) { - sb.append(mResource.getString( - PrettyPrintResources.TOKEN_YES) + "\n"); - } else { - sb.append(mResource.getString( - PrettyPrintResources.TOKEN_NO) + "\n"); - } - sb.append(pp.indent(mIndentSize + 4) + mResource.getString( - PrettyPrintResources.TOKEN_ACCESS_DESC) + "\n"); - AuthInfoAccessExtension aia = (AuthInfoAccessExtension) mExt; + sb.append(pp.indent(mIndentSize) + mResource.getString( + PrettyPrintResources.TOKEN_IDENTIFIER)); + sb.append(mResource.getString(PrettyPrintResources.TOKEN_AIA) + + "- " + mExt.getExtensionId().toString() + "\n"); + sb.append(pp.indent(mIndentSize + 4) + mResource.getString( + PrettyPrintResources.TOKEN_CRITICAL)); + if (mExt.isCritical()) { + sb.append(mResource.getString( + PrettyPrintResources.TOKEN_YES) + "\n"); + } else { + sb.append(mResource.getString( + PrettyPrintResources.TOKEN_NO) + "\n"); + } + sb.append(pp.indent(mIndentSize + 4) + mResource.getString( + PrettyPrintResources.TOKEN_ACCESS_DESC) + "\n"); + AuthInfoAccessExtension aia = (AuthInfoAccessExtension) mExt; - for (int i = 0; i < aia.numberOfAccessDescription(); i++) { - AccessDescription ad = aia.getAccessDescription(i); - ObjectIdentifier method = ad.getMethod(); + for (int i = 0; i < aia.numberOfAccessDescription(); i++) { + AccessDescription ad = aia.getAccessDescription(i); + ObjectIdentifier method = ad.getMethod(); - if (method.equals(AuthInfoAccessExtension.METHOD_OCSP)) { - sb.append(pp.indent(mIndentSize + 8) + "Method #" + i + ": " + - "ocsp" + "\n"); - } else { - sb.append(pp.indent(mIndentSize + 8) + "Method #" + i + ": " + - method.toString() + "\n"); - } - sb.append(pp.indent(mIndentSize + 8) + "Location #" + i + ": " + - ad.getLocation().toString() + "\n"); + if (method.equals(AuthInfoAccessExtension.METHOD_OCSP)) { + sb.append(pp.indent(mIndentSize + 8) + "Method #" + i + ": " + + "ocsp" + "\n"); + } else { + sb.append(pp.indent(mIndentSize + 8) + "Method #" + i + ": " + + method.toString() + "\n"); } - return sb.toString(); - } catch (Exception e) { - return sb.toString(); + sb.append(pp.indent(mIndentSize + 8) + "Location #" + i + ": " + + ad.getLocation().toString() + "\n"); } + return sb.toString(); } private String getPresenceServerExtension() { StringBuffer sb = new StringBuffer(); - try { - sb.append(pp.indent(mIndentSize) + mResource.getString( - PrettyPrintResources.TOKEN_IDENTIFIER)); - sb.append(mResource.getString(PrettyPrintResources.TOKEN_PRESENCE_SERVER) + - "- " + mExt.getExtensionId().toString() + "\n"); - sb.append(pp.indent(mIndentSize + 4) + mResource.getString( - PrettyPrintResources.TOKEN_CRITICAL)); - if (mExt.isCritical()) { - sb.append(mResource.getString( - PrettyPrintResources.TOKEN_YES) + "\n"); - } else { - sb.append(mResource.getString( - PrettyPrintResources.TOKEN_NO) + "\n"); - } + sb.append(pp.indent(mIndentSize) + mResource.getString( + PrettyPrintResources.TOKEN_IDENTIFIER)); + sb.append(mResource.getString(PrettyPrintResources.TOKEN_PRESENCE_SERVER) + + "- " + mExt.getExtensionId().toString() + "\n"); + sb.append(pp.indent(mIndentSize + 4) + mResource.getString( + PrettyPrintResources.TOKEN_CRITICAL)); + if (mExt.isCritical()) { + sb.append(mResource.getString( + PrettyPrintResources.TOKEN_YES) + "\n"); + } else { + sb.append(mResource.getString( + PrettyPrintResources.TOKEN_NO) + "\n"); + } - PresenceServerExtension pse = (PresenceServerExtension) mExt; + PresenceServerExtension pse = (PresenceServerExtension) mExt; - sb.append(pp.indent(mIndentSize + 4) + "Version : " + pse.getVersion() + "\n"); - sb.append(pp.indent(mIndentSize + 4) + "Street Address : " + pse.getStreetAddress() + "\n"); - sb.append(pp.indent(mIndentSize + 4) + "Telephone Number : " + pse.getTelephoneNumber() + "\n"); - sb.append(pp.indent(mIndentSize + 4) + "RFC822 Name : " + pse.getRFC822() + "\n"); - sb.append(pp.indent(mIndentSize + 4) + "ID : " + pse.getID() + "\n"); - sb.append(pp.indent(mIndentSize + 4) + "Host Name : " + pse.getHostName() + "\n"); - sb.append(pp.indent(mIndentSize + 4) + "Port Number : " + pse.getPortNumber() + "\n"); - sb.append(pp.indent(mIndentSize + 4) + "Max Users : " + pse.getMaxUsers() + "\n"); - sb.append(pp.indent(mIndentSize + 4) + "Service Level : " + pse.getServiceLevel() + "\n"); + sb.append(pp.indent(mIndentSize + 4) + "Version : " + pse.getVersion() + "\n"); + sb.append(pp.indent(mIndentSize + 4) + "Street Address : " + pse.getStreetAddress() + "\n"); + sb.append(pp.indent(mIndentSize + 4) + "Telephone Number : " + pse.getTelephoneNumber() + "\n"); + sb.append(pp.indent(mIndentSize + 4) + "RFC822 Name : " + pse.getRFC822() + "\n"); + sb.append(pp.indent(mIndentSize + 4) + "ID : " + pse.getID() + "\n"); + sb.append(pp.indent(mIndentSize + 4) + "Host Name : " + pse.getHostName() + "\n"); + sb.append(pp.indent(mIndentSize + 4) + "Port Number : " + pse.getPortNumber() + "\n"); + sb.append(pp.indent(mIndentSize + 4) + "Max Users : " + pse.getMaxUsers() + "\n"); + sb.append(pp.indent(mIndentSize + 4) + "Service Level : " + pse.getServiceLevel() + "\n"); - return sb.toString(); - } catch (Exception e) { - return sb.toString(); - } + return sb.toString(); } private String getPrivateKeyUsageExtension() { StringBuffer sb = new StringBuffer(); - try { - sb.append(pp.indent(mIndentSize) + mResource.getString( - PrettyPrintResources.TOKEN_IDENTIFIER)); - sb.append(mResource.getString(PrettyPrintResources.TOKEN_PRIVATE_KEY_USAGE) + - "- " + mExt.getExtensionId().toString() + "\n"); - sb.append(pp.indent(mIndentSize + 4) + mResource.getString( - PrettyPrintResources.TOKEN_CRITICAL)); - if (mExt.isCritical()) { - sb.append(mResource.getString( - PrettyPrintResources.TOKEN_YES) + "\n"); - } else { - sb.append(mResource.getString( - PrettyPrintResources.TOKEN_NO) + "\n"); - } + sb.append(pp.indent(mIndentSize) + mResource.getString( + PrettyPrintResources.TOKEN_IDENTIFIER)); + sb.append(mResource.getString(PrettyPrintResources.TOKEN_PRIVATE_KEY_USAGE) + + "- " + mExt.getExtensionId().toString() + "\n"); + sb.append(pp.indent(mIndentSize + 4) + mResource.getString( + PrettyPrintResources.TOKEN_CRITICAL)); + if (mExt.isCritical()) { + sb.append(mResource.getString( + PrettyPrintResources.TOKEN_YES) + "\n"); + } else { + sb.append(mResource.getString( + PrettyPrintResources.TOKEN_NO) + "\n"); + } - PrivateKeyUsageExtension usage = (PrivateKeyUsageExtension) mExt; + PrivateKeyUsageExtension usage = (PrivateKeyUsageExtension) mExt; - sb.append(pp.indent(mIndentSize + 4) + "Validity:\n"); + sb.append(pp.indent(mIndentSize + 4) + "Validity:\n"); - if (dateFormater == null) { - dateFormater = DateFormat.getDateInstance(DateFormat.FULL); - } - String notBefore = dateFormater.format(usage.getNotBefore()); - String notAfter = dateFormater.format(usage.getNotAfter()); + if (dateFormater == null) { + dateFormater = DateFormat.getDateInstance(DateFormat.FULL); + } + String notBefore = dateFormater.format(usage.getNotBefore()); + String notAfter = dateFormater.format(usage.getNotAfter()); - sb.append(pp.indent(mIndentSize + 8) + "Not Before: " + notBefore + "\n"); - sb.append(pp.indent(mIndentSize + 8) + "Not After: " + notAfter + "\n"); + sb.append(pp.indent(mIndentSize + 8) + "Not Before: " + notBefore + "\n"); + sb.append(pp.indent(mIndentSize + 8) + "Not After: " + notAfter + "\n"); - return sb.toString(); - } catch (Exception e) { - return sb.toString(); - } + return sb.toString(); } private String getExtendedKeyUsageExtension() { StringBuffer sb = new StringBuffer(); + sb.append(pp.indent(mIndentSize) + mResource.getString( + PrettyPrintResources.TOKEN_IDENTIFIER)); + sb.append(mResource.getString(PrettyPrintResources.TOKEN_EXTENDED_KEY_USAGE) + + "- " + mExt.getExtensionId().toString() + "\n"); + sb.append(pp.indent(mIndentSize + 4) + mResource.getString( + PrettyPrintResources.TOKEN_CRITICAL)); + if (mExt.isCritical()) { + sb.append(mResource.getString( + PrettyPrintResources.TOKEN_YES) + "\n"); + } else { + sb.append(mResource.getString( + PrettyPrintResources.TOKEN_NO) + "\n"); + } + sb.append(pp.indent(mIndentSize + 4) + mResource.getString( + PrettyPrintResources.TOKEN_EXTENDED_KEY_USAGE) + "\n"); + ExtendedKeyUsageExtension usage = (ExtendedKeyUsageExtension) mExt; + Enumeration<ObjectIdentifier> e = usage.getOIDs(); - try { - sb.append(pp.indent(mIndentSize) + mResource.getString( - PrettyPrintResources.TOKEN_IDENTIFIER)); - sb.append(mResource.getString(PrettyPrintResources.TOKEN_EXTENDED_KEY_USAGE) + - "- " + mExt.getExtensionId().toString() + "\n"); - sb.append(pp.indent(mIndentSize + 4) + mResource.getString( - PrettyPrintResources.TOKEN_CRITICAL)); - if (mExt.isCritical()) { - sb.append(mResource.getString( - PrettyPrintResources.TOKEN_YES) + "\n"); - } else { - sb.append(mResource.getString( - PrettyPrintResources.TOKEN_NO) + "\n"); - } - sb.append(pp.indent(mIndentSize + 4) + mResource.getString( - PrettyPrintResources.TOKEN_EXTENDED_KEY_USAGE) + "\n"); - ExtendedKeyUsageExtension usage = (ExtendedKeyUsageExtension) mExt; - Enumeration<ObjectIdentifier> e = usage.getOIDs(); - - if (e != null) { - while (e.hasMoreElements()) { - ObjectIdentifier oid = e.nextElement(); + if (e != null) { + while (e.hasMoreElements()) { + ObjectIdentifier oid = e.nextElement(); - if (oid.equals(ExtendedKeyUsageExtension.OID_OCSP_SIGNING)) { - sb.append(pp.indent(mIndentSize + 8) + "OCSPSigning" + "\n"); - } else { - sb.append(pp.indent(mIndentSize + 8) + oid.toString() + "\n"); - } + if (oid.equals(ExtendedKeyUsageExtension.OID_OCSP_SIGNING)) { + sb.append(pp.indent(mIndentSize + 8) + "OCSPSigning" + "\n"); + } else { + sb.append(pp.indent(mIndentSize + 8) + oid.toString() + "\n"); } } - return sb.toString(); - } catch (Exception e) { - return sb.toString(); } + return sb.toString(); } /** @@ -572,7 +538,8 @@ public class ExtPrettyPrint { sb.append(pp.indent(mIndentSize + 8) + mResource.getString(KeyUsageExtension.DECIPHER_ONLY) + "\n"); } return sb.toString(); - } catch (Exception e) { + } catch (IOException e) { + e.printStackTrace(); return sb.toString(); } @@ -620,7 +587,8 @@ public class ExtPrettyPrint { + mResource.getString(NSCertTypeExtension.OBJECT_SIGNING_CA) + "\n"); } return sb.toString(); - } catch (Exception e) { + } catch (CertificateException e) { + e.printStackTrace(); return ""; } @@ -650,7 +618,8 @@ public class ExtPrettyPrint { sb.append(pp.toHexString(keyId.getIdentifier(), 24, 16)); } return sb.toString(); - } catch (Exception e) { + } catch (IOException e) { + e.printStackTrace(); return ""; } } @@ -700,7 +669,8 @@ public class ExtPrettyPrint { "0x" + serial.getNumber().toBigInteger().toString(16).toUpperCase() + "\n"); } return sb.toString(); - } catch (Exception e) { + } catch (IOException e) { + e.printStackTrace(); return ""; } } @@ -737,29 +707,25 @@ public class ExtPrettyPrint { */ private String getInhibitAnyPolicyExtension() { StringBuffer sb = new StringBuffer(); - try { - sb.append(pp.indent(mIndentSize) + - mResource.getString(PrettyPrintResources.TOKEN_IDENTIFIER)); + sb.append(pp.indent(mIndentSize) + + mResource.getString(PrettyPrintResources.TOKEN_IDENTIFIER)); + sb.append(mResource.getString( + PrettyPrintResources.TOKEN_INHIBIT_ANY_POLICY_EXT) + "- " + + mExt.getExtensionId().toString() + "\n"); + sb.append(pp.indent(mIndentSize + 4) + + mResource.getString(PrettyPrintResources.TOKEN_CRITICAL)); + InhibitAnyPolicyExtension ext = (InhibitAnyPolicyExtension) mExt; + if (mExt.isCritical()) sb.append(mResource.getString( - PrettyPrintResources.TOKEN_INHIBIT_ANY_POLICY_EXT) + "- " + - mExt.getExtensionId().toString() + "\n"); - sb.append(pp.indent(mIndentSize + 4) + - mResource.getString(PrettyPrintResources.TOKEN_CRITICAL)); - InhibitAnyPolicyExtension ext = (InhibitAnyPolicyExtension) mExt; - if (mExt.isCritical()) - sb.append(mResource.getString( - PrettyPrintResources.TOKEN_YES) + "\n"); - else - sb.append(mResource.getString( - PrettyPrintResources.TOKEN_NO) + "\n"); - sb.append(pp.indent(mIndentSize + 4) + mResource.getString( - PrettyPrintResources.TOKEN_SKIP_CERTS)); - BigInt num = ext.getSkipCerts(); - sb.append("" + num.toInt() + "\n"); - return sb.toString(); - } catch (Exception e) { - return ""; - } + PrettyPrintResources.TOKEN_YES) + "\n"); + else + sb.append(mResource.getString( + PrettyPrintResources.TOKEN_NO) + "\n"); + sb.append(pp.indent(mIndentSize + 4) + mResource.getString( + PrettyPrintResources.TOKEN_SKIP_CERTS)); + BigInt num = ext.getSkipCerts(); + sb.append("" + num.toInt() + "\n"); + return sb.toString(); } /** @@ -805,7 +771,8 @@ public class ExtPrettyPrint { } return sb.toString(); - } catch (Exception e) { + } catch (IOException e) { + e.printStackTrace(); return ""; } } @@ -837,7 +804,8 @@ public class ExtPrettyPrint { } return sb.toString(); - } catch (Exception e) { + } catch (IOException e) { + e.printStackTrace(); return ""; } } @@ -869,7 +837,8 @@ public class ExtPrettyPrint { } return sb.toString(); - } catch (Exception e) { + } catch (IOException e) { + e.printStackTrace(); return ""; } } @@ -912,7 +881,7 @@ public class ExtPrettyPrint { } return sb.toString(); - } catch (Exception e) { + } catch (IOException e) { return ""; } } @@ -952,7 +921,8 @@ public class ExtPrettyPrint { } return sb.toString(); - } catch (Exception e) { + } catch (IOException e) { + e.printStackTrace(); return ""; } } @@ -962,47 +932,42 @@ public class ExtPrettyPrint { */ private String getCertificateScopeOfUseExtension() { StringBuffer sb = new StringBuffer(); + sb.append(pp.indent(mIndentSize) + mResource.getString(PrettyPrintResources.TOKEN_IDENTIFIER)); + sb.append(mResource.getString(PrettyPrintResources.TOKEN_CERT_SCOPE_OF_USE) + "- " + + mExt.getExtensionId().toString() + "\n"); + sb.append(pp.indent(mIndentSize + 4) + mResource.getString(PrettyPrintResources.TOKEN_CRITICAL)); + CertificateScopeOfUseExtension ext = (CertificateScopeOfUseExtension) mExt; + + if (mExt.isCritical()) { + sb.append(mResource.getString(PrettyPrintResources.TOKEN_YES) + "\n"); + } else { + sb.append(mResource.getString(PrettyPrintResources.TOKEN_NO) + "\n"); + } + Vector<CertificateScopeEntry> entries = ext.getCertificateScopeEntries(); - try { - sb.append(pp.indent(mIndentSize) + mResource.getString(PrettyPrintResources.TOKEN_IDENTIFIER)); - sb.append(mResource.getString(PrettyPrintResources.TOKEN_CERT_SCOPE_OF_USE) + "- " + - mExt.getExtensionId().toString() + "\n"); - sb.append(pp.indent(mIndentSize + 4) + mResource.getString(PrettyPrintResources.TOKEN_CRITICAL)); - CertificateScopeOfUseExtension ext = (CertificateScopeOfUseExtension) mExt; - - if (mExt.isCritical()) { - sb.append(mResource.getString(PrettyPrintResources.TOKEN_YES) + "\n"); - } else { - sb.append(mResource.getString(PrettyPrintResources.TOKEN_NO) + "\n"); - } - Vector<CertificateScopeEntry> entries = ext.getCertificateScopeEntries(); - - if (entries != null) { - sb.append(pp.indent(mIndentSize + 4) + - mResource.getString(PrettyPrintResources.TOKEN_SCOPE_OF_USE) + "\n"); - for (int i = 0; i < entries.size(); i++) { - CertificateScopeEntry se = entries.elementAt(i); - GeneralName gn = se.getGeneralName(); + if (entries != null) { + sb.append(pp.indent(mIndentSize + 4) + + mResource.getString(PrettyPrintResources.TOKEN_SCOPE_OF_USE) + "\n"); + for (int i = 0; i < entries.size(); i++) { + CertificateScopeEntry se = entries.elementAt(i); + GeneralName gn = se.getGeneralName(); - if (gn != null) { - String nameType = ""; + if (gn != null) { + String nameType = ""; - if (gn.getType() == GeneralNameInterface.NAME_DIRECTORY) - nameType = "DirectoryName: "; - sb.append(pp.indent(mIndentSize + 8) + nameType + gn.toString() + "\n"); - } - BigInt port = se.getPort(); + if (gn.getType() == GeneralNameInterface.NAME_DIRECTORY) + nameType = "DirectoryName: "; + sb.append(pp.indent(mIndentSize + 8) + nameType + gn.toString() + "\n"); + } + BigInt port = se.getPort(); - if (port != null) { - sb.append(pp.indent(mIndentSize + 8) + PrettyPrintResources.TOKEN_PORT + - port.toBigInteger().toString() + "\n"); - } + if (port != null) { + sb.append(pp.indent(mIndentSize + 8) + PrettyPrintResources.TOKEN_PORT + + port.toBigInteger().toString() + "\n"); } } - return sb.toString(); - } catch (Exception e) { - return ""; } + return sb.toString(); } /** @@ -1011,97 +976,92 @@ public class ExtPrettyPrint { private String getFreshestCRLExtension() { StringBuffer sb = new StringBuffer(); - try { - - // - // Generic stuff: name, OID, criticality - // - sb.append(pp.indent(mIndentSize) + - mResource.getString(PrettyPrintResources.TOKEN_IDENTIFIER)); + // + // Generic stuff: name, OID, criticality + // + sb.append(pp.indent(mIndentSize) + + mResource.getString(PrettyPrintResources.TOKEN_IDENTIFIER)); + sb.append(mResource.getString( + PrettyPrintResources.TOKEN_FRESHEST_CRL_EXT) + "- " + + mExt.getExtensionId().toString() + "\n"); + sb.append(pp.indent(mIndentSize + 4) + + mResource.getString(PrettyPrintResources.TOKEN_CRITICAL)); + if (mExt.isCritical()) { sb.append(mResource.getString( - PrettyPrintResources.TOKEN_FRESHEST_CRL_EXT) + "- " + - mExt.getExtensionId().toString() + "\n"); - sb.append(pp.indent(mIndentSize + 4) + - mResource.getString(PrettyPrintResources.TOKEN_CRITICAL)); - if (mExt.isCritical()) { - sb.append(mResource.getString( - PrettyPrintResources.TOKEN_YES) + "\n"); - } else { - sb.append(mResource.getString( - PrettyPrintResources.TOKEN_NO) + "\n"); - } - - // - // Now the CRLDP-specific stuff - // - FreshestCRLExtension ext = (FreshestCRLExtension) mExt; + PrettyPrintResources.TOKEN_YES) + "\n"); + } else { + sb.append(mResource.getString( + PrettyPrintResources.TOKEN_NO) + "\n"); + } - int numPoints = ext.getNumPoints(); + // + // Now the CRLDP-specific stuff + // + FreshestCRLExtension ext = (FreshestCRLExtension) mExt; - sb.append(pp.indent(mIndentSize + 4) + mResource.getString( - PrettyPrintResources.TOKEN_CRLDP_NUMPOINTS) - + numPoints + "\n"); + int numPoints = ext.getNumPoints(); - for (int i = 0; i < numPoints; i++) { + sb.append(pp.indent(mIndentSize + 4) + mResource.getString( + PrettyPrintResources.TOKEN_CRLDP_NUMPOINTS) + + numPoints + "\n"); - // - // print one individual CRL distribution point - // + for (int i = 0; i < numPoints; i++) { - int idt; + // + // print one individual CRL distribution point + // - idt = mIndentSize + 4; // reset each time through loop - boolean isEmpty = true; + int idt; - sb.append(pp.indent(idt) + - mResource.getString(PrettyPrintResources.TOKEN_CRLDP_POINTN) + - i + "\n"); + idt = mIndentSize + 4; // reset each time through loop + boolean isEmpty = true; - CRLDistributionPoint pt = ext.getPointAt(i); + sb.append(pp.indent(idt) + + mResource.getString(PrettyPrintResources.TOKEN_CRLDP_POINTN) + + i + "\n"); - idt += 4; // further indent rest of information + CRLDistributionPoint pt = ext.getPointAt(i); - if (pt.getFullName() != null) { - isEmpty = false; - sb.append(pp.indent(idt) + - mResource.getString(PrettyPrintResources.TOKEN_CRLDP_DISTPOINT) - + pt.getFullName() + "\n"); - } + idt += 4; // further indent rest of information - if (pt.getRelativeName() != null) { - isEmpty = false; - sb.append(pp.indent(idt) + - mResource.getString(PrettyPrintResources.TOKEN_CRLDP_DISTPOINT) - + pt.getRelativeName() + "\n"); - } + if (pt.getFullName() != null) { + isEmpty = false; + sb.append(pp.indent(idt) + + mResource.getString(PrettyPrintResources.TOKEN_CRLDP_DISTPOINT) + + pt.getFullName() + "\n"); + } - if (pt.getReasons() != null) { - isEmpty = false; - byte[] reasonBits = pt.getReasons().toByteArray(); - String reasonList = reasonBitsToReasonList(reasonBits); + if (pt.getRelativeName() != null) { + isEmpty = false; + sb.append(pp.indent(idt) + + mResource.getString(PrettyPrintResources.TOKEN_CRLDP_DISTPOINT) + + pt.getRelativeName() + "\n"); + } - sb.append(pp.indent(idt) + - mResource.getString(PrettyPrintResources.TOKEN_CRLDP_REASONS) - + reasonList + "\n"); - } + if (pt.getReasons() != null) { + isEmpty = false; + byte[] reasonBits = pt.getReasons().toByteArray(); + String reasonList = reasonBitsToReasonList(reasonBits); - if (pt.getCRLIssuer() != null) { - isEmpty = false; - sb.append(pp.indent(idt) + - mResource.getString(PrettyPrintResources.TOKEN_CRLDP_CRLISSUER) - + pt.getCRLIssuer() + "\n"); - } + sb.append(pp.indent(idt) + + mResource.getString(PrettyPrintResources.TOKEN_CRLDP_REASONS) + + reasonList + "\n"); + } - if (isEmpty) { - sb.append(pp.indent(idt) + "<i>empty</i>\n"); - } + if (pt.getCRLIssuer() != null) { + isEmpty = false; + sb.append(pp.indent(idt) + + mResource.getString(PrettyPrintResources.TOKEN_CRLDP_CRLISSUER) + + pt.getCRLIssuer() + "\n"); + } + if (isEmpty) { + sb.append(pp.indent(idt) + "<i>empty</i>\n"); } - return sb.toString(); - } catch (Exception e) { - return ""; } + + return sb.toString(); } /** @@ -1110,98 +1070,93 @@ public class ExtPrettyPrint { private String getCRLDistributionPointsExtension() { StringBuffer sb = new StringBuffer(); - try { - - // - // Generic stuff: name, OID, criticality - // - sb.append(pp.indent(mIndentSize) + - mResource.getString(PrettyPrintResources.TOKEN_IDENTIFIER)); + // + // Generic stuff: name, OID, criticality + // + sb.append(pp.indent(mIndentSize) + + mResource.getString(PrettyPrintResources.TOKEN_IDENTIFIER)); + sb.append(mResource.getString( + PrettyPrintResources.TOKEN_CRL_DP_EXT) + "- " + + mExt.getExtensionId().toString() + "\n"); + sb.append(pp.indent(mIndentSize + 4) + + mResource.getString(PrettyPrintResources.TOKEN_CRITICAL)); + if (mExt.isCritical()) { sb.append(mResource.getString( - PrettyPrintResources.TOKEN_CRL_DP_EXT) + "- " + - mExt.getExtensionId().toString() + "\n"); - sb.append(pp.indent(mIndentSize + 4) + - mResource.getString(PrettyPrintResources.TOKEN_CRITICAL)); - if (mExt.isCritical()) { - sb.append(mResource.getString( - PrettyPrintResources.TOKEN_YES) + "\n"); - } else { - sb.append(mResource.getString( - PrettyPrintResources.TOKEN_NO) + "\n"); - } - - // - // Now the CRLDP-specific stuff - // - CRLDistributionPointsExtension ext = - (CRLDistributionPointsExtension) mExt; + PrettyPrintResources.TOKEN_YES) + "\n"); + } else { + sb.append(mResource.getString( + PrettyPrintResources.TOKEN_NO) + "\n"); + } - int numPoints = ext.getNumPoints(); + // + // Now the CRLDP-specific stuff + // + CRLDistributionPointsExtension ext = + (CRLDistributionPointsExtension) mExt; - sb.append(pp.indent(mIndentSize + 4) + mResource.getString( - PrettyPrintResources.TOKEN_CRLDP_NUMPOINTS) - + numPoints + "\n"); + int numPoints = ext.getNumPoints(); - for (int i = 0; i < numPoints; i++) { + sb.append(pp.indent(mIndentSize + 4) + mResource.getString( + PrettyPrintResources.TOKEN_CRLDP_NUMPOINTS) + + numPoints + "\n"); - // - // print one individual CRL distribution point - // + for (int i = 0; i < numPoints; i++) { - int idt; + // + // print one individual CRL distribution point + // - idt = mIndentSize + 4; // reset each time through loop - boolean isEmpty = true; + int idt; - sb.append(pp.indent(idt) + - mResource.getString(PrettyPrintResources.TOKEN_CRLDP_POINTN) + - i + "\n"); + idt = mIndentSize + 4; // reset each time through loop + boolean isEmpty = true; - CRLDistributionPoint pt = ext.getPointAt(i); + sb.append(pp.indent(idt) + + mResource.getString(PrettyPrintResources.TOKEN_CRLDP_POINTN) + + i + "\n"); - idt += 4; // further indent rest of information + CRLDistributionPoint pt = ext.getPointAt(i); - if (pt.getFullName() != null) { - isEmpty = false; - sb.append(pp.indent(idt) + - mResource.getString(PrettyPrintResources.TOKEN_CRLDP_DISTPOINT) - + pt.getFullName() + "\n"); - } + idt += 4; // further indent rest of information - if (pt.getRelativeName() != null) { - isEmpty = false; - sb.append(pp.indent(idt) + - mResource.getString(PrettyPrintResources.TOKEN_CRLDP_DISTPOINT) - + pt.getRelativeName() + "\n"); - } + if (pt.getFullName() != null) { + isEmpty = false; + sb.append(pp.indent(idt) + + mResource.getString(PrettyPrintResources.TOKEN_CRLDP_DISTPOINT) + + pt.getFullName() + "\n"); + } - if (pt.getReasons() != null) { - isEmpty = false; - byte[] reasonBits = pt.getReasons().toByteArray(); - String reasonList = reasonBitsToReasonList(reasonBits); + if (pt.getRelativeName() != null) { + isEmpty = false; + sb.append(pp.indent(idt) + + mResource.getString(PrettyPrintResources.TOKEN_CRLDP_DISTPOINT) + + pt.getRelativeName() + "\n"); + } - sb.append(pp.indent(idt) + - mResource.getString(PrettyPrintResources.TOKEN_CRLDP_REASONS) - + reasonList + "\n"); - } + if (pt.getReasons() != null) { + isEmpty = false; + byte[] reasonBits = pt.getReasons().toByteArray(); + String reasonList = reasonBitsToReasonList(reasonBits); - if (pt.getCRLIssuer() != null) { - isEmpty = false; - sb.append(pp.indent(idt) + - mResource.getString(PrettyPrintResources.TOKEN_CRLDP_CRLISSUER) - + pt.getCRLIssuer() + "\n"); - } + sb.append(pp.indent(idt) + + mResource.getString(PrettyPrintResources.TOKEN_CRLDP_REASONS) + + reasonList + "\n"); + } - if (isEmpty) { - sb.append(pp.indent(idt) + "<i>empty</i>\n"); - } + if (pt.getCRLIssuer() != null) { + isEmpty = false; + sb.append(pp.indent(idt) + + mResource.getString(PrettyPrintResources.TOKEN_CRLDP_CRLISSUER) + + pt.getCRLIssuer() + "\n"); + } + if (isEmpty) { + sb.append(pp.indent(idt) + "<i>empty</i>\n"); } - return sb.toString(); - } catch (Exception e) { - return ""; } + + return sb.toString(); } private static String reasonBitsToReasonList(byte[] reasonBits) { @@ -1228,78 +1183,74 @@ public class ExtPrettyPrint { private String getIssuingDistributionPointExtension() { StringBuffer sb = new StringBuffer(); - try { - sb.append(pp.indent(mIndentSize) + mResource.getString(PrettyPrintResources.TOKEN_IDENTIFIER)); - sb.append(mResource.getString(PrettyPrintResources.TOKEN_ISSUING_DIST_POINT) + "- " + - mExt.getExtensionId().toString() + "\n"); - sb.append(pp.indent(mIndentSize + 4) + mResource.getString(PrettyPrintResources.TOKEN_CRITICAL)); - if (mExt.isCritical()) { - sb.append(mResource.getString(PrettyPrintResources.TOKEN_YES) + "\n"); - } else { - sb.append(mResource.getString(PrettyPrintResources.TOKEN_NO) + "\n"); - } + sb.append(pp.indent(mIndentSize) + mResource.getString(PrettyPrintResources.TOKEN_IDENTIFIER)); + sb.append(mResource.getString(PrettyPrintResources.TOKEN_ISSUING_DIST_POINT) + "- " + + mExt.getExtensionId().toString() + "\n"); + sb.append(pp.indent(mIndentSize + 4) + mResource.getString(PrettyPrintResources.TOKEN_CRITICAL)); + if (mExt.isCritical()) { + sb.append(mResource.getString(PrettyPrintResources.TOKEN_YES) + "\n"); + } else { + sb.append(mResource.getString(PrettyPrintResources.TOKEN_NO) + "\n"); + } - IssuingDistributionPointExtension ext = (IssuingDistributionPointExtension) mExt; - IssuingDistributionPoint issuingDistributionPoint = ext.getIssuingDistributionPoint(); + IssuingDistributionPointExtension ext = (IssuingDistributionPointExtension) mExt; + IssuingDistributionPoint issuingDistributionPoint = ext.getIssuingDistributionPoint(); - if (issuingDistributionPoint != null) { - GeneralNames fullNames = issuingDistributionPoint.getFullName(); - RDN relativeName = issuingDistributionPoint.getRelativeName(); + if (issuingDistributionPoint != null) { + GeneralNames fullNames = issuingDistributionPoint.getFullName(); + RDN relativeName = issuingDistributionPoint.getRelativeName(); - if (fullNames != null || relativeName != null) { - sb.append(pp.indent(mIndentSize + 4) - + mResource.getString(PrettyPrintResources.TOKEN_DIST_POINT_NAME) + "\n"); - if (fullNames != null) { - sb.append(pp.indent(mIndentSize + 8) - + mResource.getString(PrettyPrintResources.TOKEN_FULL_NAME) + "\n"); - for (int i = 0; i < fullNames.size(); i++) { - GeneralName fullName = (GeneralName) fullNames.elementAt(i); + if (fullNames != null || relativeName != null) { + sb.append(pp.indent(mIndentSize + 4) + + mResource.getString(PrettyPrintResources.TOKEN_DIST_POINT_NAME) + "\n"); + if (fullNames != null) { + sb.append(pp.indent(mIndentSize + 8) + + mResource.getString(PrettyPrintResources.TOKEN_FULL_NAME) + "\n"); + for (int i = 0; i < fullNames.size(); i++) { + GeneralName fullName = (GeneralName) fullNames.elementAt(i); - if (fullName != null) { - sb.append(pp.indent(mIndentSize + 12) + fullName.toString() + "\n"); - } + if (fullName != null) { + sb.append(pp.indent(mIndentSize + 12) + fullName.toString() + "\n"); } } - if (relativeName != null) { - sb.append(pp.indent(mIndentSize + 8) - + mResource.getString(PrettyPrintResources.TOKEN_RELATIVE_NAME) + - relativeName.toString() + "\n"); - } - } - - sb.append(pp.indent(mIndentSize + 4) + mResource.getString(PrettyPrintResources.TOKEN_ONLY_USER_CERTS)); - if (issuingDistributionPoint.getOnlyContainsUserCerts()) { - sb.append(mResource.getString(PrettyPrintResources.TOKEN_YES) + "\n"); - } else { - sb.append(mResource.getString(PrettyPrintResources.TOKEN_NO) + "\n"); } - sb.append(pp.indent(mIndentSize + 4) + mResource.getString(PrettyPrintResources.TOKEN_ONLY_CA_CERTS)); - if (issuingDistributionPoint.getOnlyContainsCACerts()) { - sb.append(mResource.getString(PrettyPrintResources.TOKEN_YES) + "\n"); - } else { - sb.append(mResource.getString(PrettyPrintResources.TOKEN_NO) + "\n"); + if (relativeName != null) { + sb.append(pp.indent(mIndentSize + 8) + + mResource.getString(PrettyPrintResources.TOKEN_RELATIVE_NAME) + + relativeName.toString() + "\n"); } + } - BitArray onlySomeReasons = issuingDistributionPoint.getOnlySomeReasons(); + sb.append(pp.indent(mIndentSize + 4) + mResource.getString(PrettyPrintResources.TOKEN_ONLY_USER_CERTS)); + if (issuingDistributionPoint.getOnlyContainsUserCerts()) { + sb.append(mResource.getString(PrettyPrintResources.TOKEN_YES) + "\n"); + } else { + sb.append(mResource.getString(PrettyPrintResources.TOKEN_NO) + "\n"); + } + sb.append(pp.indent(mIndentSize + 4) + mResource.getString(PrettyPrintResources.TOKEN_ONLY_CA_CERTS)); + if (issuingDistributionPoint.getOnlyContainsCACerts()) { + sb.append(mResource.getString(PrettyPrintResources.TOKEN_YES) + "\n"); + } else { + sb.append(mResource.getString(PrettyPrintResources.TOKEN_NO) + "\n"); + } - if (onlySomeReasons != null) { - sb.append(pp.indent(mIndentSize + 4) - + mResource.getString(PrettyPrintResources.TOKEN_ONLY_SOME_REASONS)); - sb.append("0x" + pp.toHexString(onlySomeReasons.toByteArray())); - } + BitArray onlySomeReasons = issuingDistributionPoint.getOnlySomeReasons(); - sb.append(pp.indent(mIndentSize + 4) + mResource.getString(PrettyPrintResources.TOKEN_INDIRECT_CRL)); - if (issuingDistributionPoint.getIndirectCRL()) { - sb.append(mResource.getString(PrettyPrintResources.TOKEN_YES) + "\n"); - } else { - sb.append(mResource.getString(PrettyPrintResources.TOKEN_NO) + "\n"); - } + if (onlySomeReasons != null) { + sb.append(pp.indent(mIndentSize + 4) + + mResource.getString(PrettyPrintResources.TOKEN_ONLY_SOME_REASONS)); + sb.append("0x" + pp.toHexString(onlySomeReasons.toByteArray())); } - return sb.toString(); - } catch (Exception e) { - return ""; + sb.append(pp.indent(mIndentSize + 4) + mResource.getString(PrettyPrintResources.TOKEN_INDIRECT_CRL)); + if (issuingDistributionPoint.getIndirectCRL()) { + sb.append(mResource.getString(PrettyPrintResources.TOKEN_YES) + "\n"); + } else { + sb.append(mResource.getString(PrettyPrintResources.TOKEN_NO) + "\n"); + } } + + return sb.toString(); } /** @@ -1308,27 +1259,23 @@ public class ExtPrettyPrint { private String getInvalidityDateExtension() { StringBuffer sb = new StringBuffer(); - try { - sb.append(pp.indent(mIndentSize) + mResource.getString( - PrettyPrintResources.TOKEN_IDENTIFIER)); - sb.append(mResource.getString(PrettyPrintResources.TOKEN_INVALIDITY_DATE) + - "- " + mExt.getExtensionId().toString() + "\n"); - sb.append(pp.indent(mIndentSize + 4) + mResource.getString( - PrettyPrintResources.TOKEN_CRITICAL)); - InvalidityDateExtension ext = (InvalidityDateExtension) mExt; + sb.append(pp.indent(mIndentSize) + mResource.getString( + PrettyPrintResources.TOKEN_IDENTIFIER)); + sb.append(mResource.getString(PrettyPrintResources.TOKEN_INVALIDITY_DATE) + + "- " + mExt.getExtensionId().toString() + "\n"); + sb.append(pp.indent(mIndentSize + 4) + mResource.getString( + PrettyPrintResources.TOKEN_CRITICAL)); + InvalidityDateExtension ext = (InvalidityDateExtension) mExt; - if (mExt.isCritical()) { - sb.append(mResource.getString(PrettyPrintResources.TOKEN_YES) + "\n"); - } else { - sb.append(mResource.getString(PrettyPrintResources.TOKEN_NO) + "\n"); - } - sb.append(pp.indent(mIndentSize + 4) + mResource.getString( - PrettyPrintResources.TOKEN_DATE_OF_INVALIDITY) + - ext.getInvalidityDate().toString() + "\n"); - return sb.toString(); - } catch (Exception e) { - return ""; + if (mExt.isCritical()) { + sb.append(mResource.getString(PrettyPrintResources.TOKEN_YES) + "\n"); + } else { + sb.append(mResource.getString(PrettyPrintResources.TOKEN_NO) + "\n"); } + sb.append(pp.indent(mIndentSize + 4) + mResource.getString( + PrettyPrintResources.TOKEN_DATE_OF_INVALIDITY) + + ext.getInvalidityDate().toString() + "\n"); + return sb.toString(); } /** @@ -1372,7 +1319,8 @@ public class ExtPrettyPrint { } return sb.toString(); - } catch (Exception e) { + } catch (IOException e) { + e.printStackTrace(); return ""; } } @@ -1383,27 +1331,23 @@ public class ExtPrettyPrint { private String getHoldInstructionExtension() { StringBuffer sb = new StringBuffer(); - try { - sb.append(pp.indent(mIndentSize) + mResource.getString( - PrettyPrintResources.TOKEN_IDENTIFIER)); - sb.append(mResource.getString(PrettyPrintResources.TOKEN_HOLD_INSTRUCTION) + - "- " + mExt.getExtensionId().toString() + "\n"); - sb.append(pp.indent(mIndentSize + 4) + mResource.getString( - PrettyPrintResources.TOKEN_CRITICAL)); - HoldInstructionExtension ext = (HoldInstructionExtension) mExt; + sb.append(pp.indent(mIndentSize) + mResource.getString( + PrettyPrintResources.TOKEN_IDENTIFIER)); + sb.append(mResource.getString(PrettyPrintResources.TOKEN_HOLD_INSTRUCTION) + + "- " + mExt.getExtensionId().toString() + "\n"); + sb.append(pp.indent(mIndentSize + 4) + mResource.getString( + PrettyPrintResources.TOKEN_CRITICAL)); + HoldInstructionExtension ext = (HoldInstructionExtension) mExt; - if (mExt.isCritical()) { - sb.append(mResource.getString(PrettyPrintResources.TOKEN_YES) + "\n"); - } else { - sb.append(mResource.getString(PrettyPrintResources.TOKEN_NO) + "\n"); - } - sb.append(pp.indent(mIndentSize + 4) + mResource.getString( - PrettyPrintResources.TOKEN_HOLD_INSTRUCTION_CODE) + - ext.getHoldInstructionCodeDescription() + "\n"); - return sb.toString(); - } catch (Exception e) { - return ""; + if (mExt.isCritical()) { + sb.append(mResource.getString(PrettyPrintResources.TOKEN_YES) + "\n"); + } else { + sb.append(mResource.getString(PrettyPrintResources.TOKEN_NO) + "\n"); } + sb.append(pp.indent(mIndentSize + 4) + mResource.getString( + PrettyPrintResources.TOKEN_HOLD_INSTRUCTION_CODE) + + ext.getHoldInstructionCodeDescription() + "\n"); + return sb.toString(); } /** @@ -1412,43 +1356,39 @@ public class ExtPrettyPrint { private String getPolicyConstraintsExtension() { StringBuffer sb = new StringBuffer(); - try { - sb.append(pp.indent(mIndentSize) + mResource.getString( - PrettyPrintResources.TOKEN_IDENTIFIER)); - sb.append( - mResource.getString( - PrettyPrintResources.TOKEN_POLICY_CONSTRAINTS) + - "- " + mExt.getExtensionId().toString() + "\n"); - sb.append(pp.indent(mIndentSize + 4) + mResource.getString( - PrettyPrintResources.TOKEN_CRITICAL)); - if (mExt.isCritical()) { - sb.append(mResource.getString(PrettyPrintResources.TOKEN_YES) + "\n"); - } else { - sb.append(mResource.getString(PrettyPrintResources.TOKEN_NO) + "\n"); - } - - PolicyConstraintsExtension ext = (PolicyConstraintsExtension) mExt; - int require = ext.getRequireExplicitMapping(); - int inhibit = ext.getInhibitPolicyMapping(); - - sb.append( - pp.indent(mIndentSize + 4) + - mResource.getString( - PrettyPrintResources.TOKEN_REQUIRE_EXPLICIT_POLICY) + - ((require == -1) ? - mResource.getString(PrettyPrintResources.TOKEN_NOT_SET) : - String.valueOf(require)) + "\n"); - sb.append( - pp.indent(mIndentSize + 4) + - mResource.getString( - PrettyPrintResources.TOKEN_INHIBIT_POLICY_MAPPING) + - ((inhibit == -1) ? - mResource.getString(PrettyPrintResources.TOKEN_NOT_SET) : - String.valueOf(inhibit)) + "\n"); - return sb.toString(); - } catch (Exception e) { - return ""; + sb.append(pp.indent(mIndentSize) + mResource.getString( + PrettyPrintResources.TOKEN_IDENTIFIER)); + sb.append( + mResource.getString( + PrettyPrintResources.TOKEN_POLICY_CONSTRAINTS) + + "- " + mExt.getExtensionId().toString() + "\n"); + sb.append(pp.indent(mIndentSize + 4) + mResource.getString( + PrettyPrintResources.TOKEN_CRITICAL)); + if (mExt.isCritical()) { + sb.append(mResource.getString(PrettyPrintResources.TOKEN_YES) + "\n"); + } else { + sb.append(mResource.getString(PrettyPrintResources.TOKEN_NO) + "\n"); } + + PolicyConstraintsExtension ext = (PolicyConstraintsExtension) mExt; + int require = ext.getRequireExplicitMapping(); + int inhibit = ext.getInhibitPolicyMapping(); + + sb.append( + pp.indent(mIndentSize + 4) + + mResource.getString( + PrettyPrintResources.TOKEN_REQUIRE_EXPLICIT_POLICY) + + ((require == -1) ? + mResource.getString(PrettyPrintResources.TOKEN_NOT_SET) : + String.valueOf(require)) + "\n"); + sb.append( + pp.indent(mIndentSize + 4) + + mResource.getString( + PrettyPrintResources.TOKEN_INHIBIT_POLICY_MAPPING) + + ((inhibit == -1) ? + mResource.getString(PrettyPrintResources.TOKEN_NOT_SET) : + String.valueOf(inhibit)) + "\n"); + return sb.toString(); } /** @@ -1457,50 +1397,46 @@ public class ExtPrettyPrint { private String getPolicyMappingsExtension() { StringBuffer sb = new StringBuffer(); - try { - sb.append(pp.indent(mIndentSize) + mResource.getString( - PrettyPrintResources.TOKEN_IDENTIFIER)); - sb.append(mResource.getString(PrettyPrintResources.TOKEN_POLICY_MAPPINGS) + - "- " + mExt.getExtensionId().toString() + "\n"); - sb.append(pp.indent(mIndentSize + 4) + mResource.getString( - PrettyPrintResources.TOKEN_CRITICAL)); - if (mExt.isCritical()) { - sb.append(mResource.getString(PrettyPrintResources.TOKEN_YES) + "\n"); - } else { - sb.append(mResource.getString(PrettyPrintResources.TOKEN_NO) + "\n"); - } - - PolicyMappingsExtension ext = (PolicyMappingsExtension) mExt; - Enumeration<CertificatePolicyMap> maps = ext.getMappings(); + sb.append(pp.indent(mIndentSize) + mResource.getString( + PrettyPrintResources.TOKEN_IDENTIFIER)); + sb.append(mResource.getString(PrettyPrintResources.TOKEN_POLICY_MAPPINGS) + + "- " + mExt.getExtensionId().toString() + "\n"); + sb.append(pp.indent(mIndentSize + 4) + mResource.getString( + PrettyPrintResources.TOKEN_CRITICAL)); + if (mExt.isCritical()) { + sb.append(mResource.getString(PrettyPrintResources.TOKEN_YES) + "\n"); + } else { + sb.append(mResource.getString(PrettyPrintResources.TOKEN_NO) + "\n"); + } - sb.append(pp.indent(mIndentSize + 4) + - mResource.getString(PrettyPrintResources.TOKEN_MAPPINGS)); - if (maps == null || !maps.hasMoreElements()) { - sb.append( - mResource.getString(PrettyPrintResources.TOKEN_NONE) + "\n"); - } else { - sb.append("\n"); - for (int i = 0; maps.hasMoreElements(); i++) { - sb.append(pp.indent(mIndentSize + 8) + - mResource.getString( - PrettyPrintResources.TOKEN_MAP) + i + ":" + "\n"); - CertificatePolicyMap m = - maps.nextElement(); + PolicyMappingsExtension ext = (PolicyMappingsExtension) mExt; + Enumeration<CertificatePolicyMap> maps = ext.getMappings(); - sb.append(pp.indent(mIndentSize + 12) + - mResource.getString( - PrettyPrintResources.TOKEN_ISSUER_DOMAIN_POLICY) + - m.getIssuerIdentifier().getIdentifier().toString() + "\n"); - sb.append(pp.indent(mIndentSize + 12) + - mResource.getString( - PrettyPrintResources.TOKEN_SUBJECT_DOMAIN_POLICY) + - m.getSubjectIdentifier().getIdentifier().toString() + "\n"); - } + sb.append(pp.indent(mIndentSize + 4) + + mResource.getString(PrettyPrintResources.TOKEN_MAPPINGS)); + if (maps == null || !maps.hasMoreElements()) { + sb.append( + mResource.getString(PrettyPrintResources.TOKEN_NONE) + "\n"); + } else { + sb.append("\n"); + for (int i = 0; maps.hasMoreElements(); i++) { + sb.append(pp.indent(mIndentSize + 8) + + mResource.getString( + PrettyPrintResources.TOKEN_MAP) + i + ":" + "\n"); + CertificatePolicyMap m = + maps.nextElement(); + + sb.append(pp.indent(mIndentSize + 12) + + mResource.getString( + PrettyPrintResources.TOKEN_ISSUER_DOMAIN_POLICY) + + m.getIssuerIdentifier().getIdentifier().toString() + "\n"); + sb.append(pp.indent(mIndentSize + 12) + + mResource.getString( + PrettyPrintResources.TOKEN_SUBJECT_DOMAIN_POLICY) + + m.getSubjectIdentifier().getIdentifier().toString() + "\n"); } - return sb.toString(); - } catch (Throwable e) { - return ""; } + return sb.toString(); } /** @@ -1642,7 +1578,7 @@ public class ExtPrettyPrint { } } return sb.toString(); - } catch (Exception e) { + } catch (IOException e) { return sb.toString(); } } diff --git a/base/util/src/netscape/security/util/PubKeyPrettyPrint.java b/base/util/src/netscape/security/util/PubKeyPrettyPrint.java index 88fcdddb5..21fc1f446 100644 --- a/base/util/src/netscape/security/util/PubKeyPrettyPrint.java +++ b/base/util/src/netscape/security/util/PubKeyPrettyPrint.java @@ -17,6 +17,7 @@ // --- END COPYRIGHT BLOCK --- package netscape.security.util; +import java.security.InvalidKeyException; import java.security.PublicKey; import java.util.Locale; import java.util.ResourceBundle; @@ -113,7 +114,8 @@ public class PubKeyPrettyPrint { sb.append(pp.toHexString(mX509Key.getKey(), indentSize + 4, lineLen)); } - } catch (Exception e) { + } catch(InvalidKeyException e){ + e.printStackTrace(); } return sb.toString(); diff --git a/base/util/src/netscape/security/x509/CRLDistributionPoint.java b/base/util/src/netscape/security/x509/CRLDistributionPoint.java index 435392de7..637ee57fe 100644 --- a/base/util/src/netscape/security/x509/CRLDistributionPoint.java +++ b/base/util/src/netscape/security/x509/CRLDistributionPoint.java @@ -251,7 +251,7 @@ public class CRLDistributionPoint implements ASN1Value { return templateInstance; } - public static void main(String args[]) { + public static void main(String args[]) throws Exception { ByteArrayOutputStream bos = null; FileOutputStream fos = null; try { @@ -339,13 +339,13 @@ public class CRLDistributionPoint implements ASN1Value { } catch (Exception e) { e.printStackTrace(); + throw e; } finally { if (bos != null) { - try { - bos.close(); - } catch (IOException e) { - e.printStackTrace(); - } + bos.close(); + } + if (fos != null) { + fos.close(); } if (fos != null) { try { diff --git a/base/util/src/netscape/security/x509/X509CertImpl.java b/base/util/src/netscape/security/x509/X509CertImpl.java index 05de623ce..b6d97da38 100755 --- a/base/util/src/netscape/security/x509/X509CertImpl.java +++ b/base/util/src/netscape/security/x509/X509CertImpl.java @@ -976,6 +976,7 @@ public class X509CertImpl extends X509Certificate * @param oid the Object Identifier value for the extension. */ public byte[] getExtensionValue(String oid) { + DerOutputStream out = null; try { String extAlias = OIDMap.getName(new ObjectIdentifier(oid)); Extension certExt = null; @@ -1008,11 +1009,19 @@ public class X509CertImpl extends X509Certificate if (extData == null) return null; - DerOutputStream out = new DerOutputStream(); + out = new DerOutputStream(); out.putOctetString(extData); return out.toByteArray(); } catch (Exception e) { return null; + } finally { + if (out != null) { + try { + out.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } } } diff --git a/base/util/src/netscape/security/x509/X509CertInfo.java b/base/util/src/netscape/security/x509/X509CertInfo.java index 0c44e2c92..6ad4d243f 100644 --- a/base/util/src/netscape/security/x509/X509CertInfo.java +++ b/base/util/src/netscape/security/x509/X509CertInfo.java @@ -352,12 +352,13 @@ public class X509CertInfo implements CertAttrSet, Serializable { for (int i = 0; i < extensions.size(); i++) { sb.append(" Extension[" + i + "] = "); Extension ext = extensions.elementAt(i); + DerOutputStream out = null; try { if (OIDMap.getClass(ext.getExtensionId()) == null) { sb.append(ext.toString()); byte[] extValue = ext.getExtensionValue(); if (extValue != null) { - DerOutputStream out = new DerOutputStream(); + out = new DerOutputStream(); out.putOctetString(extValue); extValue = out.toByteArray(); String extValuebits = pp.toHexString(extValue); @@ -367,8 +368,18 @@ public class X509CertInfo implements CertAttrSet, Serializable { } } else sb.append(ext.toString()); //sub-class exists - } catch (Exception e) { + } catch (CertificateException e) { sb.append(", Error parsing this extension"); + } catch (IOException e) { + sb.append(", Error parsing this extension"); + } finally { + if (out != null) { + try { + out.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } } } } |