我有一个为8.1开发的Windows Phone应用程序,其中之一的任务是客户端-服务器证书方案。我的应用程序可以正常工作,我可以发送客户端证书并登录到服务器。然而,升级到Windows 8.10.14xxxx后就不可能了。我使用Wireshark跟踪发现证书从未被发送。消息的内容长度为0。
我使用HttpClient.SendAsync (await)和HttpBaseProtocolFilter来输入证书。在升级之前它完美地工作。
你有什么想法吗?是否有什么问题?
首先,我正在安装pfx证书。
我使用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 文件中。我是否需要进行某种安装操作?