• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

SolidModules

NetworkManager-dbushelper.cpp

Go to the documentation of this file.
00001 /*  This file is part of the KDE project
00002     Copyright (C) 2007 Will Stephenson <wstephenson@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License version 2 as published by the Free Software Foundation.
00007 
00008     This library is distributed in the hope that it will be useful,
00009     but WITHOUT ANY WARRANTY; without even the implied warranty of
00010     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011     Library General Public License for more details.
00012 
00013     You should have received a copy of the GNU Library General Public License
00014     along with this library; see the file COPYING.LIB.  If not, write to
00015     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016     Boston, MA 02110-1301, USA.
00017 
00018 */
00019 
00020 #include "NetworkManager-dbushelper.h"
00021 
00022 #include <stdlib.h>
00023 //#include <wireless.h>
00024 // stuff copied from wireless.h so we don't have to include it.
00025 // take aim at foot, prepare to fire
00026 #define IW_AUTH_ALG_OPEN_SYSTEM 0x00000001
00027 #define IW_AUTH_ALG_SHARED_KEY  0x00000002
00028 #define IW_AUTH_WPA_VERSION_WPA         0x00000002
00029 #define IW_AUTH_WPA_VERSION_WPA2        0x00000004
00030 #define IW_AUTH_KEY_MGMT_802_1X 1
00031 #define IW_AUTH_KEY_MGMT_PSK    2
00032 #define IW_AUTH_CIPHER_NONE 0x00000001
00033 
00034 #include <NetworkManager/NetworkManager.h>
00035 #include <NetworkManager/cipher.h>
00036 #include <NetworkManager/cipher-wep-ascii.h>
00037 #include <NetworkManager/cipher-wep-hex.h>
00038 #include <NetworkManager/cipher-wep-passphrase.h>
00039 #include <NetworkManager/cipher-wpa-psk-hex.h>
00040 #include <NetworkManager/cipher-wpa-psk-passphrase.h>
00041 #include <QtDBus>
00042 
00043 #include <kdebug.h>
00044 #include <solid/control/ifaces/authentication.h>
00045 
00046 QList<QVariant> NMDBusHelper::serialize(Solid::Control::Authentication * auth, const QString  & essid, QList<QVariant>  & args, bool * error)
00047 {
00048     if (auth)
00049     {
00050         Solid::Control::AuthenticationNone * none = dynamic_cast<Solid::Control::AuthenticationNone *>(auth) ;
00051         if (none)
00052             return doSerialize(none, essid, args, error);
00053         Solid::Control::AuthenticationWep * wep = dynamic_cast<Solid::Control::AuthenticationWep *>(auth) ;
00054         if (wep)
00055             return doSerialize(wep, essid, args, error);
00056         Solid::Control::AuthenticationWpaPersonal * wpap = dynamic_cast<Solid::Control::AuthenticationWpaPersonal *>(auth) ;
00057         if (wpap)
00058             return doSerialize(wpap, essid, args, error);
00059         Solid::Control::AuthenticationWpaEnterprise * wpae = dynamic_cast<Solid::Control::AuthenticationWpaEnterprise *>(auth);
00060         if (wpae)
00061             return doSerialize(wpae, essid, args, error);
00062     }
00063     *error = true;
00064     return QList<QVariant>();
00065 }
00066 
00067 QList<QVariant> NMDBusHelper::doSerialize(Solid::Control::AuthenticationNone * none, const QString  & essid, QList<QVariant>  & args, bool * error)
00068 {
00069     *error = false;
00070     args << QVariant(IW_AUTH_CIPHER_NONE);
00071     return args;
00072 }
00073 
00074 QList<QVariant> NMDBusHelper::doSerialize(Solid::Control::AuthenticationWep * auth, const QString  & essid, QList<QVariant>  & args, bool * error)
00075 {
00076     // get correct cipher
00077     // what's the algorithm for deciding the right cipher to use?
00078     *error = false;
00079     IEEE_802_11_Cipher * cipher = 0;
00080     if (auth->type() == Solid::Control::AuthenticationWep::WepAscii)
00081     {
00082         if (auth->keyLength() == 40 || auth->keyLength() == 64)
00083             cipher = cipher_wep64_ascii_new();
00084         else if (auth->keyLength() == 104 || auth->keyLength() == 128)
00085             cipher = cipher_wep128_ascii_new();
00086         else
00087             //NM only supports these 2 key lengths, flag an error!
00088             *error = true;
00089     }
00090     else if (auth->type() == Solid::Control::AuthenticationWep::WepHex)
00091     {
00092         if (auth->keyLength() == 40 || auth->keyLength() == 64)
00093             cipher = cipher_wep64_hex_new();
00094         else if (auth->keyLength() == 104 || auth->keyLength() == 128)
00095             cipher = cipher_wep128_hex_new();
00096         else
00097             //NM only supports these 2 key lengths, flag an error!
00098             *error = true;
00099     }
00100     else if (auth->type() == Solid::Control::AuthenticationWep::WepPassphrase)
00101     {
00102         if (auth->keyLength() == 40 || auth->keyLength() == 64)
00103             cipher = cipher_wep64_passphrase_new();
00104         else if (auth->keyLength() == 104 || auth->keyLength() == 128)
00105             cipher = cipher_wep128_passphrase_new();
00106         else
00107             //NM only supports these 2 key lengths, flag an error!
00108             *error = true;
00109     }
00110     else
00111         // unrecognised auth type, error!
00112         *error = true;
00113     if (!(*error))
00114     {
00115         // int32 cipher
00116         int we_cipher = ieee_802_11_cipher_get_we_cipher(cipher);
00117         args << QVariant(we_cipher);
00118         // s key
00119         //   cipher, essid, key
00120         char * rawHashedKey = 0;
00121         rawHashedKey = ieee_802_11_cipher_hash(cipher, essid.toUtf8(), auth->secrets()["key"].toUtf8());
00122         QString hashedKey = QString::fromAscii(rawHashedKey);
00123         free(rawHashedKey);
00124         args << QVariant(hashedKey);
00125         // int32 auth alg
00126         if (auth->method() == Solid::Control::AuthenticationWep::WepOpenSystem)
00127             args << QVariant(IW_AUTH_ALG_OPEN_SYSTEM);
00128         else
00129             args << QVariant(IW_AUTH_ALG_SHARED_KEY);
00130     }
00131     if (cipher)
00132         kDebug(1441) << "FIXME: delete cipher object";
00133 
00134     return args;
00135 }
00136 
00137 QList<QVariant> NMDBusHelper::doSerialize(Solid::Control::AuthenticationWpaPersonal * auth, const QString  & essid, QList<QVariant>  & args, bool * error)
00138 {
00139     *error = false;
00140     IEEE_802_11_Cipher * cipher = 0;
00141     IEEE_802_11_Cipher * hexCipher = 0;
00142     IEEE_802_11_Cipher * ppCipher = 0;
00143     hexCipher = cipher_wpa_psk_hex_new();
00144     ppCipher = cipher_wpa_psk_passphrase_new();
00145     QString rawKey = auth->secrets()["key"];
00146 
00147     // cipher identification algorithm
00148     // can be either hex or passphrase
00149     // we try both methods
00150 
00151     // cipher needs the cipher setting on it
00152     // which is the protocol
00153 
00154     switch (auth->protocol())
00155     {
00156     case Solid::Control::AuthenticationWpaPersonal::WpaTkip:
00157         cipher_wpa_psk_hex_set_we_cipher(hexCipher, NM_AUTH_TYPE_WPA_PSK_TKIP);
00158         cipher_wpa_psk_passphrase_set_we_cipher(ppCipher, NM_AUTH_TYPE_WPA_PSK_TKIP);
00159         break;
00160     case Solid::Control::AuthenticationWpaPersonal::WpaCcmpAes:
00161         cipher_wpa_psk_hex_set_we_cipher(hexCipher, NM_AUTH_TYPE_WPA_PSK_CCMP);
00162         cipher_wpa_psk_passphrase_set_we_cipher(ppCipher, NM_AUTH_TYPE_WPA_PSK_CCMP);
00163         break;
00164     case Solid::Control::AuthenticationWpaPersonal::WpaAuto:
00165     default:
00166         cipher_wpa_psk_hex_set_we_cipher(hexCipher, NM_AUTH_TYPE_WPA_PSK_AUTO);
00167         cipher_wpa_psk_passphrase_set_we_cipher(ppCipher, NM_AUTH_TYPE_WPA_PSK_AUTO);
00168         break;
00169     }
00170     // now try both ciphers on the raw key
00171     if (ieee_802_11_cipher_validate(hexCipher, essid.toUtf8(), rawKey.toUtf8()) == 0)
00172     {
00173         kDebug() << "HEX";
00174         cipher = hexCipher;
00175     }
00176     else if (ieee_802_11_cipher_validate(ppCipher, essid.toUtf8(), rawKey.toUtf8()) == 0)
00177     {
00178         kDebug() << "PP";
00179         cipher = ppCipher;
00180     }
00181     else
00182         *error = true;
00183 
00184     if (!(*error))
00185     {
00186         // int32 cipher
00187         int we_cipher = ieee_802_11_cipher_get_we_cipher(cipher);
00188         args << QVariant(we_cipher);
00189         // s key
00190         char * rawHashedKey = 0;
00191         rawHashedKey = ieee_802_11_cipher_hash(cipher, essid.toUtf8(), rawKey.toUtf8());
00192         QString hashedKey = QString::fromAscii(rawHashedKey);
00193         free(rawHashedKey);
00194         args << QVariant(hashedKey);
00195         // int32 wpa version
00196         if (auth->version() == Solid::Control::AuthenticationWpaPersonal::Wpa1)
00197             args << QVariant(IW_AUTH_WPA_VERSION_WPA);
00198         else
00199             args << QVariant(IW_AUTH_WPA_VERSION_WPA2);
00200         // int32 key management
00201         if (auth->keyManagement() == Solid::Control::AuthenticationWpaPersonal::WpaPsk)
00202             args << QVariant(IW_AUTH_KEY_MGMT_PSK);
00203         else
00204             args << QVariant(IW_AUTH_KEY_MGMT_802_1X);
00205         kDebug(1411) << "Outbound args are: " << args;
00206     }
00207     return args;
00208 }
00209 
00210 QList<QVariant> NMDBusHelper::doSerialize(Solid::Control::AuthenticationWpaEnterprise * auth, const QString  & essid, QList<QVariant>  & args, bool * error)
00211 {
00212     Q_UNUSED(essid)
00213     Q_UNUSED(error)
00214     kDebug() << "Implement me!";
00215     // int32 cipher, always NM_AUTH_TYPE_WPA_EAP
00216     args << NM_AUTH_TYPE_WPA_EAP;
00217     switch (auth->method())
00218     {
00219     case Solid::Control::AuthenticationWpaEnterprise::EapPeap:
00220         args << NM_EAP_METHOD_PEAP;
00221         break;
00222     case Solid::Control::AuthenticationWpaEnterprise::EapTls:
00223         args << NM_EAP_METHOD_TLS;
00224         break;
00225     case Solid::Control::AuthenticationWpaEnterprise::EapTtls :
00226         args << NM_EAP_METHOD_TTLS;
00227         break;
00228     case Solid::Control::AuthenticationWpaEnterprise::EapMd5:
00229         args << NM_EAP_METHOD_MD5;
00230         break;
00231     case Solid::Control::AuthenticationWpaEnterprise::EapMsChap:
00232         args << NM_EAP_METHOD_MSCHAP;
00233         break;
00234     case Solid::Control::AuthenticationWpaEnterprise::EapOtp:
00235         args << NM_EAP_METHOD_OTP;
00236         break;
00237     case Solid::Control::AuthenticationWpaEnterprise::EapGtc:
00238         args << NM_EAP_METHOD_GTC;
00239         break;
00240     }
00241     // int32 key type
00242     args << NM_AUTH_TYPE_WPA_PSK_AUTO;
00243     // s identity
00244     args << auth->identity();
00245     // s password
00246     args << auth->idPasswordKey();
00247     // s anon identity
00248     args << auth->anonIdentity();
00249     // s priv key password
00250     args << auth->certPrivatePasswordKey();
00251     // s priv key file
00252     args << auth->certPrivate();
00253     // s client cert file
00254     args << auth->certClient();
00255     // s ca cert file
00256     args << auth->certCA();
00257     // int32 wpa version => {IW_AUTH_WPA_VERSION_WPA,IW_AUTH_WPA_VERSION_WPA2}
00258     args << auth->version();
00259     return QList<QVariant>();
00260 }

SolidModules

Skip menu "SolidModules"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libplasma
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal