Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hey all,

I have a problem with the certificate request/enrollment. I get this error:
CertEnroll::CX509Enrollment::_EnrollWizard: The system cannot find the file specified. 0x80070002 (WIN32: 2)


I have to create a certificate for another user, so I use basic authentication, because of delegation and impersonation to request the certificate as the user, who is logged on.

If I request a certificate with the domain user I am developing and publishing I get the right certificate. When I publish the solution with another user, I can request the certificate also for this user. If it is an other user I get the error.

First class:
WindowsIdentity wi = (WindowsIdentity)User.Identity;
         
            String templateName = "ADI01Smartphone";
            String user = User.Identity.Name.Split(new Char[] { '\\' })[1];
            String subjectName = "CN=" + user;
            String friendlyName = user + "Cert";
            WindowsImpersonationContext wic = null;
            try
            {
                wic = wi.Impersonate();
                EnrollCertificate.EnrollCert(templateName, subjectName, friendlyName, wi);
            }
            finally
            {
                if (wic != null)
                {
                    wic.Undo();
                }
            }



The certificate request:

C#
class EnrollCertificate
    {
        public static void EnrollCert(
            string templateName,
            string subjectName,
            string friendlyName,
            WindowsIdentity wi)
        {
            // create a CX509Enrollment object
            CX509Enrollment objEnroll = new CX509Enrollment();
           
            // initialize the CX509Enrollment object from template
            objEnroll.InitializeFromTemplateName(
                X509CertificateEnrollmentContext.ContextUser,
                templateName);
            
            // first get the request
            IX509CertificateRequest iRequest = objEnroll.Request;

            // then get the inner PKCS10 request
            IX509CertificateRequest iInnerRequest =
                iRequest.GetInnerRequest(InnerRequestLevel.LevelInnermost);
            IX509CertificateRequestPkcs10 iRequestPkcs10 =
                iInnerRequest as IX509CertificateRequestPkcs10;

            // create CX500DistinguishedName
            CX500DistinguishedName objName = new CX500DistinguishedName();
            objName.Encode(subjectName, X500NameFlags.XCN_CERT_NAME_STR_NONE);

            // set up the subject name
            iRequestPkcs10.Subject = objName;

            // set up friendly name
            objEnroll.CertificateFriendlyName = friendlyName;

            // enroll for the certificate, which should install the certficate
            // in store if the certificate is successfully issued by CA
            objEnroll.Enroll();
            
        }
    }


I don´t know what is wrong.
Have you got any idea?
Posted

You don't have a private key in place - The system cannot find the file specified.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900