1 /* verify.c: The opieverify() library function.
4 This software is Copyright 1996-2001 by Craig Metz, All Rights Reserved.
5 The Inner Net License Version 3 applies to this software.
6 You should have received a copy of the license with this software. If
7 you didn't get a copy, you may request one from <license@inner.net>.
11 Modified by cmetz for OPIE 2.4. Use struct opie_otpkey for keys.
12 Check that seed and sequence number are valid.
13 Modified by cmetz for OPIE 2.32. Renamed _opieparsechallenge() to
14 __opieparsechallenge() and handle new argument. Fixed init
16 Modified by cmetz for OPIE 2.31. Renamed "init" to "init-hex".
17 Modified by cmetz for OPIE 2.31. Renamed "init" and "RESPONSE_INIT"
18 to "init-hex" and "RESPONSE_INIT_HEX". Removed active attack
20 Created by cmetz for OPIE 2.3 using the old verify.c as a guide.
26 #endif /* HAVE_STRING_H */
30 #define RESPONSE_STANDARD 0
31 #define RESPONSE_WORD 1
32 #define RESPONSE_HEX 2
33 #define RESPONSE_INIT_HEX 3
34 #define RESPONSE_INIT_WORD 4
35 #define RESPONSE_UNKNOWN 5
42 static struct _rtrans rtrans
[] = {
43 { RESPONSE_WORD
, "word" },
44 { RESPONSE_HEX
, "hex" },
45 { RESPONSE_INIT_HEX
, "init-hex" },
46 { RESPONSE_INIT_WORD
, "init-word" },
47 { RESPONSE_STANDARD
, "" },
48 { RESPONSE_UNKNOWN
, NULL
}
51 static int changed
FUNCTION((opie
), struct opie
*opie
)
55 memset(&opie2
, 0, sizeof(struct opie
));
56 opie2
.opie_principal
= opie
->opie_principal
;
57 if (__opiereadrec(&opie2
))
60 if ((opie2
.opie_n
!= opie
->opie_n
) || strcmp(opie2
.opie_val
, opie
->opie_val
) || strcmp(opie2
.opie_seed
, opie
->opie_seed
))
63 memset(&opie2
, 0, sizeof(struct opie
));
67 int opieverify
FUNCTION((opie
, response
), struct opie
*opie AND
char *response
)
71 struct opie_otpkey key
, fkey
, lastkey
;
73 if (!opie
|| !response
)
76 if (!opie
->opie_principal
)
83 if (!opieatob8(&lastkey
, opie
->opie_val
))
86 for (c
= opie
->opie_seed
; *c
; c
++)
90 if (opie
->opie_n
<= 0)
93 if ((c
= strchr(response
, ':')) != NULL
) {
97 for (r
= rtrans
; r
->name
&& strcmp(r
->name
, response
); r
++);
101 i
= RESPONSE_STANDARD
;
104 case RESPONSE_STANDARD
:
107 if (opieetob(&key
, response
) == 1) {
108 memcpy(&fkey
, &key
, sizeof(struct opie_otpkey
));
109 opiehash(&fkey
, MDX
);
110 i
= memcmp(&fkey
, &lastkey
, sizeof(struct opie_otpkey
));
112 if (i
&& opieatob8(&key
, response
)) {
113 memcpy(&fkey
, &key
, sizeof(struct opie_otpkey
));
114 opiehash(&fkey
, MDX
);
115 i
= memcmp(&fkey
, &lastkey
, sizeof(struct opie_otpkey
));
121 if (opieetob(&key
, c
) == 1) {
122 memcpy(&fkey
, &key
, sizeof(struct opie_otpkey
));
123 opiehash(&fkey
, MDX
);
124 i
= memcmp(&fkey
, &lastkey
, sizeof(struct opie_otpkey
));
130 if (opieatob8(&key
, c
)) {
131 memcpy(&fkey
, &key
, sizeof(struct opie_otpkey
));
132 opiehash(&fkey
, MDX
);
133 i
= memcmp(&fkey
, &lastkey
, sizeof(struct opie_otpkey
));
136 case RESPONSE_INIT_HEX
:
137 case RESPONSE_INIT_WORD
:
141 if (!(c2
= strchr(c
, ':')))
146 if (i
== RESPONSE_INIT_HEX
) {
147 if (!opieatob8(&key
, c
))
150 if (opieetob(&key
, c
) != 1)
154 memcpy(&fkey
, &key
, sizeof(struct opie_otpkey
));
155 opiehash(&fkey
, MDX
);
157 if (memcmp(&fkey
, &lastkey
, sizeof(struct opie_otpkey
)))
165 if (!opiebtoa8(opie
->opie_val
, &key
))
168 if (__opiewriterec(opie
))
171 if (!(c2
= strchr(c
= c2
, ':')))
179 if (__opieparsechallenge(c
, &j
, &(opie
->opie_n
), &(opie
->opie_seed
), &k
) || (j
!= MDX
) || k
)
183 if (i
== RESPONSE_INIT_HEX
) {
184 if (!opieatob8(&key
, c2
))
187 if (opieetob(&key
, c2
) != 1)
192 case RESPONSE_UNKNOWN
:
211 if (!opiebtoa8(opie
->opie_val
, &key
))
213 rval
= __opiewriterec(opie
);
217 memset(opie
, 0, sizeof(struct opie
));