This repository contains a simple implementation of a secure TCP client-server application in Rust. The communication between the client and the server is secured using SSL/TLS with public/private key configuration. The server sends data to the client in real-time, and the client prints this data as it is received.
- Asynchronous TCP communication using
tokio
. - SSL/TLS encryption using
native-tls
andtokio-native-tls
. - Public/private key authentication.
- Real-time data transmission from server to client.
- Rust (latest stable version)
- OpenSSL (for generating certificates)
To run the server and client, you need to generate the necessary certificates and keys. You can use OpenSSL to generate these files.
-
Generate a private key:
openssl genrsa -out key.pem 2048
-
Generate a certificate signing request (CSR):
openssl req -new -key key.pem -out cert.csr
-
Generate a self-signed certificate:
openssl x509 -req -days 365 -in cert.csr -signkey key.pem -out cert.pem
-
Convert the key and certificate to PKCS#12 format:
openssl pkcs12 -export -out identity.pfx -inkey key.pem -in cert.pem
Use
password
when prompted for an export password.
-
Navigate to the
server
directory:cd server
-
Ensure you have the required dependencies:
cargo build --release
-
Run the server:
cargo run --release
-
Navigate to the
client
directory:cd client
-
Ensure you have the required dependencies:
cargo build --release
-
Run the client:
cargo run --release
tls.rs
├── certs
│ ├── cert.csr
│ ├── cert.pem
│ ├── identity.pfx
│ └── key.pem
├── client
│ ├── Cargo.lock
│ ├── Cargo.toml
│ └── src
│ └── main.rs
├── README.md
└── server
├── Cargo.lock
├── Cargo.toml
└── src
└── main.rs
certs/
: Directory containing the certificate and key files.client/
: Directory containing the client implementation.Cargo.toml
: Client dependencies.src/main.rs
: Main client implementation.
server/
: Directory containing the server implementation.Cargo.toml
: Server dependencies.src/main.rs
: Main server implementation.
README.md
: This readme file.