title: Use TLS client authentication with casablanca / cpprest in Linux
body: <p>I wanted to switch over to <code>cpprest</code> for <code>REST</code> requirements, however, in my scenario, <code>TLS</code> client authentication needs to be supported. </p>
  
  <p>I went through the capabilities of the library, but I am not sure whether there is built in support for client authentication.</p>
  
  <p>There are some hacks for trying to get this capability, but it seems only on <code>Windows</code> for the moment, which won't work for me, since my server is on <code>Linux</code>.</p>
  
  <p>This page here, <a href="https://github.com/Microsoft/cpprestsdk/issues/810" rel="nofollow noreferrer">https://github.com/Microsoft/cpprestsdk/issues/810</a>, describes one such get-around for Windows, and a hint of how it can work in <code>Linux</code> builds, but I am not sure how to go about it, since I have little experience in the area.</p>
  
  <p>Work around for <code>TLS</code> client authentication on <code>Windows</code> - </p>
  
  <pre><code>#include &lt;Wincrypt.h&gt;
  
  std::vector&lt;uint8_t&gt;  pkcs12_data; // "... your client certificate PKCS#12 with private key goes here ...";
  utility::string_t     password = "pkcs12_password"; 
  
  web::http::client::http_client_config cfg;
  cfg.set_nativehandle_options([=] (web::http::client::native_handle h) {
      CRYPT_DATA_BLOB data;
      data.cbData           = pkcs12_data.size();
      data.pbData           = reinterpret_cast&lt;BYTE *&gt;(pkcs12_data.data());
      HCERTSTORE hCertStore = PFXImportCertStore(&amp;data, password.c_str(), 0);
  
      PCCERT_CONTEXT hContext = CertFindCertificateInStore(
          hCertStore, X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, 0, CERT_FIND_ANY,
          NULL, NULL);
  
      WinHttpSetOption(h, WINHTTP_OPTION_CLIENT_CERT_CONTEXT, 
                       (LPVOID)hContext, sizeof(CERT_CONTEXT));
  });
  
  web::http::client::http_client http_client(PS("https://secure.com"), cfg);
  </code></pre>