Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: set removal version for Deno.ListenTlsOptions.certFile, Deno.ListenTlsOptions.keyFile and Deno.ConnectTlsOptions.certFile #22026

Merged
merged 4 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cli/tests/testdata/cert/listen_tls_alpn.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const listener = Deno.listenTls({
port: Number(Deno.args[0]),
certFile: "./tls/localhost.crt",
keyFile: "./tls/localhost.key",
cert: Deno.readTextFileSync("./tls/localhost.crt"),
key: Deno.readTextFileSync("./tls/localhost.key"),
alpnProtocols: ["h2", "http/1.1", "foobar"],
});

Expand Down
4 changes: 2 additions & 2 deletions cli/tests/testdata/cert/listen_tls_alpn_fail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { assertRejects } from "../../../../test_util/std/assert/mod.ts";

const listener = Deno.listenTls({
port: Number(Deno.args[0]),
certFile: "./tls/localhost.crt",
keyFile: "./tls/localhost.key",
cert: Deno.readTextFileSync("./tls/localhost.crt"),
key: Deno.readTextFileSync("./tls/localhost.key"),
alpnProtocols: ["h2", "http/1.1", "foobar"],
});

Expand Down
4 changes: 2 additions & 2 deletions cli/tests/testdata/run/tls_connecttls.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const port = 3505;
const listener = Deno.listenTls({
hostname,
port,
certFile: "./tls/localhost.crt",
keyFile: "./tls/localhost.key",
cert: Deno.readTextFileSync("./tls/localhost.crt"),
key: Deno.readTextFileSync("./tls/localhost.key"),
});

const response = encoder.encode(
Expand Down
4 changes: 2 additions & 2 deletions cli/tests/testdata/run/tls_starttls.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const port = 3504;
const listener = Deno.listenTls({
hostname,
port,
certFile: "./tls/localhost.crt",
keyFile: "./tls/localhost.key",
cert: Deno.readTextFileSync("./tls/localhost.crt"),
key: Deno.readTextFileSync("./tls/localhost.key"),
});

const response = encoder.encode(
Expand Down
12 changes: 6 additions & 6 deletions cli/tests/unit/http_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ Deno.test(
const listener = Deno.listenTls({
hostname,
port,
certFile: "cli/tests/testdata/tls/localhost.crt",
keyFile: "cli/tests/testdata/tls/localhost.key",
cert: Deno.readTextFileSync("cli/tests/testdata/tls/localhost.crt"),
key: Deno.readTextFileSync("cli/tests/testdata/tls/localhost.key"),
});
const conn = await listener.accept();
const httpConn = Deno.serveHttp(conn);
Expand Down Expand Up @@ -2451,8 +2451,8 @@ Deno.test(
const listener = Deno.listenTls({
hostname,
port,
certFile: "cli/tests/testdata/tls/localhost.crt",
keyFile: "cli/tests/testdata/tls/localhost.key",
cert: await Deno.readTextFile("cli/tests/testdata/tls/localhost.crt"),
key: await Deno.readTextFile("cli/tests/testdata/tls/localhost.key"),
});

const caCerts = [
Expand Down Expand Up @@ -2757,8 +2757,8 @@ for (const compression of [true, false]) {
const listener = Deno.listenTls({
hostname,
port,
certFile: "cli/tests/testdata/tls/localhost.crt",
keyFile: "cli/tests/testdata/tls/localhost.key",
cert: await Deno.readTextFile("cli/tests/testdata/tls/localhost.crt"),
key: await Deno.readTextFile("cli/tests/testdata/tls/localhost.key"),
alpnProtocols: ["h2"],
});
const server = httpServerWithErrorBody(listener, compression);
Expand Down
28 changes: 14 additions & 14 deletions cli/tests/unit/tls_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ Deno.test(
const listener = Deno.listenTls({
hostname,
port,
certFile: "cli/tests/testdata/tls/localhost.crt",
keyFile: "cli/tests/testdata/tls/localhost.key",
cert: await Deno.readTextFile("cli/tests/testdata/tls/localhost.crt"),
key: await Deno.readTextFile("cli/tests/testdata/tls/localhost.key"),
});

const response = encoder.encode(
Expand Down Expand Up @@ -296,8 +296,8 @@ async function tlsPair(): Promise<[Deno.Conn, Deno.Conn]> {
const listener = Deno.listenTls({
hostname: "localhost",
port,
certFile: "cli/tests/testdata/tls/localhost.crt",
keyFile: "cli/tests/testdata/tls/localhost.key",
cert: await Deno.readTextFile("cli/tests/testdata/tls/localhost.crt"),
key: await Deno.readTextFile("cli/tests/testdata/tls/localhost.key"),
});

const acceptPromise = listener.accept();
Expand All @@ -320,8 +320,8 @@ async function tlsAlpn(
const listener = Deno.listenTls({
hostname: "localhost",
port,
certFile: "cli/tests/testdata/tls/localhost.crt",
keyFile: "cli/tests/testdata/tls/localhost.key",
cert: await Deno.readTextFile("cli/tests/testdata/tls/localhost.crt"),
key: await Deno.readTextFile("cli/tests/testdata/tls/localhost.key"),
alpnProtocols: ["deno", "rocks"],
});

Expand Down Expand Up @@ -725,8 +725,8 @@ async function tlsWithTcpFailureTestImpl(
const tlsListener = Deno.listenTls({
hostname: "localhost",
port: tlsPort,
certFile: "cli/tests/testdata/tls/localhost.crt",
keyFile: "cli/tests/testdata/tls/localhost.key",
cert: await Deno.readTextFile("cli/tests/testdata/tls/localhost.crt"),
key: await Deno.readTextFile("cli/tests/testdata/tls/localhost.key"),
});

const tcpPort = getPort();
Expand Down Expand Up @@ -1019,8 +1019,8 @@ function createHttpsListener(port: number): Deno.Listener {
const listener = Deno.listenTls({
hostname: "localhost",
port,
certFile: "./cli/tests/testdata/tls/localhost.crt",
keyFile: "./cli/tests/testdata/tls/localhost.key",
cert: Deno.readTextFileSync("./cli/tests/testdata/tls/localhost.crt"),
key: Deno.readTextFileSync("./cli/tests/testdata/tls/localhost.key"),
});

serve(listener);
Expand Down Expand Up @@ -1285,8 +1285,8 @@ Deno.test(
const listener = Deno.listenTls({
hostname,
port,
certFile: "cli/tests/testdata/tls/localhost.crt",
keyFile: "cli/tests/testdata/tls/localhost.key",
cert: await Deno.readTextFile("cli/tests/testdata/tls/localhost.crt"),
key: await Deno.readTextFile("cli/tests/testdata/tls/localhost.key"),
});
const acceptPromise = listener.accept();
const connectPromise = Deno.connectTls({
Expand Down Expand Up @@ -1354,8 +1354,8 @@ Deno.test(
const listener = Deno.listenTls({
hostname,
port,
certFile: "cli/tests/testdata/tls/localhost.crt",
keyFile: "cli/tests/testdata/tls/localhost.key",
cert: Deno.readTextFileSync("cli/tests/testdata/tls/localhost.crt"),
key: Deno.readTextFileSync("cli/tests/testdata/tls/localhost.key"),
});
for await (const conn of listener) {
for (let i = 0; i < 10; i++) {
Expand Down
23 changes: 22 additions & 1 deletion ext/net/02_tls.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

import { core, primordials } from "ext:core/mod.js";
import { core, internals, primordials } from "ext:core/mod.js";
const {
op_net_accept_tls,
op_net_connect_tls,
Expand Down Expand Up @@ -39,6 +39,13 @@ async function connectTls({
privateKey = undefined,
alpnProtocols = undefined,
}) {
if (certFile !== undefined) {
internals.warnOnDeprecatedApi(
"Deno.ConnectTlsOptions.certFile",
new Error().stack,
"Pass the cert file contents to the `Deno.ConnectTlsOptions.certChain` option instead.",
);
}
if (transport !== "tcp") {
throw new TypeError(`Unsupported transport: '${transport}'`);
}
Expand Down Expand Up @@ -76,6 +83,20 @@ function listenTls({
if (transport !== "tcp") {
throw new TypeError(`Unsupported transport: '${transport}'`);
}
if (keyFile !== undefined) {
internals.warnOnDeprecatedApi(
"Deno.ListenTlsOptions.keyFile",
new Error().stack,
"Pass the key file contents to the `Deno.ListenTlsOptions.key` option instead.",
);
}
if (certFile !== undefined) {
internals.warnOnDeprecatedApi(
"Deno.ListenTlsOptions.certFile",
new Error().stack,
"Pass the cert file contents to the `Deno.ListenTlsOptions.cert` option instead.",
);
}
const { 0: rid, 1: localAddr } = op_net_listen_tls(
{ hostname, port: Number(port) },
{ cert, certFile, key, keyFile, alpnProtocols, reusePort },
Expand Down
19 changes: 14 additions & 5 deletions ext/net/lib.deno_net.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,17 @@ declare namespace Deno {
* `--allow-read`.
*
* @tags allow-read
* @deprecated This option is deprecated and will be removed in Deno 2.0.
* @deprecated Pass the certificate file contents directly to the
* {@linkcode Deno.ListenTlsOptions.cert} option instead. This option will
* be removed in Deno 2.0.
*/
certFile?: string;
/** Server private key file. Requires `--allow-read`.
*
* @tags allow-read
* @deprecated This option is deprecated and will be removed in Deno 2.0.
* @deprecated Pass the key file contents directly to the
* {@linkcode Deno.ListenTlsOptions.key} option instead. This option will
* be removed in Deno 2.0.
*/
keyFile?: string;

Expand All @@ -171,7 +175,11 @@ declare namespace Deno {
* security).
*
* ```ts
* const lstnr = Deno.listenTls({ port: 443, certFile: "./server.crt", keyFile: "./server.key" });
* using listener = Deno.listenTls({
* port: 443,
* cert: Deno.readTextFileSync("./server.crt"),
* key: Deno.readTextFileSync("./server.key"),
* });
* ```
*
* Requires `allow-net` permission.
Expand Down Expand Up @@ -263,8 +271,9 @@ declare namespace Deno {
/**
* Server certificate file.
*
* @deprecated This option is deprecated and will be removed in a future
* release.
* @deprecated Pass the cert file contents directly to the
* {@linkcode Deno.ConnectTlsOptions.caCerts} option instead. This option
* will be removed in Deno 2.0.
*/
certFile?: string;
/** A list of root certificates that will be used in addition to the
Expand Down