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:
class EnrollCertificate
{
public static void EnrollCert(
string templateName,
string subjectName,
string friendlyName,
WindowsIdentity wi)
{
CX509Enrollment objEnroll = new CX509Enrollment();
objEnroll.InitializeFromTemplateName(
X509CertificateEnrollmentContext.ContextUser,
templateName);
IX509CertificateRequest iRequest = objEnroll.Request;
IX509CertificateRequest iInnerRequest =
iRequest.GetInnerRequest(InnerRequestLevel.LevelInnermost);
IX509CertificateRequestPkcs10 iRequestPkcs10 =
iInnerRequest as IX509CertificateRequestPkcs10;
CX500DistinguishedName objName = new CX500DistinguishedName();
objName.Encode(subjectName, X500NameFlags.XCN_CERT_NAME_STR_NONE);
iRequestPkcs10.Subject = objName;
objEnroll.CertificateFriendlyName = friendlyName;
objEnroll.Enroll();
}
}
I don´t know what is wrong.
Have you got any idea?