001: /*
002: * ModifyTrustAttributes.java
003: *
004: */
005:
006: /**
007: *
008: * @author ss133690
009: * @version
010: */package com.sun.portal.cli.cert;
011:
012: import java.security.cert.*;
013: import com.sun.portal.log.common.PortalLogger;
014: import java.io.ByteArrayInputStream;
015:
016: public class VerifyCertificate implements Command {
017: private JSSContext cntx;
018: private String msg;
019:
020: public boolean execute(JSSContext cntx) {
021: msg = CertAdminLocale
022: .getPFString("m58", CertAdminConstants.m58)
023: + CertAdminConstants.SPACE
024: + CertAdminLocale.getPFString("m57",
025: CertAdminConstants.m57)
026: + CertAdminConstants.SPACE
027: + CertAdminLocale.getPFString("m56",
028: CertAdminConstants.m56);
029: return false;
030: }
031:
032: public String getMessage() {
033: return msg;
034: }
035:
036: public boolean execute(JSSContext cntx, String nick) {
037: this .cntx = cntx;
038: if (!JSSUtil.certExist(cntx, nick)) {
039: msg = CertAdminLocale.getPFString("m58",
040: CertAdminConstants.m58)
041: + CertAdminConstants.SPACE
042: + nick
043: + CertAdminConstants.SPACE
044: + CertAdminLocale.getPFString("m31",
045: CertAdminConstants.m31);
046: return false;
047: }
048: X509Certificate cert = null;
049: try {
050: org.mozilla.jss.crypto.X509Certificate certificate = JSSUtil
051: .getCertByNickname(cntx, nick);
052: CertificateFactory cf = CertificateFactory
053: .getInstance("X.509");
054:
055: ByteArrayInputStream bais = new ByteArrayInputStream(
056: certificate.getEncoded());
057: cert = (X509Certificate) cf.generateCertificate(bais);
058: cert.checkValidity();
059: if (cert.getIssuerDN().toString().equalsIgnoreCase(
060: cert.getSubjectDN().toString())) {
061: msg = CertAdminLocale.getPFString("m58",
062: CertAdminConstants.m58)
063: + CertAdminConstants.SPACE
064: + nick
065: + CertAdminConstants.SPACE
066: + CertAdminLocale.getPFString("m60",
067: CertAdminConstants.m60);
068: } else {
069: msg = CertAdminLocale.getPFString("m58",
070: CertAdminConstants.m58)
071: + CertAdminConstants.SPACE
072: + nick
073: + CertAdminConstants.SPACE
074: + CertAdminLocale.getPFString("m62",
075: CertAdminConstants.m62);
076: }
077:
078: } catch (CertificateExpiredException ex) {
079: msg = CertAdminLocale.getPFString("m58",
080: CertAdminConstants.m58)
081: + CertAdminConstants.SPACE
082: + nick
083: + CertAdminConstants.SPACE
084: + CertAdminLocale.getPFString("m59",
085: CertAdminConstants.m59)
086: + CertAdminConstants.SPACE + ex.getMessage();
087: return false;
088: } catch (CertificateNotYetValidException ex) {
089: msg = CertAdminLocale.getPFString("m58",
090: CertAdminConstants.m58)
091: + CertAdminConstants.SPACE
092: + nick
093: + CertAdminConstants.SPACE
094: + CertAdminLocale.getPFString("m61",
095: CertAdminConstants.m61)
096: + CertAdminConstants.SPACE + ex.getMessage();
097: return false;
098: } catch (Exception ex) {
099: //println("Could not print the certificate "+nick+" : "+ex.getMessage());
100: msg = CertAdminLocale.getPFString("m58",
101: CertAdminConstants.m58)
102: + CertAdminConstants.SPACE
103: + CertAdminLocale.getPFString("m57",
104: CertAdminConstants.m57)
105: + nick
106: + CertAdminConstants.SPACE + ex.getMessage();
107: ex.printStackTrace();
108: return false;
109: }
110: return true;
111: }
112:
113: }
|