"Invalid provider type specified." when using a high trust cert that was created with CNG in a Provider Hosted App
The short solution: When generating a cert to be used for high trust in a Provider Hosted application, choose "(no template) Legacy key", Microsoft RSA SChannel Cryptographic Provider.
The longer explanation: In my continuing journey with Provider Hosted applications, I've run into a new issue that is documented in other areas of Microsoft technology, but not SharePoint. I requested an enterprise cert that we would use for S2S high trust, typically certs that are generated for web environments are generated using a web site template, on Microsoft platforms the website templates typically use CNG (Cryptographic Next Generation) and IIS supports them just fine. High trust certs, unlike standard website SSL certs, are not imported into IIS and used to encrypt browser transactions, they are broken up into public and private key files (cer and pfx), the public key is used on the SharePoint server and the private key used on the remote web server. The files together provide secure encryption for the remote web and the SharePoint server to talk. We built our app in Visual Studio 2013 and the standard Provider Hosted Application template in Visual Studio comes with some great base code that handles all of the nitty gritty of using the private key to talk back to SharePoint. After setting up the key files and attempting to navigate to one of our I pages I received the error below. At the point where the TokenHelper class attempts to access the private key in the pfx file the error is thrown, the reason is that the crypto api does not support certs generated with CNG. See the short solution above.
Server Error in '/' Application.
An internal error occurred.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Security.Cryptography.CryptographicException: An internal error occurred.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. |
Stack Trace:
|