00001 #ifndef SST_DH_H
00002 #define SST_DH_H
00003
00004 #include <QObject>
00005 #include <QHash>
00006
00007 #include <openssl/dh.h>
00008
00009 #include "timer.h"
00010
00011
00012 namespace SST {
00013
00014
00015 #define HOSTKEY_TIMEOUT (60*60) // Host key timeout in seconds - 1 hr
00016
00017 #define KEYGROUP_JFDH_1024 0x01
00018 #define KEYGROUP_JFDH_2048 0x02
00019 #define KEYGROUP_JFDH_3072 0x03
00020 #define KEYGROUP_JFDH_MAX 0x03
00021 #define KEYGROUP_JFDH_DEFAULT KEYGROUP_JFDH_1024
00022
00023 class Host;
00024
00025 class DHKey : public QObject
00026 {
00027 friend class DHHostState;
00028 friend class KeyInitiator;
00029 friend class KeyResponder;
00030
00031 Q_OBJECT
00032
00033 private:
00034 Host *const host;
00035 Timer exptimer;
00036
00037 quint8 dhgroup;
00038 DH *dh;
00039 QByteArray pubkey;
00040 quint8 hkr[256/8];
00041
00042
00043
00044 QHash<QByteArray, QByteArray> r2cache;
00045
00046
00047 public:
00048
00049 QByteArray calcKey(const QByteArray &otherPubKey);
00050
00051 private:
00052 DHKey(Host *host, quint8 dhgroup, DH *dh,
00053 int timeoutSecs = HOSTKEY_TIMEOUT);
00054
00055 private slots:
00056 void timeout();
00057 };
00058
00059
00060
00061 class DHHostState
00062 {
00063 friend class DHKey;
00064
00065 private:
00066 DHKey *dhkeys[KEYGROUP_JFDH_MAX];
00067
00068 DHKey *gen(quint8 dhgroup, DH *(*groupfunc)());
00069
00070 public:
00071 DHHostState();
00072 virtual ~DHHostState();
00073
00074 DHKey *getDHKey(quint8 dhgroup);
00075
00076 virtual Host *host() = 0;
00077 };
00078
00079
00080 QDataStream &operator<<(QDataStream &ds, DH *dh);
00081 QDataStream &operator>>(QDataStream &ds, DH *dh);
00082
00083
00084 }
00085
00086 #endif // SST_DH_H