Actix-web OpenSSL SSL/HTTPS for Localhost, is it possible please?

Hi,

I have followed this post successfully: How to Get SSL/HTTPS for Localhost.

Basically we use OpenSSL to generate keys and a self signed certificate, so that we can test localhost via HTTPS.

This nodejs is from the above tutorial. I ran it on my Ubuntu machine:

const fs = require('fs')
const key = fs.readFileSync('./cert/localhost.decrypted.key')
const cert = fs.readFileSync('./cert/localhost.crt')

const express = require('express')
const app = express()

app.get('/', (req, res, next) => {
  res.status(200).send('Hello world!')

And from my Windows 10 Pro machine, I am able to access https://192.168.0.16:5000.

Where 192.168.0.16 is the IP address of the Ubuntu machine.

  • Firefox responds with Hello world! no warning.

  • Chrome, Edge, Opera, Brave and Vivaldi respond with Hello world! but with Not secure warning.

Please help me with the following question. Can we write an actix-web equivalence of the above NodeJs script, please?

-- That is, we would use the same localhost.decrypted.key and localhost.crt files.

Please note, I am not asking for the code. I would just like a confirmation that we can, or can not.

Thank you and best regards,

...behai.

Yes, Actix supports HTTPS. You can find an example that uses OpenSSL here.

2 Likes

Hi jofas,

Thank you for your help once again. I am able to follow the example successfully.

I would just like to mention that, if we change the binding to:

    .bind_openssl("0.0.0.0:5000", builder)?

Then we are able to access it as https://192.168.0.16:5000 where 192.168.0.16 is the address of the machine which the server is running on.

Also, I used:

openssl req -x509 -newkey rsa:4096 -keyout key-pass.pem -out cert-pass.pem -sha256 -days 365

to generate the files on Ubuntu 22.10.

I also copied key-pass.pem and cert-pass.pem to Windows 10 Pro. The example server also works with these two files on Windows 10 Pro.

That is, https://localhost:5000 also works.

Best regards,

...behai.

1 Like

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.