diff options
| author | Osmium Sorcerer <os@sof.beauty> | 2026-03-22 18:16:52 +0000 |
|---|---|---|
| committer | Osmium Sorcerer <os@sof.beauty> | 2026-03-29 22:22:25 +0000 |
| commit | 6c30e71ed08cdb838b77b3fe52dea30774574230 (patch) | |
| tree | 9620ee98a417f82f29c7ae101de0b021720c3612 /src/ext_packet.cpp | |
| parent | ade040cfa6c402bb336e7772de5e675549ded18e (diff) | |
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.
Diffstat (limited to 'src/ext_packet.cpp')
| -rw-r--r-- | src/ext_packet.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
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; +} |
