This class library may be used for secure, authenticated network communication over TCP. The main three classes are Dwm::Credence::Peer, Dwm::Credence::KeyStash and Dwm::Credence::KnownKeys. Utilizing just these three classes, it is relatively easy to create secure TCP applications.
The library depends on libsodium, boost::asio and libDwm.
Since I'm using libsodium, I'm using XChaCha20Poly1305 for encryption. User and server authentication uses signatures produced and validated with Ed25519 keys.
No passwords are used, only key files (which aren't password protected). This is intentional since my main usage is in applications that are not launched interactively. I may later add password protected keys.
The Peer class encapsulates a connection, via TCP or a UNIX domain socket. It is the main interface through which connections are initiated (via the Connect() member), accepted (via the Accept() member), and authenticated (via the Authenticate() member). It is also the interface through which messages are sent (via the Send() member) and received (via the Receive() member).
A client utilizes the Connect() member to connect to a server. A server accepts incoming connections via the Accept() member. As part of the connection setup, a shared encryption key is derived by each side. This key is ephemeral (only used for this connection), and used to encrypt all future traffic between the peers.
The Authenticate() member of the Peer class performs mutual authentication. It verifies the claimed identity of the remote service and provides verifiable evidence of the identity of the local application to the remote service. It returns true if authentication succeeds, false if it fails.
Messages are exchanged using the Send() and Receive() members of the Peer class. These are member function templates, and use Dwm::StreamIO functionality from libDwm to allow sending and receiving all types supported directly by libDwm as well as all types which implement the requirements of the Dwm::HasStreamRead and Dwm::HasStreamWrite concepts.
This library came about when I needed a replacement for Crypto++ (needed by libDwmAuth). In my own applications, libDwmAuth was replaced by libDwmCredence. The new name is a hint that it's not the same as libDwmAuth under the hood, and allowed me to migrate my applications as I had time.
I only maintain support for 4 platforms: FreeBSD, macOS, desktop linux and Raspbian (now Raspberry Pi OS). FreeBSD is my operating system of choice for servers and macOS is my operating system of choice for desktops and laptops. I have several Raspberry Pis I utilize for various tasks, and Ubuntu VMs and Ubuntu workstations.
The examples assume that you have created your key files by running credence keygen, and that they are present in the default directory (~/.credence). They also assume that you have your own public key (from ~/.credence/id_ed25519.pub) in the default ~/.credence/known_keys file.
Note that this server only accepts one client, and will exit after communicating with the client. In other words, it's not typical, but instead is a minimal illustration.