diff options
Diffstat (limited to 'src/tdebluezauth')
-rw-r--r-- | src/tdebluezauth/CMakeLists.txt | 47 | ||||
-rw-r--r-- | src/tdebluezauth/application.cpp | 156 | ||||
-rw-r--r-- | src/tdebluezauth/application.h | 79 | ||||
-rw-r--r-- | src/tdebluezauth/authdialog.ui | 52 | ||||
-rw-r--r-- | src/tdebluezauth/authorize.cpp | 52 | ||||
-rw-r--r-- | src/tdebluezauth/authorize.h | 47 | ||||
-rw-r--r-- | src/tdebluezauth/authservice.cpp | 294 | ||||
-rw-r--r-- | src/tdebluezauth/authservice.h | 230 | ||||
-rw-r--r-- | src/tdebluezauth/main.cpp | 77 | ||||
-rw-r--r-- | src/tdebluezauth/pindefdialog.ui | 87 | ||||
-rw-r--r-- | src/tdebluezauth/pindefdialog2.ui | 87 | ||||
-rw-r--r-- | src/tdebluezauth/pindialog.cpp | 58 | ||||
-rw-r--r-- | src/tdebluezauth/pindialog.h | 58 | ||||
-rw-r--r-- | src/tdebluezauth/tdebluezauth.desktop | 36 |
14 files changed, 1360 insertions, 0 deletions
diff --git a/src/tdebluezauth/CMakeLists.txt b/src/tdebluezauth/CMakeLists.txt new file mode 100644 index 0000000..055779d --- /dev/null +++ b/src/tdebluezauth/CMakeLists.txt @@ -0,0 +1,47 @@ +################################################# +# +# (C) 2018 Emanoil Kotsev +# deloptes (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +project( tdebluezauth ) + +# import required +#tde_import( lib... ) + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_SOURCE_DIR} + ${CMAKE_BINARY_DIR} + ${CMAKE_SOURCE_DIR}/src/libtdebluez + ${CMAKE_BINARY_DIR}/src/libtdebluez + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} +# ${DBUS_INCLUDE_DIRS} + ${DBUS_TQT_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + +##### tdebluezauth (tdeinit) ###################### + +tde_add_executable( tdebluezauth AUTOMOC + SOURCES + authorize.cpp authdialog.ui + pindialog.cpp pindefdialog.ui + authservice.cpp application.cpp main.cpp + LINK + ${DBUS_TQT_LIBRARIES} tdebluez-shared bluezinterfaces-static + DESTINATION ${BIN_INSTALL_DIR} +) + +##### other data ################################ +#tde_install_icons( tdebluezauth ) +install( FILES tdebluezauth.desktop DESTINATION ${XDG_APPS_INSTALL_DIR} ) diff --git a/src/tdebluezauth/application.cpp b/src/tdebluezauth/application.cpp new file mode 100644 index 0000000..3b1dec8 --- /dev/null +++ b/src/tdebluezauth/application.cpp @@ -0,0 +1,156 @@ +/* + * + * Authorization Agent implementation of bluez5 + * + * Copyright (C) 2018 Emanoil Kotsev <deloptes@gmail.com> + * + * + * This file is part of tdebluezauth. + * + * tdebluezauth is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * tdebluezauth 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with kbluetooth; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ +#include <tqdbusobjectpath.h> +#include <tdecmdlineargs.h> +#include <tdemessagebox.h> + +#include <adapterImpl.h> +#include "application.h" +#include "authservice.h" + +#define DBUS_AUTH_SERVICE "TDEBluezAuth" +#define DBUS_AUTH_SERVICE_NAME "org.trinitydesktop.tdebluez" + +TDEBluezAuth::TDEBluezAuth() : + KUniqueApplication() +{ + m_connection = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus, DBUS_AUTH_SERVICE); + + if (!m_connection.isConnected()) + { + kdError() << "Failed to open connection to system message bus: " << m_connection.lastError().message() << endl; + exit(-1); + } + + // try to get a specific service name + if (!m_connection.requestName(DBUS_AUTH_SERVICE_NAME)) + { + tqWarning("Requesting name %s failed. " + "The object will only be addressable through unique name '%s'", + DBUS_AUTH_SERVICE_NAME, m_connection.uniqueName().local8Bit().data()); + exit(-2); + } + + manager = new TDEBluetooth::ObjectManagerImpl("org.bluez", "/", this, "ObjectManager"); + if (!manager->isConnectedToDBUS()) + { + tqDebug("ObjectManager is not connected to DBus"); + exit(-3); + } + + rootService = new RootNodeService(m_connection); + orgService = new OrgNodeService(m_connection); + tdeNodeService = new TrinityDekstopNodeService(m_connection); + authService = new AuthService(m_connection); + agentManager = 0; + if (!configureAgent()) + { + tqDebug("Failed to configure the auth agent"); + } + disableSessionManagement(); + +// connect to manager signals +// connect(manager, SIGNAL(adapterAdded(const TQString&)), SLOT(slotAdapterAdded(const TQString&))); +// connect(manager, SIGNAL(adapterRemoved(const TQString&)), SLOT(slotAdapterRemoved(const TQString&))); + connect(manager, SIGNAL(adapterPowerOnChanged(const TQString&, bool)), + this, SLOT(slotPowerOnChanged(const TQString&, bool))); +} + +TDEBluezAuth::~TDEBluezAuth() +{ + disconnect(manager, SIGNAL(adapterPowerOnChanged(const TQString&, bool)), + this, SLOT(slotPowerOnChanged(const TQString&, bool))); + // close D-Bus connection + unconfigureAgent(); + + m_connection.closeConnection(DBUS_AUTH_SERVICE); + + delete authService; + delete tdeNodeService; + delete orgService; + delete rootService; + + delete manager; + agentManager = 0; +} + +bool TDEBluezAuth::isConnectedToDBUS() +{ + return m_connection.isConnected(); +} + +bool TDEBluezAuth::configureAgent() +{ + if (!agentManager) + agentManager = manager->getAgentManager(); + + if (manager->isAgentRegistered() && manager->isAgentDefaultAgent()) + { + return true; + } + + if (!manager->isAgentRegistered()) + { + if (!manager->registerAgent()) + { + tqWarning("org.bluez.Agent1 registering FAILED"); + return false; + } + } + if (!manager->isAgentDefaultAgent()) + { + if (!manager->requestDefaultAgent()) + { + tqWarning("org.bluez.Agent1 registering FAILED"); + return false; + } + } + + kdDebug() << "org.bluez.Agent1 registering OK" << endl; + + return true; +} + +bool TDEBluezAuth::unconfigureAgent() +{ + if (manager->isAgentRegistered()) + { + if (manager->unregisterAgent()) + kdDebug() << "Agent unregistered OK" << endl; + else + kdDebug() << "Agent unregistered FAILED" << endl; + } + return true; +} + +void TDEBluezAuth::slotPowerOnChanged(const TQString& adapter, bool state) +{ + if (state) + configureAgent(); + else + unconfigureAgent(); +} + +#include "application.moc" diff --git a/src/tdebluezauth/application.h b/src/tdebluezauth/application.h new file mode 100644 index 0000000..499418a --- /dev/null +++ b/src/tdebluezauth/application.h @@ -0,0 +1,79 @@ +/* + * + * Authorization Agent implementation of bluez5 + * + * Copyright (C) 2018 Emanoil Kotsev <deloptes@gmail.com> + * + * + * This file is part of tdebluezauth. + * + * tdebluezauth is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * tdebluezauth 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with kbluetooth; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ +#ifndef TDEAUTHAPP_H_ +#define TDEAUTHAPP_H_ + +#include <kuniqueapplication.h> + +#include <objectmanagerImpl.h> +#include "authservice.h" + +class TDEBluezAuth: public KUniqueApplication +{ + Q_OBJECT + +public: + TDEBluezAuth(); + virtual ~TDEBluezAuth(); + + /*! + * This function return information about connection status to the DBUS daemon. + * \return boolean with the state of the connection to D-Bus + * \retval true if connected + * \retval false if disconnected + */ + bool isConnectedToDBUS(); + +private: + /*! + * This function initialise the connection to the D-Bus daemon. + * \return boolean with the result of the operation + * \retval true if successful initialised D-Bus connection + * \retval false if unsuccessful + */ + bool configureAgent(); + //! to close the connection to D-Bus + bool unconfigureAgent(); + +private: + TQT_DBusConnection m_connection; + + AgentManager1Proxy* agentManager; + RootNodeService *rootService; + OrgNodeService *orgService; + TrinityDekstopNodeService *tdeNodeService; + AuthService *authService; + +public: + TDEBluetooth::ObjectManagerImpl *manager; + +public slots: + // void slotAdapterAdded(const TQString& adapter); + // void slotAdapterRemoved(const TQString& adapter); + void slotPowerOnChanged(const TQString&, bool); + +}; + +#endif // TDEAUTHAPP_H_ diff --git a/src/tdebluezauth/authdialog.ui b/src/tdebluezauth/authdialog.ui new file mode 100644 index 0000000..8b0efcf --- /dev/null +++ b/src/tdebluezauth/authdialog.ui @@ -0,0 +1,52 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>AuthDialog</class> +<widget class="TQWidget"> + <property name="name"> + <cstring>AuthDialog</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>425</width> + <height>300</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>400</width> + <height>300</height> + </size> + </property> + <property name="caption"> + <string>AuthenticationDialog</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="TQLabel"> + <property name="name"> + <cstring>messageLabel</cstring> + </property> + <property name="text"> + <string><font size="+2">Bluetooth Authorization Request</font> +<p><b>%1</b> (device address <b>%2</b>) %3.</p> + +<p> +If you aren't sure about the identity of the other party, then reject +this authorization request.</p></string> + </property> + </widget> + </vbox> +</widget> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/src/tdebluezauth/authorize.cpp b/src/tdebluezauth/authorize.cpp new file mode 100644 index 0000000..26aa813 --- /dev/null +++ b/src/tdebluezauth/authorize.cpp @@ -0,0 +1,52 @@ +/* + * + * Authorization dialog for kbluetooth + * + * Copyright (C) 2006 Daniel Gollub <dgollub@suse.de> + * + * + * This file is part of kbluetooth. + * + * kbluetooth is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * libkbluetooth 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with libkbluetooth; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include "authorize.h" +#include "authdialog.h" + +AuthorizeDialog::AuthorizeDialog(const TQString &addr, const TQString &devName, const TQString &service) : + KDialogBase(NULL, "authrequest", true, "Bluetooth Authorization Request", + (Ok | Cancel), Ok, false, + KGuiItem(i18n("Accept"), "accept"), + KGuiItem(i18n("Reject"), "reject")) +{ + TQString action(i18n("wants to act as Input Device")); + + if (!service.isEmpty()) + action.append(" for " + service); + + authDlg = new AuthDialog(this); + authDlg->messageLabel->setText(authDlg->messageLabel->text().arg(devName).arg(addr).arg(action)); + connect(this, SIGNAL(okClicked()), SLOT(close())); + + setMainWidget(authDlg); +} + +AuthorizeDialog::~AuthorizeDialog() +{ + delete authDlg; +} + +#include "authorize.moc" diff --git a/src/tdebluezauth/authorize.h b/src/tdebluezauth/authorize.h new file mode 100644 index 0000000..ff9e9b3 --- /dev/null +++ b/src/tdebluezauth/authorize.h @@ -0,0 +1,47 @@ +/* + * + * Authorization Agent implementation of bluez5 + * + * Copyright (C) 2018 Emanoil Kotsev <deloptes@gmail.com> + * + * + * This file is part of tdebluezauth. + * + * tdebluezauth is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * tdebluezauth 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with kbluetooth; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef AUTHORIZE_H +#define AUTHORIZE_H + +#include <tqlabel.h> + +#include <kdialogbase.h> + +#include "application.h" +#include "authdialog.h" + +class AuthorizeDialog : public KDialogBase +{ + + Q_OBJECT + +public: + AuthorizeDialog(const TQString &addr, const TQString &devName, const TQString &service); + ~AuthorizeDialog(); + AuthDialog *authDlg; +}; + +#endif diff --git a/src/tdebluezauth/authservice.cpp b/src/tdebluezauth/authservice.cpp new file mode 100644 index 0000000..419e3e1 --- /dev/null +++ b/src/tdebluezauth/authservice.cpp @@ -0,0 +1,294 @@ +/* + * + * Authorization Agent implementation of bluez5 + * + * Copyright (C) 2019 Emanoil Kotsev <deloptes@gmail.com> + * + * + * This file is part of tdebluezauth. + * + * tdebluezauth is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * tdebluezauth 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with kbluetooth; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +// TQt includes +#include <tqdbusobjectpath.h> +#include <deviceImpl.h> +#include <btuuids.h> + +#include "authservice.h" +#include "pindialog.h" +#include "authorize.h" + +#define DBUS_AUTH_SERVICE_PATH "/org/trinitydesktop/tdebluez" + +Agent1InterfaceImpl::Agent1InterfaceImpl(TQT_DBusConnection &conn) : + m_connection(&conn) +{ +} + +Agent1InterfaceImpl::~Agent1InterfaceImpl() +{ +} + + +/*! + * Implement virtual methods + * + */ + +void Agent1InterfaceImpl::handleMethodReply(const TQT_DBusMessage& reply) +{ + m_connection->send(reply); +} + +bool Agent1InterfaceImpl::Release(TQT_DBusError& error) +{ + // do something + return true; +} + +void Agent1InterfaceImpl::RequestPinCodeAsync(int asyncCallId, const TQT_DBusObjectPath& device) +{ + TQT_DBusError error; + TDEBluetooth::DeviceImpl *devImpl = new TDEBluetooth::DeviceImpl("org.bluez", device); + devImpl->setConnection((*m_connection)); + TQString addr = devImpl->getAddress(error); + TQString name = devImpl->getAlias(error); + delete devImpl; + PinDialog *pinDialog = new PinDialog(addr, name); + pinDialog->pinDlg->pinEdit->setText(TQString()); + pinDialog->pinDlg->pinEdit->setEnabled(true); + KDialogBase::centerOnScreen(pinDialog); + pinDialog->setActiveWindow(); + pinDialog->show(); + pinDialog->raise(); + + if (pinDialog->exec() == TQDialog::Accepted) + RequestPinCodeAsyncReply(asyncCallId, pinDialog->pinDlg->pinEdit->text()); + else + RequestPinCodeAsyncError(asyncCallId, TQT_DBusError::stdFailed("Request canceled")); + delete pinDialog; +} + +void Agent1InterfaceImpl::DisplayPinCodeAsync(int asyncCallId, const TQT_DBusObjectPath& device, const TQString& pincode) +{ + TQT_DBusError error; + TDEBluetooth::DeviceImpl *devImpl = new TDEBluetooth::DeviceImpl("org.bluez", device); + devImpl->setConnection((*m_connection)); + TQString addr = devImpl->getAddress(error); + TQString name = devImpl->getAlias(error); + kdDebug() << addr << " " << name << endl; + delete devImpl; + PinDialog *pinDialog = new PinDialog(addr, name); + pinDialog->pinDlg->pinEdit->setText(TQString("%1").arg(pincode)); + pinDialog->pinDlg->pinEdit->setEnabled(false); + KDialogBase::centerOnScreen(pinDialog); + pinDialog->setActiveWindow(); + pinDialog->show(); + pinDialog->raise(); + + if (pinDialog->exec() == TQDialog::Accepted) + DisplayPinCodeAsyncReply(asyncCallId); + else + DisplayPinCodeAsyncError(asyncCallId, TQT_DBusError::stdFailed("Request not accepted")); + delete pinDialog; +} + +void Agent1InterfaceImpl::RequestPasskeyAsync(int asyncCallId, const TQT_DBusObjectPath& device) +{ + TQT_DBusError error; + TDEBluetooth::DeviceImpl *devImpl = new TDEBluetooth::DeviceImpl("org.bluez", device); + devImpl->setConnection((*m_connection)); + TQString addr = devImpl->getAddress(error); + TQString name = devImpl->getAlias(error); + delete devImpl; + PinDialog *pinDialog = new PinDialog(addr, name); + pinDialog->pinDlg->pinEdit->setText(TQString()); + pinDialog->pinDlg->pinEdit->setEnabled(true); + KDialogBase::centerOnScreen(pinDialog); + pinDialog->setActiveWindow(); + pinDialog->show(); + pinDialog->raise(); + + if (pinDialog->exec() == TQDialog::Accepted) + RequestPasskeyAsyncReply(asyncCallId, pinDialog->pinDlg->pinEdit->text().toUInt()); + else + RequestPasskeyAsyncError(asyncCallId, TQT_DBusError::stdFailed("Request not accepted")); + delete pinDialog; +} + +void Agent1InterfaceImpl::DisplayPasskeyAsync(int asyncCallId, const TQT_DBusObjectPath& device, TQ_UINT32 passkey, TQ_UINT16 entered) +{ + TQT_DBusError error; + TDEBluetooth::DeviceImpl *devImpl = new TDEBluetooth::DeviceImpl("org.bluez", device); + devImpl->setConnection((*m_connection)); + TQString addr = devImpl->getAddress(error); + TQString name = devImpl->getAlias(error); + delete devImpl; + PinDialog *pinDialog = new PinDialog(addr, name); + pinDialog->pinDlg->pinEdit->setText(TQString("%1").arg(passkey)); + pinDialog->pinDlg->pinEdit->setEnabled(false); + KDialogBase::centerOnScreen(pinDialog); + pinDialog->setActiveWindow(); + pinDialog->show(); + pinDialog->raise(); + + if (pinDialog->exec() == TQDialog::Accepted) + DisplayPasskeyAsyncReply(asyncCallId); + else + DisplayPasskeyAsyncError(asyncCallId, TQT_DBusError::stdFailed("Request not accepted")); + delete pinDialog; +} + +void Agent1InterfaceImpl::RequestConfirmationAsync(int asyncCallId, const TQT_DBusObjectPath& device, TQ_UINT32 passkey) +{ + TQT_DBusError error; + TDEBluetooth::DeviceImpl *devImpl = new TDEBluetooth::DeviceImpl("org.bluez", device); + devImpl->setConnection((*m_connection)); + TQString addr = devImpl->getAddress(error); + TQString name = devImpl->getAlias(error); + delete devImpl; + PinDialog *pinDialog = new PinDialog(addr, name); + pinDialog->pinDlg->pinEdit->setText(TQString("%3").arg(passkey)); + pinDialog->pinDlg->pinEdit->setEnabled(false); + KDialogBase::centerOnScreen(pinDialog); + pinDialog->setActiveWindow(); + pinDialog->show(); + pinDialog->raise(); + + if (pinDialog->exec() == TQDialog::Accepted) + RequestConfirmationAsyncReply(asyncCallId); + else + RequestConfirmationAsyncError(asyncCallId, TQT_DBusError::stdFailed("Request not accepted")); + delete pinDialog; +} + +void Agent1InterfaceImpl::RequestAuthorizationAsync(int asyncCallId, const TQT_DBusObjectPath& device) +{ + TQT_DBusError error; + TDEBluetooth::DeviceImpl *devImpl = new TDEBluetooth::DeviceImpl("org.bluez", device); + devImpl->setConnection((*m_connection)); + TQString addr = devImpl->getAddress(error); + TQString name = devImpl->getAlias(error); + delete devImpl; + AuthorizeDialog *authDialog = new AuthorizeDialog(addr, name, TQString()); + KDialogBase::centerOnScreen(authDialog); + authDialog->setActiveWindow(); + authDialog->show(); + authDialog->raise(); + + if (authDialog->exec() == TQDialog::Accepted) + RequestAuthorizationAsyncReply(asyncCallId); + else + RequestAuthorizationAsyncError(asyncCallId, TQT_DBusError::stdFailed("Request not authorized")); + delete authDialog; +} + +void Agent1InterfaceImpl::AuthorizeServiceAsync(int asyncCallId, const TQT_DBusObjectPath& device, const TQString& uuid) +{ + kdDebug() << __func__ << "()" << endl; + + TQT_DBusError error; + TDEBluetooth::DeviceImpl *devImpl = new TDEBluetooth::DeviceImpl("org.bluez", device); + devImpl->setConnection((*m_connection)); + TQString addr = devImpl->getAddress(error); + TQString name = devImpl->getAlias(error); + delete devImpl; + AuthorizeDialog *authDialog = new AuthorizeDialog(addr, name, resolveUUID(uuid)); + KDialogBase::centerOnScreen(authDialog); + authDialog->setActiveWindow(); + authDialog->show(); + authDialog->raise(); + + if (authDialog->exec() == TQDialog::Accepted) + AuthorizeServiceAsyncReply(asyncCallId); + else + AuthorizeServiceAsyncError(asyncCallId, TQT_DBusError::stdFailed("Request not accepted")); + delete authDialog; +} + +bool Agent1InterfaceImpl::Cancel(TQT_DBusError& error) +{ + kdDebug() << __func__ << "()" << endl; + + // do something + return true; +} + +RootNodeService::RootNodeService(TQT_DBusConnection &connection) : + DBusBaseNode(), m_connection(connection) +{ + addChildNode("org"); + registerObject(m_connection, "/"); +} + +RootNodeService::~RootNodeService() +{ +} + +TQT_DBusObjectBase* RootNodeService::createInterface(const TQString& interfaceName) +{ + return (TQT_DBusObjectBase*) m_interfaces[interfaceName]; +} + +OrgNodeService::OrgNodeService(TQT_DBusConnection &connection) : + DBusBaseNode(), m_connection(connection) +{ + addChildNode("trinitydesktop"); + registerObject(m_connection, "/org"); +} + +OrgNodeService::~OrgNodeService() +{ +} + +TQT_DBusObjectBase* OrgNodeService::createInterface(const TQString& interfaceName) +{ + return (TQT_DBusObjectBase*) m_interfaces[interfaceName]; +} + +TrinityDekstopNodeService::TrinityDekstopNodeService(TQT_DBusConnection &connection) : + DBusBaseNode(), m_connection(connection) +{ + addChildNode("tdebluez"); + registerObject(m_connection, "/org/trinitydesktop"); +} + +TrinityDekstopNodeService::~TrinityDekstopNodeService() +{ +} + +TQT_DBusObjectBase* TrinityDekstopNodeService::createInterface(const TQString& interfaceName) +{ + return (TQT_DBusObjectBase*) m_interfaces[interfaceName]; +} + +AuthService::AuthService(TQT_DBusConnection &conn) : + org::trinitydesktop::tdebluezNode(), m_connection(conn) +{ + m_interfaces.insert("org.freedesktop.DBus.Introspectable", this); + m_interfaces.insert("org.bluez.Agent1", new Agent1InterfaceImpl(m_connection)); + registerObject(m_connection, DBUS_AUTH_SERVICE_PATH); +} + +AuthService::~AuthService() +{ +} + +TQT_DBusObjectBase* AuthService::createInterface(const TQString& interfaceName) +{ + return (TQT_DBusObjectBase*) m_interfaces[interfaceName]; +} diff --git a/src/tdebluezauth/authservice.h b/src/tdebluezauth/authservice.h new file mode 100644 index 0000000..187d4a0 --- /dev/null +++ b/src/tdebluezauth/authservice.h @@ -0,0 +1,230 @@ +/* + * + * Authorization Agent implementation of bluez5 + * + * Copyright (C) 2018 Emanoil Kotsev <deloptes@gmail.com> + * + * + * This file is part of tdebluezauth. + * + * tdebluezauth is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * tdebluezauth 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with kbluetooth; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ +#ifndef AGENTIMPL_H +#define AGENTIMPL_H + +#include <tqdbusconnection.h> + +#include <interfaces/agent1Interface.h> +#include <interfaces/tdebluezNode.h> +#include <interfaces/dbusbaseNode.h> + +class Agent1InterfaceImpl : public org::bluez::Agent1Interface +{ + +public: + Agent1InterfaceImpl(TQT_DBusConnection&); + virtual ~Agent1InterfaceImpl(); +protected: + /** + * void Release() + * This method gets called when the service daemon + * unregisters the agent. An agent can use it to do + * cleanup tasks. There is no need to unregister the + * agent, because when this method gets called it has + * already been unregistered. + */ + virtual bool Release(TQT_DBusError& error); + /** + * string RequestPinCode(object device) + * + * This method gets called when the service daemon + * needs to get the passkey for an authentication. + * + * The return value should be a string of 1-16 characters + * length. The string can be alphanumeric. + * + * Possible errors: org.bluez.Error.Rejected + * org.bluez.Error.Canceled + */ + virtual void RequestPinCodeAsync(int asyncCallId, const TQT_DBusObjectPath& device); + /** + * void DisplayPinCode(object device, string pincode) + + This method gets called when the service daemon + needs to display a pincode for an authentication. + + An empty reply should be returned. When the pincode + needs no longer to be displayed, the Cancel method + of the agent will be called. + + This is used during the pairing process of keyboards + that don't support Bluetooth 2.1 Secure Simple Pairing, + in contrast to DisplayPasskey which is used for those + that do. + + This method will only ever be called once since + older keyboards do not support typing notification. + + Note that the PIN will always be a 6-digit number, + zero-padded to 6 digits. This is for harmony with + the later specification. + + Possible errors: org.bluez.Error.Rejected + org.bluez.Error.Canceled + */ + virtual void DisplayPinCodeAsync(int asyncCallId, const TQT_DBusObjectPath& device, const TQString& pincode); + /** + * uint32 RequestPasskey(object device) + + This method gets called when the service daemon + needs to get the passkey for an authentication. + + The return value should be a numeric value + between 0-999999. + + Possible errors: org.bluez.Error.Rejected + org.bluez.Error.Canceled + */ + virtual void RequestPasskeyAsync(int asyncCallId, const TQT_DBusObjectPath& device); + /** + * void DisplayPasskey(object device, uint32 passkey, + uint16 entered) + + This method gets called when the service daemon + needs to display a passkey for an authentication. + + The entered parameter indicates the number of already + typed keys on the remote side. + + An empty reply should be returned. When the passkey + needs no longer to be displayed, the Cancel method + of the agent will be called. + + During the pairing process this method might be + called multiple times to update the entered value. + + Note that the passkey will always be a 6-digit number, + so the display should be zero-padded at the start if + the value contains less than 6 digits. + */ + virtual void DisplayPasskeyAsync(int asyncCallId, const TQT_DBusObjectPath& device, TQ_UINT32 passkey, TQ_UINT16 entered); + /** + * void RequestConfirmation(object device, uint32 passkey) + + This method gets called when the service daemon + needs to confirm a passkey for an authentication. + + To confirm the value it should return an empty reply + or an error in case the passkey is invalid. + + Note that the passkey will always be a 6-digit number, + so the display should be zero-padded at the start if + the value contains less than 6 digits. + + Possible errors: org.bluez.Error.Rejected + org.bluez.Error.Canceled + */ + virtual void RequestConfirmationAsync(int asyncCallId, const TQT_DBusObjectPath& device, TQ_UINT32 passkey); + /** + * void RequestAuthorization(object device) + + This method gets called to request the user to + authorize an incoming pairing attempt which + would in other circumstances trigger the just-works + model, or when the user plugged in a device that + implements cable pairing. In the latter case, the + device would not be connected to the adapter via + Bluetooth yet. + + Possible errors: org.bluez.Error.Rejected + org.bluez.Error.Canceled + */ + virtual void RequestAuthorizationAsync(int asyncCallId, const TQT_DBusObjectPath& device); + /** + * void AuthorizeService(object device, string uuid) + + This method gets called when the service daemon + needs to authorize a connection/service request. + + Possible errors: org.bluez.Error.Rejected + org.bluez.Error.Canceled + */ + virtual void AuthorizeServiceAsync(int asyncCallId, const TQT_DBusObjectPath& device, const TQString& uuid); + /** + * void Cancel() + + This method gets called to indicate that the agent + request failed before a reply was returned. + */ + virtual bool Cancel(TQT_DBusError& error); + + virtual void handleMethodReply(const TQT_DBusMessage& reply); + +private: + TQT_DBusConnection *m_connection; +}; + +class AuthService: public org::trinitydesktop::tdebluezNode +{ +public: + AuthService(TQT_DBusConnection&); + ~AuthService(); + +protected: + virtual TQT_DBusObjectBase* createInterface(const TQString&); + +private: + TQMap<TQString, TQT_DBusObjectBase*> m_interfaces; + TQT_DBusConnection m_connection; +}; + +class RootNodeService: public DBusBaseNode +{ +public: + RootNodeService(TQT_DBusConnection&); + ~RootNodeService(); +protected: + virtual TQT_DBusObjectBase* createInterface(const TQString&); +private: + TQMap<TQString, TQT_DBusObjectBase*> m_interfaces; + TQT_DBusConnection m_connection; +}; + +class OrgNodeService: public DBusBaseNode +{ +public: + OrgNodeService(TQT_DBusConnection&); + ~OrgNodeService(); +protected: + virtual TQT_DBusObjectBase* createInterface(const TQString&); +private: + TQMap<TQString, TQT_DBusObjectBase*> m_interfaces; + TQT_DBusConnection m_connection; +}; + +class TrinityDekstopNodeService: public DBusBaseNode +{ +public: + TrinityDekstopNodeService(TQT_DBusConnection&); + ~TrinityDekstopNodeService(); +protected: + virtual TQT_DBusObjectBase* createInterface(const TQString&); +private: + TQMap<TQString, TQT_DBusObjectBase*> m_interfaces; + TQT_DBusConnection m_connection; +}; + +#endif // AGENTIMPL_H diff --git a/src/tdebluezauth/main.cpp b/src/tdebluezauth/main.cpp new file mode 100644 index 0000000..98ca19e --- /dev/null +++ b/src/tdebluezauth/main.cpp @@ -0,0 +1,77 @@ +/* + * + * Adapter config dialog for tdebluez authentication + * + * Copyright (C) 2018 Emanoil Kotsev <deloptes@gmail.com> + * + * + * This file is part of tdebluezauth. + * + * tdebluezauth is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * tdebluezauth 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with kbluetooth; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + + +#include <tdecmdlineargs.h> +#include <tdeaboutdata.h> +#include <tdemessagebox.h> +#include <kuniqueapplication.h> +#include <iostream> + +#include "application.h" + +static const char *description = I18N_NOOP("TDEBluezAuth"); +static const char *copy = I18N_NOOP("Copyright (C) 2018 Emanoil."); + +static TDECmdLineOptions options[] = +{ + { 0, 0, 0 } +}; + +int main(int argc, char *argv[]) +{ + TDELocale::setMainCatalogue("tdebluetooth"); + TDEAboutData aboutData("tdebluezauth", + I18N_NOOP("TDEBluezAuth"), + 0, + description, TDEAboutData::License_GPL, + copy,0, "http://trinitydesktop.org"); + aboutData.addAuthor("Tom Patzig", I18N_NOOP("Author"), "tpatzig@suse.de"); + aboutData.addAuthor("Emanoil Kotsev", I18N_NOOP("Bluez5 and port to TDE"), "deloptes@gmail.com"); + TDECmdLineArgs::init( argc, argv, &aboutData ); + TDECmdLineArgs::addCmdLineOptions( options ); + KUniqueApplication::addCmdLineOptions(); + + if (!KUniqueApplication::start()) + { + std::cerr << i18n("TDEBluezAuth is already running.\n").local8Bit(); + return 0; + } + + TDEBluezAuth a; + + if (!a.isConnectedToDBUS()) + { + KMessageBox::error(NULL,i18n("Can't connect to DBus!\nUnable to start tdebluezauth. \n\n \ + Restart dbus and the bluetooth service")); + KUniqueApplication::kApplication()->quit(); + return -1; + } + else + { + return a.exec(); + } + +} diff --git a/src/tdebluezauth/pindefdialog.ui b/src/tdebluezauth/pindefdialog.ui new file mode 100644 index 0000000..4ebc8d4 --- /dev/null +++ b/src/tdebluezauth/pindefdialog.ui @@ -0,0 +1,87 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>PinDefaultDialog</class> +<widget class="TQWidget"> + <property name="name"> + <cstring>PinDefaultDialog</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>738</width> + <height>300</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>400</width> + <height>300</height> + </size> + </property> + <property name="caption"> + <string>PinDefaultDialog</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="TQLabel"> + <property name="name"> + <cstring>messageLabel</cstring> + </property> + <property name="text"> + <string><font size="+2">Bluetooth Pairing Request</font> +<p><b>%1</b> (device address <b>%2</b>) wants to pair with your +Bluetooth device, which is needed for authenticated and secure connections. +</p><p> +If you are sure about the identity of the other party, then please enter +the same PIN below as was used by the other device.</p></string> + </property> + </widget> + <widget class="TQLayoutWidget"> + <property name="name"> + <cstring>layout3</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="TQLineEdit"> + <property name="name"> + <cstring>pinEdit</cstring> + </property> + <property name="enabled"> + <bool>true</bool> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>spacer2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>197</width> + <height>20</height> + </size> + </property> + </spacer> + </hbox> + </widget> + </vbox> +</widget> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/src/tdebluezauth/pindefdialog2.ui b/src/tdebluezauth/pindefdialog2.ui new file mode 100644 index 0000000..4ebc8d4 --- /dev/null +++ b/src/tdebluezauth/pindefdialog2.ui @@ -0,0 +1,87 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>PinDefaultDialog</class> +<widget class="TQWidget"> + <property name="name"> + <cstring>PinDefaultDialog</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>738</width> + <height>300</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>400</width> + <height>300</height> + </size> + </property> + <property name="caption"> + <string>PinDefaultDialog</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="TQLabel"> + <property name="name"> + <cstring>messageLabel</cstring> + </property> + <property name="text"> + <string><font size="+2">Bluetooth Pairing Request</font> +<p><b>%1</b> (device address <b>%2</b>) wants to pair with your +Bluetooth device, which is needed for authenticated and secure connections. +</p><p> +If you are sure about the identity of the other party, then please enter +the same PIN below as was used by the other device.</p></string> + </property> + </widget> + <widget class="TQLayoutWidget"> + <property name="name"> + <cstring>layout3</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="TQLineEdit"> + <property name="name"> + <cstring>pinEdit</cstring> + </property> + <property name="enabled"> + <bool>true</bool> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>spacer2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>197</width> + <height>20</height> + </size> + </property> + </spacer> + </hbox> + </widget> + </vbox> +</widget> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/src/tdebluezauth/pindialog.cpp b/src/tdebluezauth/pindialog.cpp new file mode 100644 index 0000000..7f31b89 --- /dev/null +++ b/src/tdebluezauth/pindialog.cpp @@ -0,0 +1,58 @@ +/* + * + * PIN Dialog dialog for tdebluez authentication + * + * Copyright (C) 2018 Emanoil Kotsev <deloptes@gmail.com> + * + * + * This file is part of tdebluezauth. + * + * tdebluezauth is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * tdebluezauth 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with kbluetooth; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include "pindialog.h" +#include "pindefdialog.h" + +PinDialog::PinDialog(const TQString &addr, const TQString &devName) : + KDialogBase(NULL, "pinrequest", true, "Pin Request", (Ok | Cancel)) +{ + + pinDlg = new PinDefaultDialog(this); + pinDlg->messageLabel->setText(pinDlg->messageLabel->text().arg(devName).arg(addr)); + + pinDlg->pinEdit->setFocus(); + + connect(this, TQT_SIGNAL(okClicked()), TQT_SLOT(setPin())); + + setMainWidget(pinDlg); +} + +PinDialog::~PinDialog() +{ + delete pinDlg; +} + +void PinDialog::setPin() +{ + pin = pinDlg->pinEdit->text(); +} + +const TQString PinDialog::getPin() +{ + return pin; +} + +#include "pindialog.moc" diff --git a/src/tdebluezauth/pindialog.h b/src/tdebluezauth/pindialog.h new file mode 100644 index 0000000..f99fd1f --- /dev/null +++ b/src/tdebluezauth/pindialog.h @@ -0,0 +1,58 @@ +/* + * + * PIN Dialog dialog for tdebluez authentication + * + * Copyright (C) 2018 Emanoil Kotsev <deloptes@gmail.com> + * + * + * This file is part of tdebluezauth. + * + * tdebluezauth is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * tdebluezauth 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with kbluetooth; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef PINDIALOG_H +#define PINDIALOG_H + +#include <tqlineedit.h> +#include <tqlabel.h> +#include <kdialogbase.h> +#include "application.h" +#include "pindefdialog.h" + +/** +@author Fred Schaettgen + */ + +class PinDialog : public KDialogBase +{ + + Q_OBJECT + +public: + PinDialog(const TQString &addr, const TQString &devName); + ~PinDialog(); + PinDefaultDialog *pinDlg; + const TQString getPin(); + +private: + TQString pin; + +private slots: + void setPin(); + +}; + +#endif diff --git a/src/tdebluezauth/tdebluezauth.desktop b/src/tdebluezauth/tdebluezauth.desktop new file mode 100644 index 0000000..efdeaf4 --- /dev/null +++ b/src/tdebluezauth/tdebluezauth.desktop @@ -0,0 +1,36 @@ +[Desktop Entry] +Encoding=UTF-8 +Exec=tdebluezauth +Icon=tdebluez +Type=Application +Name=tdebluezauth +GenericName=Bluetooth Wizard +GenericName[de]=Bluetooth-Assistent +GenericName[es]=Asistente de bluetooth +GenericName[et]=Bluetoothi nõustaja +GenericName[it]=Assistente per Bluetooth +GenericName[ja]=Bluetooth ウィザード +GenericName[nl]=Bluetooth-assistent +GenericName[pt]=Assistente de Bluetooth +GenericName[pt_BR]=Assistente de Bluetooth +GenericName[sr]=Bluetooth чаробњак +GenericName[sr@Latn]=Bluetooth čarobnjak +GenericName[sv]=Blåtandsguide +GenericName[tg]=Устоди Bluetooth +GenericName[tr]=Bluetooth Sihirbazı +GenericName[xx]=xxBluetooth Wizardxx +Categories=Qt;TDE;System;Monitor; +Comment=TDE Bluetooth Wizard +Comment[de]=TDE Bluetooth-Assistent +Comment[es]=Asistente de bluetooth para TDE +Comment[et]=TDE Bluetoothi nõustaja +Comment[it]=Assistente per Bluetooth di TDE +Comment[ja]=TDE Bluetooth ウィザード +Comment[nl]=TDE Bluetooth-assistent +Comment[pt]=Assistente de Bluetooth do TDE +Comment[pt_BR]=Assistente de Bluetooth do TDE +Comment[sr]=TDE чаробњак за Bluetooth +Comment[sr@Latn]=TDE čarobnjak za Bluetooth +Comment[sv]=TDE:s Blåtandsguide +Comment[tg]=Устоди TDE Bluetooth +Comment[tr]=TDE Bluetooth Sihirbazı |