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

Unable to use 8192 RSA certificate #260

Closed
dns2utf8 opened this issue Jun 14, 2019 · 1 comment
Closed

Unable to use 8192 RSA certificate #260

dns2utf8 opened this issue Jun 14, 2019 · 1 comment

Comments

@dns2utf8
Copy link

I found a strange problem: I can not load keys bigger than 4096.
For testing I used these commands

	# the 8k one does not run with rustls, but does with openssl
	#openssl req -x509 -sha256 -newkey rsa:8192 -keyout key.pem -out cert.pem -days 365
	openssl req -x509 -sha256 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365
	openssl rsa -in key.pem -out key_decrypted.pem

and this rust code to load my key:

fn get_rustls_acceptor() -> Result<ServerConfig, rustls::TLSError> {
    use rustls::internal::pemfile::{certs, rsa_private_keys};
    use std::io::BufReader;

    let mut config = ServerConfig::new(NoClientAuth::new());

    let cert_file = &mut BufReader::new(File::open("cert.pem").expect("unable to read cert.pem"));
    let key_file = &mut BufReader::new(File::open("key_decrypted.pem").expect("unable to read key_decrypted.pem"));

    let cert_chain = certs(cert_file).expect("unable to construct certificate chain");

    let mut keys = rsa_private_keys(key_file).expect("unable to construct keys");

    config.set_single_cert(cert_chain, keys.pop().expect("no private keys found or unable to read, is it encrypted?"))?;

    Ok(config)
}

When I run it with the 8k key it panics:

thread 'main' panicked at 'unable to initialize TLS: General("invalid private key")'

Since the keys work with native-tls and openssl I am wondering if there is some sort of strange limit in rustls?

Best,
Stefan

@dns2utf8 dns2utf8 changed the title Unable to 8192 RSA certificate Unable to use 8192 RSA certificate Jun 14, 2019
@ctz
Copy link
Member

ctz commented Apr 18, 2020

As discussed on briansmith/ring#843 this is a restriction in ring (and, IMO, a reasonable one, since I think 8K RSA keys are not sensible given the security level/performance/size tradeoff)

@ctz ctz closed this as completed Apr 18, 2020
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