title: Connect to a Google Cloud SQL Postgres DB over SSL using psycopg2
body: <p>I did not have a clue about encryption until today so please pardon me if my question is to basic.</p>
  
  <p>I have a GCP SQL instance that is set up for Postgres with SSL encryption. I have created a client certificate on GCP and dowloaded and stored the:</p>
  
  <ul>
  <li><strong>server-ca.pem</strong> </li>
  <li><strong>client-cert.pem</strong></li>
  <li><strong>client-key.pem</strong> </li>
  </ul>
  
  <p>files in my computer.</p>
  
  <p>I am trying to connect to the remote DB using psycopg2 in python3.6 (installed using conda). I have checked the <a href="https://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-PARAMKEYWORDS" rel="noreferrer">documentation</a> for establishing the connection and apparently the above files need to be used so that I can establish the connection. In specific in the <code>psycopg2.connect()</code> function I use the arguments:</p>
  
  <ul>
  <li><code>sslmode='verify-ca'</code></li>
  <li><code>sslcert=[local path of client-cert.pem file]</code></li>
  <li><code>sslkey=[local path of client-key.pem file]</code></li>
  <li><code>sslrootcert=[local path of server-ca.pem file]</code></li>
  </ul>
  
  <p>Apparently there will be an error because according to <a href="https://www.postgresql.org/docs/9.1/static/ssl-tcp.html" rel="noreferrer">this</a> the the above files need to end in the following formats: <code>.crt</code> , <code>.key</code>.</p>
  
  <p>After my research I found out that I (maybe) have to use <code>openssl</code> to generate the <code>.crt</code> and <code>.key</code> formats. How am I supposed to do that?</p>
  
  <p>If I convert the <code>.pem</code> files and pass the converted ones to the <code>psycopg2.connect()</code> will I be able to connect to my remote DB?</p>