-
Notifications
You must be signed in to change notification settings - Fork 3
/
securid.c
78 lines (67 loc) · 1.97 KB
/
securid.c
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
/*
* OpenConnect (SSL + DTLS) VPN client
*
* Copyright © 2008 Intel Corporation.
*
* Author: David Woodhouse <dwmw2@infradead.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to:
*
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#include <unistd.h>
#include <time.h>
#include <ctype.h>
#include <errno.h>
#include "openconnect.h"
int add_securid_pin(char *token, char *pin)
{
int i;
/* If PIN longer than original token, move token up to cope */
if (strlen(pin) > strlen(token)) {
int extend = strlen(token) - strlen(pin);
memmove(token, token + extend, strlen(token)+1);
for (i=0; i<extend; i++)
token[i] = '0';
}
token += strlen(token) - strlen(pin);
for (i=0; token[i]; i++) {
if (!isdigit(token[i]) || !isdigit(pin[i]))
return -EINVAL;
token[i] += pin[i] - '0';
if (token[i] > '9')
token[i] -= 10;
}
return 0;
}
int generate_securid_tokencodes(struct openconnect_info *vpninfo)
{
/* FIXME: Script the Windows or Java binaries to get the current
and next tokens, and put them in vpninfo->sid_tokencode and
vpninfo->sid_nexttokencode. This dirty hack is just for testing. */
static int got_from_env = 0;
if (!got_from_env) {
char *t1, *t2;
got_from_env = 1;
t1 = getenv("SID_TOKEN1");
t2 = getenv("SID_TOKEN2");
if (t1 && t2) {
strncpy(vpninfo->sid_tokencode, t1, 8);
strncpy(vpninfo->sid_nexttokencode, t2, 8);
return 0;
}
}
return -EINVAL;
}