Skip to content

Commit

Permalink
feat(unstable): ALPN config in listenTls
Browse files Browse the repository at this point in the history
This commit adds the ability for users to configure ALPN protocols when
calling `Deno.listenTls`.
  • Loading branch information
lucacasonato committed Apr 9, 2021
1 parent a87da4b commit a748bfe
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cli/dts/lib.deno.unstable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,16 @@ declare namespace Deno {
options?: StartTlsOptions,
): Promise<Conn>;

export interface ListenTlsOptions {
/** **UNSTABLE**: new API, yet to be vetted.
*
* Application-Layer Protocol Negotiation (ALPN) protocols to announce to
* the client. If not specified, no ALPN extension will be included in the
* TLS handshake.
*/
alpnProtocols?: string[];
}

/** **UNSTABLE**: The `signo` argument may change to require the Deno.Signal
* enum.
*
Expand Down
2 changes: 2 additions & 0 deletions runtime/js/40_tls.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@
keyFile,
hostname = "0.0.0.0",
transport = "tcp",
alpnProtocols,
}) {
const res = opListenTls({
port,
certFile,
keyFile,
hostname,
transport,
alpnProtocols,
});
return new TLSListener(res.rid, res.localAddr);
}
Expand Down
6 changes: 6 additions & 0 deletions runtime/ops/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ pub struct ListenTlsArgs {
port: u16,
cert_file: String,
key_file: String,
alpn_protocols: Option<Vec<String>>,
}

fn op_listen_tls(
Expand All @@ -318,6 +319,11 @@ fn op_listen_tls(
permissions.read.check(Path::new(&key_file))?;
}
let mut config = ServerConfig::new(NoClientAuth::new());
if let Some(alpn_protocols) = args.alpn_protocols {
super::check_unstable(state, "Deno.listenTls#alpn_protocols");
config.alpn_protocols =
alpn_protocols.into_iter().map(|s| s.into_bytes()).collect();
}
config
.set_single_cert(load_certs(&cert_file)?, load_keys(&key_file)?.remove(0))
.expect("invalid key or certificate");
Expand Down

0 comments on commit a748bfe

Please sign in to comment.