diff options
author | Bob Beck <beck@cvs.openbsd.org> | 2014-05-12 08:47:38 +0000 |
---|---|---|
committer | Bob Beck <beck@cvs.openbsd.org> | 2014-05-12 08:47:38 +0000 |
commit | 0f9289663f6ac00114d1aeb41b44f8f6991af059 (patch) | |
tree | b4053a13b14f3d49084fce094f80e29cc4a50fc0 | |
parent | 2bf1d05cc7e0bebdb7eb1966925f39010be84b61 (diff) |
Make ifconfig do something intelligent based on the required length of
WEP keys rather then being silently dumb, so when using WEP:
1) If the key is a plausible size try to use it.
2) If they key would be a plausible size with '0x' in front of it, add that.
3) If the key is not a plausible size, emit a warning and do not try to use it.
ok sthen@
-rw-r--r-- | sbin/ifconfig/ifconfig.c | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index d2ea3790ab0..764db00c75b 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ifconfig.c,v 1.282 2014/03/05 20:46:50 tedu Exp $ */ +/* $OpenBSD: ifconfig.c,v 1.283 2014/05/12 08:47:37 beck Exp $ */ /* $NetBSD: ifconfig.c,v 1.40 1997/10/01 02:19:43 enami Exp $ */ /* @@ -1576,8 +1576,40 @@ setifnwkey(const char *val, int d) return; } } else { + /* + * length of each key must be either a 5 + * character ASCII string or 10 hex digits for + * 40 bit encryption, or 13 character ASCII + * string or 26 hex digits for 128 bit + * encryption. + */ + int j; + char *tmp = NULL; + size_t vlen = strlen(val); + switch(vlen) { + case 10: + case 26: + /* 0x must be missing for these lengths */ + j = asprintf(&tmp, "0x%s", val); + if (j == -1) { + warnx("malloc failed"); + return; + } + val = tmp; + break; + case 12: + case 28: + case 5: + case 13: + /* 0xkey or string case - all is ok */ + break; + default: + warnx("Invalid WEP key length"); + return; + } len = sizeof(keybuf[0]); val = get_string(val, NULL, keybuf[0], &len); + free(tmp); if (val == NULL) return; nwkey.i_key[0].i_keylen = len; |