Implementing HTTPS server using Rustls with Hyper

Hi,

I am trying to implement implement HTTPS server using Rustls with Hyper, but am not able to get proper example of how to implement the same. And for that i have followed and tried example given on hyper-rustls repository here (Hyper Rustls server example)

It always gives this error
FAILED: error accepting connection: TLS Error: Custom { kind: InvalidData, error: AlertReceived(CertificateUnknown) }

I am completely new to Rust and hence don't know how to properly implement the HTTPS over Hyper. I also gone through question related to this here

But still not able to find the solution. If more information is required do let me know for the same.

It sounds like there was some sort of certificate failure. Are you using a self-signed certificate?

1 Like

I am using same certificate in the Rustls examples here

Are you also using the client from that example? That server will not work with any other client, because of that self-signed certificate.

If you want a server that works with regular HTTPS clients (browsers, etc.) you can't use anyone else's certificate. You must obtain your own real certificate for your own real domain (e.g. from Let'sEncrypt), and run that server at that domain.

1 Like

As you said, I used the client example provided. it worked perfectly. Hence the error was finally with the SSL only. Actually I tried my real certificate and key also but it was not working, it was not returning any private key in the code. Then I found that the problem was with rsa_private_keys() function of rustls as it only works on RSA private keys. Instead I used pkcs8_private_keys() from rustls as my key was beginning with "-----BEGIN PRIVATE KEY-----" instead of "-----BEGIN RSA PRIVATE KEY-----" and, amazing that was the real problem that I was facing. Now it worked just perfectly with my real SSL certificate and thus the HTTPS works perfectly. Many thanks for you helps.

1 Like