// --- BEGIN COPYRIGHT BLOCK --- // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; version 2 of the License. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along // with this program; if not, write to the Free Software Foundation, Inc., // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. // // (C) 2007 Red Hat, Inc. // All rights reserved. // --- END COPYRIGHT BLOCK --- package com.netscape.cms.policy.constraints; import java.io.IOException; import java.util.Enumeration; import java.util.Locale; import java.util.Vector; import netscape.security.x509.CertificateExtensions; import netscape.security.x509.CertificateSubjectName; import netscape.security.x509.KeyUsageExtension; import netscape.security.x509.X509CertImpl; import netscape.security.x509.X509CertInfo; import com.netscape.certsrv.apps.CMS; import com.netscape.certsrv.authority.ICertAuthority; import com.netscape.certsrv.base.EBaseException; import com.netscape.certsrv.base.IConfigStore; import com.netscape.certsrv.base.IExtendedPluginInfo; import com.netscape.certsrv.base.ISubsystem; import com.netscape.certsrv.ca.ICertificateAuthority; import com.netscape.certsrv.dbs.certdb.ICertRecord; import com.netscape.certsrv.logging.ILogger; import com.netscape.certsrv.policy.IEnrollmentPolicy; import com.netscape.certsrv.policy.IPolicyProcessor; import com.netscape.certsrv.request.IRequest; import com.netscape.certsrv.request.PolicyResult; import com.netscape.cms.policy.APolicyRule; /** * Checks the uniqueness of the subject name. This policy * can only be used (installed) in Certificate Authority * subsystem. * * This policy can perform pre-agent-approval checking or * post-agent-approval checking based on configuration * setting. * * In some situations, user may want to have 2 certificates with * the same subject name. For example, one key for encryption, * and one for signing. This policy does not deal with this case * directly. But it can be easily extended to do that. *
* *
* NOTE: The Policy Framework has been replaced by the Profile Framework. **
* * @deprecated * @version $Revision$, $Date$ */ public class UniqueSubjectNameConstraints extends APolicyRule implements IEnrollmentPolicy, IExtendedPluginInfo { protected static final String PROP_PRE_AGENT_APPROVAL_CHECKING = "enablePreAgentApprovalChecking"; protected static final String PROP_KEY_USAGE_EXTENSION_CHECKING = "enableKeyUsageExtensionChecking"; public ICertificateAuthority mCA = null; public boolean mPreAgentApprovalChecking = false; public boolean mKeyUsageExtensionChecking = true; public UniqueSubjectNameConstraints() { NAME = "UniqueSubjectName"; DESC = "Ensure the uniqueness of the subject name."; } public String[] getExtendedPluginInfo(Locale locale) { String[] params = { PROP_PRE_AGENT_APPROVAL_CHECKING + ";boolean;If checked, check subject name uniqueness BEFORE agent approves, (else checks AFTER approval)", PROP_KEY_USAGE_EXTENSION_CHECKING + ";boolean;If checked, allow non-unique subject names if Key Usage Extension differs", IExtendedPluginInfo.HELP_TOKEN + ";configuration-policyrules-uniquesubjectname", IExtendedPluginInfo.HELP_TEXT + ";Rejects a request if there exists an unrevoked, unexpired " + "certificate with the same subject name" }; return params; } /** * Initializes this policy rule. *
*
* The entries probably are of the form:
*
* ca.Policy.rule.
*
* @param req The request on which to apply policy.
* @return The policy result object.
*/
public PolicyResult apply(IRequest req) {
if (!mPreAgentApprovalChecking) {
// post agent approval checking
if (!agentApproved(req))
return PolicyResult.ACCEPTED;
}
PolicyResult result = PolicyResult.ACCEPTED;
try {
// Get the certificate templates
X509CertInfo[] certInfos = req.getExtDataInCertInfoArray(
IRequest.CERT_INFO);
if (certInfos == null) {
setError(req, CMS.getUserMessage("CMS_POLICY_NO_CERT_INFO",
getInstanceName()), "");
return PolicyResult.REJECTED;
}
// retrieve the subject name and check its unqiueness
for (int i = 0; i < certInfos.length; i++) {
CertificateSubjectName subName = (CertificateSubjectName)
certInfos[i].get(X509CertInfo.SUBJECT);
// if there is no name set, set one here.
if (subName == null) {
setError(req, CMS.getUserMessage("CMS_POLICY_NO_SUBJECT_NAME",
getInstanceName()), "");
return PolicyResult.REJECTED;
}
String certSubjectName = subName.toString();
String filter = "x509Cert.subject=" + certSubjectName;
// subject name is indexed, so we only use subject name
// in the filter
Enumeration