PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, November 8, 2022

[FIXED] How to Create Connection Pools for Digital Ocean Managed Postgres Database using SSL with Nodejs?

 November 08, 2022     database, digital-ocean, node.js, postgresql, ssl     No comments   

Issue

I writing an API using nodejs and express. My database got hacked and I decided to use the Digital Ocean Managed Database. Digital Ocean Managed database requires SSL and they ONLY provide you with one CA certificate. In all the tutorials out there, SSL requires 3 files. I didn't find any tutorial on how to connect node-pg with only one file. I finally found the solution and I want to share it with the community. Hopefully, I save someone a few hours of digging.


Solution

The certificate that the Digital Ocean provides you is a Root Certificate NOT Client Certificate. In node-pg cert is referring to the client certificate and CA refers to the root certificate. CA option is the one that should be used, not Cert.

  1. CA: root.crt (For Incoming messages; Digital Ocean gives you this one)
  2. Key: postgresql.key (You don't need it)
  3. Cert: Client Certificate (You don't need it)

const config = {
  database: 'database-name',
  host: 'host-or-ip',
  user: 'username',
  password: 'password',
  port: 1234,
  // this object will be passed to the TLSSocket constructor
  ssl: {
    ca: fs.readFileSync('/path/to/digitalOcean/certificate.crt').toString()
  }
}

If this answer was useful to you give a thumbs up so other people can find it as well.



Answered By - Soli Technology LLC
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing