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

rustls failed to parse private key as RSA, EDSA or EdDSA #379

Open
havok4u opened this issue Apr 25, 2024 · 9 comments
Open

rustls failed to parse private key as RSA, EDSA or EdDSA #379

havok4u opened this issue Apr 25, 2024 · 9 comments

Comments

@havok4u
Copy link

havok4u commented Apr 25, 2024

I am using mysql and changed the default to use rustls
mysql = { version = "25.0.0", default-features = false, features = ["default-rustls"] }

Can anyone tell me why I would get this error doing mtls
Err(TlsError { unexpected error: failed to parse private key as RSA, ECDSA, or EdDSA })

I use these same certificates with the mysql client and in Golang and it works flawlessly.

@havok4u
Copy link
Author

havok4u commented Apr 25, 2024

For additional context, here is the code snippet

      let client_identity = ClientIdentity::new(
            Path::new("/opt/mysql/certs/client.pem"),
            Path::new("/opt/mysql/certs/client.key")
        );
        let ssl_opts = SslOpts::default()
            .with_root_cert_path(Some(Path::new("/opt/mysql/certs/ca.crt")))
            .with_client_identity(Some(client_identity));
        let opts = OptsBuilder::new()
            .ip_or_hostname(Some("mysql.somedomain.com"))
            .user(Some("someuser"))
            .pass(Some("somepass"))
            .tcp_port(3306u16)
            .db_name(Some("mydb"))
            .ssl_opts(ssl_opts)
            .secure_auth(true);
        let p = Pool::new(opts)?;  <--- this is where things fail

Let me know if I am missing something here, but reading through the code for rustls, I don't think so.

@blackbeam
Copy link
Owner

blackbeam commented Apr 25, 2024

Hi.

Fyi the error comes from here. It would be helpful to know which key do you actually use (RSA, ECDSA, or EdDSA) and in which format (Pkcs1, Pkcs8, sec1). Is in in pem or in der?

@havok4u
Copy link
Author

havok4u commented Apr 25, 2024

We found that in the code. We use RSA and pem format. We did convert our pem to der and got the same problem. Interesting aside my coworker is using rustls in GRPC with certs gen'd from same source and he gets no problems using rustls (tonic uses rustls) for GRPC.

@havok4u
Copy link
Author

havok4u commented Apr 25, 2024

another note, we switched out rustls back to default and it works. I'd like to see this work with rustls as it seems to be pretty most used. We wanted rustls cause it supports more modern TLS ciphers and protocols.

@blackbeam
Copy link
Owner

Interesting aside my coworker is using rustls in GRPC with certs gen'd from same source and he gets no problems using rustls (tonic uses rustls) for GRPC.

Just to clarify, which version of rustls?

We use RSA and pem format.

Still unclear what is inside of your pem-formatted file.

Can you please generate a random keypair and send it to me in the same format for investigation?

@havok4u
Copy link
Author

havok4u commented Apr 25, 2024

So we figured it out, based on your above questions. This triggered my co-worker to question what format we actually had. Turns out we were pkcs8, thus we converted to pkcs1 (aka traditional) and it now works. Question is why does rustls not support the pkcs8 in this library? Because in the grpc mtls the pkcs8 (using rustls) does work.

And btw thank you for your quick responses, much appreciated.

@havok4u
Copy link
Author

havok4u commented Apr 26, 2024

We dug into the code and when it comes to the mysql library calling rustls, it seems the call is statically defined for pkcs1. So as that was the way it was implemented, maybe this could be a feature request for pkcs8 support as well.

@havok4u
Copy link
Author

havok4u commented Apr 29, 2024

Just an update, openssl now gens by default pkcs8 and it was mentioned on a google forum that the -traditional switch (which takes a pkcs8 and converts to pkcs1 is gone in current versions or going away.

@blackbeam
Copy link
Owner

@havok4u, hi. Can you please try the pkcs8 branch (#381) with your pkcs8 keys?

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

2 participants