[SCM] ktp-auth-handler packaging branch, master, updated. debian/15.12.1-2-282-g080758e

Maximiliano Curia maxy at moszumanska.debian.org
Fri May 27 23:58:14 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-auth-handler.git;a=commitdiff;h=96adc2f

The following commit has been merged in the master branch:
commit 96adc2fc5c7352a7d5d806d904723255d8eb9253
Author: Andre Moreira Magalhaes (andrunko) <andre.magalhaes at collabora.co.uk>
Date:   Sat Sep 17 14:10:06 2011 +0100

    Refactor
    Start TLS Auth
---
 CMakeLists.txt                                     |  23 +--
 KDE.AuthHandler.client                             |   2 +-
 handler-auth.cpp                                   | 152 -------------------
 main.cpp                                           |  48 +++---
 ...op.Telepathy.Client.KDE.SASL.Handler.service.in |   2 +-
 ...top.Telepathy.Client.KDE.TLS.Handler.service.in |   2 +-
 password-prompt.cpp                                |  28 +++-
 password-prompt.h                                  |  23 ++-
 sasl-auth-op.cpp                                   | 161 +++++++++++++++++++++
 handler-auth.h => sasl-auth-op.h                   |  34 +++--
 sasl-channel.cpp                                   |  34 -----
 sasl-channel.h                                     |  32 ----
 handler.cpp => sasl-handler.cpp                    |  50 ++++---
 handler.h => sasl-handler.h                        |  23 +--
 tls-cert-verifier-op.cpp                           |  73 ++++++++++
 handler-auth.h => tls-cert-verifier-op.h           |  38 +++--
 handler.cpp => tls-handler.cpp                     |  57 ++++----
 handler.h => tls-handler.h                         |  21 ++-
 types.cpp                                          |  14 ++
 types.h                                            |  14 ++
 20 files changed, 474 insertions(+), 357 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7469589..3f22e91 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -19,14 +19,14 @@ include_directories (${KDE4_INCLUDES}
                      ${TELEPATHY_QT4_INCLUDE_DIR}
 )
 
-
 set(telepathy_kde_auth_handler_SRCS
     main.cpp
-    handler.cpp
-    handler-auth.cpp
-    sasl-channel.cpp
-    password-prompt.cpp)
-
+    password-prompt.cpp
+    sasl-handler.cpp
+    sasl-auth-op.cpp
+    tls-cert-verifier-op.cpp
+    tls-handler.cpp
+    types.cpp)
 
 kde4_add_ui_files(telepathy_kde_auth_handler_SRCS password-prompt.ui)
 kde4_add_executable(telepathy-kde-auth-handler ${telepathy_kde_auth_handler_SRCS})
@@ -41,10 +41,15 @@ target_link_libraries(telepathy-kde-auth-handler
     ${KDE4_KDEUI_LIBS}
 )
 
-configure_file(org.freedesktop.Telepathy.Client.KDE.AuthHandler.service.in
-               ${CMAKE_CURRENT_BINARY_DIR}/org.freedesktop.Telepathy.Client.KDE.AuthHandler.service)
+configure_file(org.freedesktop.Telepathy.Client.KDE.SASL.Handler.service.in
+               ${CMAKE_CURRENT_BINARY_DIR}/org.freedesktop.Telepathy.Client.KDE.SASL.Handler.service)
+configure_file(org.freedesktop.Telepathy.Client.KDE.TLS.Handler.service.in
+               ${CMAKE_CURRENT_BINARY_DIR}/org.freedesktop.Telepathy.Client.KDE.TLS.Handler.service)
+
 
 install(TARGETS telepathy-kde-auth-handler ${INSTALL_TARGETS_DEFAULT_ARGS})
-install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.freedesktop.Telepathy.Client.KDE.AuthHandler.service
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.freedesktop.Telepathy.Client.KDE.SASL.Handler.service
+        DESTINATION ${DBUS_SERVICES_INSTALL_DIR})
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.freedesktop.Telepathy.Client.KDE.TLS.Handler.service
         DESTINATION ${DBUS_SERVICES_INSTALL_DIR})
 install(FILES KDE.AuthHandler.client DESTINATION ${SHARE_INSTALL_PREFIX}/telepathy/clients/)
diff --git a/KDE.AuthHandler.client b/KDE.AuthHandler.client
index ec7a31a..fca9c62 100644
--- a/KDE.AuthHandler.client
+++ b/KDE.AuthHandler.client
@@ -4,5 +4,5 @@ Interfaces=org.freedesktop.Telepathy.Client.Handler
 [org.freedesktop.Telepathy.Client.Handler.HandlerChannelFilter 0]
 org.freedesktop.Telepathy.Channel.ChannelType s=org.freedesktop.Telepathy.Channel.Type.ServerAuthentication
 org.freedesktop.Telepathy.Channel.TargetHandleType u=0
-org.freedesktop.Telepathy.Channel.Requested b=false 
+org.freedesktop.Telepathy.Channel.Requested b=false
 org.freedesktop.Telepathy.Channel.Type.ServerAuthentication.AuthenticationMethod s=org.freedesktop.Telepathy.Channel.Interface.SASLAuthentication
diff --git a/handler-auth.cpp b/handler-auth.cpp
deleted file mode 100644
index 2e4c9b6..0000000
--- a/handler-auth.cpp
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * This file is part of TelepathyQt4
- *
- * Copyright (C) 2011 Collabora Ltd. <http://www.collabora.co.uk/>
- * Copyright (C) David Edmundson <kde at davidedmundson.co.uk>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- */
-
-#include "handler-auth.h"
-
-#include <TelepathyQt4/PendingVariant>
-
-#include <KDebug>
-
-#include "password-prompt.h"
-
-HandlerAuth::HandlerAuth(const Tp::AccountPtr &account,
-    const Tp::ConnectionPtr &connection,
-    const Tp::ChannelPtr &channel)
-    : Tp::PendingOperation(channel),
-      m_account(account),
-      m_connection(connection),
-      m_channel(new SaslChannel(channel))
-{
-    m_wallet = KWallet::Wallet::openWallet(KWallet::Wallet::NetworkWallet(),
-                                  0,
-                                  KWallet::Wallet::Asynchronous);
-
-
-    Tp::Client::ChannelInterfaceSASLAuthenticationInterface *saslIface =
-        channel->interface<Tp::Client::ChannelInterfaceSASLAuthenticationInterface>();
-    connect(saslIface,
-            SIGNAL(SASLStatusChanged(uint,QString,QVariantMap)),
-            SLOT(onSASLStatusChanged(uint,QString,QVariantMap)));
-    connect(saslIface->requestPropertyAvailableMechanisms(),
-            SIGNAL(finished(Tp::PendingOperation*)),
-            SLOT(gotAvailableSASLMechanisms(Tp::PendingOperation*)));
-}
-
-HandlerAuth::~HandlerAuth()
-{
-}
-
-void HandlerAuth::gotAvailableSASLMechanisms(Tp::PendingOperation *op)
-{
-    if (op->isError()) {
-        kWarning() << "Unable to retrieve available SASL mechanisms";
-        setFinishedWithError(op->errorName(), op->errorMessage());
-        return;
-    }
-
-    Tp::PendingVariant *pv = qobject_cast<Tp::PendingVariant*>(op);
-    QStringList mechanisms = qdbus_cast<QStringList>(pv->result());
-    if (!mechanisms.contains(QLatin1String("X-TELEPATHY-PASSWORD"))) {
-        setFinishedWithError(TP_QT4_ERROR_NOT_IMPLEMENTED,
-                QLatin1String("X-TELEPATHY-PASSWORD is the only supported SASL mechanisms"));
-        return;
-    }
-
-    promptUser(true);
-}
-
-void HandlerAuth::onSASLStatusChanged(uint status, const QString &reason,
-        const QVariantMap &details)
-{
-    if (status == Tp::SASLStatusServerSucceeded) {
-
-        m_channel->acceptSasl();
-        kDebug() << "Authentication handshake";
-    } else if (status == Tp::SASLStatusSucceeded) {
-        kDebug() << "Authentication succeeded";
-        setFinished();
-    } else if (status == Tp::SASLStatusInProgress) {
-        kDebug() << "Authenticating...";
-    } else if (status == Tp::SASLStatusServerFailed) {
-        kDebug() << "Error authenticating - reason:" << reason << "- details:" << details;
-
-        //FIXME add - if can retry.
-        promptUser(false);
-    }
-}
-
-void HandlerAuth::promptUser(bool isFirstRun)
-{
-    //if we have a password
-
-    kDebug() << "trying to load from wallet";
-    if (m_wallet->hasFolder("telepathy") && isFirstRun) {
-        m_wallet->setFolder("telepathy");
-
-        QString password;
-        kDebug() << "has telepathy folder";
-
-        if (m_wallet->hasEntry(m_account->uniqueIdentifier())) {
-            kDebug() << "has entry";
-
-            int returnValue = m_wallet->readPassword(m_account->uniqueIdentifier(), password);
-            if (returnValue == 0) {
-                kDebug() << "using saved password";
-                m_channel->startMechanismWithData(QLatin1String("X-TELEPATHY-PASSWORD"),
-                                                  password.toUtf8());
-                return;
-            }
-            else {
-                kDebug() << "Error reading wallet entry";
-            }
-        }
-    }
-
-    //otherwise prompt the user
-
-    PasswordPrompt dialog(m_account);
-
-    if (dialog.exec() == QDialog::Rejected) {
-        kDebug() << "Authentication canceled";
-        m_channel->close();
-        return;
-    }
-
-    kDebug() << "Starting authentication...";
-
-    m_channel->startMechanismWithData(QLatin1String("X-TELEPATHY-PASSWORD"),
-            dialog.password().toUtf8());
-
-    //save password in kwallet...
-    if (dialog.savePassword()) {
-        kDebug() << "Saving password";
-        if (!m_wallet->hasFolder("telepathy-kde")) {
-            m_wallet->createFolder("telepathy-kde");
-        }
-        m_wallet->setFolder("telepathy-kde");
-        m_wallet->writePassword(m_account->uniqueIdentifier(), dialog.password());
-    }
-}
-
-
-
-
-#include "handler-auth.moc"
diff --git a/main.cpp b/main.cpp
index 3798334..131af12 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,7 +1,6 @@
 /*
- * This file is part of TelepathyQt4
- *
  * Copyright (C) 2011 Collabora Ltd. <http://www.collabora.co.uk/>
+ *   @author Andre Moreira Magalhaes <andre.magalhaes at collabora.co.uk>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -32,18 +31,21 @@
 #include <TelepathyQt4/Debug>
 #include <TelepathyQt4/Types>
 
-#include "handler.h"
+#include "sasl-handler.h"
+#include "tls-handler.h"
+
+// FIXME: Move this to tp-qt4 itself
+#include "types.h"
 
 int main(int argc, char *argv[])
 {
     KAboutData aboutData("telepathy-kde-auth-handler",
                          0,
-                         ki18n("Telepathy File Auth Handler"),
+                         ki18n("Telepathy Authentication Handler"),
                          "0.1");
     aboutData.addAuthor(ki18n("David Edmundson"), ki18n("Developer"), "kde at davidedmundson.co.uk");
     aboutData.setProductName("telepathy/auth-handler");
 
-
     // Add --debug commandline options
     KCmdLineOptions options;
     options.add("debug", ki18n("Show Telepathy debugging information"));
@@ -54,24 +56,13 @@ int main(int argc, char *argv[])
     app.setQuitOnLastWindowClosed(false);
 
     Tp::registerTypes();
+    // FIXME: Move this to tp-qt4 itself
+    registerTypes();
     Tp::enableDebug(KCmdLineArgs::parsedArgs()->isSet("debug"));
     Tp::enableWarnings(true);
 
-    Tp::ChannelClassSpecList channelSpecList;
-
-    QVariantMap otherProperties;
-    otherProperties.insert(
-            QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_SERVER_AUTHENTICATION ".AuthenticationMethod"),
-            TP_QT4_IFACE_CHANNEL_INTERFACE_SASL_AUTHENTICATION);
-    channelSpecList.append(Tp::ChannelClassSpec(TP_QT4_IFACE_CHANNEL_TYPE_SERVER_AUTHENTICATION,
-                Tp::HandleTypeNone, false, otherProperties));
-
-    // create the channel approver
-    Handler handler(channelSpecList);
-
     Tp::AccountFactoryPtr accountFactory = Tp::AccountFactory::create(
-            QDBusConnection::sessionBus(),
-                Tp::Features() << Tp::Account::FeatureCore << Tp::Account::FeatureProfile);
+            QDBusConnection::sessionBus(), Tp::Account::FeatureCore);
     Tp::ConnectionFactoryPtr connectionFactory = Tp::ConnectionFactory::create(
             QDBusConnection::sessionBus(), Tp::Connection::FeatureCore);
     Tp::ChannelFactoryPtr channelFactory = Tp::ChannelFactory::create(
@@ -80,8 +71,25 @@ int main(int argc, char *argv[])
     Tp::ClientRegistrarPtr clientRegistrar = Tp::ClientRegistrar::create(
             accountFactory, connectionFactory, channelFactory);
 
+    Tp::ChannelClassSpecList saslFilter;
+    QVariantMap saslOtherProperties;
+    saslOtherProperties.insert(
+            QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_SERVER_AUTHENTICATION ".AuthenticationMethod"),
+            TP_QT4_IFACE_CHANNEL_INTERFACE_SASL_AUTHENTICATION);
+    saslFilter.append(Tp::ChannelClassSpec(TP_QT4_IFACE_CHANNEL_TYPE_SERVER_AUTHENTICATION,
+                Tp::HandleTypeNone, false, saslOtherProperties));
+    SaslHandler saslHandler(saslFilter);
+    if (!clientRegistrar->registerClient(
+                Tp::AbstractClientPtr(&saslHandler), QLatin1String("KDE.SASL.Handler"))) {
+        return 1;
+    }
+
+    Tp::ChannelClassSpecList tlsFilter;
+    tlsFilter.append(Tp::ChannelClassSpec(TP_QT4_IFACE_CHANNEL_TYPE_SERVER_TLS_CONNECTION,
+                Tp::HandleTypeNone, false));
+    TlsHandler tlsHandler(tlsFilter);
     if (!clientRegistrar->registerClient(
-                Tp::AbstractClientPtr(&handler), QLatin1String("KDE.AuthHanlder"))) {
+                Tp::AbstractClientPtr(&tlsHandler), QLatin1String("KDE.TLS.Handler"))) {
         return 1;
     }
 
diff --git a/org.freedesktop.Telepathy.Client.KDE.AuthHandler.service.in b/org.freedesktop.Telepathy.Client.KDE.SASL.Handler.service.in
similarity index 57%
copy from org.freedesktop.Telepathy.Client.KDE.AuthHandler.service.in
copy to org.freedesktop.Telepathy.Client.KDE.SASL.Handler.service.in
index ab24b91..7e0478a 100644
--- a/org.freedesktop.Telepathy.Client.KDE.AuthHandler.service.in
+++ b/org.freedesktop.Telepathy.Client.KDE.SASL.Handler.service.in
@@ -1,3 +1,3 @@
 [D-BUS Service]
-Name=org.freedesktop.Telepathy.Client.KDE.AuthHandler
+Name=org.freedesktop.Telepathy.Client.KDE.SASL.Handler
 Exec=@CMAKE_INSTALL_PREFIX@/bin/telepathy-kde-auth-handler
diff --git a/org.freedesktop.Telepathy.Client.KDE.AuthHandler.service.in b/org.freedesktop.Telepathy.Client.KDE.TLS.Handler.service.in
similarity index 58%
rename from org.freedesktop.Telepathy.Client.KDE.AuthHandler.service.in
rename to org.freedesktop.Telepathy.Client.KDE.TLS.Handler.service.in
index ab24b91..2f9b7cb 100644
--- a/org.freedesktop.Telepathy.Client.KDE.AuthHandler.service.in
+++ b/org.freedesktop.Telepathy.Client.KDE.TLS.Handler.service.in
@@ -1,3 +1,3 @@
 [D-BUS Service]
-Name=org.freedesktop.Telepathy.Client.KDE.AuthHandler
+Name=org.freedesktop.Telepathy.Client.KDE.TLS.Handler
 Exec=@CMAKE_INSTALL_PREFIX@/bin/telepathy-kde-auth-handler
diff --git a/password-prompt.cpp b/password-prompt.cpp
index 8dd6596..36ab1d6 100644
--- a/password-prompt.cpp
+++ b/password-prompt.cpp
@@ -1,29 +1,43 @@
+/*
+ * Copyright (C) 2011 David Edmundson <kde at davidedmundson.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
 #include "password-prompt.h"
 #include "ui_password-prompt.h"
 
 #include <KIcon>
 #include <KDebug>
 
-PasswordPrompt::PasswordPrompt(const Tp::AccountPtr &account, QWidget *parent) :
-    KDialog(parent),
-    ui(new Ui::PasswordPrompt)
+PasswordPrompt::PasswordPrompt(const Tp::AccountPtr &account, QWidget *parent)
+    : KDialog(parent),
+      ui(new Ui::PasswordPrompt)
 {
     ui->setupUi(mainWidget());
 
-//    setWindowTitle(ki18n("Password Required"));
     setWindowIcon(KIcon("telepathy-kde"));
 
     ui->accountName->setText(account->displayName());
     ui->accountIcon->setPixmap(KIcon("dialog-password").pixmap(60,60));
     ui->title->setPixmap(KIcon(account->iconName()).pixmap(22,22));
-
-    //dialog-password
 }
 
 PasswordPrompt::~PasswordPrompt()
 {
     delete ui;
-    kDebug() << "I've been deleted";
 }
 
 QString PasswordPrompt::password() const
diff --git a/password-prompt.h b/password-prompt.h
index e54cb87..3945fb4 100644
--- a/password-prompt.h
+++ b/password-prompt.h
@@ -1,3 +1,21 @@
+/*
+ * Copyright (C) 2011 David Edmundson <kde at davidedmundson.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
 #ifndef PASSWORDPROMPT_H
 #define PASSWORDPROMPT_H
 
@@ -5,7 +23,8 @@
 
 #include <TelepathyQt4/Account>
 
-namespace Ui {
+namespace Ui
+{
     class PasswordPrompt;
 }
 
@@ -17,8 +36,6 @@ public:
     explicit PasswordPrompt(const Tp::AccountPtr &account, QWidget *parent = 0);
     ~PasswordPrompt();
 
-    void setDefaultPassword() const;
-
     QString password() const;
     bool savePassword() const;
 
diff --git a/sasl-auth-op.cpp b/sasl-auth-op.cpp
new file mode 100644
index 0000000..b12fd0a
--- /dev/null
+++ b/sasl-auth-op.cpp
@@ -0,0 +1,161 @@
+/*
+ * Copyright (C) 2011 Collabora Ltd. <http://www.collabora.co.uk/>
+ *   @author Andre Moreira Magalhaes <andre.magalhaes at collabora.co.uk>
+ * Copyright (C) 2011 David Edmundson <kde at davidedmundson.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "sasl-auth-op.h"
+
+#include <TelepathyQt4/PendingVariantMap>
+
+#include <KDebug>
+
+#include "password-prompt.h"
+
+SaslAuthOp::SaslAuthOp(const Tp::AccountPtr &account,
+        const Tp::ConnectionPtr &connection,
+        const Tp::ChannelPtr &channel,
+        KWallet::Wallet *wallet)
+    : Tp::PendingOperation(channel),
+      m_account(account),
+      m_connection(connection),
+      m_channel(channel),
+      m_saslIface(channel->interface<Tp::Client::ChannelInterfaceSASLAuthenticationInterface>()),
+      m_wallet(wallet),
+      m_canTryAgain(false)
+{
+    connect(m_saslIface->requestAllProperties(),
+            SIGNAL(finished(Tp::PendingOperation*)),
+            SLOT(gotProperties(Tp::PendingOperation*)));
+}
+
+SaslAuthOp::~SaslAuthOp()
+{
+}
+
+void SaslAuthOp::gotProperties(Tp::PendingOperation *op)
+{
+    if (op->isError()) {
+        kWarning() << "Unable to retrieve available SASL mechanisms";
+        m_channel->requestClose();
+        setFinishedWithError(op->errorName(), op->errorMessage());
+        return;
+    }
+
+    Tp::PendingVariantMap *pvm = qobject_cast<Tp::PendingVariantMap*>(op);
+    QVariantMap props = qdbus_cast<QVariantMap>(pvm->result());
+    m_canTryAgain = qdbus_cast<bool>(props.value("CanTryAgain"));
+    QStringList mechanisms = qdbus_cast<QStringList>(props.value("AvailableMechanisms"));
+    if (!mechanisms.contains(QLatin1String("X-TELEPATHY-PASSWORD"))) {
+        kWarning() << "X-TELEPATHY-PASSWORD is the only supported SASL mechanism and "
+            "is not available";
+        m_channel->requestClose();
+        setFinishedWithError(TP_QT4_ERROR_NOT_IMPLEMENTED,
+                QLatin1String("X-TELEPATHY-PASSWORD is the only supported SASL mechanism and "
+                    " is not available"));
+        return;
+    }
+
+    // everything ok, we can return from handleChannels now
+    emit ready(this);
+
+    connect(m_saslIface,
+            SIGNAL(SASLStatusChanged(uint,QString,QVariantMap)),
+            SLOT(onSASLStatusChanged(uint,QString,QVariantMap)));
+    uint status = qdbus_cast<uint>(props.value("SASLStatus"));
+    QString error = qdbus_cast<QString>(props.value("SASLError"));
+    QVariantMap errorDetails = qdbus_cast<QVariantMap>(props.value("SASLErrorDetails"));
+    onSASLStatusChanged(status, error, errorDetails);
+}
+
+void SaslAuthOp::onSASLStatusChanged(uint status, const QString &reason,
+        const QVariantMap &details)
+{
+    if (status == Tp::SASLStatusNotStarted) {
+        kDebug() << "Requesting password";
+        promptUser(true);
+    } else if (status == Tp::SASLStatusServerSucceeded) {
+        kDebug() << "Authentication handshake";
+        m_saslIface->AcceptSASL();
+    } else if (status == Tp::SASLStatusSucceeded) {
+        kDebug() << "Authentication succeeded";
+        m_channel->requestClose();
+        setFinished();
+    } else if (status == Tp::SASLStatusInProgress) {
+        kDebug() << "Authenticating...";
+    } else if (status == Tp::SASLStatusServerFailed) {
+        kDebug() << "Error authenticating - reason:" << reason << "- details:" << details;
+
+        if (m_canTryAgain) {
+            kDebug() << "Retrying...";
+            promptUser(false);
+        } else {
+            m_channel->requestClose();
+            setFinished();
+        }
+    }
+}
+
+void SaslAuthOp::promptUser(bool isFirstRun)
+{
+    kDebug() << "Trying to load from wallet";
+    if (m_wallet->hasFolder("telepathy-kde") && isFirstRun) {
+        m_wallet->setFolder("telepathy-kde");
+
+        QString password;
+        kDebug() << "Wallet contains telepathy folder";
+
+        if (m_wallet->hasEntry(m_account->uniqueIdentifier())) {
+            kDebug() << "Wallet contains saved password";
+
+            int ret = m_wallet->readPassword(m_account->uniqueIdentifier(), password);
+            if (ret == 0) {
+                kDebug() << "Using saved password";
+                m_saslIface->StartMechanismWithData(QLatin1String("X-TELEPATHY-PASSWORD"),
+                        password.toUtf8());
+                return;
+            } else {
+                kDebug() << "Error reading saved password";
+            }
+        }
+    }
+
+    PasswordPrompt dialog(m_account);
+    if (dialog.exec() == QDialog::Rejected) {
+        kDebug() << "Authentication cancelled";
+        m_saslIface->AbortSASL(Tp::SASLAbortReasonUserAbort, "User cancelled auth");
+        m_channel->requestClose();
+        setFinished();
+        return;
+    }
+
+    kDebug() << "Starting authentication...";
+    m_saslIface->StartMechanismWithData(QLatin1String("X-TELEPATHY-PASSWORD"),
+            dialog.password().toUtf8());
+
+    // save password in kwallet...
+    if (dialog.savePassword()) {
+        kDebug() << "Saving password in wallet";
+        if (!m_wallet->hasFolder("telepathy-kde")) {
+            m_wallet->createFolder("telepathy-kde");
+        }
+        m_wallet->setFolder("telepathy-kde");
+        m_wallet->writePassword(m_account->uniqueIdentifier(), dialog.password());
+    }
+}
+
+#include "sasl-auth-op.moc"
diff --git a/handler-auth.h b/sasl-auth-op.h
similarity index 67%
copy from handler-auth.h
copy to sasl-auth-op.h
index 4122417..68399f4 100644
--- a/handler-auth.h
+++ b/sasl-auth-op.h
@@ -1,7 +1,7 @@
 /*
- * This file is part of TelepathyQt4
- *
  * Copyright (C) 2011 Collabora Ltd. <http://www.collabora.co.uk/>
+ *   @author Andre Moreira Magalhaes <andre.magalhaes at collabora.co.uk>
+ * Copyright (C) 2011 David Edmundson <kde at davidedmundson.co.uk>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,8 +18,8 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#ifndef _TelepathyQt4_examples_saslauth_handler_auth_h_HEADER_GUARD_
-#define _TelepathyQt4_examples_saslauth_handler_auth_h_HEADER_GUARD_
+#ifndef SASLAUTHOP_H
+#define SASLAUTHOP_H
 
 #include <TelepathyQt4/Account>
 #include <TelepathyQt4/Channel>
@@ -27,29 +27,35 @@
 #include <TelepathyQt4/PendingOperation>
 #include <TelepathyQt4/Types>
 
-#include "KWallet/Wallet"
-
-#include "sasl-channel.h"
+#include <KWallet/Wallet>
 
-class HandlerAuth : public Tp::PendingOperation
+class SaslAuthOp : public Tp::PendingOperation
 {
     Q_OBJECT
+
 public:
-    HandlerAuth(const Tp::AccountPtr &account,
+    SaslAuthOp(const Tp::AccountPtr &account,
             const Tp::ConnectionPtr &connection,
-            const Tp::ChannelPtr &channel);
-    ~HandlerAuth();
+            const Tp::ChannelPtr &channel,
+            KWallet::Wallet *wallet);
+    ~SaslAuthOp();
+
+Q_SIGNALS:
+    void ready(Tp::PendingOperation *self);
 
 private Q_SLOTS:
-    void gotAvailableSASLMechanisms(Tp::PendingOperation *op);
+    void gotProperties(Tp::PendingOperation *op);
     void onSASLStatusChanged(uint status, const QString &reason, const QVariantMap &details);
-    void promptUser(bool isFirstPrompt);
 
 private:
+    void promptUser(bool isFirstPrompt);
+
     Tp::AccountPtr m_account;
     Tp::ConnectionPtr m_connection;
-    SaslChannel *m_channel; //FIXME
+    Tp::ChannelPtr m_channel;
+    Tp::Client::ChannelInterfaceSASLAuthenticationInterface *m_saslIface;
     KWallet::Wallet *m_wallet;
+    bool m_canTryAgain;
 };
 
 #endif
diff --git a/sasl-channel.cpp b/sasl-channel.cpp
deleted file mode 100644
index b4fd22a..0000000
--- a/sasl-channel.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-#include "sasl-channel.h"
-
-SaslChannel::SaslChannel(const Tp::ChannelPtr &channel)
-{
-    m_channel = channel;
-}
-
-SaslChannel::~SaslChannel()
-{
-
-}
-
-void SaslChannel::startMechanismWithData(const QString &mechanism, const QByteArray &data)
-{
-    iface()->StartMechanismWithData(mechanism, data);
-}
-
-
-void SaslChannel::acceptSasl()
-{
-    iface()->AcceptSASL();
-}
-
-
-void SaslChannel::close()
-{
-    m_channel->requestClose();
-}
-
-
-Tp::Client::ChannelInterfaceSASLAuthenticationInterface * SaslChannel::iface()
-{
-    return m_channel->interface<Tp::Client::ChannelInterfaceSASLAuthenticationInterface>();
-}
diff --git a/sasl-channel.h b/sasl-channel.h
deleted file mode 100644
index f63db3d..0000000
--- a/sasl-channel.h
+++ /dev/null
@@ -1,32 +0,0 @@
-//this is all utterly bollucks. Rewrite this.
-
-#include <TelepathyQt4/Channel>
-#include <TelepathyQt4/PendingStringList>
-
-//: public Tp::RefCounted
-
-class SaslChannel
-{
-public:
-    SaslChannel(const Tp::ChannelPtr &channel);
-    virtual ~SaslChannel();
-
-    void startMechanismWithData(const QString &mechanism, const QByteArray &data);
-//    void respond(const QByteArray &data);
-    void acceptSasl();
-//    void abortSasl(int reason, const QString &message=QString()); //FIXME enum type
-    void close();
-    
-    //properties
-    Tp::PendingStringList availableMechanims() const;
-//    bool canTryAgain() const;
-    
-signals:
-//    void saslStatusChanged(SASLStatus status, const QString &reason, const QVariantMap &details);
-//  void newChallenge()
-    
-private:
-    Tp::ChannelPtr m_channel;  
-
-    Tp::Client::ChannelInterfaceSASLAuthenticationInterface* iface();
-};
diff --git a/handler.cpp b/sasl-handler.cpp
similarity index 60%
copy from handler.cpp
copy to sasl-handler.cpp
index e42b7ef..c845eb8 100644
--- a/handler.cpp
+++ b/sasl-handler.cpp
@@ -1,8 +1,7 @@
 /*
- * This file is part of TelepathyQt4
- *
  * Copyright (C) 2011 Collabora Ltd. <http://www.collabora.co.uk/>
- * Copyright (C) David Edmundson <kde at davidedmundson.co.uk>
+ *   @author Andre Moreira Magalhaes <andre.magalhaes at collabora.co.uk>
+ * Copyright (C) 2011 David Edmundson <kde at davidedmundson.co.uk>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -19,9 +18,9 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include "handler.h"
+#include "sasl-handler.h"
 
-#include "handler-auth.h"
+#include "sasl-auth-op.h"
 
 #include <QDBusConnection>
 
@@ -29,21 +28,25 @@
 #include <TelepathyQt4/ChannelDispatchOperation>
 #include <TelepathyQt4/MethodInvocationContext>
 
-Handler::Handler(const Tp::ChannelClassSpecList &channelFilter)
+#include <KDebug>
+
+SaslHandler::SaslHandler(const Tp::ChannelClassSpecList &channelFilter)
     : Tp::AbstractClientHandler(channelFilter)
 {
+    m_wallet = KWallet::Wallet::openWallet(KWallet::Wallet::NetworkWallet(),
+            0, KWallet::Wallet::Asynchronous);
 }
 
-Handler::~Handler()
+SaslHandler::~SaslHandler()
 {
 }
 
-bool Handler::bypassApproval() const
+bool SaslHandler::bypassApproval() const
 {
     return true;
 }
 
-void Handler::handleChannels(const Tp::MethodInvocationContextPtr<> &context,
+void SaslHandler::handleChannels(const Tp::MethodInvocationContextPtr<> &context,
         const Tp::AccountPtr &account,
         const Tp::ConnectionPtr &connection,
         const QList<Tp::ChannelPtr> &channels,
@@ -55,31 +58,36 @@ void Handler::handleChannels(const Tp::MethodInvocationContextPtr<> &context,
     Q_UNUSED(userActionTime);
     Q_UNUSED(handlerInfo);
 
-    Q_ASSERT(channels.size() == 1);
-    HandlerAuth *auth = new HandlerAuth(account, connection, channels.first());
-
+    SaslAuthOp *auth = new SaslAuthOp(
+            account, connection, channels.first(), m_wallet);
+    connect(auth,
+            SIGNAL(ready(Tp::PendingOperation*)),
+            SLOT(onAuthReady(Tp::PendingOperation*)));
     connect(auth,
             SIGNAL(finished(Tp::PendingOperation*)),
             SLOT(onAuthFinished(Tp::PendingOperation*)));
     mAuthContexts.insert(auth, context);
-
 }
 
-void Handler::onAuthFinished(Tp::PendingOperation *op)
+void SaslHandler::onAuthReady(Tp::PendingOperation *op)
 {
-    HandlerAuth *auth = qobject_cast<HandlerAuth*>(op);
+    SaslAuthOp *auth = qobject_cast<SaslAuthOp*>(op);
     Q_ASSERT(mAuthContexts.contains(auth));
 
     Tp::MethodInvocationContextPtr<> context = mAuthContexts.value(auth);
+    context->setFinished();
+}
+
+void SaslHandler::onAuthFinished(Tp::PendingOperation *op)
+{
+    SaslAuthOp *auth = qobject_cast<SaslAuthOp*>(op);
+    Q_ASSERT(mAuthContexts.contains(auth));
+
     if (op->isError()) {
-        context->setFinishedWithError(op->errorName(), op->errorMessage());
-    } else {
-        context->setFinished();
+        kWarning() << "Error in SASL auth:" << op->errorName() << "-" << op->errorMessage();
     }
 
     mAuthContexts.remove(auth);
-
-    //if mAuthContexts.size == 0 then close?
 }
 
-#include "handler.moc"
+#include "sasl-handler.moc"
diff --git a/handler.h b/sasl-handler.h
similarity index 72%
copy from handler.h
copy to sasl-handler.h
index c8b6706..7ef499f 100644
--- a/handler.h
+++ b/sasl-handler.h
@@ -1,8 +1,7 @@
 /*
- * This file is part of TelepathyQt4
- *
  * Copyright (C) 2011 Collabora Ltd. <http://www.collabora.co.uk/>
- * Copyright (C) David Edmundson <kde at davidedmundson.co.uk>
+ *   @author Andre Moreira Magalhaes <andre.magalhaes at collabora.co.uk>
+ * Copyright (C) 2011 David Edmundson <kde at davidedmundson.co.uk>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -19,27 +18,29 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#ifndef _TelepathyQt4_examples_saslauth_handler_h_HEADER_GUARD_
-#define _TelepathyQt4_examples_saslauth_handler_h_HEADER_GUARD_
+#ifndef SASLHANDLER_H
+#define SASLHANDLER_H
 
 #include <QObject>
 
 #include <TelepathyQt4/AbstractClientHandler>
 
+#include <KWallet/Wallet>
+
 namespace Tp
 {
     class PendingOperation;
 };
 
-class HandlerAuth;
+class SaslAuthOp;
 
-class Handler : public QObject, public Tp::AbstractClientHandler
+class SaslHandler : public QObject, public Tp::AbstractClientHandler
 {
     Q_OBJECT
 
 public:
-    explicit Handler(const Tp::ChannelClassSpecList &channelFilter);
-    ~Handler();
+    explicit SaslHandler(const Tp::ChannelClassSpecList &channelFilter);
+    ~SaslHandler();
 
     bool bypassApproval() const;
 
@@ -52,10 +53,12 @@ public:
             const Tp::AbstractClientHandler::HandlerInfo &handlerInfo);
 
 private Q_SLOTS:
+    void onAuthReady(Tp::PendingOperation *op);
     void onAuthFinished(Tp::PendingOperation *op);
 
 private:
-    QHash<HandlerAuth *, Tp::MethodInvocationContextPtr<> > mAuthContexts;
+    KWallet::Wallet *m_wallet;
+    QHash<Tp::PendingOperation *, Tp::MethodInvocationContextPtr<> > mAuthContexts;
 };
 
 #endif
diff --git a/tls-cert-verifier-op.cpp b/tls-cert-verifier-op.cpp
new file mode 100644
index 0000000..6b1a07a
--- /dev/null
+++ b/tls-cert-verifier-op.cpp
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2011 Collabora Ltd. <http://www.collabora.co.uk/>
+ *   @author Andre Moreira Magalhaes <andre.magalhaes at collabora.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "tls-cert-verifier-op.h"
+
+#include <TelepathyQt4/PendingVariantMap>
+
+#include <KDebug>
+
+TlsCertVerifierOp::TlsCertVerifierOp(const Tp::AccountPtr &account,
+        const Tp::ConnectionPtr &connection,
+        const Tp::ChannelPtr &channel)
+    : Tp::PendingOperation(channel),
+      m_account(account),
+      m_connection(connection),
+      m_channel(channel)
+{
+    QString certificatePath = qdbus_cast<QString>(channel->immutableProperties().value(
+                TP_QT4_IFACE_CHANNEL_TYPE_SERVER_TLS_CONNECTION + ".ServerCertificate"));
+    m_hostname = qdbus_cast<QString>(channel->immutableProperties().value(
+                TP_QT4_IFACE_CHANNEL_TYPE_SERVER_TLS_CONNECTION + ".Hostname"));
+    m_referenceIdentities = qdbus_cast<QStringList>(channel->immutableProperties().value(
+                TP_QT4_IFACE_CHANNEL_TYPE_SERVER_TLS_CONNECTION + ".ReferenceIdentities"));
+
+    m_authTLSCertificateIface = new Tp::Client::AuthenticationTLSCertificateInterface(
+            channel->dbusConnection(), channel->busName(), certificatePath);
+    connect(m_authTLSCertificateIface->requestAllProperties(),
+            SIGNAL(finished(Tp::PendingOperation*)),
+            SLOT(gotProperties(Tp::PendingOperation*)));
+}
+
+TlsCertVerifierOp::~TlsCertVerifierOp()
+{
+}
+
+void TlsCertVerifierOp::gotProperties(Tp::PendingOperation *op)
+{
+    if (op->isError()) {
+        kWarning() << "Unable to retrieve properties from AuthenticationTLSCertificate object at" <<
+            m_authTLSCertificateIface->path();
+        setFinishedWithError(op->errorName(), op->errorMessage());
+        return;
+    }
+
+    // everything ok, we can return from handleChannels now
+    emit ready(this);
+
+    Tp::PendingVariantMap *pvm = qobject_cast<Tp::PendingVariantMap*>(op);
+    QVariantMap props = qdbus_cast<QVariantMap>(pvm->result());
+    m_certType = qdbus_cast<QString>(props.value("CertificateType"));
+    m_certData = qdbus_cast<CertificateDataList>(props.value("certificateChainData"));
+
+    // FIXME: verify cert
+    setFinished();
+}
+
+#include "tls-cert-verifier-op.moc"
diff --git a/handler-auth.h b/tls-cert-verifier-op.h
similarity index 56%
rename from handler-auth.h
rename to tls-cert-verifier-op.h
index 4122417..ac5b09e 100644
--- a/handler-auth.h
+++ b/tls-cert-verifier-op.h
@@ -1,7 +1,7 @@
 /*
- * This file is part of TelepathyQt4
- *
  * Copyright (C) 2011 Collabora Ltd. <http://www.collabora.co.uk/>
+ *   @author Andre Moreira Magalhaes <andre.magalhaes at collabora.co.uk>
+ * Copyright (C) 2011 David Edmundson <kde at davidedmundson.co.uk>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,38 +18,46 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#ifndef _TelepathyQt4_examples_saslauth_handler_auth_h_HEADER_GUARD_
-#define _TelepathyQt4_examples_saslauth_handler_auth_h_HEADER_GUARD_
+#ifndef TLSCERTVERIFIEROP_H
+#define TLSCERTVERIFIEROP_H
 
 #include <TelepathyQt4/Account>
+#include <TelepathyQt4/AuthenticationTLSCertificateInterface>
 #include <TelepathyQt4/Channel>
 #include <TelepathyQt4/Connection>
 #include <TelepathyQt4/PendingOperation>
 #include <TelepathyQt4/Types>
 
-#include "KWallet/Wallet"
-
-#include "sasl-channel.h"
+// FIXME: Move this to tp-qt4 itself
+#include "types.h"
 
-class HandlerAuth : public Tp::PendingOperation
+class TlsCertVerifierOp : public Tp::PendingOperation
 {
     Q_OBJECT
+
 public:
-    HandlerAuth(const Tp::AccountPtr &account,
+    TlsCertVerifierOp(const Tp::AccountPtr &account,
             const Tp::ConnectionPtr &connection,
             const Tp::ChannelPtr &channel);
-    ~HandlerAuth();
+    ~TlsCertVerifierOp();
+
+Q_SIGNALS:
+    void ready(TlsCertVerifierOp *self);
+    void error(TlsCertVerifierOp *self, const QString &error, const QString &errorMessage);
+    void finished(TlsCertVerifierOp *self);
 
 private Q_SLOTS:
-    void gotAvailableSASLMechanisms(Tp::PendingOperation *op);
-    void onSASLStatusChanged(uint status, const QString &reason, const QVariantMap &details);
-    void promptUser(bool isFirstPrompt);
+    void gotProperties(Tp::PendingOperation *op);
 
 private:
     Tp::AccountPtr m_account;
     Tp::ConnectionPtr m_connection;
-    SaslChannel *m_channel; //FIXME
-    KWallet::Wallet *m_wallet;
+    Tp::ChannelPtr m_channel;
+    QString m_hostname;
+    QStringList m_referenceIdentities;
+    Tp::Client::AuthenticationTLSCertificateInterface *m_authTLSCertificateIface;
+    QString m_certType;
+    CertificateDataList m_certData;
 };
 
 #endif
diff --git a/handler.cpp b/tls-handler.cpp
similarity index 52%
rename from handler.cpp
rename to tls-handler.cpp
index e42b7ef..b8489b7 100644
--- a/handler.cpp
+++ b/tls-handler.cpp
@@ -1,8 +1,6 @@
 /*
- * This file is part of TelepathyQt4
- *
  * Copyright (C) 2011 Collabora Ltd. <http://www.collabora.co.uk/>
- * Copyright (C) David Edmundson <kde at davidedmundson.co.uk>
+ *   @author Andre Moreira Magalhaes <andre.magalhaes at collabora.co.uk>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -19,9 +17,9 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include "handler.h"
+#include "tls-handler.h"
 
-#include "handler-auth.h"
+#include "tls-cert-verifier-op.h"
 
 #include <QDBusConnection>
 
@@ -29,21 +27,23 @@
 #include <TelepathyQt4/ChannelDispatchOperation>
 #include <TelepathyQt4/MethodInvocationContext>
 
-Handler::Handler(const Tp::ChannelClassSpecList &channelFilter)
+#include <KDebug>
+
+TlsHandler::TlsHandler(const Tp::ChannelClassSpecList &channelFilter)
     : Tp::AbstractClientHandler(channelFilter)
 {
 }
 
-Handler::~Handler()
+TlsHandler::~TlsHandler()
 {
 }
 
-bool Handler::bypassApproval() const
+bool TlsHandler::bypassApproval() const
 {
     return true;
 }
 
-void Handler::handleChannels(const Tp::MethodInvocationContextPtr<> &context,
+void TlsHandler::handleChannels(const Tp::MethodInvocationContextPtr<> &context,
         const Tp::AccountPtr &account,
         const Tp::ConnectionPtr &connection,
         const QList<Tp::ChannelPtr> &channels,
@@ -55,31 +55,36 @@ void Handler::handleChannels(const Tp::MethodInvocationContextPtr<> &context,
     Q_UNUSED(userActionTime);
     Q_UNUSED(handlerInfo);
 
-    Q_ASSERT(channels.size() == 1);
-    HandlerAuth *auth = new HandlerAuth(account, connection, channels.first());
-
-    connect(auth,
+    TlsCertVerifierOp *verifier = new TlsCertVerifierOp(
+            account, connection, channels.first());
+    connect(verifier,
+            SIGNAL(ready(Tp::PendingOperation*)),
+            SLOT(onCertVerifierReady(Tp::PendingOperation*)));
+    connect(verifier,
             SIGNAL(finished(Tp::PendingOperation*)),
-            SLOT(onAuthFinished(Tp::PendingOperation*)));
-    mAuthContexts.insert(auth, context);
+            SLOT(onCertVerifierFinished(Tp::PendingOperation*)));
+    mVerifiers.insert(verifier, context);
+}
 
+void TlsHandler::onCertVerifierReady(Tp::PendingOperation *op)
+{
+    TlsCertVerifierOp *verifier = qobject_cast<TlsCertVerifierOp*>(op);
+    Q_ASSERT(mVerifiers.contains(verifier));
+
+    Tp::MethodInvocationContextPtr<> context = mVerifiers.value(verifier);
+    context->setFinished();
 }
 
-void Handler::onAuthFinished(Tp::PendingOperation *op)
+void TlsHandler::onCertVerifierFinished(Tp::PendingOperation *op)
 {
-    HandlerAuth *auth = qobject_cast<HandlerAuth*>(op);
-    Q_ASSERT(mAuthContexts.contains(auth));
+    TlsCertVerifierOp *verifier = qobject_cast<TlsCertVerifierOp*>(op);
+    Q_ASSERT(mVerifiers.contains(verifier));
 
-    Tp::MethodInvocationContextPtr<> context = mAuthContexts.value(auth);
     if (op->isError()) {
-        context->setFinishedWithError(op->errorName(), op->errorMessage());
-    } else {
-        context->setFinished();
+        kWarning() << "Error verifying TLS certificate:" << op->errorName() << "-" << op->errorMessage();
     }
 
-    mAuthContexts.remove(auth);
-
-    //if mAuthContexts.size == 0 then close?
+    mVerifiers.remove(verifier);
 }
 
-#include "handler.moc"
+#include "tls-handler.moc"
diff --git a/handler.h b/tls-handler.h
similarity index 73%
rename from handler.h
rename to tls-handler.h
index c8b6706..4d88315 100644
--- a/handler.h
+++ b/tls-handler.h
@@ -1,8 +1,6 @@
 /*
- * This file is part of TelepathyQt4
- *
  * Copyright (C) 2011 Collabora Ltd. <http://www.collabora.co.uk/>
- * Copyright (C) David Edmundson <kde at davidedmundson.co.uk>
+ *   @author Andre Moreira Magalhaes <andre.magalhaes at collabora.co.uk>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -19,8 +17,8 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#ifndef _TelepathyQt4_examples_saslauth_handler_h_HEADER_GUARD_
-#define _TelepathyQt4_examples_saslauth_handler_h_HEADER_GUARD_
+#ifndef TLSHANDLER_H
+#define TLSHANDLER_H
 
 #include <QObject>
 
@@ -31,15 +29,15 @@ namespace Tp
     class PendingOperation;
 };
 
-class HandlerAuth;
+class TlsCertVerifierOp;
 
-class Handler : public QObject, public Tp::AbstractClientHandler
+class TlsHandler : public QObject, public Tp::AbstractClientHandler
 {
     Q_OBJECT
 
 public:
-    explicit Handler(const Tp::ChannelClassSpecList &channelFilter);
-    ~Handler();
+    explicit TlsHandler(const Tp::ChannelClassSpecList &channelFilter);
+    ~TlsHandler();
 
     bool bypassApproval() const;
 
@@ -52,10 +50,11 @@ public:
             const Tp::AbstractClientHandler::HandlerInfo &handlerInfo);
 
 private Q_SLOTS:
-    void onAuthFinished(Tp::PendingOperation *op);
+    void onCertVerifierReady(Tp::PendingOperation *op);
+    void onCertVerifierFinished(Tp::PendingOperation *op);
 
 private:
-    QHash<HandlerAuth *, Tp::MethodInvocationContextPtr<> > mAuthContexts;
+    QHash<Tp::PendingOperation *, Tp::MethodInvocationContextPtr<> > mVerifiers;
 };
 
 #endif
diff --git a/types.cpp b/types.cpp
new file mode 100644
index 0000000..ff2192e
--- /dev/null
+++ b/types.cpp
@@ -0,0 +1,14 @@
+// FIXME: Move this to tp-qt4 itself
+#include "types.h"
+
+#include <QDBusMetaType>
+
+void registerTypes()
+{
+    static bool registered = false;
+    if (registered)
+        return;
+    registered = true;
+
+    qDBusRegisterMetaType<CertificateDataList>();
+}
diff --git a/types.h b/types.h
new file mode 100644
index 0000000..256bd48
--- /dev/null
+++ b/types.h
@@ -0,0 +1,14 @@
+// FIXME: Move this to tp-qt4 itself
+#ifndef TYPES_H
+#define TYPES_H
+
+#include <QByteArray>
+#include <QList>
+#include <QMetaType>
+
+typedef QList<QByteArray> CertificateDataList;
+Q_DECLARE_METATYPE(CertificateDataList)
+
+void registerTypes();
+
+#endif

-- 
ktp-auth-handler packaging



More information about the pkg-kde-commits mailing list