SolidModules
NetworkManager-dbushelper.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "NetworkManager-dbushelper.h"
00021
00022 #include <stdlib.h>
00023
00024
00025
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
00077
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
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
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
00108 *error = true;
00109 }
00110 else
00111
00112 *error = true;
00113 if (!(*error))
00114 {
00115
00116 int we_cipher = ieee_802_11_cipher_get_we_cipher(cipher);
00117 args << QVariant(we_cipher);
00118
00119
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
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
00148
00149
00150
00151
00152
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
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
00187 int we_cipher = ieee_802_11_cipher_get_we_cipher(cipher);
00188 args << QVariant(we_cipher);
00189
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
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
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
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
00242 args << NM_AUTH_TYPE_WPA_PSK_AUTO;
00243
00244 args << auth->identity();
00245
00246 args << auth->idPasswordKey();
00247
00248 args << auth->anonIdentity();
00249
00250 args << auth->certPrivatePasswordKey();
00251
00252 args << auth->certPrivate();
00253
00254 args << auth->certClient();
00255
00256 args << auth->certCA();
00257
00258 args << auth->version();
00259 return QList<QVariant>();
00260 }