【发布时间】:2014-12-09 11:17:26
【问题描述】:
我需要帮助:
我们的后端由自签名证书保护。让我们称之为:OurMegaCoolCertificate.cer
因此,我们已使用 certmgr.msc 将此证书导入我们的开发人员计算机。现在我们可以使用以下代码从后端检索数据:
async public static Task<string> getData(string Id, string Type)
{
String url = "https://BACKEND/API/?Id=" + Id + "&Type=" + Type;
HttpClientHandler aHandler = new HttpClientHandler();
aHandler.ClientCertificateOptions = ClientCertificateOption.Automatic;
HttpClient aClient = new HttpClient(aHandler);
aClient.DefaultRequestHeaders.ExpectContinue = false;
aClient.DefaultRequestHeaders.MaxForwards = 3;
Uri requestUri = new Uri(url);
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUri);
//request.Headers.ExpectContinue = false;
var result = await aClient.GetAsync(requestUri, HttpCompletionOption.ResponseContentRead);
var responseHeader = result.Headers;
//Debug.WriteLine(responseHeader.WwwAuthenticate);
var responseBody = await result.Content.ReadAsStringAsync();
return responseBody;
}
但是当然我们不能告诉我们应用程序的用户手动安装证书,有没有办法将此证书添加到项目中并使用它?还是以编程方式导入用户机器?请指导我,我是 SSL 安全新手
我已经做到了,没有错误,但是请求失败,看起来请求没有找到证书:
private async void GetOverHere()
{
//await Windows.Security.Cryptography.Certificates.CertificateEnrollmentManager.InstallCertificateAsync("",InstallOptions.None);
StorageFolder packageLocation = Windows.ApplicationModel.Package.Current.InstalledLocation;
StorageFolder certificateFolder = await packageLocation.GetFolderAsync("Certificates");
StorageFile certificate = await certificateFolder.GetFileAsync("OurMegaCoolCertificate.cer");
IBuffer buffer = await Windows.Storage.FileIO.ReadBufferAsync(certificate);
string encodedString = Windows.Security.Cryptography.CryptographicBuffer.EncodeToBase64String(buffer);
await Windows.Security.Cryptography.Certificates.CertificateEnrollmentManager.InstallCertificateAsync(encodedString, InstallOptions.None);
}
我们也尝试在清单中这样做:
</Capabilities>
<Extensions>
<!--Certificates Extension-->
<Extension Category="windows.certificates">
<Certificates>
<Certificate StoreName="Root" Content="Assets\OurMegaCoolCertificate.cer" />
</Certificates>
</Extension>
同样,当我们使用 certmgr.msc 导入受信任的根证书时 - 一切正常
【问题讨论】:
-
您的链接仅在 Windows 8.1 中可用
-
我试过了,但我得到了响应码 404。GetOverHere() 方法将在哪里使用?
标签: c# ssl windows-8 windows-runtime windows-8.1