Rust, Software Development

Secure Actix-Web Application With TLS

This post is about how to secure an Actix-web web application with TLS in Rust.

Requirements

These are items used for this post.

New Actix-Web Application

First, create a new project in Ubuntu using the following command. We are using Ubuntu because it has build tools related to TLS. Then, copy the 2 pem files to the project directory – please do not use these files in real environments. Actix-Web application uses these files with TLS to secure its communications with the clients.

Then, we update Cargo.toml to add some dependencies. We need to ssl feature of the Actix-Web crate.

Next, we update main.rs as follows. The application simply returns a list of country codes when users request for the /countries URI. However, the key lines related to TLS are lines 18-21.

Test Secure Actix-Web Application

For testing, we use Mozilla Firefox because it allows for accessing URLs with self-signed SSL certificates. First, build the application using cargo build command. Then, run it using cargo run command.

Next, access the URL https://localhost:8088/countries using a web browser.

This test is for demonstration purposes only.

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.


You Might Also Like