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

Why client redirect to ssl connection? #262

Open
NiuBlibing opened this issue Mar 3, 2023 · 1 comment
Open

Why client redirect to ssl connection? #262

NiuBlibing opened this issue Mar 3, 2023 · 1 comment

Comments

@NiuBlibing
Copy link

I'm try to connect plaintext connection but the client auto redirect the ssl protocol which leading something wrong:

[2023-03-03T10:23:23Z ERROR pulsar::connection] connection error, not retryable: [Tls(Ssl(Error { code: ErrorCode(1), cause: Some(Ssl(ErrorStack([Error { code: 167772294, library: "SSL routines", function: "tls_post_process_server_certificate", reason: "certificate verify failed", file: "ssl/statem/statem_clnt.c", line: 1889 }]))) }, X509VerifyResult { code: 64, error: "IP address mismatch" }))]
use std::path;

use apache_avro::Schema;
use pulsar::{
    message::proto, producer, Authentication, Error as PulsarError, Pulsar, SerializeMessage,
    TokioExecutor,
};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
struct Test {
    a: i64,
    b: String,
}

const raw_schema:&str = r#"
{
    "type": "record",
    "name": "test",
    "fields": [
        {"name": "a", "type": "long", "default": 42},
        {"name": "b", "type": "string"}
    ]
}
"#;
impl SerializeMessage for Test {
    fn serialize_message(input: Self) -> Result<producer::Message, PulsarError> {
        let schema = Schema::parse_str(raw_schema).unwrap();
        let value = apache_avro::to_value(input).unwrap();
    let value = value.resolve(&schema).unwrap();
    let payload = apache_avro::to_avro_datum(&schema, value).unwrap();
        // let payload = serde_json::to_vec(&input).map_err(|e| PulsarError::Custom(e.to_string()))?;
        Ok(producer::Message {
            payload,
            ..Default::default()
        })
    }
}

#[tokio::main]
async fn main() -> Result<(), pulsar::Error> {
    env_logger::init();
    
    let addr = "pulsar://localhost:6650/";
    let pulsar: Pulsar<_> = Pulsar::builder(addr, TokioExecutor)
        .with_auth(Authentication {
            name: "token".to_string(),
            data: "key".to_string().into_bytes(),
        })
        .with_allow_insecure_connection(true)
        .with_certificate_chain_file(path::Path::new("./ca.cert.pem")).unwrap()
        .with_tls_hostname_verification_enabled(true)
        .build()
        .await?;

    let mut producer = pulsar
        .producer()
        .with_topic("persistent://test/test-ns/topic3")
        .with_name("my producer")
        .with_options(producer::ProducerOptions {
            schema: Some(proto::Schema {
                schema_data: raw_schema.as_bytes().into(),
                r#type: proto::schema::Type::Avro as i32,
                ..Default::default()
            }),
            ..Default::default()
        })
        .build()
        .await?;

    let mut counter = 0usize;
    loop {
        producer
            .send(Test {
                a: 27,
                b: "foo".to_owned(),
            })
            .await?;

        counter += 1;
        println!("{} messages", counter);
        tokio::time::sleep(std::time::Duration::from_millis(2000)).await;
    }
}

@NiuBlibing
Copy link
Author

And disable hostname verification by .with_tls_hostname_verification_enabled(false),it still verify the ip name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant