// SPDX-FileCopyrightText: 2026 Matvey Shcherbinin // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL // A TLS identity the LAN/VPN transport can trust the same way the handshake // used to be trusted. The KOutNet identity is an Ed25519 keypair that // libsodium has no X.509 story for, and QSslKey does not speak Ed25519, so the // TLS identity is a P-256 self-signed certificate deterministically derived // from the identity seed: same seed, same public key, forever. What gets // pinned and compared for TOFU is a digest of that public key, not of the // certificate bytes - the signature over a time-based body changes every // process (ECDSA is only statistically deterministic), the key does not. #pragma once #include #include #include #include namespace koutnet { // Everything a TLS peer needs to present itself, plus the identity it speaks // for. keyDer outlives key: QSslKey still references the bytes it was built // from on some backends, so the two travel together. struct IdentityCertificate { QString identityId; // the peer's address in the app's key model (CN) QSslCertificate cert; QByteArray keyDer; // PKCS8 DER QSslKey key; bool isValid() const { return !cert.isNull() && !key.isNull(); } }; // Deterministic P-256 keypair + self-signed certificate from a 32-byte seed // (CryptoManager's identity seed, the first 32 bytes of the Ed25519 secret // key). Returns an invalid IdentityCertificate when the seed cannot form a // valid P-256 scalar. IdentityCertificate buildIdentityCertificate(const QByteArray &seed32, const QString &identityId); // SHA-256 of the certificate's public key (SPKI DER). This is the value TOFU // pins store and compare: it is stable for a given identity across every // restart, independence from the certificate's validity window. QByteArray identityFingerprint(const QSslCertificate &cert); } // namespace koutnet