From 15253d1995ea49b114ef5c627e15b661dbd602b2 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Sun, 30 Sep 2012 19:41:17 +0200 Subject: add some trivial authentication --- distfoldd/agent.h | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'distfoldd/agent.h') diff --git a/distfoldd/agent.h b/distfoldd/agent.h index fa202f5..0d25077 100644 --- a/distfoldd/agent.h +++ b/distfoldd/agent.h @@ -3,6 +3,7 @@ #include #include +#include #include #include "compressor.h" @@ -22,7 +23,7 @@ public: Q_DECLARE_FLAGS(SyncFlags, SyncFlag) public: - explicit Agent(QSslSocket *socket, const QDir& dir, SyncFlags flags, QObject *parent = 0); + explicit Agent(QSslSocket *socket, const QDir& dir, const QString& passwd, SyncFlags flags, QObject *parent = 0); static const uint servicePort = 17451; @@ -33,14 +34,16 @@ protected: #pragma pack(push) #pragma pack(1) enum MessageType { - MSG_HELLO = 0, - MSG_HELLO_REPLY, + MSG_HELLO = 0, //args: uint32 (proto_version) + string (client challenge) + MSG_HELLO_REPLY, //args: string (server challenge) + MSG_AUTH, //args: string (challenge response) + MSG_AUTH_REPLY, // args: uint8 (AuthResult) MSG_SET_SUBROOT, //args: string MSG_FILE_LIST, //args: FileListItem[] MSG_FILE_ACTIONS_REPLY, //args: ActionItem[] MSG_PULL_FILE, //args: string - MSG_PULL_FILE_REPLY, //args: data - MSG_PUSH_FILE, //args: FileNameItem + data + MSG_PULL_FILE_REPLY, //args: file data + MSG_PUSH_FILE, //args: FileNameItem + file data MSG_PUSH_FILE_METADATA, //args: FileListItem[] MSG_DELETE_FILE, //args: string MSG_BYE @@ -49,6 +52,16 @@ protected: quint32 msg; quint32 len; }; + enum ProtoVersion { + PROTO_BAD = -1, + PROTO_0 = 0, + PROTO_1 = 1, + PROTO_CURRENT = PROTO_1 + }; + enum AuthResult { + AUTH_OK = 0, + AUTH_FAILED + }; enum FileType { FILE_TYPE_NONE = 0, FILE_TYPE_FILE, @@ -169,6 +182,16 @@ protected: static bool lessPathDepthThan(const QString& s1, const QString& s2); static bool morePathDepthThan(const QString& s1, const QString& s2); + QByteArray encodeHelloMessage(const QByteArray& client_challenge); + ProtoVersion decodeHelloMessage(const QByteArray& ba, QByteArray* client_challenge); + + static QByteArray hmacSha1(const QByteArray& key, const QByteArray& message); + QByteArray generateChallenge(); + QByteArray generateChallengeResponse(const QByteArray& server_challenge, const QByteArray& client_challenge); + + QByteArray encodeAuthReply(AuthResult result); + AuthResult decodeAuthReply(const QByteArray& ba); + static QFileInfoList scanFiles(const QDir& dir); QByteArray encodeFileInfoList(const QFileInfoList& list); RemoteFileInfoList decodeFileInfoList(const QByteArray& ba); @@ -187,6 +210,7 @@ protected: protected: QDir _dir; QString _subPath; + QString _passwd; SyncFlags _flags; QSslSocket *_socket; QByteArray _inBuf; -- cgit v1.2.3