Request Client Certificate on JavaScript

纵饮孤独 提交于 2020-12-11 08:59:47

问题


The Objective

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

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):

  • Request Client Certificate

  • How do I get the X509Certificate sent from the client in web service?

  • Browser is not prompting for a client certificate

  • Get client certificate in asp.net c# browser application using server side coding


回答1:


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 base64, to later when I need converting it to a X509Certificate



来源:https://stackoverflow.com/questions/47942288/request-client-certificate-on-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!