01: /*
02: * PrintCertificate.java
03: *
04: */
05:
06: /**
07: *
08: * @author ss133690
09: * @version
10: */package com.sun.portal.cli.cert;
11:
12: import java.security.cert.*;
13: import com.sun.portal.log.common.PortalLogger;
14: import java.io.ByteArrayInputStream;
15:
16: public class PrintCertificate implements Command {
17: public boolean execute(JSSContext cntx) {
18: //String nick = CertAdminUtil.question("Please enter the name of the certificate:");
19: String nick = CertAdminUtil.question(CertAdminLocale
20: .getPFString("q18", CertAdminConstants.q9));
21:
22: if (nick.trim().equals("")) {
23: //println("Certifcate name entered is not valid.");
24: CertAdminUtil.println(CertAdminLocale.getPFString("m30",
25: CertAdminConstants.m30));
26: return false;
27: }
28:
29: if (!JSSUtil.certExist(cntx, nick)) {
30: //println("Specified certifcate does not exist.");
31: CertAdminUtil.println(CertAdminLocale.getPFString("m31",
32: CertAdminConstants.m31));
33: return false;
34: }
35: try {
36: org.mozilla.jss.crypto.X509Certificate certificate = JSSUtil
37: .getCertByNickname(cntx, nick);
38: CertificateFactory cf = CertificateFactory
39: .getInstance("X.509");
40:
41: ByteArrayInputStream bais = new ByteArrayInputStream(
42: certificate.getEncoded());
43: Certificate cert = cf.generateCertificate(bais);
44: CertAdminUtil.println(cert.toString());
45:
46: //java.security.cert.X509Certificate cert = (java.security.cert.X509Certificate)cntx.getKeyStore().getCertificate(nick);
47: return true;
48: } catch (Exception ex) {
49: //println("Could not print the certificate "+nick+" : "+ex.getMessage());
50: CertAdminUtil.println(CertAdminLocale.getPFString("m39",
51: CertAdminConstants.m39)
52: + CertAdminConstants.SPACE
53: + nick
54: + CertAdminConstants.SPACE);
55: ex.printStackTrace();
56: return false;
57: }
58: }
59:
60: }
|