【问题标题】:Calling relying party over HTTPS and token encryption通过 HTTPS 和令牌加密调用依赖方
【发布时间】:2016-05-27 15:46:51
【问题描述】:

我在使用 Windows Azure ACS 时遇到了问题,我不能完全确定它是否应该这样,或者我的代码中是否存在错误。

我在 ACS 中配置了许多依赖方,并且所有依赖方都配置了 HTTPS。每个服务都以需要令牌加密的方式配置。为此,我上传了使用 MakeCert.exe 创建的证书。

当客户端与依赖方通信时,我将证书的公共部分添加为服务证书,并将主题名称添加为 DnsIdentity:

var identity = EndpointIdentity.CreateDnsIdentity( GetClientCertificateSubjectName() );
var serviceEndpointAddress = new EndpointAddress( new Uri( _serviceAddress ), identity );

// Creation of channel factory

if( channelFactory.Credentials != null ) {
  channelFactory.Credentials.ServiceCertificate.DefaultCertificate = GetClientCertificate();
  channelFactory.Credentials.ClientCertificate.Certificate = GetServiceIdentityCertificate();
}

事情是这样的:当我通过HTTPS调用依赖方时,我可以跳过EndpointIdentity的创建,然后依赖方会给我一个正确的答案。我也可以跳过设置ServiceCertificate.DefaultCertificate属性或者设置一个完全随机的证书,依赖方仍然会给我一个正确的答案。

通过 HTTP 调用时,执行上述任何操作都会导致 ACS 出错,并显示消息表明我没有使用正确的证书。简而言之:通过 HTTP 调用时,我只能使用正确的客户端证书进行通信。我预计 HTTPS 也是如此。

我可以想象ChannelFactory<T> 或 ACS 足够智能,可以检测到使用 HTTPS 并跳过配置的加密,转而支持 SSL 加密。遗憾的是,我找不到任何支持这个想法的文档。

我的问题是:通过 HTTPS 调用依赖方时忽略 EndpointIdentity 和证书是否正常?还是我需要额外的配置才能完成这项工作?

提前致谢!

【问题讨论】:

    标签: azure https acs


    【解决方案1】:

    事实证明,我提供的信息量不足以正确回答问题。事实证明,这一切都在我们正在创建的绑定中。它使用以下代码创建一个绑定:

    public static Binding CreateServiceBinding( string acsCertificateEndpoint, string bindingNameSpace, bool useSsl ) {
      var binding = new IssuedTokenWSTrustBinding( CreateAcsCertificateBinding(), new EndpointAddress( acsCertificateEndpoint ) );
    
      if( useSsl ) {
        binding.SecurityMode = SecurityMode.TransportWithMessageCredential;
      }
    
      if( !string.IsNullOrWhiteSpace( bindingNameSpace ) ) {
        binding.Namespace = bindingNameSpace;
      }
    
      return binding;
    }
    
    public static CertificateWSTrustBinding CreateAcsCertificateBinding() {
      return new CertificateWSTrustBinding( SecurityMode.TransportWithMessageCredential );
    }
    

    结果如下:

    1. 如果是http通信,则通过MutualCertificate认证方式流程,仅应用于消息层。这就是为什么要求客户出示客户证书的原因。此绑定元素创建一个非对称安全绑定元素,该元素被配置为需要基于证书的客户端身份验证以及基于证书的服务器身份验证。
    2. 如果是https通信,则通过CertificateOverTransport认证模式流程,仅应用于传输层。这就是为什么即使没有提供客户端证书,它也可以工作。此绑定元素期望传输提供服务器身份验证以及消息保护(例如 HTTPS)。

    有关安全模式的更多信息,请查看以下链接:

    https://msdn.microsoft.com/en-us/library/ms733098%28v=vs.110%29.aspx https://msdn.microsoft.com/en-us/library/ms731074%28v=vs.110%29.aspx

    希望这对某人有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-11
      • 1970-01-01
      • 2011-06-17
      • 2013-03-16
      • 2018-07-05
      • 1970-01-01
      • 2016-03-30
      相关资源
      最近更新 更多