wpa: do not prompt for key when there is already one in factotum
This commit is contained in:
parent
ed238e7ef8
commit
8799bf292d
1 changed files with 28 additions and 20 deletions
|
@ -481,7 +481,8 @@ setpmk(uchar pmk[PMKlen])
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
getptk( uchar smac[Eaddrlen], uchar amac[Eaddrlen],
|
getptk(AuthGetkey *getkey,
|
||||||
|
uchar smac[Eaddrlen], uchar amac[Eaddrlen],
|
||||||
uchar snonce[Noncelen], uchar anonce[Noncelen],
|
uchar snonce[Noncelen], uchar anonce[Noncelen],
|
||||||
uchar ptk[PTKlen])
|
uchar ptk[PTKlen])
|
||||||
{
|
{
|
||||||
|
@ -519,6 +520,14 @@ getptk( uchar smac[Eaddrlen], uchar amac[Eaddrlen],
|
||||||
memmove(ptk, rpc->arg, PTKlen);
|
memmove(ptk, rpc->arg, PTKlen);
|
||||||
ret = 0;
|
ret = 0;
|
||||||
out:
|
out:
|
||||||
|
if(getkey != nil){
|
||||||
|
switch(ret){
|
||||||
|
case ARneedkey:
|
||||||
|
case ARbadkey:
|
||||||
|
(*getkey)(rpc->arg);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
free(s);
|
free(s);
|
||||||
if(afd >= 0) close(afd);
|
if(afd >= 0) close(afd);
|
||||||
if(rpc != nil) auth_freerpc(rpc);
|
if(rpc != nil) auth_freerpc(rpc);
|
||||||
|
@ -1143,10 +1152,10 @@ usage(void)
|
||||||
void
|
void
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
uchar mac[Eaddrlen], buf[4096];
|
uchar mac[Eaddrlen], buf[4096], snonce[Noncelen], anonce[Noncelen];
|
||||||
static uchar brsne[258];
|
static uchar brsne[258];
|
||||||
static Eapconn conn;
|
static Eapconn conn;
|
||||||
char addr[128], *s;
|
char addr[128];
|
||||||
uchar *rsne;
|
uchar *rsne;
|
||||||
int rsnelen;
|
int rsnelen;
|
||||||
int n, try;
|
int n, try;
|
||||||
|
@ -1238,20 +1247,24 @@ Connect:
|
||||||
if(write(cfd, buf, n) != n)
|
if(write(cfd, buf, n) != n)
|
||||||
sysfatal("write auth: %r");
|
sysfatal("write auth: %r");
|
||||||
|
|
||||||
|
conn.fd = fd;
|
||||||
|
conn.write = eapwrite;
|
||||||
|
conn.type = 1; /* Start */
|
||||||
|
conn.version = 1;
|
||||||
|
memmove(conn.smac, mac, Eaddrlen);
|
||||||
|
getbssid(conn.amac);
|
||||||
|
|
||||||
if(prompt){
|
if(prompt){
|
||||||
prompt = 0;
|
prompt = 0;
|
||||||
if(ispsk){
|
if(ispsk){
|
||||||
s = smprint("proto=wpapsk essid=%q !password?", essid);
|
/* dummy to for factotum keyprompt */
|
||||||
auth_getkey(s);
|
genrandom(anonce, sizeof(anonce));
|
||||||
free(s);
|
genrandom(snonce, sizeof(snonce));
|
||||||
|
getptk(auth_getkey, conn.smac, conn.amac, snonce, anonce, ptk);
|
||||||
} else {
|
} else {
|
||||||
UserPasswd *up;
|
UserPasswd *up;
|
||||||
|
|
||||||
s = smprint("proto=pass service=wpa essid=%q user? !password?", essid);
|
if((up = auth_getuserpasswd(auth_getkey, "proto=pass service=wpa essid=%q", essid)) != nil){
|
||||||
auth_getkey(s);
|
|
||||||
free(s);
|
|
||||||
|
|
||||||
if((up = auth_getuserpasswd(nil, "proto=pass service=wpa essid=%q", essid)) != nil){
|
|
||||||
factotumctl("key proto=mschapv2 role=client service=wpa essid=%q user=%q !password=%q\n",
|
factotumctl("key proto=mschapv2 role=client service=wpa essid=%q user=%q !password=%q\n",
|
||||||
essid, up->user, up->passwd);
|
essid, up->user, up->passwd);
|
||||||
freeup(up);
|
freeup(up);
|
||||||
|
@ -1277,18 +1290,13 @@ Connect:
|
||||||
/* wait for getting associated before sending start message */
|
/* wait for getting associated before sending start message */
|
||||||
for(try = 10; (background || try >= 0) && !connected(1); try--)
|
for(try = 10; (background || try >= 0) && !connected(1); try--)
|
||||||
sleep(500);
|
sleep(500);
|
||||||
|
|
||||||
conn.fd = fd;
|
|
||||||
conn.write = eapwrite;
|
|
||||||
conn.type = 1; /* Start */
|
|
||||||
conn.version = 1;
|
|
||||||
memmove(conn.smac, mac, Eaddrlen);
|
|
||||||
if(getbssid(conn.amac) == 0)
|
if(getbssid(conn.amac) == 0)
|
||||||
eapwrite(&conn, nil, 0);
|
eapwrite(&conn, nil, 0);
|
||||||
|
|
||||||
lastrepc = 0ULL;
|
lastrepc = 0ULL;
|
||||||
for(;;){
|
for(;;){
|
||||||
uchar snonce[Noncelen], anonce[Noncelen], *p, *e, *m;
|
uchar *p, *e, *m;
|
||||||
int proto, flags, vers, datalen;
|
int proto, flags, vers, datalen;
|
||||||
uvlong repc, rsc, tsc;
|
uvlong repc, rsc, tsc;
|
||||||
Keydescr *kd;
|
Keydescr *kd;
|
||||||
|
@ -1375,7 +1383,7 @@ Connect:
|
||||||
|
|
||||||
memmove(anonce, kd->nonce, sizeof(anonce));
|
memmove(anonce, kd->nonce, sizeof(anonce));
|
||||||
genrandom(snonce, sizeof(snonce));
|
genrandom(snonce, sizeof(snonce));
|
||||||
if(getptk(conn.smac, conn.amac, snonce, anonce, ptk) != 0){
|
if(getptk(nil, conn.smac, conn.amac, snonce, anonce, ptk) != 0){
|
||||||
if(debug)
|
if(debug)
|
||||||
fprint(2, "getptk: %r\n");
|
fprint(2, "getptk: %r\n");
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue