JavaScript请求客户端证书

6

目标

我需要在浏览器上打开这个JavaScript证书模态框,让用户选择他们的证书(它是用葡萄牙语显示的,抱歉):

enter image description here

然后将其保存到我的Action中,如下所示:

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

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

问题

因为这是我第一次接触这种技术,所以我花费了很多时间进行研究,但无论我做什么,模态框都不会弹出,ClientCertificate始终为空。真的有可能在JavaScript上实现这个吗?

背景

ISS配置

<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
    });
});

链接

以下是目前我看到的问题(其中一半未回答):


4
当请求需要客户端认证的SSL/TLS URL时,浏览器会自动提示用户选择证书。但这并不适用于AJAX请求。如果在输入正确的URL后浏览器没有显示证书表单,则需检查服务器配置。确保客户端证书选项被设置为“强制”,并且已正确设置接受的CA证书。如果浏览器没有由接受的CA颁发的证书,则不会显示该表单。 - pedrofb
1个回答

8
经过大量研究(并得到@pedrofb的帮助),我发现通过Ajax (或JavaScript) 触发请求客户端证书的提示是不可能的,必须通过服务器配置通过url触发它,这使我改变了我的方法。
我通过要求用户上传证书的.pptx文件并将其保存到我们的数据库中作为来解决这个问题,以便在需要时将其转换为X509Certificate

我正在实现客户端证书认证,并在这里看到了这篇文章。请问是否有可能在使用JavaScript进行服务器请求之前解析/拦截X509证书?我想将该证书的颁发者名称传递到请求头中。 - vikash.gupta
@VikashGupta 你好,你需要一个JS库,比如这个,在请求之前在浏览器中解析证书。 - Matheus Cuba

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接