X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fcoresessioneventprocessor.cpp;h=1e9bf050bc7bf680fe177de6d5586c8e30bc4819;hp=d0c75971921e38254d0a619faee82d4d666632e3;hb=4f2d0000935e5f040940aca85a44b905bd916147;hpb=3146ad01b5b29c30adcf0044a52b39aa7e5796d0 diff --git a/src/core/coresessioneventprocessor.cpp b/src/core/coresessioneventprocessor.cpp index d0c75971..1e9bf050 100644 --- a/src/core/coresessioneventprocessor.cpp +++ b/src/core/coresessioneventprocessor.cpp @@ -30,6 +30,10 @@ #include "netsplit.h" #include "quassel.h" +#ifdef HAVE_QCA2 +# include "keyevent.h" +#endif + CoreSessionEventProcessor::CoreSessionEventProcessor(CoreSession *session) : BasicHandler("handleCtcp", session), _coreSession(session) @@ -418,6 +422,42 @@ void CoreSessionEventProcessor::processIrcEventTopic(IrcEvent *e) } +#ifdef HAVE_QCA2 +void CoreSessionEventProcessor::processKeyEvent(KeyEvent *e) +{ + if (!Cipher::neededFeaturesAvailable()) { + emit newEvent(new MessageEvent(Message::Error, e->network(), tr("Unable to perform key exchange."), e->prefix(), e->target(), Message::None, e->timestamp())); + return; + } + CoreNetwork *net = qobject_cast(e->network()); + Cipher *c = net->cipher(e->target()); + if (!c) // happens when there is no CoreIrcChannel for the target (i.e. never?) + return; + + if (e->exchangeType() == KeyEvent::Init) { + QByteArray pubKey = c->parseInitKeyX(e->key()); + if (pubKey.isEmpty()) { + emit newEvent(new MessageEvent(Message::Error, e->network(), tr("Unable to parse the DH1080_INIT. Key exchange failed."), e->prefix(), e->target(), Message::None, e->timestamp())); + return; + } else { + net->setCipherKey(e->target(), c->key()); + emit newEvent(new MessageEvent(Message::Info, e->network(), tr("Your key is set and messages will be encrypted."), e->prefix(), e->target(), Message::None, e->timestamp())); + QList p; + p << net->serverEncode(e->target()) << net->serverEncode("DH1080_FINISH ")+pubKey; + net->putCmd("NOTICE", p); + } + } else { + if (c->parseFinishKeyX(e->key())) { + net->setCipherKey(e->target(), c->key()); + emit newEvent(new MessageEvent(Message::Info, e->network(), tr("Your key is set and messages will be encrypted."), e->prefix(), e->target(), Message::None, e->timestamp())); + } else { + emit newEvent(new MessageEvent(Message::Info, e->network(), tr("Failed to parse DH1080_FINISH. Key exchange failed."), e->prefix(), e->target(), Message::None, e->timestamp())); + } + } +} +#endif + + /* RPL_WELCOME */ void CoreSessionEventProcessor::processIrcEvent001(IrcEvent *e) {