How dalof41014/ruipmi works
Project Type and Purpose
• ruipmi is an open-source Rust library (crate) that implements an asynchronous RMCP+ IPMI v2.0 client over UDP.
• It provides session handshake (Open Session + RAKP1–4), message encryption (AES-CBC-128), integrity (HMAC-SHA1/MD5/SHA256), and IPMB encapsulation.
• Consumers embed it in higher-level tooling to manage BMCs (baseboard management controllers) over the network.
File-Structure Analysis
• Top level:
• Cargo.toml / Cargo.lock: Rust build config and dependencies.
• README.md, LICENSE, .gitignore: project metadata.
• src/
– lib.rs: crate root, public API (IpmiClient, CipherSuite, etc.).
– ruipmi.rs: internal implementation (session builder, crypto, encode/decode).
• No binary or example folder in tree, but README references examples/demo.rs.
Key README Insights
• Dependencies: tokio (async UDP), aes, cbc, hmac, md-5, sha1, sha2, rand, thiserror, log.
• Core functions: build_open_session_request, build_rakp1/3, build_v2_encrypted_msg, decode_and_decrypt.
• Layers: RMCP header → RMCP+ session header → payload → integrity trailer.
• API: IpmiClient::new, connect, request, close, build_ipmb_send_message.
Main Components
a. Consumer Application
• e.g. examples/demo.rs or any management tool that calls IpmiClient API.
b. IpmiClient Library
• Session Manager: orchestrates RMCP+ handshake (OpenSession, RAKP1–4).
• Message Builder / Parser: constructs RMCP/RMCP+ headers, payload, trailers.
• Crypto Module: AES-CBC-128 encryption/decryption, HMAC-SHA*/MD5, key derivation (SIK, K1, K2).
• UDP Transport Layer: tokio::net::UdpSocket for send/receive.
c. External Service
• Remote BMC (IPMI server) over the LAN.
d. Third-party Dependencies
• tokio runtime, aes/cbc crates, hmac, md-5, sha1, sha2, rand, thiserror, log.
Relationships and Data Flow
1. Application calls IpmiClient::new() → instantiates Session Manager.
2. IpmiClient.connect():
• Session Manager → Message Builder → UDP Transport → BMC.
• BMC → UDP Transport → Session Manager → Crypto Module → parser.
3. Once session is open:
• Application → IpmiClient.request() → Message Builder → Crypto Module → UDP Transport → BMC.
• Responses flow back → UDP Transport → Crypto Module → Session Manager → Application.
4. IpmiClient.close() sends Close Session command via same path.
Architectural Patterns & Principles
• Modular layering: separation of concerns between session orchestration, message composition, cryptography, and I/O.
• Asynchronous, event-driven I/O using Tokio.
• Clean library boundary: public API (lib.rs) vs. implementation (ruipmi.rs).
• Dependency Injection: configurable CipherSuite.
• Error handling via thiserror.