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-1997 by Craig Metz, All Rights Reserved.
13 The Inner Net License Version 2 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.31. Added a couple of new checks,
20 removed a few commented-out checks for functions that
21 no longer exist, added test-skip capability.
22 Modified by cmetz for OPIE 2.3. Use new calling conventions for
23 opiebtoa8()/atob8(). opiegenerator() outputs hex now.
24 Modified by cmetz for OPIE 2.22. Test opielock()/opieunlock()
26 Created by cmetz for OPIE 2.2.
36 static char testin[] = "0123456789abcdef";
37 static unsigned char testout[] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
39 if (!opieatob8(buffer, testin))
42 if (memcmp(buffer, testout, sizeof(testout)))
50 static unsigned char testin[] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
51 static char testout[] = "0123456789abcdef";
53 if (!opiebtoa8(buffer, testin))
56 if (memcmp(buffer, testout, sizeof(testout)))
64 static unsigned char testin[] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
65 static char testout[] = "AIM HEW BLUM FED MITE WARM";
67 if (!opiebtoe(buffer, testin))
70 if (memcmp(buffer, testout, sizeof(testout)))
78 static char testin[] = "AIM HEW BLUM FED MITE WARM";
79 static unsigned char testout[] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
81 if (opieetob(buffer, testin) != 1)
84 if (memcmp(buffer, testout, sizeof(testout)))
92 static char testin1[] = "otp-md5 123 ke1234";
93 static char testin2[] = "this is a test";
94 /* static char testout[] = "END KERN BALM NICK EROS WAVY"; */
95 static char testout[] = "11D4 C147 E227 C1F1";
97 if (opiegenerator(testin1, testin2, buffer))
100 if (memcmp(buffer, testout, sizeof(testout)))
106 int testgetsequence()
111 if (opiegetsequence(&testin) != 42)
119 static unsigned char testin[] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
120 static unsigned char testout[] = { 0x9f, 0x40, 0xfb, 0x84, 0xb, 0xf8, 0x7f, 0x4b };
124 if (memcmp(testin, testout, sizeof(testout)))
132 static unsigned char testin[] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
133 static unsigned char testout[] = { 0x78, 0xdd, 0x1a, 0x37, 0xf8, 0x91, 0x54, 0xe1 };
137 if (memcmp(testin, testout, sizeof(testout)))
152 static char testin1[] = "ke1234";
153 static char testin2[] = "this is a test";
154 static unsigned char testout[] = { 0x2e, 0xd3, 0x5d, 0x74, 0x3e, 0xa9, 0xe9, 0xe8 };
156 if (opiekeycrunch(5, buffer, testin1, testin2))
159 if (memcmp(buffer, testout, sizeof(testout)))
172 for (i = 0; i < 3; i++)
173 if (opielock("__opietest"))
181 static char testin1[] = "abadone";
182 static char testin2[] = "A more reasonable choice.";
184 if (!opiepasscheck(testin1))
187 if (opiepasscheck(testin2))
193 int testrandomchallenge()
195 char buffer[OPIE_CHALLENGE_MAX+1];
197 opierandomchallenge(buffer);
199 if (strncmp(buffer, "otp-", 4))
212 for (i = 0; i < 3; i++)
216 if (opieunlock() != -1)
227 static struct opietest opietests[] = {
228 { testatob8, "atob8" },
229 { testbtoa8, "btoa8" },
230 { testbtoe, "btoe" },
231 { testetob, "etob" },
232 /* { testchallenge, "challenge" }, */
233 { testgenerator, "generator" },
234 { testgetsequence, "getsequence" },
235 { testhashmd4, "hash(MD4)" },
236 { testhashmd5, "hash(MD5)" },
237 { testinsecure, "insecure" },
238 { testkeycrunch, "keycrunch" },
239 { testlock, "lock" },
240 { testrandomchallenge, "randomchallenge" },
241 /* { testreadpass, "readpass" }, */
242 { testunlock, "unlock" },
243 /* { testverify, "verify" }, */
247 int main FUNCTION((argc, argv), int argc AND char *argv[])
249 struct opietest *opietest;
250 int tests_passed = 0;
251 int tests_failed = 0;
252 int tests_skipped = 0;
253 int ntests = 0, testn = 0;
255 if (getuid() != geteuid()) {
256 fprintf(stderr, "opietest: do not make this program setuid!\n");
260 for (opietest = opietests; opietest->n; opietest++)
263 printf("opietest: executing %d tests\n", ntests);
265 for (opietest = opietests, testn = 1; opietest->n; opietest++) {
266 printf("(%2d/%2d) testing opie%s... ", testn++, ntests, opietest->n);
267 switch(opietest->f()) {
285 printf("opietest: completed %d tests. %d tests passed, %d tests skipped, %d tests failed.\n", ntests, tests_passed, tests_skipped, tests_failed);
287 printf("opietest: please correct the following failures before attempting to use OPIE:\n");
288 for (opietest = opietests; opietest->n; opietest++)
290 printf(" opie%s\n", opietest->n);