diff options
author | Javier S. Pedro <maemo@javispedro.com> | 2012-09-30 19:41:17 +0200 |
---|---|---|
committer | Javier S. Pedro <maemo@javispedro.com> | 2012-09-30 19:41:17 +0200 |
commit | 15253d1995ea49b114ef5c627e15b661dbd602b2 (patch) | |
tree | 1111441406a0b043f45ab19fe42e567be36d4d09 /distfoldd/agent.h | |
parent | c8f89279026af6bb03ef3d66e44e859fb7208925 (diff) | |
download | distfold-15253d1995ea49b114ef5c627e15b661dbd602b2.tar.gz distfold-15253d1995ea49b114ef5c627e15b661dbd602b2.zip |
add some trivial authentication
Diffstat (limited to 'distfoldd/agent.h')
-rw-r--r-- | distfoldd/agent.h | 34 |
1 files changed, 29 insertions, 5 deletions
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 <QtCore/QDateTime> #include <QtCore/QDir> +#include <QtCore/QCryptographicHash> #include <QtNetwork/QSslSocket> #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; |