001: /*
002: * ModifyTrustAttributes.java
003: *
004: */
005:
006: /**
007: *
008: * @author ss133690
009: * @version
010: */package com.sun.portal.cli.cert;
011:
012: import org.mozilla.jss.crypto.*;
013: import com.sun.portal.log.common.PortalLogger;
014: import org.mozilla.jss.crypto.KeyPairGenerator;
015: import org.mozilla.jss.crypto.X509Certificate;
016: import org.mozilla.jss.util.*;
017: import org.mozilla.jss.ssl.*;
018: import org.mozilla.jss.*;
019: import org.mozilla.jss.pkcs11.*;
020: import java.security.cert.*;
021: import java.security.interfaces.*;
022: import java.security.*;
023: import java.security.PrivateKey;
024: import org.mozilla.jss.pkix.primitive.*;
025: import org.mozilla.jss.pkix.cert.*;
026: import org.mozilla.jss.pkix.cert.Certificate;
027: import org.mozilla.jss.asn1.*;
028: import org.mozilla.jss.pkcs7.*;
029: import java.util.StringTokenizer;
030:
031: public class ModifyTrustAttributes implements Command {
032: private JSSContext cntx;
033:
034: public boolean execute(JSSContext cntx) {
035: this .cntx = cntx;
036: CertAdminUtil.println(CertAdminHelpText.getTrustHelpText());
037:
038: //String certnick = CertAdminUtil.question("Please enter the name of the certificate:");
039: String certnick = CertAdminUtil.question(CertAdminLocale
040: .getPFString("q18", CertAdminConstants.q18));
041: if (certnick.trim().equals("")) {
042: //println("Invalid Certificate nickname");
043: CertAdminUtil.println(CertAdminLocale.getPFString("m30",
044: CertAdminConstants.m30));
045: return false;
046: }
047:
048: if (!JSSUtil.certExist(cntx, certnick)) {
049: //println("Certificate "+certnick+" does not exist");
050: CertAdminUtil.println(CertAdminLocale.getPFString("m31",
051: CertAdminConstants.m31));
052: return false;
053: }
054: String tmpattrib = "CT,CT,c";
055: //String attrib = CertAdminUtil.question("Please enter the trust attribute you want the certificate to have ["+tmpattrib+"]");
056: String attrib = CertAdminUtil.question(CertAdminLocale
057: .getPFString("q19", CertAdminConstants.q19)
058: + tmpattrib
059: + CertAdminLocale.getPFString("q1",
060: CertAdminConstants.q1));
061: if (attrib.trim().equals("")) {
062: attrib = tmpattrib;
063: }
064:
065: StringTokenizer st = new StringTokenizer(attrib, ",");
066: if (st.countTokens() != 3) {
067: //println("Invalid trust attribute "+attrib+" specified");
068: CertAdminUtil.println(CertAdminLocale.getPFString("m34",
069: CertAdminConstants.m34)
070: + CertAdminConstants.SPACE
071: + attrib
072: + CertAdminConstants.SPACE
073: + CertAdminLocale.getPFString("m35",
074: CertAdminConstants.m35));
075: return false;
076: }
077: CertAdminUtil.println(CertAdminConstants.newline);
078: //println("Modifying the trust attribute ...");
079: CertAdminUtil.println(CertAdminLocale.getPFString("m36",
080: CertAdminConstants.m35));
081: try {
082: X509Certificate cert = JSSUtil.getCertByNickname(cntx,
083: certnick);
084: X509Certificate updatedCert = JSSUtil
085: .changeCertificateTrust(cert,
086: st.nextToken().trim(), st.nextToken()
087: .trim(), st.nextToken().trim());
088: cntx.getCryptoManager().importCertToPerm(updatedCert,
089: certnick);
090: } catch (Exception ex) {
091: //println("Could not modify the trust attributes of the certificate "+certnick+" : "+ex.getMessage());
092: CertAdminUtil.println(CertAdminLocale.getPFString("m37",
093: CertAdminConstants.m37)
094: + CertAdminConstants.SPACE
095: + certnick
096: + CertAdminConstants.SPACE);
097: ex.printStackTrace();
098: return false;
099: }
100: //println("Success.");
101: CertAdminUtil.println(CertAdminLocale.getPFString("m38",
102: CertAdminConstants.m38));
103: return true;
104: }
105:
106: }
|