Привязка SAML: ошибка при получении X509Certificate2.PrivateKey на Azure - PullRequest
1 голос
/ 04 мая 2020

Библиотека ITFoxte c Identity SAML 2.0 содержит функцию для привязки запроса, который извлекает закрытый ключ из сертификата подписи.

 if(certificate is Saml2X509Certificate)
        {
            return (certificate as Saml2X509Certificate).GetRSAPrivateKey();
        }
        else
        {
            return certificate.GetRSAPrivateKey();
        }

Работает на локальной машине, но на azure выдает следующую ошибку.

System.Security.Cryptography.CryptographicException: Invalid provider type specified.
    at System.Security.Cryptography.Utils.CreateProvHandle(CspParameters parameters, Boolean 
  randomKeyContainer)
  at System.Security.Cryptography.Utils.GetKeyPairHelper(CspAlgorithmType keyType, CspParameters 
 parameters, Boolean randomKeyContainer, Int32 dwKeySize, SafeProvHandle& safeProvHandle, SafeKeyHandle& 
 safeKeyHandle)
  at System.Security.Cryptography.RSACryptoServiceProvider.GetKeyPair()
  at System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32 dwKeySize, CspParameters 
 parameters, Boolean useDefaultKeySize)
  at System.Security.Cryptography.X509Certificates.X509Certificate2.get_PrivateKey()
  at System.Security.Cryptography.X509Certificates.RSACertificateExtensions.GetRSAPrivateKey(X509Certificate2 certificate)
  at ITfoxtec.Identity.Saml2.X509Certificate2Extensions.GetSamlRSAPrivateKey(X509Certificate2 certificate)
  at ITfoxtec.Identity.Saml2.Saml2Binding<code>1.BindInternal(Saml2Request saml2RequestResponse)
  at ITfoxtec.Identity.Saml2.Saml2RedirectBinding.BindInternal(Saml2Request saml2RequestResponse, String messageName)
  at ITfoxtec.Identity.Saml2.Saml2Binding</code>1.Bind(Saml2Request saml2Request)  
.

Не уверен, является ли это проблемой библиотеки saml или azure, поскольку она работает на локальном компьютере. Я использую сертификат, указанный в примере с тестовым веб-приложением. Так что это не выглядит испорченным.

Кто-нибудь знает причину этого?

1 Ответ

0 голосов
/ 04 мая 2020

Если вы используете службу приложений Azure, возможно, проблема в том, что вам нужно сделать закрытый ключ сертификатов SSL / TLS доступным для вашего веб-приложения.

Добавление параметра приложения с именем WEBSITE_LOAD_CERTIFICATES вместе с его значение, указанное в отпечатке сертификата, сделает его доступным для вашего веб-приложения.

...