sfifo
sfifo is a Rust library designed to manage FIFO (named pipe) files with advanced features including process authentication and deadlock prevention. It provides functionalities to create, open, and delete FIFO files, along with support for timeouts and file deletion notifications.Use blocking mode also will not cause deadlock.
Features
- Create and manage FIFO files with process authentication
- Secure inter-process communication using token-based handshake mechanism
- Open FIFO files with configurable options (read, write, blocking, non-blocking)
- Support for fifo operation timeouts and file deletion notifications
- Prevention of user mode deadlock through authenticated connections
- Three-way handshake protocol (Request → Response → Acknowledgment)
- Timestamp-based replay attack protection
- Process identification and authentication
Problem
How to rehandle the fifo one side is closed? remove this fifo file, and rehandle the fifo?
Installation
Add the following to your Cargo.toml:
[]
= { = "../path/to/sfifo" } # Replace with the actual path or version
Usage
Basic Example
Here's a basic example of how to create and open a FIFO file using sfifo.
use Sfifo;
use Duration;
async
Authenticated FIFO Communication
For secure inter-process communication with authentication:
Server Side
use Sfifo;
use AsyncWriteExt;
async
Client Side
use Sfifo;
use AsyncReadExt;
async
Security Features
- Token-based Authentication: Both processes must share the same secret token
- Timestamp Validation: Messages older than 30 seconds are rejected to prevent replay attacks
- Process Identification: Each handshake includes process ID and name for logging
- Three-way Handshake: Request → Response → Acknowledgment ensures both sides are authenticated
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contributing
Contributions are welcome! Please open an issue or submit a pull request if you have any improvements or bug fixes.
For more detailed information, please refer to the source code and documentation.