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

Handle incorrect private keys and support pkcs8 keys #418

Merged
merged 3 commits into from
Jan 9, 2023

Conversation

hakanlundvall
Copy link
Contributor

When I tried using TLS transport using a certificate and key not created using minica, it would not read the key file. It instead gave the following error:
thread 'main' panicked at 'removal index (is 0) should be < len (is 0)', io/zenoh-links/zenoh-link-tls/src/unicast.rs:380:40

The reason turned out to be that the function used (rustls_pemfile::rsa_private_keys) only reads keys in the pkcs#1 format and just silently returns an empty list if no such key is found.

My solution is to check if no key was found and if not, try the pkcs#8 format and ultimately, if a key is still not found, give a better error message.

Copy link
Contributor

@p-avital p-avital left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
Thanks for contributing to Zenoh.
Since this has to do with security, I'll request @Mallets to also review the PR, but I don't see anything wrong with it myself.

}

if keys.len() == 0 {
return Err(zerror!("No private key found.").into());
Copy link
Contributor

@p-avital p-avital Jan 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole return statement can be shortened to bail!("No private key found") :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replaced the return statement according to your suggestion. Also I fixed a failed CI check so now it passes the CI.

@p-avital p-avital requested a review from Mallets January 9, 2023 08:40
@Mallets Mallets merged commit 5c72f24 into eclipse-zenoh:master Jan 9, 2023
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

Successfully merging this pull request may close these issues.

3 participants