Add SSL Certificate During WCF HTTPS Development Testing

IIS: Add a certificate (name as "localhost-cert") :

cmd>makecert -sr LocalMachine -ss My -n CN=localhost -sky exchange
This command creates a certificate with the subject “localhost” and places it in the Personal store of the local computer.The subject name for a service certificate should match the name of host computer in the URL that the client application uses to connect to the service

After Add the certificate, certificate will appear at IIS Server Certificates and Personal store of the local computer





How to open LocalMachine Certificates Management Console

Once this command has been run and succeeded, you need to make this certificate a trusted authority. You do this by using the MMC snap in console. Go to the run window and type "mmc", hit enter. Then in the window that opens (called the "Microsoft Management Console, for those who care) perform the following actions.
File -> Add/Remove Snap-in -> Add… -> Double click Certificates -> Select Computer Account and Click Next -> Finish -> Close -> OK
Then select the Certificates (Local Computer) -> Personal -> Certificates node.



http://msdn.microsoft.com/en-us/library/ms733791.aspx

Bind sthe certificate with the thumbprint to the port

cmd>netsh http add sslcert ipport=0.0.0.0:1234 certhash=22e12b61467135349fa061446a89c30369e95fcb appid={00112233-4455-6677-8899-AABBCCDDEEFF}

  • The certhash parameter specifies the thumbprint of the certificate.
  • The ipport parameter specifies the IP address and port, and functions just like the -i switch of the Httpcfg.exe tool described.
  • The appid parameter is a GUID that can be used to identify the owning application.
Add code to client to skip certificate verification entirely
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(
    delegate
    {
        return true;
    });


Or

ServicePointManager.ServerCertificateValidationCallback += customXertificateValidation;

 private static bool customXertificateValidation(object sender, X509Certificate cert,
            X509Chain chain, SslPolicyErrors error)
        {
            X509Certificate2 certificate = (X509Certificate2)cert;
            if (certificate.Subject == "CN=127.0.0.1" && !String.IsNullOrEmpty(certificate.Thumbprint) &&
                certificate.Thumbprint.ToLower() == "cfdf5d1140b94614d047dd77c7bd4d4d4422e1c9")
            {
                return true;
            }
            return false;
        }



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值