From 6c30e71ed08cdb838b77b3fe52dea30774574230 Mon Sep 17 00:00:00 2001 From: Osmium Sorcerer Date: Sun, 22 Mar 2026 18:16:52 +0000 Subject: Add the extension packets Introduce the subprotocol ("Einsof"), its prototype serialization and parsing functions, and its first set of messages. These messages are carriers of public-key authentication mechanism which involves client request, server challenge, and client response. An "ident" message is used to tell a compatible server that you support a particular version of the subprotocol. Note: the functions that handle encoding are very specialized. They're not representative of how the wire format should be generally handled, and were written this way because the first set of messages is tiny and simple enough. --- src/ext_packet.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/ext_packet.cpp (limited to 'src/ext_packet.cpp') diff --git a/src/ext_packet.cpp b/src/ext_packet.cpp new file mode 100644 index 0000000..76ac492 --- /dev/null +++ b/src/ext_packet.cpp @@ -0,0 +1,53 @@ +#include "ext_packet.h" + +extern "C" +{ +#include "vli.h" +} + +QByteArray serializeIdent(const Ident &m) +{ + QByteArray msg; + msg.reserve(3); + msg.append((char)ExMsgType::ident); + msg.append('\0'); + msg.append(m.version); + return msg; +} + +QByteArray serializeAuthRequest(const AuthRequest &m) +{ + QByteArray msg; + const QByteArray username = m.username.toUtf8(); + uint8_t method[sizeof(quint32) + 1]; + uint8_t ulen[sizeof(quint32) + 1]; + size_t method_n = vli32_encode(method, (quint32)m.method); + size_t ulen_n = vli32_encode(ulen, username.size()); + msg.reserve(2 + ulen_n + username.size() + method_n); + msg.append((char)ExMsgType::auth_request); + msg.append('\0'); + msg.append((const char *)ulen, ulen_n); + msg.append(username, username.size()); + msg.append((const char *)method, method_n); + return msg; +} + +QByteArray serializeAuthResponse(const AuthResponse &m) +{ + QByteArray msg; + msg.reserve(2 + m.response.size()); + msg.append((char)ExMsgType::auth_response); + msg.append('\0'); + msg.append(m.response); + return msg; +} + +bool parseAuthChallenge(QByteArrayView in, AuthChallenge &out) +{ + if (in.size() < 1 + 32) + { + return false; + } + out.challenge = QByteArray(in.constData() + 1, 32); + return true; +} -- cgit