changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: wpa: fix password avp padding, recognize wpa1 authentication oui

changeset 4230: 772adc4423b0
parent 4229: 1afc89787f72
child 4231: 5cc0ae0ee525
author: cinap_lenrek@felloff.net
date: Tue, 27 Jan 2015 14:09:24 +0100
files: sys/src/cmd/aux/wpa.c
description: wpa: fix password avp padding, recognize wpa1 authentication oui

we have to padd the data portion in the password avp,
not add padding after the avp.
     1.1--- a/sys/src/cmd/aux/wpa.c
     1.2+++ b/sys/src/cmd/aux/wpa.c
     1.3@@ -117,6 +117,7 @@ uchar	rsnie[] = {
     1.4 uchar wpa1oui[4]    = {0x00, 0x50, 0xF2, 0x01};
     1.5 uchar wpatkipoui[4] = {0x00, 0x50, 0xF2, 0x02};
     1.6 uchar wpaapskoui[4] = {0x00, 0x50, 0xF2, 0x02};
     1.7+uchar wpaawpaoui[4] = {0x00, 0x50, 0xF2, 0x01};
     1.8 
     1.9 uchar	wpaie[] = {
    1.10 	0xdd,			/* vendor specific */
    1.11@@ -352,8 +353,14 @@ trunc:		sysfatal("invalid or truncated R
    1.12 				break;
    1.13 			}
    1.14 		} else {
    1.15+			/* look for PSK oui */
    1.16 			if(memcmp(p, wpaapskoui, 4) == 0)
    1.17 				break;
    1.18+			/* look for WPA oui */
    1.19+			if(memcmp(p, wpaawpaoui, 4) == 0){
    1.20+				ispsk = 0;
    1.21+				break;
    1.22+			}
    1.23 		}
    1.24 		p += 4;
    1.25 	}
    1.26@@ -1054,23 +1061,21 @@ eapreq(Eapconn *conn, int code, int id, 
    1.27 int
    1.28 avp(uchar *p, int n, int code, void *val, int len, int pad)
    1.29 {
    1.30-	len += 8;
    1.31-	if(len > n){
    1.32-		len = n - 8;
    1.33-		pad = 0;
    1.34-	}
    1.35+	pad = 8 + ((len + pad) & ~pad);	/* header + data + data pad */
    1.36+	assert(((pad + 3) & ~3) <= n);
    1.37 	p[0] = code >> 24;
    1.38 	p[1] = code >> 16;
    1.39 	p[2] = code >> 8;
    1.40 	p[3] = code;
    1.41 	p[4] = 2;
    1.42-	p[5] = len >> 16;
    1.43-	p[6] = len >> 8;
    1.44-	p[7] = len;
    1.45-	memmove(p+8, val, len-8);
    1.46-	n = (len + pad) & ~pad;
    1.47-	memset(p + len, 0, n - len);
    1.48-	return n;
    1.49+	p[5] = pad >> 16;
    1.50+	p[6] = pad >> 8;
    1.51+	p[7] = pad;
    1.52+	memmove(p+8, val, len);
    1.53+	len += 8;
    1.54+	pad = (pad + 3) & ~3;	/* packet padding */
    1.55+	memset(p+len, 0, pad - len);
    1.56+	return pad;
    1.57 }
    1.58 
    1.59 enum {
    1.60@@ -1091,7 +1096,7 @@ ttlsclient(int fd)
    1.61 	fd = tlswrap(fd, "ttls keying material");
    1.62 	if((up = auth_getuserpasswd(nil, "proto=pass service=wpa essid=%q", essid)) == nil)
    1.63 		sysfatal("auth_getuserpasswd: %r");
    1.64-	n = avp(buf, sizeof(buf), AvpUserName, up->user, strlen(up->user), 3);
    1.65+	n = avp(buf, sizeof(buf), AvpUserName, up->user, strlen(up->user), 0);
    1.66 	n += avp(buf+n, sizeof(buf)-n, AvpUserPass, up->passwd, strlen(up->passwd), 15);
    1.67 	freeup(up);
    1.68 	write(fd, buf, n);