How do I generate keys with ring and load into rustls?


I am having trouble getting ring keys to load in rustls
All the files that I write to disk do have data. Windows reports 1KB size for each file in explorer.

Creating & Loading Private Keys

Generating with ring

let rng = rand::SystemRandom::new();
let pkcs8_bytes = signature::Ed25519KeyPair::generate_pkcs8(&rng).unwrap();

let mut key_pairf = File::create("F:\\rust_projects\\andrew-testing\\andrew.keypair").unwrap();

When I read them in rustls, it just prints [] :frowning:

let mut key_pairf = File::open("F:\\rust_projects\\andrew-testing\\andrew.keypair").unwrap();
let mut bufkey = io::BufReader::new(key_pairf);

let keypair = rustls::internal::pemfile::pkcs8_private_keys(&mut bufkey).unwrap();
println!("{:?}", keypair)

How do I load my keypair into rustls correctly?

Creating & Loading Custom Clients' Public Keys

I'd like to only trust specific public keys from the clients.
Here is my attempt.
I'm pretty confused on how to do this, but here's my attempt at starting this

Creating public key

let rng = rand::SystemRandom::new();
let pkcs8_bytes = signature::Ed25519KeyPair::generate_pkcs8(&rng).unwrap();
let key_pair = signature::Ed25519KeyPair::from_pkcs8(pkcs8_bytes.as_ref()).unwrap();
let peer_public_key_bytes = key_pair.public_key().as_ref();
let mut x = File::create("F:\\rust_projects\\andrew-testing\\").unwrap();

Loading them
Prints (0, 0)

let mut pubf = File::open("F:\\rust_projects\\andrew-testing\\").unwrap();
let mut bufkey = io::BufReader::new(pubf);

let x = pemfile::certs(&mut bufkey);
let mut config = rustls::ClientConfig::new();

let q = config.root_store.add_pem_file(&mut bufkey).unwrap();
println!("{:?}", q);

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.