Skip to content

optimumood/grpc-file-transfer-rust

Repository files navigation

grpc-file-transfer-rust

Status License


gRPC file sharing server and client with mTLS (mutual Transport Layer Security), which provides communications security over a computer network.

📜 Table of Contents

🤔 About

This project consists of gRPC server and client applications. Server and client are authenticated by mTLS (mutual Transport Layer Security) cryptographic protocol using server and client certificates. TLS encrypts data transfer between client and server so that external parties cannot spy on the communications.

Available features:

  • list available files on server
  • upload files to server
  • download files from server

🚀 Getting started

Read:

  • how to build and install binaries
  • how to run end-to-end tests and benchmarks
  • about project's automated workflow
  • about usage

🛒 Prerequisites

If you want to build and run applications or tests, you need to install:

🔨 Building binaries

debug mode

cargo make build

release mode

cargo make build-release

🔌 Installing binaries

server

cargo make install-server

client

cargo make install-client

✔️ Running end-to-end tests

cargo make e2e-tests

🐢 Running end-to-end benchmarks

cargo make e2e-bench

🚩 Automated workflow

This project has GitHub Actions workflow, which:

  • checks formatting
  • checks lints
  • checks if client and server binaries are building
  • runs end-to-end tests
  • runs end-to-end benchmarks

🖥️ Usage

First, install server and client applications using Installing binaries instruction.
Now, you can use applications.
Below are presented example commands.

  • Server help command
$ server --help
Usage: server [OPTIONS] --directory <DIRECTORY> --cert <CERT> --key <KEY> --ca-cert <CA_CERT>

Options:
  -d, --directory <DIRECTORY>
  -H, --address <ADDRESS>      [default: 127.0.0.1]
  -p, --port <PORT>
  -v, --verbose <VERBOSE>      [default: info]
      --cert <CERT>
      --key <KEY>
      --ca-cert <CA_CERT>
  -i, --insecure
  -h, --help                   Print help information
  -V, --version                Print version information
  • Client help command
$ client --help
Usage: client [OPTIONS] --port <PORT> --cert <CERT> --key <KEY> --ca-cert <CA_CERT> <COMMAND>

Commands:
  download
  upload
  list
  help      Print this message or the help of the given subcommand(s)

Options:
  -H, --address <ADDRESS>  [default: 127.0.0.1]
  -p, --port <PORT>
  -v, --verbose <VERBOSE>  [default: info]
      --cert <CERT>
      --key <KEY>
      --ca-cert <CA_CERT>
  -i, --insecure
  -h, --help               Print help information
  -V, --version            Print version information
  • Run server on IPv6 localhost address with 50051 port and /tmp/server path as server directory:

    • mTLS secured
    $ server --directory /tmp/server -p 50051 --address ::1 --cert secrets/server-cert.pem --key secrets/server-key.pem --ca-cert secrets/ca-cert.pem
    • insecure
    $ server --directory /tmp/server -p 50051 --address ::1 --insecure
  • List files command

    • mTLS secured
    $ client --port 50051 --address localhost --cert secrets/client-cert.pem --key secrets/client-key.pem --ca-cert secrets/ca-cert.pem list
    File name  Size
    abc        12B
    abc2       0B
    • insecure
    $ client --port 50051 --address localhost --insecure list
    File name  Size
    abc        12B
    abc2       0B

🔄 Diagrams

High level sequence diagrams

  • list files
sequenceDiagram
  actor User
  participant Client
  participant Server
  User ->> Client: list files
  Client ->> Server: gRPC ListFilesRequest
  loop over all files on server side
    Server ->> Client: gRPC ListFilesResponse
  end
  Client ->> User: print files list to stdout
  • download file
sequenceDiagram
  actor User
  participant Client
  participant Server
  User ->> Client: download file
  Client ->> Server: gRPC DownloadFileRequest
  loop read next file's data chunk
    Server ->> Client: gRPC DownloadFileResponse
    Client ->> Client: save file's data chunk on disk
  end
  Client -->> User:#nbsp;
  • upload file
sequenceDiagram
  actor User
  participant Client
  participant Server
  User ->> Client: upload file
  loop read next file's data chunk
    Client ->> Server: gRPC UploadFileRequest
    Server ->> Server: save file's chunk data on disk
  end
  Server ->> Client: gRPC UploadFileResponse
  Client -->> User:#nbsp;

🏗️ Technology stack

  • Rust - Programming language
  • Tonic - Asynchronous Rust implementation of gRPC
  • PROST! - Protocol Buffers implementation for the Rust Language
  • Tokio - Asynchronous runtime for Rust