Search code examples
javascriptc#asp.netssldigital-certificate

Request Client Certificate on JavaScript


The Objective

I need to open this JavaScript certificate Modal on Browser to user select their Certificate (It's on Portuguese sorry):

enter image description here

Then save it on my Action like this:

[HttpGet]
public ActionResult GetClientCertificate() {
    var requestCertificate = System.Web.HttpContext.Current.Request.ClientCertificate;

    ///Transform to byte[] and save on DataBase
}

The Problem

I have spend a lot of time researching because it's my first contact to this kind of Technology, but no metter what I do, i can't make it work. Modal never open's and ClientCertificate is always empty. It's really possible to achive this on JavaScript?

Context

ISS Config

<access sslFlags="SslNegotiateCert" />

<applicationDependencies>
    <application name="Active Server Pages" groupId="ASP" />
</applicationDependencies>

<authentication>

    <anonymousAuthentication enabled="true" userName="" />

    <basicAuthentication enabled="false" />

    <clientCertificateMappingAuthentication enabled="true" />

    <digestAuthentication enabled="false" />

    <iisClientCertificateMappingAuthentication enabled="true">
    </iisClientCertificateMappingAuthentication>

    <windowsAuthentication enabled="false">
        <providers>
            <add value="Negotiate" />
            <add value="NTLM" />
        </providers>
    </windowsAuthentication>

</authentication>

<authorization>
    <add accessType="Allow" users="*" />
</authorization>

JS

$(document).on("click", "#btnCertificate", function() {
    $.get("/Gerenciamento/CertificadoDigital/GetCertificate", null, function(data) {
        //// Redirect to other page
    });
});

Links

This are the questions that I had seem so far (half of then unanswered):


Solution

  • After a lot of research (and with the help of @pedrofb), I discover that is impossible to trigger the Prompt Requesting Client Certificate by Ajax (or JavaScript) , having to make the server configuration trigger it by the url, leading me to change my approch to this.

    I solve it by asking the user to uploud the .pptx file of the certificate to save on our database as a , to later when I need converting it to a X509Certificate