Connecting to WEP network via wpa_supplicant/dbus/python

Dan Williams dcbw
Tue Apr 28 07:41:48 PDT 2009


On Tue, 2009-04-28 at 21:25 +1000, James Rayner wrote:
> On Wed, Feb 18, 2009 at 2:19 AM, Dan Williams <dcbw at redhat.com> wrote:
> >
> > How is the key stored in 'profile'?  It's likely you're storing the key
> > as a hex string, right?  That's *not* actually the binary key.  To get
> > the actual binary key, you need to convert the key from hex string
> > representation to bytes.  For every two characters of the hex key,
> > convert that hex value to a byte value from 0 - 255 (ie, '1a' == 0x1a).
> > Thus, of course, the binary key will be 1/2 the size of the hexadecimal
> > key.
> >
> > Note that WPA-PSK keys can be sent as the passphrase, and the D-Bus
> > interface will quote them correctly.  But since WEP has no standard
> > passphrase -> key hashing mechanism, that's not really do-able for WEP.
> > Furthermore, for WEP, hex keys are actually acceptable passphrases.  So
> > the D-Bus interface takes the position that for WEP, since the key type
> > cannot be detected based on the input material, the caller must do the
> > hashing themselves, and pass the actual 5- or 13-byte WEP key to the
> > supplicant.
> >
> > Yeah, the D-Bus interface is somewhat ugly; I admit that.  I've got
> > vague, hand-wavy plans to fix it.
> >
> 
> Thanks!
> 
> Still having some slight problems getting the right syntax to pass.
> 
> I have a hex key of 017CF3C0EE
> I split that up, convert and I get
>  key=[1, 124, 243, 192, 238].
> 
> If I pass dbus a dbus.ByteArray(key), it errors:
>  "Did not receive correct message arguments"

looks like the dbus-python constructor for ByteArray assumes a string or
something there.  Doing that yields:

>>> k = [1, 124, 243, 192]
>>> p = dbus.ByteArray(k)
>>> p
dbus.ByteArray('[1, 124, 243, 192]')

which clearly isn't right; it's converting what you're passing is to a
string, which works great for the SSID (since you don't have any
non-ascii characters in it), but not for the WEP key, which is actually
binary data.  You'll want something like:

a = dbus.ByteArray()
for b in wepkey:
    a += chr(b)

ex - 

>>> k = [1, 124, 243, 192]
>>> k
[1, 124, 243, 192]
>>> a = dbus.ByteArray()
>>> for b in k:
...     a+=chr(b)
... 
>>> a
'\x01|\xf3\xc0'

which looks a bit better.

The vague hand-wavy plans also include introspection, which is why
you're having so much trouble.  dbus-python relies heavily on
introspection to figure out how to automatically convert arguments from
python (where variables are not strongly typed) to dbus (where they
are).  But since wpa_supplicant doesn't provide introspection data, this
falls down and you are required to explicitly cast in python, which is
ugly.  Fortunately, that wouldn't be too hard to fix in wpa_supplicant,
and would be backwards compatible while some new dbus API gets written.

Dan

> I also tried joining them as a string 001124243192238 however this did
> not associate.
> 
> The code is effectively the same as my original email, and the
> arguments passed are:
>   {"ssid":dbus.ByteArray("some essid"), "key_mgmt":
> dbus.String("NONE"), "wep_tx_idx": dbus.Int32(1 or 0, neither work),
> "wep_key0": ??? }
> 
> Thanks in advance.
> James




More information about the Hostap mailing list