/************************************************************************* * * * EJBCA Community: The OpenSource Certificate Authority * * * * This software is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or any later version. * * * * See terms of license at gnu.org. * * * *************************************************************************/ package org.ejbca.ui.web.pub; import java.util.ArrayList; import java.util.HashMap; import javax.ejb.EJBException; import org.apache.log4j.Logger; import org.bouncycastle.asn1.x509.KeyPurposeId; import org.cesecore.authentication.tokens.AuthenticationToken; import org.cesecore.authorization.AuthorizationDeniedException; import org.cesecore.certificates.certificate.CertificateConstants; import org.cesecore.certificates.certificateprofile.CertificateProfile; import org.cesecore.certificates.certificateprofile.CertificateProfileExistsException; import org.cesecore.certificates.certificateprofile.CertificateProfileSession; import org.cesecore.certificates.util.DNFieldExtractor; import org.cesecore.certificates.util.DnComponents; import org.cesecore.util.CertTools; import org.ejbca.core.ejb.ra.raadmin.AdminPreferenceSession; import org.ejbca.core.ejb.ra.raadmin.EndEntityProfileSession; import org.ejbca.core.model.ra.raadmin.EndEntityProfile; import org.ejbca.core.model.ra.raadmin.EndEntityProfileExistsException; import org.ejbca.core.model.ra.raadmin.EndEntityProfileNotFoundException; /** * @version $Id: MSCertTools.java 25552 2017-03-21 08:16:31Z anatom $ */ public class MSCertTools { private static final Logger log = Logger.getLogger(MSCertTools.class); private static final String REQUESTSTART = "-----BEGIN NEW CERTIFICATE REQUEST-----"; private static final String REQUESTEND = "-----END NEW CERTIFICATE REQUEST-----"; private static final String CERTIFICATE_TEMPLATENAME_USER = "User"; private static final String CERTIFICATE_TEMPLATENAME_MACHINE = "Machine"; private static final String CERTIFICATE_TEMPLATENAME_DOMAINCONTROLLER = "DomainController"; //private static final String CERTIFICATE_TEMPLATENAME_SMARTCARDLOGON = "SmartcardLogon"; private static final String[] SUPPORTEDCERTIFICATETEMPLATES = { CERTIFICATE_TEMPLATENAME_USER, CERTIFICATE_TEMPLATENAME_MACHINE, CERTIFICATE_TEMPLATENAME_DOMAINCONTROLLER /*, CERTIFICATE_TEMPLATENAME_SMARTCARDLOGON*/}; /* Non-crit key usage, NC Template Name: User NC CPD NC AIA NC EKU NC UPN User cert: SMIME Capabilities (non crit) [1]SMIME Capability Object ID=1.2.840.113549.3.2 Parameters=02 01 38 [2]SMIME Capability Object ID=1.2.840.113549.3.4 Parameters=02 01 38 [3]SMIME Capability Object ID=1.3.14.3.2.7 Administrator: Microsoft Trust List Signing (1.3.6.1.4.1.311.10.3.1) */ private static final int[][] KEYUSAGES = { // "User" Key Usage: Digital signature, Allow key exchange only with key encryption {CertificateConstants.DIGITALSIGNATURE, CertificateConstants.KEYENCIPHERMENT}, // "Machine" Key Usage: Digital signature, Allow key exchange only with key encryption {CertificateConstants.DIGITALSIGNATURE, CertificateConstants.KEYENCIPHERMENT}, // "DomainController" Key Usage: {CertificateConstants.DIGITALSIGNATURE}, // "SmartcardLogon" Key Usage: {CertificateConstants.DIGITALSIGNATURE, CertificateConstants.KEYENCIPHERMENT} }; private static final String[][] EXTENDEDKEYUSAGES = { // "User" Extended Key Usage: Encrypting File System, Secure Email, Client Authentication {CertTools.EFS_OBJECTID, KeyPurposeId.id_kp_emailProtection.getId(), KeyPurposeId.id_kp_clientAuth.getId()}, // "Machine" Extended Key Usage: Client Authentication, Server Authentication {KeyPurposeId.id_kp_clientAuth.getId(), KeyPurposeId.id_kp_serverAuth.getId()}, // "DomainController" Extended Key Usage: {KeyPurposeId.id_kp_clientAuth.getId(), KeyPurposeId.id_kp_serverAuth.getId()}, // "SmartcardLogon" Extended Key Usage: {KeyPurposeId.id_kp_clientAuth.getId(), KeyPurposeId.id_kp_smartcardlogon.getId()} }; public static final String GET_SUBJECTDN_FROM_AD = "GET_SUBJECTDN_FROM_AD"; private static final String[][] DNFIELDS = { // Required fields for "User" {GET_SUBJECTDN_FROM_AD, DnComponents.UPN}, // Required fields for "Machine" {DnComponents.COMMONNAME}, // Required fields for "DomainController" {DnComponents.COMMONNAME, DnComponents.DNSNAME, DnComponents.GUID}, // Required fields for "SmartcardLogon" {GET_SUBJECTDN_FROM_AD, DnComponents.UPN} }; // Special properties: // User: UPN is remote user? Is UPN even required? // Machine: // DomainController - Use CDP, Use CA defined CDP, Use MS Template Value, DomainController, GUID in request, DNS-name in request // SmartcardLogon - Use CDP, Use CA defined CDP, UPN is remote user private static final boolean[] USE_CA_CDP = { false, false, true, true }; private static final String[] MS_TEMPLATE_VALUE = { null, null, "DomainController", null }; public static String extractRequestFromRawData(String requestData) { if (requestData == null || "".equals(requestData)) { return null; } requestData = requestData.replaceFirst(REQUESTSTART, "").replaceFirst(REQUESTEND, ""); return requestData.replaceAll(" ", "+"); // Replace lost +-chars in b64-encoding } public static int getTemplateIndex(String certificateTemplate) { int templateIndex = -1; if (certificateTemplate != null) { for (int i=0; i eku = new ArrayList(); for (int i=0; i hmFields = dnfe.getNumberOfFields(); for (int j=0; j<100; j++) { // TODO: 100 is really an internal constant.. Integer fieldsOfType = hmFields.get(Integer.valueOf(j)); if (fieldsOfType != null) { log.info("fieldsOfType="+fieldsOfType); for (int k = 0; k