Skip to content

Commit eb5857e

Browse files
authored
feat: Add support for 'verify-ca' and 'verify-full' TLS modes (denodrivers#397)
1 parent 44dfcf0 commit eb5857e

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

connection/connection_params.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,13 @@ export interface ConnectionOptions {
5050
attempts: number;
5151
}
5252

53-
type TLSModes = "disable" | "prefer" | "require";
53+
/** https://www.postgresql.org/docs/14/libpq-ssl.html#LIBPQ-SSL-PROTECTION */
54+
type TLSModes =
55+
| "disable"
56+
| "prefer"
57+
| "require"
58+
| "verify-ca"
59+
| "verify-full";
5460

5561
// TODO
5662
// Refactor enabled and enforce into one single option for 1.0
@@ -261,13 +267,15 @@ function parseOptionsFromUri(connection_string: string): ClientOptions {
261267
tls = { enabled: true, enforce: false, caCertificates: [] };
262268
break;
263269
}
264-
case "require": {
270+
case "require":
271+
case "verify-ca":
272+
case "verify-full": {
265273
tls = { enabled: true, enforce: true, caCertificates: [] };
266274
break;
267275
}
268276
default: {
269277
throw new ConnectionParamsError(
270-
`Supplied DSN has invalid sslmode '${postgres_uri.sslmode}'. Only 'disable', 'require', and 'prefer' are supported`,
278+
`Supplied DSN has invalid sslmode '${postgres_uri.sslmode}'`,
271279
);
272280
}
273281
}

docs/README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,14 @@ of search parameters such as the following:
116116
values for connection (ej: options=--cluster=your_cluster_name)
117117
- sslmode: Allows you to specify the tls configuration for your client, the
118118
allowed values are the following:
119-
- disable: Skip TLS connection altogether
120-
- prefer: Attempt to stablish a TLS connection, default to unencrypted if the
121-
negotiation fails
119+
120+
- verify-full: Same behaviour as `require`
121+
- verify-ca: Same behaviour as `require`
122122
- require: Attempt to stablish a TLS connection, abort the connection if the
123123
negotiation fails
124+
- prefer: Attempt to stablish a TLS connection, default to unencrypted if the
125+
negotiation fails
126+
- disable: Skip TLS connection altogether
124127
- user: If user is not specified in the url, this will be taken instead
125128

126129
#### Password encoding

tests/connection_params_test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,10 @@ Deno.test("Throws on connection string with invalid ssl mode", function () {
242242
assertThrows(
243243
() =>
244244
createParams(
245-
"postgres://some_user@some_host:10101/deno_postgres?sslmode=verify-full",
245+
"postgres://some_user@some_host:10101/deno_postgres?sslmode=invalid",
246246
),
247247
ConnectionParamsError,
248-
"Supplied DSN has invalid sslmode 'verify-full'. Only 'disable', 'require', and 'prefer' are supported",
248+
"Supplied DSN has invalid sslmode 'invalid'",
249249
);
250250
});
251251

0 commit comments

Comments
 (0)