1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-24 16:19:12 -05:00

fix(runtime/tls): handle invalid host for connectTls/startTls (#9453)

This commit is contained in:
Erik Price 2021-02-11 03:45:10 -08:00 committed by GitHub
parent 61108935f1
commit a097c4089b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 4 deletions

View file

@ -20,6 +20,24 @@ unitTest(async function connectTLSNoPerm(): Promise<void> {
}, Deno.errors.PermissionDenied);
});
unitTest(
{ perms: { read: true, net: true } },
async function connectTLSInvalidHost(): Promise<void> {
const listener = await Deno.listenTls({
hostname: "localhost",
port: 3567,
certFile: "cli/tests/tls/localhost.crt",
keyFile: "cli/tests/tls/localhost.key",
});
await assertThrowsAsync(async () => {
await Deno.connectTls({ hostname: "127.0.0.1", port: 3567 });
}, Error);
listener.close();
},
);
unitTest(async function connectTLSCertFileNoReadPerm(): Promise<void> {
await assertThrowsAsync(async () => {
await Deno.connectTls({

View file

@ -140,8 +140,8 @@ async fn op_start_tls(
}
let tls_connector = TlsConnector::from(Arc::new(config));
let dnsname =
DNSNameRef::try_from_ascii_str(&domain).expect("Invalid DNS lookup");
let dnsname = DNSNameRef::try_from_ascii_str(&domain)
.map_err(|_| generic_error("Invalid DNS lookup"))?;
let tls_stream = tls_connector.connect(dnsname, tcp_stream).await?;
let rid = {
@ -202,8 +202,8 @@ async fn op_connect_tls(
config.root_store.add_pem_file(reader).unwrap();
}
let tls_connector = TlsConnector::from(Arc::new(config));
let dnsname =
DNSNameRef::try_from_ascii_str(&domain).expect("Invalid DNS lookup");
let dnsname = DNSNameRef::try_from_ascii_str(&domain)
.map_err(|_| generic_error("Invalid DNS lookup"))?;
let tls_stream = tls_connector.connect(dnsname, tcp_stream).await?;
let rid = {
let mut state_ = state.borrow_mut();