【问题标题】:ITfoxtec - ADFS SAML2 The remote certificate is invalid according to the validation procedureITfoxtec - ADFS SAML2 根据验证程序,远程证书无效
【发布时间】:2021-10-07 11:44:44
【问题描述】:

我是 SAML2 身份验证的新手,并尝试过使用 ITfoxtec。当我运行我的应用程序时出现此错误

AuthenticationException: 根据远程证书无效 到验证程序。 System.Net.Security.SslStream.StartSendAuthResetSignal(协议令牌 消息,AsyncProtocolRequest asyncRequest,ExceptionDispatchInfo 例外)

HttpRequestException:无法建立 SSL 连接,请参阅 内部异常。 System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(流 流,SslClientAuthenticationOptions sslOptions,CancellationToken 取消令牌)

WebException:无法建立 SSL 连接,请参阅内部 例外。远程证书无效根据 验证程序。 System.Net.HttpWebRequest.GetResponse()

我正在使用使用 OpenSSL 生成的证书,并将 pfx 证书安装在 MMC 的受信任根 CA 存储中。我不确定为什么它仍然会导致我出错。我已经在我的 ADFS 中将该应用程序添加为依赖信任方。## Heading ##

这是我的 StartUp.cs 的 sn-p

  services.Configure<Saml2Configuration>(Configuration.GetSection("Saml2"));

            services.Configure<Saml2Configuration>(saml2Configuration =>
            {

                //saml2Configuration.SignAuthnRequest = true;
                saml2Configuration.SigningCertificate = CertificateUtil.Load(Configuration["Saml2:SigningCertificateFile"], Configuration["Saml2:SigningCertificatePassword"]);
               //saml2Configuration.SigningCertificate = CertificateUtil.Load(AppEnvironment.MapToPhysicalFilePath(Configuration["Saml2:SigningCertificateFile"]), Configuration["Saml2:SigningCertificatePassword"]);



                var entityDescriptor = new EntityDescriptor();
                entityDescriptor.ReadIdPSsoDescriptorFromUrl(new Uri(Configuration["Saml2:IdPMetadata"]));
                if (entityDescriptor.IdPSsoDescriptor != null)
                {
                    saml2Configuration.AllowedIssuer = entityDescriptor.EntityId;
                    saml2Configuration.SingleSignOnDestination = entityDescriptor.IdPSsoDescriptor.SingleSignOnServices.First().Location;
                    saml2Configuration.SingleLogoutDestination = entityDescriptor.IdPSsoDescriptor.SingleLogoutServices.First().Location;
                    saml2Configuration.SignatureValidationCertificates.AddRange(entityDescriptor.IdPSsoDescriptor.SigningCertificates);
                    if (entityDescriptor.IdPSsoDescriptor.WantAuthnRequestsSigned.HasValue)
                    {
                        saml2Configuration.SignAuthnRequest = entityDescriptor.IdPSsoDescriptor.WantAuthnRequestsSigned.Value;
                    }
                }
                else
                {
                    throw new Exception("IdPSsoDescriptor not loaded from metadata.");
                }
            });
            services.AddSaml2(); 

这是我的appsettings.json

  "Saml2": {
    "IdPMetadata": "adfs url/FederationMetadata/2007-06/FederationMetadata.xml",
    "Issuer": "saml_Example",
    "SingleSignOnDestination": "http://adfs url/adfs/ls/",
    "SignatureAlgorithm": "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256",
    "SigningCertificateFile": "cert.pfx",
    "SigningCertificatePassword": "pw",
    "CertificateValidationMode": "None",
    "RevocationMode": "NoCheck"
  },

【问题讨论】:

    标签: ssl adfs itfoxtec-identity-saml2 adfs4.0


    【解决方案1】:

    根据错误,您的机器/服务器不信任 AD FS SSL/TLS 证书。

    您已配置"IdPMetadata": "adfs url/FederationMetadata/2007-06/FederationMetadata.xml"。它应该是一个真实的 URL,例如 https://...

    【讨论】:

    • 你好,我的 idp 配置是 -> https://.cloudapp.azure.com/FederationMetadata/2007-06/FederationMetadata.xml。我通过 Powershell 使用 CN 创建了一个自签名证书,因为我的 IDP 将它安装在根目录中,但仍然出现相同的错误。
    • 你可以试试 ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; stackoverflow.com/questions/2675133/…
    • 试过了,但我遇到了与 stackoverflow.com/questions/65324798/… 相关的差异问题,我的 idp 不是 okta 而是 adfs 4
    • 好的,那么您需要更新到 .NET Core 或 .NET 5.0。
    • 好的。我已经多次阅读 AD FS 元数据文件。这应该不是问题。
    猜你喜欢
    • 2011-03-28
    • 2016-11-28
    • 2013-08-08
    • 2012-07-20
    • 2015-03-17
    • 2021-05-30
    • 1970-01-01
    相关资源
    最近更新 更多