1997-02-06 17:52:29 +00:00
|
|
|
/* verify.c: The opieverify() library function.
|
|
|
|
|
1997-09-29 08:53:38 +00:00
|
|
|
%%% copyright-cmetz-96
|
2002-03-21 22:50:02 +00:00
|
|
|
This software is Copyright 1996-2001 by Craig Metz, All Rights Reserved.
|
|
|
|
The Inner Net License Version 3 applies to this software.
|
1997-02-06 17:52:29 +00:00
|
|
|
You should have received a copy of the license with this software. If
|
|
|
|
you didn't get a copy, you may request one from <license@inner.net>.
|
|
|
|
|
|
|
|
History:
|
|
|
|
|
2002-03-21 22:50:02 +00:00
|
|
|
Modified by cmetz for OPIE 2.4. Use struct opie_otpkey for keys.
|
|
|
|
Check that seed and sequence number are valid.
|
2000-04-10 11:09:42 +00:00
|
|
|
Modified by cmetz for OPIE 2.32. Renamed _opieparsechallenge() to
|
|
|
|
__opieparsechallenge() and handle new argument. Fixed init
|
|
|
|
response parsing bug.
|
|
|
|
Modified by cmetz for OPIE 2.31. Renamed "init" to "init-hex".
|
1997-09-29 08:53:38 +00:00
|
|
|
Modified by cmetz for OPIE 2.31. Renamed "init" and "RESPONSE_INIT"
|
|
|
|
to "init-hex" and "RESPONSE_INIT_HEX". Removed active attack
|
|
|
|
protection support.
|
1997-02-06 17:52:29 +00:00
|
|
|
Created by cmetz for OPIE 2.3 using the old verify.c as a guide.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "opie_cfg.h"
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
#include <string.h>
|
|
|
|
#endif /* HAVE_STRING_H */
|
|
|
|
#include "opie.h"
|
|
|
|
|
|
|
|
#define RESPONSE_STANDARD 0
|
|
|
|
#define RESPONSE_WORD 1
|
|
|
|
#define RESPONSE_HEX 2
|
1997-09-29 08:53:38 +00:00
|
|
|
#define RESPONSE_INIT_HEX 3
|
1997-02-06 17:52:29 +00:00
|
|
|
#define RESPONSE_INIT_WORD 4
|
|
|
|
#define RESPONSE_UNKNOWN 5
|
|
|
|
|
|
|
|
struct _rtrans {
|
|
|
|
int type;
|
|
|
|
char *name;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct _rtrans rtrans[] = {
|
|
|
|
{ RESPONSE_WORD, "word" },
|
|
|
|
{ RESPONSE_HEX, "hex" },
|
1997-09-29 08:53:38 +00:00
|
|
|
{ RESPONSE_INIT_HEX, "init-hex" },
|
1997-02-06 17:52:29 +00:00
|
|
|
{ RESPONSE_INIT_WORD, "init-word" },
|
|
|
|
{ RESPONSE_STANDARD, "" },
|
|
|
|
{ RESPONSE_UNKNOWN, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static char *algids[] = { NULL, NULL, NULL, "sha1", "md4", "md5" };
|
|
|
|
|
|
|
|
static int changed FUNCTION((opie), struct opie *opie)
|
|
|
|
{
|
|
|
|
struct opie opie2;
|
|
|
|
|
|
|
|
memset(&opie2, 0, sizeof(struct opie));
|
|
|
|
opie2.opie_principal = opie->opie_principal;
|
|
|
|
if (__opiereadrec(&opie2))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if ((opie2.opie_n != opie->opie_n) || strcmp(opie2.opie_val, opie->opie_val) || strcmp(opie2.opie_seed, opie->opie_seed))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
memset(&opie2, 0, sizeof(struct opie));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int opieverify FUNCTION((opie, response), struct opie *opie AND char *response)
|
|
|
|
{
|
|
|
|
int i, rval = -1;
|
|
|
|
char *c;
|
2002-03-21 22:50:02 +00:00
|
|
|
struct opie_otpkey key, fkey, lastkey;
|
1997-02-06 17:52:29 +00:00
|
|
|
struct opie nopie;
|
|
|
|
|
|
|
|
if (!opie || !response)
|
|
|
|
goto verret;
|
|
|
|
|
|
|
|
if (!opie->opie_principal)
|
|
|
|
#if DEBUG
|
|
|
|
abort();
|
|
|
|
#else /* DEBUG */
|
|
|
|
goto verret;
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2002-03-21 22:50:02 +00:00
|
|
|
if (!opieatob8(&lastkey, opie->opie_val))
|
|
|
|
goto verret;
|
|
|
|
|
|
|
|
for (c = opie->opie_seed; *c; c++)
|
|
|
|
if (!isalnum(*c))
|
|
|
|
goto verret;
|
|
|
|
|
|
|
|
if (opie->opie_n <= 0)
|
1997-02-06 17:52:29 +00:00
|
|
|
goto verret;
|
|
|
|
|
|
|
|
if (c = strchr(response, ':')) {
|
|
|
|
*(c++) = 0;
|
|
|
|
{
|
|
|
|
struct _rtrans *r;
|
|
|
|
for (r = rtrans; r->name && strcmp(r->name, response); r++);
|
|
|
|
i = r->type;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
i = RESPONSE_STANDARD;
|
|
|
|
|
|
|
|
switch(i) {
|
|
|
|
case RESPONSE_STANDARD:
|
|
|
|
i = 1;
|
|
|
|
|
2002-03-21 22:50:02 +00:00
|
|
|
if (opieetob(&key, response) == 1) {
|
|
|
|
memcpy(&fkey, &key, sizeof(struct opie_otpkey));
|
|
|
|
opiehash(&fkey, MDX);
|
|
|
|
i = memcmp(&fkey, &lastkey, sizeof(struct opie_otpkey));
|
1997-02-06 17:52:29 +00:00
|
|
|
}
|
2002-03-21 22:50:02 +00:00
|
|
|
if (i && opieatob8(&key, response)) {
|
|
|
|
memcpy(&fkey, &key, sizeof(struct opie_otpkey));
|
|
|
|
opiehash(&fkey, MDX);
|
|
|
|
i = memcmp(&fkey, &lastkey, sizeof(struct opie_otpkey));
|
1997-02-06 17:52:29 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RESPONSE_WORD:
|
|
|
|
i = 1;
|
|
|
|
|
2002-03-21 22:50:02 +00:00
|
|
|
if (opieetob(&key, c) == 1) {
|
|
|
|
memcpy(&fkey, &key, sizeof(struct opie_otpkey));
|
|
|
|
opiehash(&fkey, MDX);
|
|
|
|
i = memcmp(&fkey, &lastkey, sizeof(struct opie_otpkey));
|
1997-02-06 17:52:29 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RESPONSE_HEX:
|
|
|
|
i = 1;
|
|
|
|
|
2002-03-21 22:50:02 +00:00
|
|
|
if (opieatob8(&key, c)) {
|
|
|
|
memcpy(&fkey, &key, sizeof(struct opie_otpkey));
|
|
|
|
opiehash(&fkey, MDX);
|
|
|
|
i = memcmp(&fkey, &lastkey, sizeof(struct opie_otpkey));
|
1997-02-06 17:52:29 +00:00
|
|
|
}
|
|
|
|
break;
|
1997-09-29 08:53:38 +00:00
|
|
|
case RESPONSE_INIT_HEX:
|
1997-02-06 17:52:29 +00:00
|
|
|
case RESPONSE_INIT_WORD:
|
|
|
|
{
|
|
|
|
char *c2;
|
|
|
|
|
|
|
|
if (!(c2 = strchr(c, ':')))
|
|
|
|
goto verret;
|
|
|
|
|
|
|
|
*(c2++) = 0;
|
|
|
|
|
1997-09-29 08:53:38 +00:00
|
|
|
if (i == RESPONSE_INIT_HEX) {
|
2002-03-21 22:50:02 +00:00
|
|
|
if (!opieatob8(&key, c))
|
1997-02-06 17:52:29 +00:00
|
|
|
goto verret;
|
|
|
|
} else {
|
2002-03-21 22:50:02 +00:00
|
|
|
if (opieetob(&key, c) != 1)
|
1997-02-06 17:52:29 +00:00
|
|
|
goto verret;
|
|
|
|
}
|
|
|
|
|
2002-03-21 22:50:02 +00:00
|
|
|
memcpy(&fkey, &key, sizeof(struct opie_otpkey));
|
|
|
|
opiehash(&fkey, MDX);
|
1997-02-06 17:52:29 +00:00
|
|
|
|
2002-03-21 22:50:02 +00:00
|
|
|
if (memcmp(&fkey, &lastkey, sizeof(struct opie_otpkey)))
|
1997-02-06 17:52:29 +00:00
|
|
|
goto verret;
|
|
|
|
|
|
|
|
if (changed(opie))
|
|
|
|
goto verret;
|
|
|
|
|
|
|
|
opie->opie_n--;
|
|
|
|
|
2002-03-21 22:50:02 +00:00
|
|
|
if (!opiebtoa8(opie->opie_val, &key))
|
1997-02-06 17:52:29 +00:00
|
|
|
goto verret;
|
|
|
|
|
|
|
|
if (__opiewriterec(opie))
|
|
|
|
goto verret;
|
|
|
|
|
|
|
|
if (!(c2 = strchr(c = c2, ':')))
|
|
|
|
goto verret;
|
|
|
|
|
|
|
|
*(c2++) = 0;
|
|
|
|
|
|
|
|
{
|
2000-04-10 11:09:42 +00:00
|
|
|
int j, k;
|
1997-02-06 17:52:29 +00:00
|
|
|
|
2000-04-10 11:09:42 +00:00
|
|
|
if (__opieparsechallenge(c, &j, &(opie->opie_n), &(opie->opie_seed), &k) || (j != MDX) || k)
|
1997-02-06 17:52:29 +00:00
|
|
|
goto verret;
|
|
|
|
}
|
|
|
|
|
1997-09-29 08:53:38 +00:00
|
|
|
if (i == RESPONSE_INIT_HEX) {
|
2002-03-21 22:50:02 +00:00
|
|
|
if (!opieatob8(&key, c2))
|
1997-02-06 17:52:29 +00:00
|
|
|
goto verret;
|
|
|
|
} else {
|
2002-03-21 22:50:02 +00:00
|
|
|
if (opieetob(&key, c2) != 1)
|
1997-02-06 17:52:29 +00:00
|
|
|
goto verret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
goto verwrt;
|
|
|
|
case RESPONSE_UNKNOWN:
|
|
|
|
rval = 1;
|
|
|
|
goto verret;
|
|
|
|
default:
|
|
|
|
rval = -1;
|
|
|
|
goto verret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i) {
|
|
|
|
rval = 1;
|
|
|
|
goto verret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (changed(opie))
|
|
|
|
goto verret;
|
|
|
|
|
|
|
|
opie->opie_n--;
|
|
|
|
|
|
|
|
verwrt:
|
2002-03-21 22:50:02 +00:00
|
|
|
if (!opiebtoa8(opie->opie_val, &key))
|
1997-02-06 17:52:29 +00:00
|
|
|
goto verret;
|
|
|
|
rval = __opiewriterec(opie);
|
|
|
|
|
|
|
|
verret:
|
|
|
|
opieunlock();
|
|
|
|
memset(opie, 0, sizeof(struct opie));
|
|
|
|
return rval;
|
|
|
|
}
|