Hey guys, I'm trying to set up an HTTPS server, but it doesn't want to load. I feel like I've tried everything, but nothing seems to work. this is really important so thanks for looking at my question
Any help is welcome!
So, when I set my code up like below, I get this error:
Identity PEM is missing a private key such as RSA, ECC or PKCS8
My code:
let routes = warp::any().map(|| "Hello, World!");
let cert_path = "/etc/letsencrypt/live/merivilla.com/fullchain.pem";
let key_path = "/home/ubuntu/new_certs/pkcs8.key";
warp::serve(routes)
.tls()
.cert(cert_path)
.key(key_path)
.run(([0, 0, 0, 0], 443))
.await;
I then tried:
warp::serve(routes)
.tls()
.cert_path(cert_path)
.key_path(key_path)
.run(([0, 0, 0, 0], 443))
.await;
and no error appeared, but when I went to look at my website using https, it stalled and it never said hello world.
To confirm that I can actually access my server, I did:
warp::serve(routes)
.run(([0, 0, 0, 0], 80))
.await;
and I could see hello world when I used http .
Originally, when I asked this question on stackoverflow, I just used the original key that certbot gave me. However, becaue of the error, someone recommended I type the command below to change my key to pkcs8 format:
openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt -in privkey.pem -out /home/ubuntu/new_certs/pkcs8.key
This resulted in the same error showing up.
I then tried to read the cert and private key into memory and pass it into .cert()
and .key()
:
let routes = warp::any().map(|| "Hello, World!");
// Load SSL keys and certs
let cert_path = "/etc/letsencrypt/live/merivilla.com/fullchain.pem";
let key_path = "/home/ubuntu/new_certs/pkcs8.key";
// Read the cert and private key file into memory
let cert_contents = std::fs::read(cert_path).expect("failed to read cert file");
let key_contents = std::fs::read(key_path).expect("Failed to read private key file");
warp::serve(routes)
.tls()
.cert(cert_contents)
.key(key_contents)
.run(([0, 0, 0, 0], 443))
.await;
and no runtime error, but the website would not load when I did https . Nor http of course.
I'm using Warp version 0.3.7