简体   繁体   English

在 Azure 应用程序服务上运行的 WCF 服务的 SSL 设置出现问题

[英]Problem with SSL settings for WCF service running on Azure app service

I'm currently developing a wcf webservice(.NET 4.7.2) that accepts soap messages from different sources.我目前正在开发一个 wcf 网络服务(.NET 4.7.2),它接受来自不同来源的 soap 消息。 One of the sources requires us to create a endpoint secured by a certificate using a custom authority(CA).其中一个来源要求我们使用自定义授权机构 (CA) 创建一个由证书保护的端点。

For this, I have created a new.svc file that initializes with the following binding and imports a certificate.为此,我创建了一个 new.svc 文件,该文件使用以下绑定进行初始化并导入证书。 This certificate is accessible in the azure web app:此证书可在 azure web 应用程序中访问:

public static void Configure(ServiceConfiguration config)
        {
            // Enable "Add Service Reference" support
            config.Description.Behaviors.Add(new ServiceMetadataBehavior { HttpsGetEnabled = true, HttpGetEnabled = false }); //mex
            //setup support for certficate security
            var binding = new WSHttpBinding
            {
                Name = "CertificateBinding",
                ReaderQuotas = { MaxArrayLength = int.MaxValue },
                MaxReceivedMessageSize = int.MaxValue,
                Security = new WSHttpSecurity
                {
                    Mode = SecurityMode.Transport,
                    Transport = new HttpTransportSecurity
                    {
                        ClientCredentialType = HttpClientCredentialType.Certificate
                    },
                },
            };

            config.EnableProtocol(binding);

            config.Credentials.ServiceCertificate.SetCertificate(StoreLocation.CurrentUser, StoreName.My, X509FindType.FindByThumbprint, "Thumbprint inserted here");

            config.Description.Behaviors.Add(new ServiceDebugBehavior { IncludeExceptionDetailInFaults = true });
        }

To enable certificate authentication for this endpoint I added the following to the web.config;为了为此端点启用证书身份验证,我将以下内容添加到 web.config;

 <location path="IntegrationWebService_CertificateSecurity.svc">
    <system.webServer>
    <httpErrors errorMode="Detailed"></httpErrors>
      <security>
        <access sslFlags="Ssl, SslNegotiateCert, SslRequireCert" />
      </security>
    </system.webServer>
 </location>

I tested this and this all works well locally, but when deploying to an azure web app it shows a 500 error.我对此进行了测试,这一切都在本地运行良好,但是当部署到 azure web 应用程序时,它显示 500 错误。 I can't seem to figure out the cause of this 500 error.我似乎无法弄清楚这个 500 错误的原因。 Other.svc files keep working properly. Other.svc 文件继续正常工作。

What I have tried;我尝试过的;

  • Adding ELMAH;添加 ELMAH; no exception is logged.没有记录异常。

  • Multiple configurations for SslSettings, none worked though only adding "SslRequireCert" changes the error to "The SSL settings for the service 'SslRequireCert' does not match those of the IIS 'None'". SslSettings 的多个配置,虽然仅添加“SslRequireCert”将错误更改为“服务‘SslRequireCert’的 SSL 设置与 IIS‘无’的设置不匹配”,但没有一个起作用。 I stopped persuing this because as far as I know the SslNegotiateCert part is required.我不再坚持这一点,因为据我所知,SslNegotiateCert 部分是必需的。

  • Tried, to no avail, adding an applicationHost.xdt file that transforms overrideModeDefault to allow override like this:尝试添加一个 applicationHost.xdt 文件,但没有成功,该文件转换 overrideModeDefault 以允许像这样覆盖:

     <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> <configSections> <sectionGroup name="system.webServer" xdt:Locator="Match(name)"> <sectionGroup name="security" xdt:Locator="Match(name)"> <section name="access" overrideModeDefault="Allow" xdt:Locator="Match(name)" xdt:Transform="SetAttributes(overrideModeDefault)" /> </sectionGroup> </sectionGroup> </configSections> </configuration>

Could it be that Azure does not allow a custom value in SslFlags?难道是 Azure 不允许在 SslFlags 中自定义值?

Apparently, for Azure, you can't require client certificates using System.ServiceModel.显然,对于 Azure,您不能使用 System.ServiceModel 要求客户端证书。 So, first you can turn off the require client certificate part.因此,首先您可以关闭需要客户端证书的部分。 Doing this using a CustomBinding looks like this:使用 CustomBinding 执行此操作如下所示:

var httpsBE = new HttpsTransportBindingElement();
httpsBE.RequireClientCertificate = false;
httpsBE.AuthenticationScheme = AuthenticationSchemes.Anonymous;

Go to your App service app settings and require client certificates from there; Go 到您的应用程序服务应用程序设置,并从那里需要客户端证书; Azure 传入客户端证书应用程序设置

Then, what Azure does, is move the certificate from the original request to a X-ARR-ClientCert header. This is accessible in a webservice like this;然后,Azure 所做的是将证书从原始请求移动到 X-ARR-ClientCert header。这可以在这样的 Web 服务中访问;

var certHeader = WebOperationContext.Current.IncomingRequest.Headers["X-ARR-ClientCert"];

And to convert it to a X509Certificate2:并将其转换为 X509Certificate2:

var clientCertBytes = Convert.FromBase64String(certHeader);
var x509Certificate2 = new X509Certificate2(clientCertBytes);

Then you'd have to run your own certificate validation.然后您必须运行自己的证书验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM