zoukankan      html  css  js  c++  java
  • EndpointIdentity.CreateDnsIdentity 方法

    通过此标识连接到终结点的安全 客户端将验证由服务器提供的声明是否包含一个表示此标识的 DNS 声明。

    public static void CreateRSAIdentity()
    {
        // Create a ServiceHost for the CalculatorService type. Base Address is supplied in app.config.
        using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService)))
        {
            // The base address is read from the app.config.
            Uri dnsrelativeAddress = new Uri(serviceHost.BaseAddresses[0], "dnsidentity");
            Uri certificaterelativeAddress = new Uri(serviceHost.BaseAddresses[0], "certificateidentity");
            Uri rsarelativeAddress = new Uri(serviceHost.BaseAddresses[0], "rsaidentity");
    
            // Set the service's X509Certificate to protect the messages.
            serviceHost.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine,
                                                               StoreName.My,
                                                               X509FindType.FindBySubjectDistinguishedName,
                                                                "CN=identity.com, O=Contoso");
            //Cache a reference to the server's certificate.
            X509Certificate2 servercert = serviceHost.Credentials.ServiceCertificate.Certificate;
    
            //Create endpoints for the service using a WSHttpBinding set for anonymous clients.
            WSHttpBinding wsAnonbinding = new WSHttpBinding(SecurityMode.Message);
            //Clients are anonymous to the service.
            wsAnonbinding.Security.Message.ClientCredentialType = MessageCredentialType.None;
            //Secure conversation (session) is turned off.
            wsAnonbinding.Security.Message.EstablishSecurityContext = false;
    
            //Create a service endpoint and change its identity to the DNS for an X509 Certificate.
            ServiceEndpoint ep = serviceHost.AddServiceEndpoint(typeof(ICalculator),
                                                                wsAnonbinding,
                                                                String.Empty);
            EndpointAddress epa = new EndpointAddress(dnsrelativeAddress, EndpointIdentity.CreateDnsIdentity("identity.com"));
            ep.Address = epa;
    
            //Create a service endpoint and change its identity to the X509 certificate's RSA key value.
            ServiceEndpoint ep3 = serviceHost.AddServiceEndpoint(typeof(ICalculator), wsAnonbinding, String.Empty);
            EndpointAddress epa3 = new EndpointAddress(rsarelativeAddress, EndpointIdentity.CreateRsaIdentity(servercert));
            ep3.Address = epa3;
    
  • 相关阅读:
    《SpringBoot揭秘 快速构建微服务体系》读后感(二)
    《SpringBoot揭秘 快速构建微服务体系》读后感(一)
    《Java多线程编程核心技术》读后感(十八)
    4.Go-结构体、结构体指针和方法
    3.GO-项目结构、包访问权限、闭包和值传递引用传递
    3.Flask-SQLAlchemy
    3.django Model
    2.深入类和对象
    2.shell编程-函数的高级用法
    mysql命令
  • 原文地址:https://www.cnblogs.com/EasyLive2006/p/1932334.html
Copyright © 2011-2022 走看看