#pragma once // TeamSpeak client identity: an ECDSA P-256 keypair plus the libtomcrypt-style // public-key export ("omega"), the derived unique-id, and the hashcash // key-offset that raises the identity's "security level". // Ported from ts6-manager tslib/identity.ts. #include #include #include #include #include namespace Echoion::Protocol { class Identity { public: using Bytes = std::vector; using ByteView = std::span; // Generate a fresh identity and raise it to at least `securityLevel` // leading-zero bits (hashcash over the public key + offset). static Identity generate(int securityLevel = 8); // Load / save the identity to a small text file: // privateKeyPem, publicKeyString, keyOffset (one per line). static Identity load(const std::string& path); // Import an identity exported by the TeamSpeak client. The export is // an INI file containing its obfuscated "V" key. static Identity importTeamSpeakIni(const std::string& path); void save(const std::string& path) const; // libtomcrypt ASN.1 public key, base64 ("omega" in clientinitiv). const std::string& publicKeyString() const { return publicKeyString_; } // base64(sha1(ascii(publicKeyString))). const std::string& uid() const { return uid_; } uint64_t keyOffset() const { return keyOffset_; } int securityLevel() const; // ECDSA sign `data` with SHA-256; returns the raw signature. Bytes sign(ByteView data) const; // ECDH(this private key, server public key) → SHA-1 of the shared // x-coordinate. `serverPublicKeyDer` is the libtomcrypt DER blob // (base64-decoded "omega" from initivexpand). Bytes sharedSecret(ByteView serverPublicKeyDer) const; private: Identity() = default; struct PKeyDeleter { void operator()(void* p) const noexcept; }; // EVP_PKEY* held opaquely so this header stays OpenSSL-free. std::shared_ptr pkey_; std::string publicKeyString_; std::string uid_; uint64_t keyOffset_ = 0; }; } // namespace Echoion::Protocol