diff options
Diffstat (limited to 'pki/base/common/src/com/netscape/cms/profile/def/PrivateKeyUsagePeriodExtDefault.java')
-rw-r--r-- | pki/base/common/src/com/netscape/cms/profile/def/PrivateKeyUsagePeriodExtDefault.java | 197 |
1 files changed, 110 insertions, 87 deletions
diff --git a/pki/base/common/src/com/netscape/cms/profile/def/PrivateKeyUsagePeriodExtDefault.java b/pki/base/common/src/com/netscape/cms/profile/def/PrivateKeyUsagePeriodExtDefault.java index dd522f306..f1a71ff98 100644 --- a/pki/base/common/src/com/netscape/cms/profile/def/PrivateKeyUsagePeriodExtDefault.java +++ b/pki/base/common/src/com/netscape/cms/profile/def/PrivateKeyUsagePeriodExtDefault.java @@ -17,6 +17,7 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cms.profile.def; + import java.text.ParsePosition; import java.text.SimpleDateFormat; import java.util.Date; @@ -36,10 +37,12 @@ import com.netscape.certsrv.property.EPropertyException; import com.netscape.certsrv.property.IDescriptor; import com.netscape.certsrv.request.IRequest; + /** - * This class implements an enrollment default policy that populates a Private - * Key Usage Period extension into the certificate template. - * + * This class implements an enrollment default policy + * that populates a Private Key Usage Period extension + * into the certificate template. + * * @version $Revision$, $Date$ */ public class PrivateKeyUsagePeriodExtDefault extends EnrollExtDefault { @@ -67,115 +70,125 @@ public class PrivateKeyUsagePeriodExtDefault extends EnrollExtDefault { } public void init(IProfile profile, IConfigStore config) - throws EProfileException { + throws EProfileException { super.init(profile, config); } - public IDescriptor getConfigDescriptor(Locale locale, String name) { + public IDescriptor getConfigDescriptor(Locale locale, String name) { if (name.equals(CONFIG_CRITICAL)) { - return new Descriptor(IDescriptor.BOOLEAN, null, "false", + return new Descriptor(IDescriptor.BOOLEAN, null, + "false", CMS.getUserMessage(locale, "CMS_PROFILE_CRITICAL")); } else if (name.equals(CONFIG_START_TIME)) { - return new Descriptor(IDescriptor.STRING, null, "0", - CMS.getUserMessage(locale, - "CMS_PROFILE_VALIDITY_START_TIME")); + return new Descriptor(IDescriptor.STRING, null, + "0", + CMS.getUserMessage(locale, "CMS_PROFILE_VALIDITY_START_TIME")); } else if (name.equals(CONFIG_DURATION)) { - return new Descriptor(IDescriptor.STRING, null, "365", + return new Descriptor(IDescriptor.STRING, null, + "365", CMS.getUserMessage(locale, "CMS_PROFILE_VALIDITY_RANGE")); } else { return null; } } - public void setConfig(String name, String value) throws EPropertyException { + public void setConfig(String name, String value) + throws EPropertyException { if (name.equals(CONFIG_START_TIME)) { - try { - Integer.parseInt(value); - } catch (Exception e) { - throw new EPropertyException(CMS.getUserMessage( - "CMS_INVALID_PROPERTY", CONFIG_START_TIME)); - } + try { + Integer.parseInt(value); + } catch (Exception e) { + throw new EPropertyException(CMS.getUserMessage( + "CMS_INVALID_PROPERTY", CONFIG_START_TIME)); + } } else if (name.equals(CONFIG_DURATION)) { - try { - Integer.parseInt(value); - } catch (Exception e) { - throw new EPropertyException(CMS.getUserMessage( - "CMS_INVALID_PROPERTY", CONFIG_DURATION)); - } + try { + Integer.parseInt(value); + } catch (Exception e) { + throw new EPropertyException(CMS.getUserMessage( + "CMS_INVALID_PROPERTY", CONFIG_DURATION)); + } } super.setConfig(name, value); } public IDescriptor getValueDescriptor(Locale locale, String name) { if (name.equals(VAL_CRITICAL)) { - return new Descriptor(IDescriptor.BOOLEAN, null, "false", + return new Descriptor(IDescriptor.BOOLEAN, null, + "false", CMS.getUserMessage(locale, "CMS_PROFILE_CRITICAL")); } else if (name.equals(VAL_NOT_BEFORE)) { - return new Descriptor(IDescriptor.STRING, null, "0", + return new Descriptor(IDescriptor.STRING, null, + "0", CMS.getUserMessage(locale, "CMS_PROFILE_NOT_BEFORE")); } else if (name.equals(VAL_NOT_AFTER)) { - return new Descriptor(IDescriptor.STRING, null, "30", + return new Descriptor(IDescriptor.STRING, null, + "30", CMS.getUserMessage(locale, "CMS_PROFILE_NOT_AFTER")); } else { return null; } } - public void setValue(String name, Locale locale, X509CertInfo info, - String value) throws EPropertyException { + public void setValue(String name, Locale locale, + X509CertInfo info, String value) + throws EPropertyException { try { PrivateKeyUsageExtension ext = null; if (name == null) { - throw new EPropertyException(CMS.getUserMessage(locale, - "CMS_INVALID_PROPERTY", name)); + throw new EPropertyException(CMS.getUserMessage( + locale, "CMS_INVALID_PROPERTY", name)); } ObjectIdentifier oid = PKIXExtensions.PrivateKeyUsage_Id; - ext = (PrivateKeyUsageExtension) getExtension(oid.toString(), info); + ext = (PrivateKeyUsageExtension) + getExtension(oid.toString(), info); - if (ext == null) { - populate(null, info); + if(ext == null) { + populate(null,info); } if (name.equals(VAL_CRITICAL)) { - ext = (PrivateKeyUsageExtension) getExtension(oid.toString(), - info); + ext = (PrivateKeyUsageExtension) + getExtension(oid.toString(), info); boolean val = Boolean.valueOf(value).booleanValue(); - if (ext == null) { + if (ext == null) { return; } - ext.setCritical(val); - } else if (name.equals(VAL_NOT_BEFORE)) { - SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT); - ParsePosition pos = new ParsePosition(0); + ext.setCritical(val); + } else if (name.equals(VAL_NOT_BEFORE)) { + SimpleDateFormat formatter = + new SimpleDateFormat(DATE_FORMAT); + ParsePosition pos = new ParsePosition(0); Date date = formatter.parse(value, pos); - ext = (PrivateKeyUsageExtension) getExtension(oid.toString(), - info); + ext = (PrivateKeyUsageExtension) + getExtension(oid.toString(), info); - if (ext == null) { + if (ext == null) { return; } ext.set(PrivateKeyUsageExtension.NOT_BEFORE, date); - } else if (name.equals(VAL_NOT_AFTER)) { - SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT); - ParsePosition pos = new ParsePosition(0); + } else if (name.equals(VAL_NOT_AFTER)) { + SimpleDateFormat formatter = + new SimpleDateFormat(DATE_FORMAT); + ParsePosition pos = new ParsePosition(0); Date date = formatter.parse(value, pos); - ext = (PrivateKeyUsageExtension) getExtension(oid.toString(), - info); + ext = (PrivateKeyUsageExtension) + getExtension(oid.toString(), info); - if (ext == null) { + if (ext == null) { return; } ext.set(PrivateKeyUsageExtension.NOT_AFTER, date); } else { - throw new EPropertyException(CMS.getUserMessage(locale, - "CMS_INVALID_PROPERTY", name)); + throw new EPropertyException(CMS.getUserMessage( + locale, "CMS_INVALID_PROPERTY", name)); } replaceExtension(ext.getExtensionId().toString(), ext, info); @@ -186,33 +199,37 @@ public class PrivateKeyUsagePeriodExtDefault extends EnrollExtDefault { } } - public String getValue(String name, Locale locale, X509CertInfo info) - throws EPropertyException { + public String getValue(String name, Locale locale, + X509CertInfo info) + throws EPropertyException { PrivateKeyUsageExtension ext = null; if (name == null) { - throw new EPropertyException(CMS.getUserMessage(locale, - "CMS_INVALID_PROPERTY", name)); + throw new EPropertyException(CMS.getUserMessage( + locale, "CMS_INVALID_PROPERTY", name)); } ObjectIdentifier oid = PKIXExtensions.PrivateKeyUsage_Id; - ext = (PrivateKeyUsageExtension) getExtension(oid.toString(), info); + ext = (PrivateKeyUsageExtension) + getExtension(oid.toString(), info); - if (ext == null) { + if(ext == null) + { try { - populate(null, info); + populate(null,info); } catch (EProfileException e) { - throw new EPropertyException(CMS.getUserMessage(locale, - "CMS_INVALID_PROPERTY", name)); + throw new EPropertyException(CMS.getUserMessage( + locale, "CMS_INVALID_PROPERTY", name)); } } if (name.equals(VAL_CRITICAL)) { - ext = (PrivateKeyUsageExtension) getExtension(oid.toString(), info); + ext = (PrivateKeyUsageExtension) + getExtension(oid.toString(), info); if (ext == null) { return null; @@ -222,74 +239,80 @@ public class PrivateKeyUsagePeriodExtDefault extends EnrollExtDefault { } else { return "false"; } - } else if (name.equals(VAL_NOT_BEFORE)) { - SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT); + } else if (name.equals(VAL_NOT_BEFORE)) { + SimpleDateFormat formatter = + new SimpleDateFormat(DATE_FORMAT); - ext = (PrivateKeyUsageExtension) getExtension(oid.toString(), info); + ext = (PrivateKeyUsageExtension) + getExtension(oid.toString(), info); if (ext == null) return ""; return formatter.format(ext.getNotBefore()); - } else if (name.equals(VAL_NOT_AFTER)) { - SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT); + } else if (name.equals(VAL_NOT_AFTER)) { + SimpleDateFormat formatter = + new SimpleDateFormat(DATE_FORMAT); - ext = (PrivateKeyUsageExtension) getExtension(oid.toString(), info); + ext = (PrivateKeyUsageExtension) + getExtension(oid.toString(), info); if (ext == null) return ""; return formatter.format(ext.getNotAfter()); } else { - throw new EPropertyException(CMS.getUserMessage(locale, - "CMS_INVALID_PROPERTY", name)); + throw new EPropertyException(CMS.getUserMessage( + locale, "CMS_INVALID_PROPERTY", name)); } } public String getText(Locale locale) { - String params[] = { getConfig(CONFIG_CRITICAL), - getConfig(CONFIG_START_TIME), getConfig(CONFIG_DURATION) }; + String params[] = { + getConfig(CONFIG_CRITICAL), + getConfig(CONFIG_START_TIME), + getConfig(CONFIG_DURATION) + }; - return CMS.getUserMessage(locale, "CMS_PROFILE_DEF_PRIVATE_KEY_EXT", - params); + return CMS.getUserMessage(locale, "CMS_PROFILE_DEF_PRIVATE_KEY_EXT", params); } /** * Populates the request with this policy default. */ public void populate(IRequest request, X509CertInfo info) - throws EProfileException { + throws EProfileException { PrivateKeyUsageExtension ext = createExtension(); addExtension(ext.getExtensionId().toString(), ext, info); } public PrivateKeyUsageExtension createExtension() { - PrivateKeyUsageExtension ext = null; + PrivateKeyUsageExtension ext = null; try { boolean critical = getConfigBoolean(CONFIG_CRITICAL); - // always + 60 seconds + // always + 60 seconds String startTimeStr = getConfig(CONFIG_START_TIME); - if (startTimeStr == null || startTimeStr.equals("")) { - startTimeStr = "60"; - } - int startTime = Integer.parseInt(startTimeStr); - Date notBefore = new Date(CMS.getCurrentDate().getTime() - + (1000 * startTime)); + if (startTimeStr == null || startTimeStr.equals("")) { + startTimeStr = "60"; + } + int startTime = Integer.parseInt(startTimeStr); + Date notBefore = new Date(CMS.getCurrentDate().getTime() + + (1000 * startTime)); long notAfterVal = 0; - notAfterVal = notBefore.getTime() - + (mDefault * Integer.parseInt(getConfig(CONFIG_DURATION))); + notAfterVal = notBefore.getTime() + + (mDefault * Integer.parseInt(getConfig(CONFIG_DURATION))); Date notAfter = new Date(notAfterVal); ext = new PrivateKeyUsageExtension(notBefore, notAfter); - ext.setCritical(critical); + ext.setCritical(critical); } catch (Exception e) { - CMS.debug("PrivateKeyUsagePeriodExt: createExtension " - + e.toString()); + CMS.debug("PrivateKeyUsagePeriodExt: createExtension " + + e.toString()); } return ext; } |