azure模拟器不接受客户端证书

时间:2015-06-04 23:02:00

标签: c# azure ssl client-certificates

我尝试在Azure Web API服务中执行客户端身份验证。我相信我正确地将证书附加到客户端请求,但证书在服务端上是空的。这就是我发送客户端请求的方式(我也尝试过使用处理程序的HttpClient,结果相似):

// connectionUri points to my service
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(connectionUri);
var cert = GetCert(); // this isn't null, i've checked
req.ClientCertificates.Add(cert);
req.Method = "GET";
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
using (var readStream = new StreamReader(resp.GetResponseStream()))
{
    Console.WriteLine(readStream.ReadToEnd());
}

在服务端,我按如下方式处理请求: (WebApiConfig.cs)

public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        // "mycontroller" is an example, it never even gets to the controller
        config.Routes.MapHttpRoute(
            "controller", "api/{action}", new { controller = "mycontroller" },
            null, new Validator());
    }
}

验证器的定义如下:

public class Validator
{
    // ...
    protected override Task<HttpResponseMessage> SendAsync(
                HttpRequestMessage req, CancellationToken tok)
    {
        if (req.GetClientCertificate() == null)
        {
            return Task.Factory.StartNew(() =>
               req.CreateErrorResponse(
                   HttpStatusCode.Unauthorized, "NULL CERT"), tok);
        }
        else
        {
            return Task.Factory.StartNew(() =>
               req.CreateErrorResponse(HttpStatusCode.Found, "YES"), tok);
        }
    }
}

虽然GetCert()(我写的一个函数)返回了正确的证书(我已检查过它的指纹,但它确实存在),req.GetClientCertificate()总是返回null。我根据this article在服务上设置了ssl配置,因为我使用相同的证书(它是真正的签名证书)用于服务器和客户端(因为我和#39;我只是在本地测试它,并且预期目的包括&#34;客户端身份验证,&#34;我不认为服务器拒绝证书,因为证书无效。

我合理地确定了天蓝色的模拟器(以及实际的天蓝色服务;我已尝试使用类似的结果部署到azure。顺便说一句,我已将证书上传到azure)不过,无论出于何种原因拒绝客户的证书。我可能会遗漏哪些选项会导致它这样做?

0 个答案:

没有答案
相关问题