5

I did not have a clue about encryption until today so please pardon me if my question is to basic.

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:

  • server-ca.pem
  • client-cert.pem
  • client-key.pem

files in my computer.

I am trying to connect to the remote DB using psycopg2 in python3.6 (installed using conda). I have checked the documentation for establishing the connection and apparently the above files need to be used so that I can establish the connection. In specific in the psycopg2.connect() function I use the arguments:

  • sslmode='verify-ca'
  • sslcert=[local path of client-cert.pem file]
  • sslkey=[local path of client-key.pem file]
  • sslrootcert=[local path of server-ca.pem file]

Apparently there will be an error because according to this the the above files need to end in the following formats: .crt , .key.

After my research I found out that I (maybe) have to use openssl to generate the .crt and .key formats. How am I supposed to do that?

If I convert the .pem files and pass the converted ones to the psycopg2.connect() will I be able to connect to my remote DB?

1 Answer 1

2

Use openssl to convert the .pem files to .crt and .key files

First of all using command prompt/ terminal go to the directory where the .pem files are stored.

For the .crt file type:

  • openssl x509 -in client-cert.pem -out ssl-cert.crt
  • openssl x509 -in server-ca.pem -out ca-cert.crt

For the .key file type:

  • openssl rsa -in client-key.pem -out ssl-key.key

and finally for connecting to the DB using psycopg2.connect() simply pass the file path of the above files to the sslcert , sslkey and sslrootcert arguments.

Sign up to request clarification or add additional context in comments.

1 Comment

Still times out for me :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.