diff options
20 files changed, 756 insertions, 799 deletions
diff --git a/base/common/src/com/netscape/certsrv/base/MessageFormatter.java b/base/common/src/com/netscape/certsrv/base/MessageFormatter.java index 40275b516..f573a227e 100644 --- a/base/common/src/com/netscape/certsrv/base/MessageFormatter.java +++ b/base/common/src/com/netscape/certsrv/base/MessageFormatter.java @@ -88,67 +88,63 @@ public class MessageFormatter { String localizedFormat = null; try { - try { - // if you are worried about the efficiency of the - // following line, dont worry. ResourceBundle has - // an internal cache. So resource bundle wont be - // instantiated everytime you call toString(). + // if you are worried about the efficiency of the + // following line, dont worry. ResourceBundle has + // an internal cache. So resource bundle wont be + // instantiated everytime you call toString(). - localizedFormat = ResourceBundle.getBundle( - resourceBundleBaseName, locale).getString(formatString); - } catch (MissingResourceException e) { - return formatString; + localizedFormat = ResourceBundle.getBundle( + resourceBundleBaseName, locale).getString(formatString); + } catch (MissingResourceException e) { + return formatString; - } - Object[] localizedParams = params; - Object[] localeArg = null; - - if (params != null) { - for (int i = 0; i < params.length; ++i) { - if (!(params[i] instanceof String) || - !(params[i] instanceof Date) || - !(params[i] instanceof Number)) { - if (localizedParams == params) { + } + Object[] localizedParams = params; + Object[] localeArg = null; + + if (params != null) { + for (int i = 0; i < params.length; ++i) { + if (!(params[i] instanceof String) || + !(params[i] instanceof Date) || + !(params[i] instanceof Number)) { + if (localizedParams == params) { + + // only done once + // NB if the following variant of cloning code is used + // localizedParams = (Object [])mParams.clone(); + // it causes ArrayStoreException in + // localizedParams[i] = params[i].toString(); + // below + + localizedParams = new Object[params.length]; + System.arraycopy(params, 0, localizedParams, 0, + params.length); + } + try { + Method toStringMethod = params[i].getClass().getMethod( + "toString", toStringSignature); + if (localeArg == null) { // only done once - // NB if the following variant of cloning code is used - // localizedParams = (Object [])mParams.clone(); - // it causes ArrayStoreException in - // localizedParams[i] = params[i].toString(); - // below - - localizedParams = new Object[params.length]; - System.arraycopy(params, 0, localizedParams, 0, - params.length); - } - try { - Method toStringMethod = params[i].getClass().getMethod( - "toString", toStringSignature); - - if (localeArg == null) { - // only done once - localeArg = new Object[] { locale }; - } - localizedParams[i] = toStringMethod.invoke( - params[i], localeArg); - } catch (Exception e) { - // no method for localization, fall back - localizedParams[i] = params[i].toString(); + localeArg = new Object[] { locale }; } + localizedParams[i] = toStringMethod.invoke( + params[i], localeArg); + } catch (Exception e) { + // no method for localization, fall back + localizedParams[i] = params[i].toString(); } } } - try { - // XXX - runtime exception may be raised by the following function - MessageFormat format = new MessageFormat(localizedFormat); - - return format.format(localizedParams); - } catch (IllegalArgumentException e) { - // XXX - for now, we just print the unformatted message - // if the exception is raised - return localizedFormat; - } - } catch (Exception e) { + } + try { + // XXX - runtime exception may be raised by the following function + MessageFormat format = new MessageFormat(localizedFormat); + + return format.format(localizedParams); + } catch (IllegalArgumentException e) { + // XXX - for now, we just print the unformatted message + // if the exception is raised return localizedFormat; } } diff --git a/base/common/src/com/netscape/cmscore/apps/CMSEngine.java b/base/common/src/com/netscape/cmscore/apps/CMSEngine.java index cbdfee8fc..13a8bb6bf 100644 --- a/base/common/src/com/netscape/cmscore/apps/CMSEngine.java +++ b/base/common/src/com/netscape/cmscore/apps/CMSEngine.java @@ -531,8 +531,9 @@ public class CMSEngine implements ICMSEngine { /** * Parse server.xml to get the ports and IPs + * @throws EBaseException */ - private void parseServerXML() { + private void parseServerXML() throws EBaseException { try { String instanceRoot = mConfig.getString("instanceRoot"); String path = instanceRoot + File.separator + "conf" + File.separator + SERVER_XML; @@ -628,6 +629,7 @@ public class CMSEngine implements ICMSEngine { } catch (Exception e) { CMS.debug("CMSEngine: parseServerXML exception: " + e.toString()); + throw new EBaseException("CMSEngine: Cannot parse the configuration file. " + e.toString()); } } @@ -1586,8 +1588,10 @@ public class CMSEngine implements ICMSEngine { process.waitFor(); - } catch (Exception e) { - + } catch (IOException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); } } // end shutdownHttpServer diff --git a/base/common/src/com/netscape/cmscore/cert/CertUtils.java b/base/common/src/com/netscape/cmscore/cert/CertUtils.java index ee1e1568c..b7942e5a1 100644 --- a/base/common/src/com/netscape/cmscore/cert/CertUtils.java +++ b/base/common/src/com/netscape/cmscore/cert/CertUtils.java @@ -28,6 +28,7 @@ import java.security.cert.CertificateEncodingException; import java.security.cert.CertificateException; import java.security.cert.CertificateExpiredException; import java.security.cert.CertificateNotYetValidException; +import java.security.cert.CertificateParsingException; import java.security.cert.X509CRL; import java.security.cert.X509Certificate; import java.util.Arrays; @@ -453,7 +454,7 @@ public class CertUtils { return ((recentCert == currentCert) ? null : recentCert); } - public static String getCertType(X509CertImpl cert) { + public static String getCertType(X509CertImpl cert) throws CertificateParsingException, IOException { StringBuffer sb = new StringBuffer(); if (isSigningCert(cert)) @@ -465,27 +466,24 @@ public class CertUtils { } // Is is object signing cert? - try { - CertificateExtensions extns = (CertificateExtensions) - cert.get(X509CertImpl.NAME + "." + - X509CertImpl.INFO + "." + - X509CertInfo.EXTENSIONS); - - if (extns != null) { - NSCertTypeExtension nsExtn = (NSCertTypeExtension) - extns.get(NSCertTypeExtension.NAME); - - if (nsExtn != null) { - String nsType = getNSExtensionInfo(nsExtn); - - if (nsType != null) { - if (sb.length() > 0) - sb.append(" "); - sb.append(nsType); - } + CertificateExtensions extns = (CertificateExtensions) + cert.get(X509CertImpl.NAME + "." + + X509CertImpl.INFO + "." + + X509CertInfo.EXTENSIONS); + + if (extns != null) { + NSCertTypeExtension nsExtn = (NSCertTypeExtension) + extns.get(NSCertTypeExtension.NAME); + + if (nsExtn != null) { + String nsType = getNSExtensionInfo(nsExtn); + + if (nsType != null) { + if (sb.length() > 0) + sb.append(" "); + sb.append(nsType); } } - } catch (Exception e) { } return (sb.length() > 0) ? sb.toString() : null; } @@ -793,14 +791,21 @@ public class CertUtils { // if the OID isn't valid (ex. n.n) the error isn't caught til // encoding time leaving a bad request in the request queue. + DerOutputStream derOut = null; try { - DerOutputStream derOut = new DerOutputStream(); + derOut = new DerOutputStream(); derOut.putOID(oid); new ObjectIdentifier(new DerInputStream(derOut.toByteArray())); } catch (Exception e) { throw new EBaseException(CMS.getUserMessage("CMS_BASE_INVALID_ATTR_VALUE", - attrName, msg1)); + attrName, msg1)); + } finally { + try { + derOut.close(); + } catch (IOException e) { + e.printStackTrace(); + } } return oid; } diff --git a/base/common/src/com/netscape/cmscore/connector/LocalConnector.java b/base/common/src/com/netscape/cmscore/connector/LocalConnector.java index 9c4825494..ed0d5aa6d 100644 --- a/base/common/src/com/netscape/cmscore/connector/LocalConnector.java +++ b/base/common/src/com/netscape/cmscore/connector/LocalConnector.java @@ -36,7 +36,6 @@ import com.netscape.certsrv.request.RequestStatus; import com.netscape.cmscore.util.Debug; public class LocalConnector implements IConnector { - ILogger mLogger = CMS.getLogger(); ICertAuthority mSource = null; IAuthority mDest = null; Hashtable<String, IRequest> mSourceReqs = new Hashtable<String, IRequest>(); diff --git a/base/common/src/com/netscape/cmscore/ldap/LdapPredicateParser.java b/base/common/src/com/netscape/cmscore/ldap/LdapPredicateParser.java index 8c2b730d5..699877ffa 100644 --- a/base/common/src/com/netscape/cmscore/ldap/LdapPredicateParser.java +++ b/base/common/src/com/netscape/cmscore/ldap/LdapPredicateParser.java @@ -262,7 +262,6 @@ class PredicateTokenizer { int currentIndex; int endOfString; String nextToken; - boolean first; public PredicateTokenizer(String predString) { input = predString; diff --git a/base/common/src/com/netscape/cmscore/policy/PolicyPredicateParser.java b/base/common/src/com/netscape/cmscore/policy/PolicyPredicateParser.java index 09316ceff..849417869 100644 --- a/base/common/src/com/netscape/cmscore/policy/PolicyPredicateParser.java +++ b/base/common/src/com/netscape/cmscore/policy/PolicyPredicateParser.java @@ -265,7 +265,6 @@ class PredicateTokenizer { int currentIndex; int endOfString; String nextToken; - boolean first; public PredicateTokenizer(String predString) { input = predString; diff --git a/base/common/src/com/netscape/cmscore/security/PWCBsdr.java b/base/common/src/com/netscape/cmscore/security/PWCBsdr.java index 0ff50668c..a62a8561d 100644 --- a/base/common/src/com/netscape/cmscore/security/PWCBsdr.java +++ b/base/common/src/com/netscape/cmscore/security/PWCBsdr.java @@ -17,9 +17,6 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.security; -import java.io.InputStream; -import java.io.OutputStream; - import org.mozilla.jss.util.Password; import org.mozilla.jss.util.PasswordCallback; import org.mozilla.jss.util.PasswordCallbackInfo; @@ -36,8 +33,6 @@ import com.netscape.cmscore.base.JDialogPasswordCallback; */ public class PWCBsdr implements PasswordCallback { - InputStream in = null; - OutputStream out = null; String mprompt = ""; boolean firsttime = true; private PasswordCallback mCB = null; @@ -49,8 +44,6 @@ public class PWCBsdr implements PasswordCallback { } public PWCBsdr(String prompt) { - in = System.in; - out = System.out; mprompt = prompt; /* to get the test program work diff --git a/base/common/src/com/netscape/cmscore/security/PWUtil.java b/base/common/src/com/netscape/cmscore/security/PWUtil.java index fa0de3c4b..78678b98b 100644 --- a/base/common/src/com/netscape/cmscore/security/PWUtil.java +++ b/base/common/src/com/netscape/cmscore/security/PWUtil.java @@ -21,53 +21,48 @@ import org.mozilla.jss.util.Password; import org.mozilla.jss.util.PasswordCallback; public class PWUtil { - public static Password - readPasswordFromStream() - throws PasswordCallback.GiveUpException { + + public static Password readPasswordFromStream() throws PasswordCallback.GiveUpException { StringBuffer buf = new StringBuffer(); String passwordString = ""; int c; - + // System.out.println( "about to do read" ); try { - // System.out.println( "about to do read" ); - try { - while ((c = System.in.read()) != -1) { - char ch = (char) c; + while ((c = System.in.read()) != -1) { + char ch = (char) c; - // System.out.println( "read [" + ch + "]" ); - // System.out.println( "char is [" + ch + "]" ); - if (ch != '\r') { - if (ch != '\n') { - buf.append(ch); - } else { - passwordString = buf.toString(); - buf.setLength(0); - break; - } + // System.out.println( "read [" + ch + "]" ); + // System.out.println( "char is [" + ch + "]" ); + if (ch != '\r') { + if (ch != '\n') { + buf.append(ch); + } else { + passwordString = buf.toString(); + buf.setLength(0); + break; } } - } catch (Exception e) { - System.out.println("READ EXCEPTION"); - } - - // memory problem? - // String passwordString = in.readLine(); - // System.out.println( "done read" ); - // System.out.println( " password recieved is [" - // + passwordString + "]" ); - if (passwordString == null) { - throw new PasswordCallback.GiveUpException(); } + } catch (Exception e) { + System.out.println("READ EXCEPTION"); + } - if (passwordString.equals("")) { - throw new PasswordCallback.GiveUpException(); - } + // memory problem? + // String passwordString = in.readLine(); + // System.out.println( "done read" ); + // System.out.println( " password recieved is [" + // + passwordString + "]" ); + if (passwordString == null) { + throw new PasswordCallback.GiveUpException(); + } - // System.out.println( "returning pw" ); - return (new Password(passwordString.toCharArray())); - } catch (Exception e) { + if (passwordString.equals("")) { throw new PasswordCallback.GiveUpException(); } + + // System.out.println( "returning pw" ); + return (new Password(passwordString.toCharArray())); + } } diff --git a/base/common/src/com/netscape/cmscore/security/PWsdrCache.java b/base/common/src/com/netscape/cmscore/security/PWsdrCache.java index b0445bd6d..810605d41 100644 --- a/base/common/src/com/netscape/cmscore/security/PWsdrCache.java +++ b/base/common/src/com/netscape/cmscore/security/PWsdrCache.java @@ -542,50 +542,52 @@ public class PWsdrCache { return ((File.separator).equals("\\")); } - public static boolean exec(String cmd) throws EBaseException { + public static boolean exec(String cmd) throws IOException { + String cmds[] = null; + + if (isNT()) { + // NT + cmds = new String[3]; + cmds[0] = "cmd"; + cmds[1] = "/c"; + cmds[2] = cmd; + } else { + // UNIX + cmds = new String[3]; + cmds[0] = "/bin/sh"; + cmds[1] = "-c"; + cmds[2] = cmd; + } + Process process = null; try { - String cmds[] = null; - - if (isNT()) { - // NT - cmds = new String[3]; - cmds[0] = "cmd"; - cmds[1] = "/c"; - cmds[2] = cmd; - } else { - // UNIX - cmds = new String[3]; - cmds[0] = "/bin/sh"; - cmds[1] = "-c"; - cmds[2] = cmd; - } - Process process = Runtime.getRuntime().exec(cmds); - + process = Runtime.getRuntime().exec(cmds); process.waitFor(); + } catch (IOException e) { + throw e; + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } - if (process.exitValue() == 0) { + if (process != null && process.exitValue() == 0) { - /** - * pOut = new BufferedReader( - * new InputStreamReader(process.getInputStream())); - * while ((l = pOut.readLine()) != null) { - * System.out.println(l); - * } - **/ - return true; - } else { + /** + * pOut = new BufferedReader( + * new InputStreamReader(process.getInputStream())); + * while ((l = pOut.readLine()) != null) { + * System.out.println(l); + * } + **/ + return true; + } else { - /** - * pOut = new BufferedReader( - * new InputStreamReader(process.getErrorStream())); - * l = null; - * while ((l = pOut.readLine()) != null) { - * System.out.println(l); - * } - **/ - return false; - } - } catch (Exception e) { + /** + * pOut = new BufferedReader( + * new InputStreamReader(process.getErrorStream())); + * l = null; + * while ((l = pOut.readLine()) != null) { + * System.out.println(l); + * } + **/ return false; } } diff --git a/base/java-tools/src/com/netscape/cmstools/PasswordCache.java b/base/java-tools/src/com/netscape/cmstools/PasswordCache.java index dbc52a02a..89254a2a5 100644 --- a/base/java-tools/src/com/netscape/cmstools/PasswordCache.java +++ b/base/java-tools/src/com/netscape/cmstools/PasswordCache.java @@ -818,9 +818,12 @@ class PWsdrCache { **/ return false; } - } catch (Exception e) { - return false; + } catch (IOException e) { + throw e; + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); } + return false; } public void debug(String msg) { diff --git a/base/kra/src/com/netscape/kra/SecurityDataRecoveryService.java b/base/kra/src/com/netscape/kra/SecurityDataRecoveryService.java index a2c6fd9f5..527548381 100644 --- a/base/kra/src/com/netscape/kra/SecurityDataRecoveryService.java +++ b/base/kra/src/com/netscape/kra/SecurityDataRecoveryService.java @@ -236,6 +236,7 @@ public class SecurityDataRecoveryService implements IService { throw new IOException("Failed to create cipher"); } } catch (Exception e) { + e.printStackTrace(); throw new EBaseException("Can't wrap pass phrase!"); } } 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(); + } + } } } } |