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

Failing to connect wit TLS #323

Open
plaeremans opened this issue Nov 30, 2023 · 2 comments
Open

Failing to connect wit TLS #323

plaeremans opened this issue Nov 30, 2023 · 2 comments

Comments

@plaeremans
Copy link

I' have problems trying to connect to SQL Server with Tiberius.
I was trying to use rustls instead of the default, but I don't get Tiberius to compile

[package]
name = "getsam"
version = "0.1.0"
edition = "2021"

[dependencies]
tiberius = { version = "0.12.2", features = ["rustls"] }
tokio = { version = "1.34.0", features = ["full"] }

The Tiberius crate does not compile. Any ideas ?

   Compiling tiberius v0.12.2
error[E0428]: the name `create_tls_stream` is defined multiple times
  --> /Users/pieter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tiberius-0.12.2/src/client/tls_stream.rs:31:1
   |
23 | / pub(crate) async fn create_tls_stream<S: AsyncRead + AsyncWrite + Unpin + Send>(
24 | |     config: &Config,
25 | |     stream: S,
26 | | ) -> crate::Result<TlsStream<S>> {
27 | |     TlsStream::new(config, stream).await
28 | | }
   | |_- previous definition of the value `create_tls_stream` here
...
31 | / pub(crate) async fn create_tls_stream<S: AsyncRead + AsyncWrite + Unpin + Send>(
32 | |     config: &Config,
33 | |     stream: S,
34 | | ) -> crate::Result<TlsStream<S>> {
35 | |     native_tls_stream::create_tls_stream(config, stream).await
36 | | }
   | |_^ `create_tls_stream` redefined here
   |
   = note: `create_tls_stream` must be defined only once in the value namespace of this module

error[E0252]: the name `TlsStream` is defined multiple times
  --> /Users/pieter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tiberius-0.12.2/src/client/tls_stream.rs:17:16
   |
14 | pub(crate) use native_tls_stream::TlsStream;
   |                ---------------------------- previous import of the type `TlsStream` here
...
17 | pub(crate) use rustls_tls_stream::TlsStream;
   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `TlsStream` reimported here
   |
   = note: `TlsStream` must be defined only once in the type namespace of this module
help: you can use `as` to change the binding name of the import
   |
17 | pub(crate) use rustls_tls_stream::TlsStream as OtherTlsStream;
   |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

error[E0624]: associated function `new` is private
  --> /Users/pieter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tiberius-0.12.2/src/client/tls_stream.rs:27:16
   |
27 |     TlsStream::new(config, stream).await
   |                ^^^ private associated function
   |
  ::: /Users/pieter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-native-tls-0.4.0/src/tls_stream.rs:23:5
   |
23 |     pub(crate) fn new(stream: native_tls::TlsStream<StdAdapter<S>>) -> Self {
   |     ----------------------------------------------------------------------- private associated function defined here

error[E0061]: this function takes 1 argument but 2 arguments were supplied
  --> /Users/pieter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tiberius-0.12.2/src/client/tls_stream.rs:27:5
   |
27 |     TlsStream::new(config, stream).await
   |     ^^^^^^^^^^^^^^         ------ unexpected argument of type `S`
   |
note: expected `TlsStream<StdAdapter<_>>`, found `&Config`
  --> /Users/pieter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tiberius-0.12.2/src/client/tls_stream.rs:27:20
   |
27 |     TlsStream::new(config, stream).await
   |                    ^^^^^^
   = note: expected struct `native_tls::TlsStream<async_native_tls::std_adapter::StdAdapter<_>>`
           found reference `&config::Config`
note: associated function defined here
  --> /Users/pieter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-native-tls-0.4.0/src/tls_stream.rs:23:19
   |
23 |     pub(crate) fn new(stream: native_tls::TlsStream<StdAdapter<S>>) -> Self {
   |                   ^^^
help: remove the extra argument
   |
27 -     TlsStream::new(config, stream).await
27 +     TlsStream::new(/* stream */).await
   |

error[E0277]: `async_native_tls::TlsStream<_>` is not a future
  --> /Users/pieter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tiberius-0.12.2/src/client/tls_stream.rs:27:36
   |
27 |     TlsStream::new(config, stream).await
   |     -------------------------------^^^^^
   |     |                             ||
   |     |                             |`async_native_tls::TlsStream<_>` is not a future
   |     |                             help: remove the `.await`
   |     this call returns `async_native_tls::TlsStream<_>`
   |
   = help: the trait `futures_util::Future` is not implemented for `async_native_tls::TlsStream<_>`
   = note: async_native_tls::TlsStream<_> must be a future or must implement `IntoFuture` to be awaited
   = note: required for `async_native_tls::TlsStream<_>` to implement `std::future::IntoFuture`

Some errors have detailed explanations: E0061, E0252, E0277, E0428, E0624.
For more information about an error, try `rustc --explain E0061`.
error: could not compile `tiberius` (lib) due to 5 previous errors
@AnthonyPoncet
Copy link

Hello,

This looks like #317.

You probably need to disable default features in cargo.toml and then enable rustls. By default native-tls is enabled and what you see is probably conflict between two enabled tls implememtations.

@NTmatter
Copy link

NTmatter commented Feb 21, 2024

In case it helps anyone with the same issue, you can disable default features and enable rustls with:

[dependencies]
tiberius = { version = "0.12.2", default-features = false, features = ["rustls"] }

Going slightly further, you can selectively use rustls for macOS, and native-tls on all other platforms. This works around issues with macOS Security Framework having issues with Azure SQL Server, and does not impact other platforms:

[target.'cfg(target_os = "macos")'.dependencies]
tiberius = { version = "0.12.2", default-features = false, features = ["chrono", "time", "tds73", "rust_decimal", "bigdecimal", "rustls"] }

# Different syntax to keep things narrow
[target.'cfg(not(target_os = "macos"))'.dependencies.tiberius]
version = "0.12.2"
default-features = false
features = ["chrono", "time", "tds73", "rust_decimal", "bigdecimal", "native-tls"]

edit: TOML syntax

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

3 participants