環境:
Windows 10, localhost, same machine
pg 12
node 14
openssl 1.1.1k
我已經閱讀并完成了從
但是一個簡單的節點專案可以在沒有 SSL 的情況下連接:
require('dotenv').config({ path: './environment/PostgreSql.env'});
const pgp = require('pg-promise')();
const db = pgp(
{
user: process.env.PGuser,
host: process.env.PGhost,
database: process.env.PGdatabase,
password: process.env.PGpassword,
port: process.env.PGport,
ssl: false // optional, but true gets code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE'
}
);
var sql = 'select * from current.testssl()';
db.any(sql)
.then
(
good =>
{
console.log(good); // ssl false gets data
},
bad =>
{
console.log(bad);
/* ssl true gets
at TLSWrap.callbackTrampoline (internal/async_hooks.js:130:17)
{
code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE',
stack: 'Error: unable to verify the first certificate…ckTrampoline (internal/async_hooks.js:130:17)',
message: 'unable to verify the first certificate'
}
*/
}
);
基于@Lauranz Albe 和@jjanes,pg_hba.conf 的最終解決方案:
# TYPE DATABASE USER ADDRESS METHOD
hostnossl all all 0.0.0.0/0 reject # must be the 1st line!
host all all 127.0.0.1/32 md5
host all all ::1/128 md5
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5
hostssl all all 0.0.0.0/0 cert clientcert=verify-full
uj5u.com熱心網友回復:
在您的開頭添加以下行pg_hba.conf:
hostnossl all all 0.0.0.0/0 reject
然后你必須重新加載 PostgreSQL(如果重新加載導致任何錯誤,請檢查日志檔案)。
這將拒絕所有使用未加密 TCP 連接的連接嘗試。
有關詳細資訊,請參閱檔案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/372272.html
標籤:PostgreSQL的 ssl
