281 int retval = 0;
282
283 for (int i = 1; i < rawCertInfo.length; i++) {
284 retval += rawCertInfo[i] * i;
285 }
286 return(retval);
287 }
288
289 /**
290 * Returns a printable representation of the certificate.
291 */
292 public String toString() {
293
294 if (subject == null || pubKey == null || interval == null
295 || issuer == null || algId == null || serialNum == null) {
296 throw new NullPointerException("X.509 cert is incomplete");
297 }
298 StringBuilder sb = new StringBuilder();
299
300 sb.append("[\n");
301 sb.append(" " + version.toString() + "\n");
302 sb.append(" Subject: " + subject.toString() + "\n");
303 sb.append(" Signature Algorithm: " + algId.toString() + "\n");
304 sb.append(" Key: " + pubKey.toString() + "\n");
305 sb.append(" " + interval.toString() + "\n");
306 sb.append(" Issuer: " + issuer.toString() + "\n");
307 sb.append(" " + serialNum.toString() + "\n");
308
309 // optional v2, v3 extras
310 if (issuerUniqueId != null) {
311 sb.append(" Issuer Id:\n" + issuerUniqueId.toString() + "\n");
312 }
313 if (subjectUniqueId != null) {
314 sb.append(" Subject Id:\n" + subjectUniqueId.toString() + "\n");
315 }
316 if (extensions != null) {
317 Collection<Extension> allExts = extensions.getAllExtensions();
318 Extension[] exts = allExts.toArray(new Extension[0]);
319 sb.append("\nCertificate Extensions: " + exts.length);
320 for (int i = 0; i < exts.length; i++) {
321 sb.append("\n[" + (i+1) + "]: ");
322 Extension ext = exts[i];
323 try {
324 if (OIDMap.getClass(ext.getExtensionId()) == null) {
325 sb.append(ext.toString());
326 byte[] extValue = ext.getExtensionValue();
327 if (extValue != null) {
328 DerOutputStream out = new DerOutputStream();
329 out.putOctetString(extValue);
330 extValue = out.toByteArray();
331 HexDumpEncoder enc = new HexDumpEncoder();
332 sb.append("Extension unknown: "
333 + "DER encoded OCTET string =\n"
334 + enc.encodeBuffer(extValue) + "\n");
335 }
336 } else
337 sb.append(ext.toString()); //sub-class exists
338 } catch (Exception e) {
339 sb.append(", Error parsing this extension");
340 }
341 }
342 Map<String,Extension> invalid = extensions.getUnparseableExtensions();
343 if (invalid.isEmpty() == false) {
344 sb.append("\nUnparseable certificate extensions: " + invalid.size());
345 int i = 1;
346 for (Extension ext : invalid.values()) {
347 sb.append("\n[" + (i++) + "]: ");
348 sb.append(ext);
349 }
350 }
351 }
352 sb.append("\n]");
353 return sb.toString();
354 }
355
356 /**
357 * Set the certificate attribute.
358 *
359 * @params name the name of the Certificate attribute.
360 * @params val the value of the Certificate attribute.
361 * @exception CertificateException on invalid attributes.
362 * @exception IOException on other errors.
363 */
364 public void set(String name, Object val)
365 throws CertificateException, IOException {
366 X509AttributeName attrName = new X509AttributeName(name);
367
|
281 int retval = 0;
282
283 for (int i = 1; i < rawCertInfo.length; i++) {
284 retval += rawCertInfo[i] * i;
285 }
286 return(retval);
287 }
288
289 /**
290 * Returns a printable representation of the certificate.
291 */
292 public String toString() {
293
294 if (subject == null || pubKey == null || interval == null
295 || issuer == null || algId == null || serialNum == null) {
296 throw new NullPointerException("X.509 cert is incomplete");
297 }
298 StringBuilder sb = new StringBuilder();
299
300 sb.append("[\n");
301 sb.append(" ").append(version).append('\n');
302 sb.append(" Subject: ").append(subject).append('\n');
303 sb.append(" Signature Algorithm: ").append(algId).append('\n');
304 sb.append(" Key: ").append(pubKey).append('\n');
305 sb.append(" ").append(interval).append('\n');
306 sb.append(" Issuer: ").append(issuer).append('\n');
307 sb.append(" ").append(serialNum).append('\n');
308
309 // optional v2, v3 extras
310 if (issuerUniqueId != null) {
311 sb.append(" Issuer Id:\n").append(issuerUniqueId).append('\n');
312 }
313 if (subjectUniqueId != null) {
314 sb.append(" Subject Id:\n").append(subjectUniqueId).append('\n');
315 }
316 if (extensions != null) {
317 Collection<Extension> allExts = extensions.getAllExtensions();
318 Extension[] exts = allExts.toArray(new Extension[0]);
319 sb.append("\nCertificate Extensions: ").append(exts.length);
320 for (int i = 0; i < exts.length; i++) {
321 sb.append("\n[").append(i + 1).append("]: ");
322 Extension ext = exts[i];
323 try {
324 if (OIDMap.getClass(ext.getExtensionId()) == null) {
325 sb.append(ext.toString());
326 byte[] extValue = ext.getExtensionValue();
327 if (extValue != null) {
328 DerOutputStream out = new DerOutputStream();
329 out.putOctetString(extValue);
330 extValue = out.toByteArray();
331 HexDumpEncoder enc = new HexDumpEncoder();
332 sb.append("Extension unknown: " + "DER encoded OCTET string =\n")
333 .append(enc.encodeBuffer(extValue)).append('\n');
334 }
335 } else
336 sb.append(ext.toString()); //sub-class exists
337 } catch (Exception e) {
338 sb.append(", Error parsing this extension");
339 }
340 }
341 Map<String,Extension> invalid = extensions.getUnparseableExtensions();
342 if (invalid.isEmpty() == false) {
343 sb.append("\nUnparseable certificate extensions: ").append(invalid.size());
344 int i = 1;
345 for (Extension ext : invalid.values()) {
346 sb.append("\n[").append(i++).append("]: ");
347 sb.append(ext);
348 }
349 }
350 }
351 sb.append("\n]");
352 return sb.toString();
353 }
354
355 /**
356 * Set the certificate attribute.
357 *
358 * @params name the name of the Certificate attribute.
359 * @params val the value of the Certificate attribute.
360 * @exception CertificateException on invalid attributes.
361 * @exception IOException on other errors.
362 */
363 public void set(String name, Object val)
364 throws CertificateException, IOException {
365 X509AttributeName attrName = new X509AttributeName(name);
366
|