在Restful POST上从请求获取证书信息 [英] Getting the certificate info from the request on Restful POST

查看:634
本文介绍了在Restful POST上从请求获取证书信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我在HTTPS中有一个Restful服务(DotNet 4.0 WCF VS 2012)。我的客户端将附加一个证书到它(证书是由我给出的(.cer文件))我需要从请求获取证书并读取其信息认证它,序列号,Thumprint存储在DB当我需要检查相同。

Hi I am having a Restful service (DotNet 4.0 WCF VS 2012) in HTTPS. My client will attach a certificate to it (certificate is given by me (.cer file)) I need to get the certificate back from the request and read its information to authenticate it, The serial Number, Thumprint are stored in DB when I need to check the same.

我做了SSL并将cer文件共享给客户端。

I did the SSL and Share the cer file to the client.

以下代码回读我的证书

C#代码开始

if(OperationContext.Current.ServiceSecurityContext.AuthorizationContext .ClaimSets == null)
throw new Exception(No claimset service configured wrong);

if (OperationContext.Current.ServiceSecurityContext.AuthorizationContext.ClaimSets == null) throw new Exception ("No claimset service configured wrong");

        if (OperationContext.Current.ServiceSecurityContext.AuthorizationContext.ClaimSets.Count <= 0)
                 throw new Exception  ("No claimset service configured wrong");



       var cert = ((X509CertificateClaimSet)OperationContext.Current.ServiceSecurityContext.
       AuthorizationContext.ClaimSets[0]).X509Certificate;

C#code end

C# code end

代码我总是得到claimSets.Count = 0。

in the above code i always gets claimSets.Count = 0.

在我的服务器web.config中我需要做的任何设置,我在我的服务器端web中做了以下设置。 config

Is any setting I need to do in my server web.config, I did the following setting in my Server Side web.config

'security mode =Transport'
'transport clientCredentialType =None'
'security'

'security mode="Transport"' 'transport clientCredentialType="None"' 'security'

请让我知道我在客户端或服务器端缺少任何设置。

Please let me know Is I am missing any settings in the client side or the server side.

在客户端我使用以下代码

In the client side I am using following code the add the cer to the request

C#代码开始

X509Certificate2 cert = new X509Certificate2 ("C:\\xxxxxx.cer");

            System.Net.ServicePointManager.ServerCertificateValidationCallback = 
            delegate(Object obj, X509Certificate X509certificate, X509Chain chain, System.Net.Security.SslPolicyErrors errors)
            {
                return true;
            };


            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(xxxxx.Text.Trim());
            webRequest.ClientCertificates.Add(cert);

C#代码结束

在我的客户端web.config文件中有任何特殊设置。

I did not have any special setting in my client web.config file.

推荐答案

为什么使用 clientCredentialType =None 而不是 clientCredentialType =证书

不发送任何证书。尝试在客户端的App.config中启用网络跟踪 - 说明。这应该创建network.log更多的调试信息。在日志中查找 SecureChannel 条目。

It is also possible your client does not send any certificate. Try to enable Network Tracing in App.config on the client - instructions here. That should create network.log with more debug info. Look for SecureChannel entries in log.

这篇关于在Restful POST上从请求获取证书信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆