Programmly使用SSL证书在Windows 8应用 [英] Programmly using SSL certificates in Windows 8 app

查看:351
本文介绍了Programmly使用SSL证书在Windows 8应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要这方面的帮助:

我们的后端是自签名证书保护。让我们把它叫做:OurMegaCoolCertificate.cer

Our backend is secured by self-signed certificate. Lets call it: OurMegaCoolCertificate.cer

所以,我们引进这个证书给开发者的机器使用的 certmgr.msc 。现在我们可以使用下面的代码检索我们的后端数据:

So, we have imported this certificate to our developers machines by using certmgr.msc. And now we can retrieve data from our backend using this code:

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;
    }



但offcourse我们不能告诉我们的应用程序的用户,安装证书手动,有没有办法添加此证书项目并使用它?或导入到用户计算机programmly?请指引我,我是新来的SSL安全

我已成功地做到这一点,没有错误,但请求失败,貌似请求不找到证书:

I have managed to do this, no errors, but request fails, looks like request doesn't find certificate:

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);


    }



此外,我们曾试图做到这一点清单:

Also we have tried to do this in manifest:

</Capabilities>
<Extensions>
<!--Certificates Extension-->
 <Extension Category="windows.certificates">
  <Certificates>
    <Certificate StoreName="Root" Content="Assets\OurMegaCoolCertificate.cer" />

  </Certificates>
</Extension>



和同样,当我们导入使用certmgr.msc到受信任的根证书 - 所有的作品

And again, when we import using certmgr.msc to Trusted Root Certificates - all works

推荐答案

我设法得到这个工作:

我在packagemanifest增加这样的:

I have added this in packagemanifest:

</Capabilities>
<Extensions>
<!--Certificates Extension-->
<Extension Category="windows.certificates">
   <Certificates>
       <Certificate StoreName="Root" Content="Assets\OurMegaCoolCertificate.cer" />
   </Certificates>
</Extension>



但我有出口我的证书没有使用DER(或类似的东西),但为base64它工作。但是,所有的教程说,需要导出为DER ...

But i have exported my certificate not using DER ( or something like that ), but as base64 and it worked. But all tutorials say that needs to be exported as DER...

这篇关于Programmly使用SSL证书在Windows 8应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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