【问题标题】:ITfoxtec SAML 2.0 Azure Ad Certificate Format Issue .Cer to .PFXITfoxtec SAML 2.0 Azure 广告证书格式问题 .Cer 到 .PFX
【发布时间】:2022-01-20 21:15:07
【问题描述】:

我正在尝试使用 Azure AD 在 .Net Core 3.1 中实现 SSO SAML 身份验证 遵循此指南Here

我的问题是: 我是否可以删除引用 SigningCertificatePassword(.pfx 文件)的代码并添加对我的 .cer 文件的引用,因为 Azure Ad 仅提供 .cer/.pem 文件,而 ITfoxtec SAML 2.0 仅支持 .PFX 文件,所以如何转换这些文件?

【问题讨论】:

    标签: azure-active-directory single-sign-on saml-2.0 itfoxtec-identity-saml2


    【解决方案1】:

    PFX 是由certificate 及其private key 组成的完整包(密钥库)。因此,如果您同时拥有这两个实体,则可以将这些实体添加到 Keystore。

    openssl pkcs12 -inkey private_key.pem -in certificate.cert -export -out keystore.pfx
    

    【讨论】:

    • 但我在 Azure 广告中没有看到任何可用的私钥,我在哪里可以得到这个?
    【解决方案2】:

    PXT 证书包含私钥和公钥。 DER 证书只包含公钥。

    您需要为您的应用程序创建自己的 PXT 证书,或者可能使用与 TLS/SSL 相同的证书。

    .NET 示例代码展示了如何在 .NET 中创建证书: https://github.com/ITfoxtec/FoxIDs.Samples/blob/b6dd1f8211015a5b366ce2b062dde481e38848fc/src/FoxIDs.SampleHelperLibrary/TestCertificate.cs

    using (var rsa = RSA.Create(2048))
    {
        var certRequest = new CertificateRequest(
            $"CN={cn}, O=FoxIDs",
            rsa,
            HashAlgorithmName.SHA256,
            RSASignaturePadding.Pkcs1);
    
        certRequest.CertificateExtensions.Add(
            new X509BasicConstraintsExtension(false, false, 0, false));
    
        certRequest.CertificateExtensions.Add(
            new X509SubjectKeyIdentifierExtension(certRequest.PublicKey, false));
    
        certRequest.CertificateExtensions.Add(
            new X509KeyUsageExtension(
                X509KeyUsageFlags.DigitalSignature | X509KeyUsageFlags.KeyEncipherment | X509KeyUsageFlags.DataEncipherment | X509KeyUsageFlags.KeyAgreement,
                false));
    
        var now = DateTimeOffset.UtcNow;
        var cert = certRequest.CreateSelfSigned(now.AddDays(-1), now.AddYears(100));
    
        File.WriteAllBytes(PfxFile(path, cn), cert.Export(X509ContentType.Pfx));
        File.WriteAllBytes(CrtFile(path, cn), cert.Export(X509ContentType.Cert));
    }
    

    【讨论】:

      猜你喜欢
      • 2013-09-10
      • 2020-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-22
      • 2021-12-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多