升级到最新的Windows Phone 8.1后无法发送证书

19
我有一个为8.1开发的Windows Phone应用程序,其中之一的任务是客户端-服务器证书方案。我的应用程序可以正常工作,我可以发送客户端证书并登录到服务器。然而,升级到Windows 8.10.14xxxx后就不可能了。我使用Wireshark跟踪发现证书从未被发送。消息的内容长度为0。
我使用HttpClient.SendAsync (await)和HttpBaseProtocolFilter来输入证书。在升级之前它完美地工作。
你有什么想法吗?是否有什么问题?
首先,我正在安装pfx证书。
async private void btnInstall_Click(object sender, RoutedEventArgs e)
{
    //Install the self signed client cert to the user certificate store

    string CACertificate = null;
    try
    {
        Uri uri = new Uri("ms-appx:///certificates/test.pfx");
        var file = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(uri);
        IBuffer buffer = await FileIO.ReadBufferAsync(file);
        using (DataReader dataReader = DataReader.FromBuffer(buffer))
        {
            byte[] bytes = new byte[buffer.Length];
            dataReader.ReadBytes(bytes);
            // convert to Base64 for using with ImportPfx
            CACertificate = System.Convert.ToBase64String(bytes);
        }
        await CertificateEnrollmentManager.UserCertificateEnrollmentManager.ImportPfxDataAsync(
            CACertificate,
            "xxxxx",
            ExportOption.Exportable,
            KeyProtectionLevel.NoConsent,
            InstallOptions.None,
            "ClientCert1");


    }
    catch (Exception ex)
    {
        //;
    }
}

然后我正在调用服务

string serviceURL = "https://my.web.services";
Certificate cert = null;

CertificateQuery query = new CertificateQuery();
query.FriendlyName = "ClientCert1";
IReadOnlyCollection<Certificate> certs = await CertificateStores.FindAllAsync(query);

HttpBaseProtocolFilter bpf = new HttpBaseProtocolFilter();
//if you install the CA you don't need to ignore the ServerCertificate Errors
//bpf.IgnorableServerCertificateErrors.Add(ChainValidationResult.Untrusted);

if (certs.Count > 0)
{
    cert = certs.ElementAt(0);
    bpf.ClientCertificate = cert;
}

HttpClient httpClient = new HttpClient(bpf);
try
{

    var response = await httpClient.GetInputStreamAsync(new Uri(serviceURL));
    //take data
}
catch (Exception ex)
{              
    //0x80072F0D 
}

在运行 8.10.14xxxx 版本的 Windows 手机时,我经常遇到一个异常 (0x80072F0D)。在更新之前,我的代码能正常运行,但现在始终返回这个错误代码。证书已经加载到 httpClient 中。使用调试器停止应用程序时,证书似乎是存在的,但是 0x800072F0D 错误代码可能表示证书未被发送?

在此情况下,存在一个中间证书颁发机构,该证书包含在 pfx 文件中。我是否需要进行某种安装操作?


你有可重现的演示吗? - kiewic
@kiewic,你知道这个问题吗?我可以分享一些源代码。 - cateof
可以,我可以看一下。你可以把复现步骤放在GitHub或其他任何地方。 - kiewic
你遇到了什么异常?是TaskCanceledException还是其他的异常? - user3497034
抱歉之前没有回复。源代码现在已经在问题正文中了。 - cateof
这可能是您要找的那篇文章吗?http://blogs.msdn.com/b/wsdevsol/archive/2015/03/20/how-to-use-a-shared-user-certificate-for-https-authentication-in-an-enterprise-application.aspx - cateof
1个回答

1
我假设您已经将客户端证书放置在应用程序证书存储中。 如果没有,请按照以下步骤操作:
1)下载PFX文件。
2)按照以下步骤在应用程序的证书存储中安装证书。
await CertificateEnrollmentManager.ImportPfxDataAsync(certString, "Your_PFX_Password", ExportOption.Exportable, KeyProtectionLevel.NoConsent, InstallOptions.None, friendlyName);

3) 在证书存储中检查证书。

CertificateQuery certQuery = new CertificateQuery();
certQuery.FriendlyName = friendlyName;
IReadOnlyList<Certificate> certs = await CertificateStores.FindAllAsync(certQuery);

certs[0] 应该包含你所需的证书。

4) 现在,将证书附加到 HTTP 请求中。

HttpBaseProtocolFilter protolFilter = new HttpBaseProtocolFilter();
protolFilter.ClientCertificate = certs[0] //from previous step
HttpClient client = new HttpClient(protolFilter)

PS:您不应该使用System.Net.htpp.HttpClient,而应该使用Windows.Web.Http.HttpClient


不,它不起作用。这似乎是正确的过程,我已经调用了那些行(请参见我的上面的代码),但在安装Windows Phone 8.1更新后,这些行不起作用。 - cateof
你使用的是哪个设备?一个建议是,对你的设备进行硬重置,然后再尝试。而且你的问题有点奇怪。 - user3497034
这是一部诺基亚Lumia 925手机。我认为硬重置并不能解决问题。 - cateof

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