<p>I am attempting to use the .Net System.Security.SslStream class to process the server side of a SSL/TLS stream with client authentication.</p>

<p>To perform the handshake, I am using this code:</p>

<pre><code>SslStream sslStream = new SslStream(innerStream, false, RemoteCertificateValidation, LocalCertificateSelectionCallback);
sslStream.AuthenticateAsServer(serverCertificate, true, SslProtocols.Default, false);
</code></pre>

<p>Unfortunately, this results in the SslStream transmitting a CertificateRequest containing the subjectnames of all certificates in my CryptoAPI Trusted Root Store.</p>

<p>I would like to be able to override this. It is not an option for me to require the user to install or remove certificates from the Trusted Root Store.</p>

<p>It looks like the SslStream uses SSPI/SecureChannel underneath, so if anyone knows how to do the equivalent with that API, that would be helpful, too.</p>

<p>Any ideas?</p>

[{'answer_id': 54321, 'author': 'Peter Ritchie', 'author_id': 5620, 'author_profile': 'https://Stackoverflow.com/users/5620', 'pm_score': 2, 'selected': False, 'text': "<p>What the certificate validation is doing is validating all certificates in the chain.  In order to truely do that it just contact the root store of each of those cerficates.</p>\n\n<p>If that's not something you want to happen you can deploy your own root store locally.</p>\n"}, {'answer_id': 54749, 'author': 'Rasmus Faber', 'author_id': 5542, 'author_profile': 'https://Stackoverflow.com/users/5542', 'pm_score': 1, 'selected': False, 'text': '<p>It is not the validation part I want to change. The problem is in the initial handshake, the server transmits the message informing the client that client authentication is required (that is the CertificateRequest message). As part of this message, the server sends the names of CAs that it will accept as issuers of the client certificate. It is that list which per default contains all the Trusted Roots in the store.</p>\n\n<p>But if is possible to override the certificate root store for a single application, that would probably fix the problem. Is that what you mean? And if so, how do I do that?</p>\n'}, {'answer_id': 62274, 'author': 'Rasmus Faber', 'author_id': 5542, 'author_profile': 'https://Stackoverflow.com/users/5542', 'pm_score': 3, 'selected': True, 'text': '<p>It does not look like this is currently possible using the .NET libraries. </p>\n\n<p>I solved it by using the Mono class library implementation of System.Security.SslStream, which gives better access to overriding the servers behavior during the handshake.</p>\n'}]
['https://Stackoverflow.com/questions/53824', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5542/']