Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What type of file is PathToCertificate? If it's just a .cer file, it will not contain the private key for the certificate and trying to use that certificate for SSL/TLS will fail.</p> <p>However, if you have a PKCS7 or PKCS12 file that includes the public and private key for the certificate, your code will work (you might need to use the overload that takes a password if the private key has one).</p> <p>To test this, I went to <a href="http://www.mono-project.com/UsingClientCertificatesWithXSP" rel="nofollow noreferrer">http://www.mono-project.com/UsingClientCertificatesWithXSP</a> and created my client.p12 file following those instructions. I also created a simple HTTPS server using HttpListener for testing.</p> <p>Then I compiled the following program into 'client.exe' and run like:</p> <pre><code> client.exe https://&lt;MYSSLSERVER&gt;/ client.p12 password </code></pre> <p>where client.p12 is the PKCS12 file generated before and 'password' is the password I set for the private key of the certificate.</p> <pre><code>using System; using System.IO; using System.Net; using System.Security.Cryptography.X509Certificates; using System.Text; public class HttpWebRequestClientCertificateTest : ICertificatePolicy { public bool CheckValidationResult (ServicePoint sp, X509Certificate certificate, WebRequest request, int error) { return true; // server certificate's CA is not known to windows. } static void Main (string[] args) { string host = "https://localhost:1234/"; if (args.Length &gt; 0) host = args[0]; X509Certificate2 certificate = null; if (args.Length &gt; 1) { string password = null; if (args.Length &gt; 2) password = args [2]; certificate = new X509Certificate2 (args[1], password); } ServicePointManager.CertificatePolicy = new HttpWebRequestClientCertificateTest (); HttpWebRequest req = (HttpWebRequest) WebRequest.Create (host); if (certificate != null) req.ClientCertificates.Add (certificate); WebResponse resp = req.GetResponse (); Stream stream = resp.GetResponseStream (); StreamReader sr = new StreamReader (stream, Encoding.UTF8); Console.WriteLine (sr.ReadToEnd ()); } } </code></pre> <p>Let me know if you want me to upload the server code and the certificates used on both sides of the test.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload