summaryrefslogtreecommitdiffstats
path: root/pki/base/util/src/netscape/security/util/CrlPrettyPrint.java
diff options
context:
space:
mode:
Diffstat (limited to 'pki/base/util/src/netscape/security/util/CrlPrettyPrint.java')
-rw-r--r--pki/base/util/src/netscape/security/util/CrlPrettyPrint.java248
1 files changed, 115 insertions, 133 deletions
diff --git a/pki/base/util/src/netscape/security/util/CrlPrettyPrint.java b/pki/base/util/src/netscape/security/util/CrlPrettyPrint.java
index 83b6ac56..ba74a0d7 100644
--- a/pki/base/util/src/netscape/security/util/CrlPrettyPrint.java
+++ b/pki/base/util/src/netscape/security/util/CrlPrettyPrint.java
@@ -17,6 +17,7 @@
// --- END COPYRIGHT BLOCK ---
package netscape.security.util;
+
import java.text.DateFormat;
import java.util.Iterator;
import java.util.Locale;
@@ -29,46 +30,46 @@ import netscape.security.x509.Extension;
import netscape.security.x509.RevokedCertImpl;
import netscape.security.x509.X509CRLImpl;
+
/**
- * This class will display the certificate content in predefined format.
- *
+ * This class will display the certificate content in predefined
+ * format.
+ *
* @author Andrew Wnuk
* @version $Revision$, $Date$
*/
-public class CrlPrettyPrint {
+public class CrlPrettyPrint
+{
- /*
- * ========================================================== constants
- * ==========================================================
- */
+ /*==========================================================
+ * constants
+ *==========================================================*/
private final static String CUSTOM_LOCALE = "Custom";
- /*
- * ========================================================== variables
- * ==========================================================
- */
+ /*==========================================================
+ * variables
+ *==========================================================*/
private X509CRLImpl mCRL = null;
private PrettyPrintFormat pp = null;
- /*
- * ========================================================== constructors
- * ==========================================================
- */
+ /*==========================================================
+ * constructors
+ *==========================================================*/
public CrlPrettyPrint(X509CRLImpl crl) {
mCRL = crl;
pp = new PrettyPrintFormat(":");
}
- /*
- * ========================================================== public methods
- * ==========================================================
- */
+ /*==========================================================
+ * public methods
+ *==========================================================*/
/**
- * This method return string representation of the certificate revocation
- * list in predefined format using specified client local. I18N Support.
- *
+ * This method return string representation of the certificate
+ * revocation list in predefined format using specified client
+ * local. I18N Support.
+ *
* @param clientLocale Locale to be used for localization
* @return string representation of the certificate
*/
@@ -76,60 +77,60 @@ public class CrlPrettyPrint {
return toString(clientLocale, 0, 0, 0);
}
- public String toString(Locale clientLocale, long crlSize, long pageStart,
- long pageSize) {
+ public String toString(Locale clientLocale, long crlSize, long pageStart, long pageSize) {
- // get I18N resources
- ResourceBundle resource = ResourceBundle
- .getBundle(PrettyPrintResources.class.getName());
+ //get I18N resources
+ ResourceBundle resource = ResourceBundle.getBundle(
+ PrettyPrintResources.class.getName());
DateFormat dateFormater = DateFormat.getDateTimeInstance(
DateFormat.FULL, DateFormat.FULL, clientLocale);
- // get timezone and timezone ID
+ //get timezone and timezone ID
String tz = " ";
String tzid = " ";
StringBuffer sb = new StringBuffer();
try {
- sb.append(pp.indent(4)
- + resource.getString(PrettyPrintResources.TOKEN_CRL) + "\n");
- sb.append(pp.indent(8)
- + resource.getString(PrettyPrintResources.TOKEN_DATA)
- + "\n");
- sb.append(pp.indent(12)
- + resource.getString(PrettyPrintResources.TOKEN_VERSION)
- + " v");
+ sb.append(pp.indent(4) + resource.getString(
+ PrettyPrintResources.TOKEN_CRL) + "\n");
+ sb.append(pp.indent(8) + resource.getString(
+ PrettyPrintResources.TOKEN_DATA) + "\n");
+ sb.append(pp.indent(12) + resource.getString(
+ PrettyPrintResources.TOKEN_VERSION) + " v");
sb.append((mCRL.getVersion() + 1) + "\n");
- sb.append(pp.indent(12)
- + resource.getString(PrettyPrintResources.TOKEN_SIGALG)
- + mCRL.getSigAlgName() + " - " + mCRL.getSigAlgOID() + "\n");
- sb.append(pp.indent(12)
- + resource.getString(PrettyPrintResources.TOKEN_ISSUER)
- + mCRL.getIssuerDN().toString() + "\n");
+ sb.append(pp.indent(12) + resource.getString(
+ PrettyPrintResources.TOKEN_SIGALG) + mCRL.getSigAlgName() +
+ " - " + mCRL.getSigAlgOID() + "\n");
+ sb.append(pp.indent(12) + resource.getString(
+ PrettyPrintResources.TOKEN_ISSUER) +
+ mCRL.getIssuerDN().toString() + "\n");
// Format thisUpdate
String thisUpdate = dateFormater.format(mCRL.getThisUpdate());
// get timezone and timezone ID
if (TimeZone.getDefault() != null) {
tz = TimeZone.getDefault().getDisplayName(
- TimeZone.getDefault().inDaylightTime(
- mCRL.getThisUpdate()), TimeZone.SHORT,
- clientLocale);
+ TimeZone.getDefault().inDaylightTime(
+ mCRL.getThisUpdate()),
+ TimeZone.SHORT,
+ clientLocale);
tzid = TimeZone.getDefault().getID();
}
// Specify ThisUpdate
if (tz.equals(tzid) || tzid.equals(CUSTOM_LOCALE)) {
// Do NOT append timezone ID
sb.append(pp.indent(12)
- + resource
- .getString(PrettyPrintResources.TOKEN_THIS_UPDATE)
- + thisUpdate + "\n");
+ + resource.getString(
+ PrettyPrintResources.TOKEN_THIS_UPDATE)
+ + thisUpdate
+ + "\n");
} else {
// Append timezone ID
sb.append(pp.indent(12)
- + resource
- .getString(PrettyPrintResources.TOKEN_THIS_UPDATE)
- + thisUpdate + " " + tzid + "\n");
+ + resource.getString(
+ PrettyPrintResources.TOKEN_THIS_UPDATE)
+ + thisUpdate
+ + " " + tzid + "\n");
}
// Check for presence of NextUpdate
if (mCRL.getNextUpdate() != null) {
@@ -139,42 +140,40 @@ public class CrlPrettyPrint {
// re-get timezone (just in case it is different . . .)
if (TimeZone.getDefault() != null) {
tz = TimeZone.getDefault().getDisplayName(
- TimeZone.getDefault().inDaylightTime(
- mCRL.getNextUpdate()), TimeZone.SHORT,
- clientLocale);
+ TimeZone.getDefault().inDaylightTime(
+ mCRL.getNextUpdate()),
+ TimeZone.SHORT,
+ clientLocale);
}
// Specify NextUpdate
if (tz.equals(tzid) || tzid.equals(CUSTOM_LOCALE)) {
// Do NOT append timezone ID
sb.append(pp.indent(12)
- + resource
- .getString(PrettyPrintResources.TOKEN_NEXT_UPDATE)
- + nextUpdate + "\n");
+ + resource.getString(
+ PrettyPrintResources.TOKEN_NEXT_UPDATE)
+ + nextUpdate
+ + "\n");
} else {
// Append timezone ID
sb.append(pp.indent(12)
- + resource
- .getString(PrettyPrintResources.TOKEN_NEXT_UPDATE)
- + nextUpdate + " " + tzid + "\n");
+ + resource.getString(
+ PrettyPrintResources.TOKEN_NEXT_UPDATE)
+ + nextUpdate
+ + " " + tzid + "\n");
}
}
if (crlSize > 0 && pageStart == 0 && pageSize == 0) {
- sb.append(pp.indent(12)
- + resource
- .getString(PrettyPrintResources.TOKEN_REVOKED_CERTIFICATES)
- + crlSize + "\n");
- } else if ((crlSize == 0 && pageStart == 0 && pageSize == 0)
- || (crlSize > 0 && pageStart > 0 && pageSize > 0)) {
- sb.append(pp.indent(12)
- + resource
- .getString(PrettyPrintResources.TOKEN_REVOKED_CERTIFICATES));
+ sb.append(pp.indent(12) + resource.getString(
+ PrettyPrintResources.TOKEN_REVOKED_CERTIFICATES) + crlSize + "\n");
+ } else if ((crlSize == 0 && pageStart == 0 && pageSize == 0) ||
+ (crlSize > 0 && pageStart > 0 && pageSize > 0)) {
+ sb.append(pp.indent(12) + resource.getString(
+ PrettyPrintResources.TOKEN_REVOKED_CERTIFICATES));
if (crlSize > 0 && pageStart > 0 && pageSize > 0) {
- long upperLimit = (pageStart + pageSize - 1 > crlSize) ? crlSize
- : pageStart + pageSize - 1;
+ long upperLimit = (pageStart + pageSize - 1 > crlSize) ? crlSize : pageStart + pageSize - 1;
- sb.append("" + pageStart + "-" + upperLimit + " of "
- + crlSize);
+ sb.append("" + pageStart + "-" + upperLimit + " of " + crlSize);
}
sb.append("\n");
@@ -184,62 +183,52 @@ public class CrlPrettyPrint {
Iterator i = revokedCerts.iterator();
long l = 1;
- while ((i.hasNext())
- && ((crlSize == 0) || (pageStart + pageSize > l))) {
- RevokedCertImpl revokedCert = (RevokedCertImpl) i
- .next();
-
- if ((crlSize == 0)
- || ((pageStart <= l) && (pageStart + pageSize > l))) {
- sb.append(pp.indent(16)
- + resource
- .getString(PrettyPrintResources.TOKEN_SERIAL)
- + "0x"
- + revokedCert.getSerialNumber()
- .toString(16).toUpperCase() + "\n");
- String revocationDate = dateFormater
- .format(revokedCert.getRevocationDate());
+ while ((i.hasNext()) && ((crlSize == 0) || (pageStart + pageSize > l))) {
+ RevokedCertImpl revokedCert =
+ (RevokedCertImpl) i.next();
+
+ if ((crlSize == 0) || ((pageStart <= l) && (pageStart + pageSize > l))) {
+ sb.append(pp.indent(16) + resource.getString(
+ PrettyPrintResources.TOKEN_SERIAL) + "0x" +
+ revokedCert.getSerialNumber().toString(16).toUpperCase() + "\n");
+ String revocationDate =
+ dateFormater.format(revokedCert.getRevocationDate());
// re-get timezone
// (just in case it is different . . .)
if (TimeZone.getDefault() != null) {
- tz = TimeZone
- .getDefault()
- .getDisplayName(
- TimeZone.getDefault()
- .inDaylightTime(
- revokedCert
- .getRevocationDate()),
- TimeZone.SHORT, clientLocale);
+ tz = TimeZone.getDefault().getDisplayName(
+ TimeZone.getDefault().inDaylightTime(
+ revokedCert.getRevocationDate()),
+ TimeZone.SHORT,
+ clientLocale);
}
// Specify revocationDate
- if (tz.equals(tzid) || tzid.equals(CUSTOM_LOCALE)) {
+ if (tz.equals(tzid) ||
+ tzid.equals(CUSTOM_LOCALE)) {
// Do NOT append timezone ID
sb.append(pp.indent(16)
- + resource
- .getString(PrettyPrintResources.TOKEN_REVOCATION_DATE)
- + revocationDate + "\n");
+ + resource.getString(
+ PrettyPrintResources.TOKEN_REVOCATION_DATE)
+ + revocationDate
+ + "\n");
} else {
// Append timezone ID
sb.append(pp.indent(16)
- + resource
- .getString(PrettyPrintResources.TOKEN_REVOCATION_DATE)
- + revocationDate + " " + tzid + "\n");
+ + resource.getString(
+ PrettyPrintResources.TOKEN_REVOCATION_DATE)
+ + revocationDate
+ + " " + tzid + "\n");
}
if (revokedCert.hasExtensions()) {
- sb.append(pp.indent(16)
- + resource
- .getString(PrettyPrintResources.TOKEN_EXTENSIONS)
- + "\n");
- CRLExtensions crlExtensions = revokedCert
- .getExtensions();
+ sb.append(pp.indent(16) + resource.getString(
+ PrettyPrintResources.TOKEN_EXTENSIONS) + "\n");
+ CRLExtensions crlExtensions = revokedCert.getExtensions();
if (crlExtensions != null) {
for (int k = 0; k < crlExtensions.size(); k++) {
- Extension ext = (Extension) crlExtensions
- .elementAt(k);
- ExtPrettyPrint extpp = new ExtPrettyPrint(
- ext, 20);
+ Extension ext = (Extension) crlExtensions.elementAt(k);
+ ExtPrettyPrint extpp = new ExtPrettyPrint(ext, 20);
sb.append(extpp.toString());
}
@@ -254,10 +243,8 @@ public class CrlPrettyPrint {
CRLExtensions crlExtensions = mCRL.getExtensions();
if (crlExtensions != null) {
- sb.append(pp.indent(8)
- + resource
- .getString(PrettyPrintResources.TOKEN_EXTENSIONS)
- + "\n");
+ sb.append(pp.indent(8) + resource.getString(
+ PrettyPrintResources.TOKEN_EXTENSIONS) + "\n");
for (int k = 0; k < crlExtensions.size(); k++) {
Extension ext = (Extension) crlExtensions.elementAt(k);
ExtPrettyPrint extpp = new ExtPrettyPrint(ext, 12);
@@ -266,25 +253,20 @@ public class CrlPrettyPrint {
}
}
- // take care of signature
- sb.append(pp.indent(8)
- + resource.getString(PrettyPrintResources.TOKEN_SIGNATURE)
- + "\n");
- // XXX I18N Algorithm Name ?
- sb.append(pp.indent(12)
- + resource.getString(PrettyPrintResources.TOKEN_ALGORITHM)
- + mCRL.getSigAlgName() + " - " + mCRL.getSigAlgOID() + "\n");
- sb.append(pp.indent(12)
- + resource.getString(PrettyPrintResources.TOKEN_SIGNATURE)
- + "\n");
+ //take care of signature
+ sb.append(pp.indent(8) + resource.getString(
+ PrettyPrintResources.TOKEN_SIGNATURE) + "\n");
+ //XXX I18N Algorithm Name ?
+ sb.append(pp.indent(12) + resource.getString(
+ PrettyPrintResources.TOKEN_ALGORITHM) +
+ mCRL.getSigAlgName() + " - " + mCRL.getSigAlgOID() + "\n");
+ sb.append(pp.indent(12) + resource.getString(
+ PrettyPrintResources.TOKEN_SIGNATURE) + "\n");
sb.append(pp.toHexString(mCRL.getSignature(), 16, 16));
} catch (Exception e) {
- sb.append("\n\n"
- + pp.indent(4)
- + resource
- .getString(PrettyPrintResources.TOKEN_DECODING_ERROR)
- + "\n\n");
+ sb.append("\n\n" + pp.indent(4) + resource.getString(
+ PrettyPrintResources.TOKEN_DECODING_ERROR) + "\n\n");
e.printStackTrace();
}