1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
/* opiegen.c: Sample OTP generator based on the opiegenerator()
library routine.
%%% portions-copyright-cmetz-96
Portions of this software are Copyright 1996-1997 by Craig Metz, All Rights
Reserved. The Inner Net License Version 2 applies to these portions of
the software.
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:
Modified by cmetz for OPIE 2.3. OPIE_PASS_MAX changed to
OPIE_SECRET_MAX. Send debug info to syslog.
Modified by cmetz for OPIE 2.2. Use FUNCTION definition et al.
Fixed include order.
Created at NRL for OPIE 2.2.
*/
#include "opie_cfg.h"
#include <stdio.h>
#if DEBUG
#include <syslog.h>
#endif /* DEBUG */
#include "opie.h"
int main FUNCTION((argc, argv), int argc AND char *argv[])
{
char buffer[OPIE_CHALLENGE_MAX+1];
char secret[OPIE_SECRET_MAX+1];
char response[OPIE_RESPONSE_MAX+1];
int result;
if (opieinsecure()) {
fputs("Sorry, but you don't seem to be on a secure terminal.\n", stderr);
#if !DEBUG
exit(1);
#endif /* !DEBUG */
}
if (argc <= 1) {
fputs("Challenge: ", stderr);
if (!opiereadpass(buffer, sizeof(buffer)-1, 1))
fprintf(stderr, "Error reading challenge!");
} else {
char *ap, *ep, *c;
int i;
ep = buffer + sizeof(buffer) - 1;
for (i = 1, ap = buffer; (i < argc) && (ap < ep); i++) {
c = argv[i];
while ((*(ap++) = *(c++)) && (ap < ep));
*(ap - 1) = ' ';
}
*(ap - 1) = 0;
#if DEBUG
syslog(LOG_DEBUG, "opiegen: challenge is +%s+\n", buffer);
#endif /* DEBUG */
}
buffer[sizeof(buffer)-1] = 0;
fputs("Secret pass phrase: ", stderr);
if (!opiereadpass(secret, OPIE_SECRET_MAX, 0)) {
fputs("Error reading secret pass phrase!\n", stderr);
exit(1);
};
switch (result = opiegenerator(buffer, secret, response)) {
case -2:
fputs("Not a valid OTP secret pass phrase.\n", stderr);
break;
case -1:
fputs("Error processing challenge!\n", stderr);
break;
case 1:
fputs("Not a valid OTP challenge.\n", stderr);
break;
case 0:
fputs(response, stdout);
fputc('\n', stdout);
fflush(stdout);
memset(secret, 0, sizeof(secret));
exit(0);
default:
fprintf(stderr, "Unknown error %d!\n", result);
}
memset(secret, 0, sizeof(secret));
return 1;
}
|