commit
38e86d4a07
23 files changed
+3219
No files matched your search
@@ -0,0 +1,62 @@
|
||||
#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 <cstdint>
|
||||
#include <memory>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Echoion::Protocol
|
||||
{
|
||||
|
||||
class Identity
|
||||
{
|
||||
public:
|
||||
|
||||
using Bytes = std::vector<uint8_t>;
|
||||
using ByteView = std::span<const uint8_t>;
|
||||
|
||||
// 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);
|
||||
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<void> pkey_;
|
||||
std::string publicKeyString_;
|
||||
std::string uid_;
|
||||
uint64_t keyOffset_ = 0;
|
||||
};
|
||||
|
||||
} // namespace Echoion::Protocol
|
||||
Reference in new issue
Block a user