01: /*
02: * AddRootCA.java
03: *
04: */
05:
06: /**
07: *
08: * @author ss133690
09: * @version
10: */package com.sun.portal.cli.cert;
11:
12: import org.mozilla.jss.crypto.X509Certificate;
13: import com.sun.portal.log.common.PortalLogger;
14: import org.mozilla.jss.*;
15: import java.io.File;
16:
17: public class AddRootCA implements Command {
18: private JSSContext cntx;
19:
20: public boolean execute(JSSContext cntx) {
21: this .cntx = cntx;
22: CertAdminUtil.println(CertAdminHelpText.getDNHelpText());
23: //String cacertfile = CertAdminUtil.question("What is the name (including path) of file that contains the root"+CertAdminConstants.newline+
24: // "certificate that you would like to add to your database?");
25: String cacertfile = CertAdminUtil.question(CertAdminLocale
26: .getPFString("q14", CertAdminConstants.q14)
27: + CertAdminConstants.newline
28: + CertAdminLocale.getPFString("q141",
29: CertAdminConstants.q141));
30:
31: File file = new File(cacertfile);
32: if (!file.exists()) {
33: //println("Certificate file "+cacertfile+ " doesn't exists");
34: CertAdminUtil.println(CertAdminLocale.getPFString("m23",
35: CertAdminConstants.m23)
36: + CertAdminConstants.SPACE
37: + cacertfile
38: + CertAdminConstants.SPACE
39: + CertAdminLocale.getPFString("m231",
40: CertAdminConstants.m231));
41: return false;
42: }
43:
44: try {
45: X509Certificate cert = addCACertificate(file);
46: //Load the certificat efrom the certfile.
47: String certnick = cert.getNickname();
48: //Change the certificate trust attributes.
49: X509Certificate updatedCert = JSSUtil
50: .changeCertificateTrust(cert, "CT", "CT", "c");
51: //Import the ceriticate to the certificate database.
52: cntx.getCryptoManager().importCertToPerm(updatedCert,
53: certnick);
54: //println("Added the Root CA certificate successfully");
55:
56: CertAdminUtil.println(CertAdminConstants.newline);
57: CertAdminUtil.println(CertAdminLocale.getPFString("m24",
58: CertAdminConstants.m23));
59: return true;
60: } catch (Exception ex) {
61: //println("Could not add the Root CA certificate : "+ex.getMessage());
62: CertAdminUtil.println(CertAdminLocale.getPFString("m25",
63: CertAdminConstants.m24));
64: ex.printStackTrace();
65: return false;
66: }
67: }
68:
69: //Add CA certiticate from the encoded file
70: private X509Certificate addCACertificate(File certfile)
71: throws Exception {
72: return JSSUtil.addCertificate(cntx, certfile, null, true);
73: }
74:
75: }
|