Skip to content

Channel connect with tls with IP address will failed with InvalidDNSNameError #279

@Sherlock-Holo

Description

@Sherlock-Holo

Bug Report

Version 0.1.1

└── tonic v0.1.1

Platform

Linux SherlockHolo 5.5.7-arch1-1 #1 SMP PREEMPT Sat, 29 Feb 2020 19:06:02 +0000 x86_64 GNU/Linux

Description

my dependencies is

http = "0.2"
tonic = { version = "0.1", features = ["transport", "tls"] }
tokio = { version = "0.2", features = ["rt-core", "macros", "sync", "time", "rt-util", "fs"] }

I try

use std::str::FromStr;
use std::time::Duration;

use http::Uri;
use tokio::fs;
use tonic::transport::{Certificate, Channel, ClientTlsConfig, Identity};

#[tokio::main]
async fn main() {
    let uri = Uri::from_str("https://127.0.0.1:9876").unwrap();

    let ca = fs::read("ca.pem").await.unwrap();

    let ca = Certificate::from_pem(ca);

    let key = fs::read("key.pem").await.unwrap();
    let cert = fs::read("cert.pem").await.unwrap();

    let identity = Identity::from_pem(cert, key);

    let tls_config = ClientTlsConfig::new()
        .ca_certificate(ca)
        .identity(identity);

    let channel = Channel::builder(uri)
        .tls_config(tls_config)
        .tcp_keepalive(Some(Duration::from_secs(5)))
        .connect()
        .await.unwrap();
}

and use nc -l 127.0.0.1 9876 to listen, it should connect success and nc will print something aboult tls handshake, but it failed with thread 'main' panicked at 'called Result::unwrap()on anErr value: tonic::transport::Error(Transport, hyper::Error(Connect, InvalidDNSNameError))', src/libcore/result.rs:1188:5.

If I use https://localhost:9876 it connects successfully and nc print something about tls handshake messages. It should not happen.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions