diff options
Diffstat (limited to 'pki/base/common/src/com/netscape/cms/policy/extensions/CertificateRenewalWindowExt.java')
-rw-r--r-- | pki/base/common/src/com/netscape/cms/policy/extensions/CertificateRenewalWindowExt.java | 109 |
1 files changed, 57 insertions, 52 deletions
diff --git a/pki/base/common/src/com/netscape/cms/policy/extensions/CertificateRenewalWindowExt.java b/pki/base/common/src/com/netscape/cms/policy/extensions/CertificateRenewalWindowExt.java index bb665d9e2..c5a24d630 100644 --- a/pki/base/common/src/com/netscape/cms/policy/extensions/CertificateRenewalWindowExt.java +++ b/pki/base/common/src/com/netscape/cms/policy/extensions/CertificateRenewalWindowExt.java @@ -17,6 +17,7 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cms.policy.extensions; + import java.io.IOException; import java.security.cert.CertificateException; import java.util.Date; @@ -39,20 +40,20 @@ import com.netscape.certsrv.request.IRequest; import com.netscape.certsrv.request.PolicyResult; import com.netscape.cms.policy.APolicyRule; + /** * Certificate Renewal Window Extension Policy * <P> - * * <PRE> * NOTE: The Policy Framework has been replaced by the Profile Framework. * </PRE> * <P> - * + * * @deprecated * @version $Revision$, $Date$ */ -public class CertificateRenewalWindowExt extends APolicyRule implements - IEnrollmentPolicy, IExtendedPluginInfo { +public class CertificateRenewalWindowExt extends APolicyRule + implements IEnrollmentPolicy, IExtendedPluginInfo { protected static final String PROP_END_TIME = "relativeEndTime"; protected static final String PROP_BEGIN_TIME = "relativeBeginTime"; @@ -63,8 +64,9 @@ public class CertificateRenewalWindowExt extends APolicyRule implements protected String mEndTime; /** - * Adds the Netscape comment in the end-entity certificates or CA - * certificates. The policy is set to be non-critical with the provided OID. + * Adds the Netscape comment in the end-entity certificates or + * CA certificates. The policy is set to be non-critical with the + * provided OID. */ public CertificateRenewalWindowExt() { NAME = "CertificateRenewalWindowExt"; @@ -73,11 +75,11 @@ public class CertificateRenewalWindowExt extends APolicyRule implements /** * Initializes this policy rule. - * - * @param config The config store reference + * + * @param config The config store reference */ public void init(ISubsystem owner, IConfigStore config) - throws EBaseException { + throws EBaseException { mCritical = config.getBoolean(PROP_CRITICAL, false); mBeginTime = config.getString(PROP_BEGIN_TIME, null); mEndTime = config.getString(PROP_END_TIME, null); @@ -87,15 +89,16 @@ public class CertificateRenewalWindowExt extends APolicyRule implements /** * Applies the policy on the given Request. * <p> - * - * @param req The request on which to apply policy. + * + * @param req The request on which to apply policy. * @return The policy result object. */ public PolicyResult apply(IRequest req) { PolicyResult res = PolicyResult.ACCEPTED; // get cert info. - X509CertInfo[] ci = req.getExtDataInCertInfoArray(IRequest.CERT_INFO); + X509CertInfo[] ci = + req.getExtDataInCertInfoArray(IRequest.CERT_INFO); if (ci == null || ci[0] == null) { setError(req, CMS.getUserMessage("CMS_POLICY_NO_CERT_INFO"), NAME); @@ -116,8 +119,8 @@ public class CertificateRenewalWindowExt extends APolicyRule implements CertificateExtensions extensions = null; try { - extensions = (CertificateExtensions) certInfo - .get(X509CertInfo.EXTENSIONS); + extensions = (CertificateExtensions) + certInfo.get(X509CertInfo.EXTENSIONS); } catch (IOException e) { } catch (CertificateException e) { } @@ -125,8 +128,8 @@ public class CertificateRenewalWindowExt extends APolicyRule implements if (extensions == null) { extensions = new CertificateExtensions(); try { - certInfo.set(X509CertInfo.VERSION, new CertificateVersion( - CertificateVersion.V3)); + certInfo.set(X509CertInfo.VERSION, + new CertificateVersion(CertificateVersion.V3)); certInfo.set(X509CertInfo.EXTENSIONS, extensions); } catch (Exception e) { } @@ -134,10 +137,10 @@ public class CertificateRenewalWindowExt extends APolicyRule implements // remove any previously computed version of the extension try { extensions.delete(CertificateRenewalWindowExtension.NAME); - + } catch (IOException e) { // this is the hack: for some reason, the key which is the name - // of the policy has been converted into the OID + // of the policy has been converted into the OID try { extensions.delete("2.16.840.1.113730.1.15"); } catch (IOException ee) { @@ -150,21 +153,23 @@ public class CertificateRenewalWindowExt extends APolicyRule implements CertificateRenewalWindowExtension crwExt = null; if (mEndTime == null || mEndTime.equals("")) { - crwExt = new CertificateRenewalWindowExtension(mCritical, - getDateValue(now, mBeginTime), null); + crwExt = new CertificateRenewalWindowExtension( + mCritical, + getDateValue(now, mBeginTime), + null); } else { - crwExt = new CertificateRenewalWindowExtension(mCritical, - getDateValue(now, mBeginTime), getDateValue(now, - mEndTime)); + crwExt = new CertificateRenewalWindowExtension( + mCritical, + getDateValue(now, mBeginTime), + getDateValue(now, mEndTime)); } - extensions.set(CertificateRenewalWindowExtension.NAME, crwExt); + extensions.set(CertificateRenewalWindowExtension.NAME, + crwExt); } catch (Exception e) { - log(ILogger.LL_FAILURE, CMS.getLogMessage( - "POLICY_ERROR_CERTIFICATE_POLICIES_1", NAME)); - setError( - req, - CMS.getUserMessage("CMS_POLICY_CERTIFICATE_POLICIES_ERROR"), - NAME); + log(ILogger.LL_FAILURE, + CMS.getLogMessage("POLICY_ERROR_CERTIFICATE_POLICIES_1", NAME)); + setError(req, + CMS.getUserMessage("CMS_POLICY_CERTIFICATE_POLICIES_ERROR"), NAME); return PolicyResult.REJECTED; } return PolicyResult.ACCEPTED; @@ -174,18 +179,20 @@ public class CertificateRenewalWindowExt extends APolicyRule implements long time; if (s.endsWith("s")) { - time = 1000 * Long.parseLong(s.substring(0, s.length() - 1)); + time = 1000 * Long.parseLong(s.substring(0, + s.length() - 1)); } else if (s.endsWith("m")) { - time = 60 * 1000 * Long.parseLong(s.substring(0, s.length() - 1)); + time = 60 * 1000 * Long.parseLong(s.substring(0, + s.length() - 1)); } else if (s.endsWith("h")) { - time = 60 * 60 * 1000 * Long.parseLong(s.substring(0, - s.length() - 1)); + time = 60 * 60 * 1000 * Long.parseLong(s.substring(0, + s.length() - 1)); } else if (s.endsWith("D")) { - time = 24 * 60 * 60 * 1000 - * Long.parseLong(s.substring(0, s.length() - 1)); + time = 24 * 60 * 60 * 1000 * Long.parseLong( + s.substring(0, s.length() - 1)); } else if (s.endsWith("M")) { - time = 30 * 60 * 60 * 1000 - * Long.parseLong(s.substring(0, s.length() - 1)); + time = 30 * 60 * 60 * 1000 * Long.parseLong( + s.substring(0, s.length() - 1)); } else { time = 1000 * Long.parseLong(s); } @@ -195,16 +202,14 @@ public class CertificateRenewalWindowExt extends APolicyRule implements public String[] getExtendedPluginInfo(Locale locale) { String[] params = { - PROP_CRITICAL - + ";boolean;Netscape recommendation: non-critical.", - PROP_BEGIN_TIME - + ";string;Start Time in seconds (Relative to the time of issuance). Optionally, time unit (s - seconds, m - minutes, h - hours, D - days, M - months) can be specified right after the value. For example, 5 days can be expressed as 5D.", - PROP_END_TIME - + ";string;End Time in seconds (Optional, Relative to the time of issuance). Optionally, time unit (s - seconds, m - minutes, h - hours, D - days, M - months) can be specified right after the value. For example, 5 days can be expressed as 5D.", - IExtendedPluginInfo.HELP_TOKEN - + ";configuration-policyrules-certificaterenewalwindow", - IExtendedPluginInfo.HELP_TEXT - + ";Adds 'Certificate Renewal Window' extension. See manual" }; + PROP_CRITICAL + ";boolean;Netscape recommendation: non-critical.", + PROP_BEGIN_TIME + ";string;Start Time in seconds (Relative to the time of issuance). Optionally, time unit (s - seconds, m - minutes, h - hours, D - days, M - months) can be specified right after the value. For example, 5 days can be expressed as 5D.", + PROP_END_TIME + ";string;End Time in seconds (Optional, Relative to the time of issuance). Optionally, time unit (s - seconds, m - minutes, h - hours, D - days, M - months) can be specified right after the value. For example, 5 days can be expressed as 5D.", + IExtendedPluginInfo.HELP_TOKEN + + ";configuration-policyrules-certificaterenewalwindow", + IExtendedPluginInfo.HELP_TEXT + + ";Adds 'Certificate Renewal Window' extension. See manual" + }; return params; @@ -212,10 +217,10 @@ public class CertificateRenewalWindowExt extends APolicyRule implements /** * Return configured parameters for a policy rule instance. - * + * * @return nvPairs A Vector of name/value pairs. */ - public Vector getInstanceParams() { + public Vector getInstanceParams() { Vector params = new Vector(); params.addElement(PROP_CRITICAL + "=" + mCritical); @@ -234,10 +239,10 @@ public class CertificateRenewalWindowExt extends APolicyRule implements /** * Return default parameters for a policy implementation. - * + * * @return nvPairs A Vector of name/value pairs. */ - public Vector getDefaultParams() { + public Vector getDefaultParams() { Vector defParams = new Vector(); defParams.addElement(PROP_CRITICAL + "=false"); |