1 /* opietest.c: Quick, though definitely not complete, regression test for
2 libopie. This is intended to catch two things:
4 (1) when changes break something
5 (2) if some system wierdness (libc, compiler, or CPU/hardware) is
6 not getting along at all with OPIE.
8 It's safe to say that, if tests fail, OPIE isn't going to work right
9 on your system. The converse is not such a safe statement.
11 %%% copyright-cmetz-96
12 This software is Copyright 1996-2001 by Craig Metz, All Rights Reserved.
13 The Inner Net License Version 3 applies to this software.
14 You should have received a copy of the license with this software. If
15 you didn't get a copy, you may request one from <license@inner.net>.
19 Modified by cmetz for OPIE 2.4. Use struct opie_key for key blocks.
20 Modified by cmetz for OPIE 2.31. Added a couple of new checks,
21 removed a few commented-out checks for functions that
22 no longer exist, added test-skip capability.
23 Modified by cmetz for OPIE 2.3. Use new calling conventions for
24 opiebtoa8()/atob8(). opiegenerator() outputs hex now.
25 Modified by cmetz for OPIE 2.22. Test opielock()/opieunlock()
27 Created by cmetz for OPIE 2.2.
37 static char testin
[] = "0123456789abcdef";
38 static unsigned char testout
[sizeof(struct opie_otpkey
)] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
39 struct opie_otpkey key
;
41 if (!opieatob8(&key
, testin
))
44 if (memcmp(&key
, testout
, sizeof(testout
)))
52 static unsigned char testin
[sizeof(struct opie_otpkey
)] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
53 static char testout
[] = "0123456789abcdef";
54 struct opie_otpkey testin_aligned
;
56 memcpy(&testin_aligned
, testin
, sizeof(struct opie_otpkey
));
58 if (!opiebtoa8(buffer
, &testin_aligned
))
61 if (memcmp(buffer
, testout
, sizeof(testout
)))
69 static unsigned char testin
[sizeof(struct opie_otpkey
)] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
70 static char testout
[] = "AIM HEW BLUM FED MITE WARM";
71 struct opie_otpkey testin_aligned
;
73 memcpy(&testin_aligned
, testin
, sizeof(struct opie_otpkey
));
75 if (!opiebtoe(buffer
, &testin_aligned
))
78 if (memcmp(buffer
, testout
, sizeof(testout
)))
86 static char testin
[] = "AIM HEW BLUM FED MITE WARM";
87 static unsigned char testout
[sizeof(struct opie_otpkey
)] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
88 struct opie_otpkey key
;
90 if (opieetob(&key
, testin
) != 1)
93 if (memcmp(&key
, testout
, sizeof(testout
)))
101 static char testin1
[] = "otp-md5 123 ke1234";
102 static char testin2
[] = "this is a test";
103 /* static char testout[] = "END KERN BALM NICK EROS WAVY"; */
104 static char testout
[] = "11D4 C147 E227 C1F1";
106 if (opiegenerator(testin1
, testin2
, buffer
))
109 if (memcmp(buffer
, testout
, sizeof(testout
)))
115 int testgetsequence()
120 if (opiegetsequence(&testin
) != 42)
128 static unsigned char testin
[sizeof(struct opie_otpkey
)] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
129 static unsigned char testout
[sizeof(struct opie_otpkey
)] = { 0x9f, 0x40, 0xfb, 0x84, 0xb, 0xf8, 0x7f, 0x4b };
130 struct opie_otpkey testin_aligned
;
132 memcpy(&testin_aligned
, testin
, sizeof(struct opie_otpkey
));
134 opiehash(&testin_aligned
, 4);
136 if (memcmp(&testin_aligned
, testout
, sizeof(struct opie_otpkey
)))
144 static unsigned char testin
[] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
145 static unsigned char testout
[] = { 0x78, 0xdd, 0x1a, 0x37, 0xf8, 0x91, 0x54, 0xe1 };
146 struct opie_otpkey testin_aligned
;
148 memcpy(&testin_aligned
, testin
, sizeof(struct opie_otpkey
));
150 opiehash(&testin_aligned
, 5);
152 if (memcmp(&testin_aligned
, testout
, sizeof(struct opie_otpkey
)))
167 static char testin1
[] = "ke1234";
168 static char testin2
[] = "this is a test";
169 static unsigned char testout
[sizeof(struct opie_otpkey
)] = { 0x2e, 0xd3, 0x5d, 0x74, 0x3e, 0xa9, 0xe9, 0xe8 };
170 struct opie_otpkey opie_otpkey
;
172 if (opiekeycrunch(5, &opie_otpkey
, testin1
, testin2
))
175 if (memcmp(&opie_otpkey
, testout
, sizeof(struct opie_otpkey
)))
188 for (i
= 0; i
< 3; i
++)
189 if (opielock("__opietest"))
197 static char testin1
[] = "abadone";
198 static char testin2
[] = "A more reasonable choice.";
200 if (!opiepasscheck(testin1
))
203 if (opiepasscheck(testin2
))
209 int testrandomchallenge()
211 char buffer
[OPIE_CHALLENGE_MAX
+1];
213 opierandomchallenge(buffer
);
215 if (strncmp(buffer
, "otp-", 4))
228 for (i
= 0; i
< 3; i
++)
232 if (opieunlock() != -1)
243 static struct opietest opietests
[] = {
244 { testatob8
, "atob8" },
245 { testbtoa8
, "btoa8" },
246 { testbtoe
, "btoe" },
247 { testetob
, "etob" },
248 /* { testchallenge, "challenge" }, */
249 { testgenerator
, "generator" },
250 { testgetsequence
, "getsequence" },
251 { testhashmd4
, "hash(MD4)" },
252 { testhashmd5
, "hash(MD5)" },
253 { testinsecure
, "insecure" },
254 { testkeycrunch
, "keycrunch" },
255 { testlock
, "lock" },
256 { testrandomchallenge
, "randomchallenge" },
257 /* { testreadpass, "readpass" }, */
258 { testunlock
, "unlock" },
259 /* { testverify, "verify" }, */
263 int main
FUNCTION((argc
, argv
), int argc AND
char *argv
[])
265 struct opietest
*opietest
;
266 int tests_passed
= 0;
267 int tests_failed
= 0;
268 int tests_skipped
= 0;
269 int ntests
= 0, testn
= 0;
271 if (getuid() != geteuid()) {
272 fprintf(stderr
, "opietest: do not make this program setuid!\n");
276 for (opietest
= opietests
; opietest
->n
; opietest
++)
279 printf("opietest: executing %d tests\n", ntests
);
281 for (opietest
= opietests
, testn
= 1; opietest
->n
; opietest
++) {
282 printf("(%2d/%2d) testing opie%s... ", testn
++, ntests
, opietest
->n
);
283 switch(opietest
->f()) {
301 printf("opietest: completed %d tests. %d tests passed, %d tests skipped, %d tests failed.\n", ntests
, tests_passed
, tests_skipped
, tests_failed
);
303 printf("opietest: please correct the following failures before attempting to use OPIE:\n");
304 for (opietest
= opietests
; opietest
->n
; opietest
++)
306 printf(" opie%s\n", opietest
->n
);