1 /* client.c --- SASL mechanism SECURID from RFC 2808, client side.
2 * Copyright (C) 2002-2012 Simon Josefsson
4 * This file is part of GNU SASL Library.
6 * GNU SASL Library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either version 2.1 of
9 * the License, or (at your option) any later version.
11 * GNU SASL Library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with GNU SASL Library; if not, write to the Free
18 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
27 /* Get specification. */
30 /* Get malloc, free. */
33 /* Get strdup, strlen. */
36 #define PASSCODE "passcode"
40 _gsasl_securid_client_start (Gsasl_session * sctx, void **mech_data)
44 step = (int *) malloc (sizeof (*step));
46 return GSASL_MALLOC_ERROR;
56 _gsasl_securid_client_step (Gsasl_session * sctx,
60 char **output, size_t * output_len)
62 int *step = mech_data;
63 const char *authzid = NULL, *authid = NULL, *passcode = NULL, *pin = NULL;
64 size_t authzidlen, authidlen, passcodelen, pinlen = 0;
71 if (input_len == strlen (PASSCODE) &&
72 memcmp (input, PASSCODE, strlen (PASSCODE)) == 0)
76 else if (input_len >= strlen (PIN) &&
77 memcmp (input, PIN, strlen (PIN)) == 0)
91 authzid = gsasl_property_get (sctx, GSASL_AUTHZID);
93 authzidlen = strlen (authzid);
97 authid = gsasl_property_get (sctx, GSASL_AUTHID);
99 return GSASL_NO_AUTHID;
100 authidlen = strlen (authid);
102 passcode = gsasl_property_get (sctx, GSASL_PASSCODE);
104 return GSASL_NO_PASSCODE;
105 passcodelen = strlen (passcode);
109 if (input_len > strlen (PIN))
110 gsasl_property_set_raw (sctx, GSASL_SUGGESTED_PIN,
111 &input[strlen (PIN)],
112 input_len - strlen (PIN));
114 pin = gsasl_property_get (sctx, GSASL_PIN);
117 pinlen = strlen (pin);
120 *output_len = authzidlen + 1 + authidlen + 1 + passcodelen + 1;
122 *output_len += pinlen + 1;
123 *output = malloc (*output_len);
125 return GSASL_MALLOC_ERROR;
128 memcpy (*output, authzid, authzidlen);
129 (*output)[authzidlen] = '\0';
130 memcpy (*output + authzidlen + 1, authid, authidlen);
131 (*output)[authzidlen + 1 + authidlen] = '\0';
132 memcpy (*output + authzidlen + 1 + authidlen + 1, passcode,
134 (*output)[authzidlen + 1 + authidlen + 1 + passcodelen] = '\0';
137 memcpy (*output + authzidlen + 1 + authidlen + 1 + passcodelen + 1,
139 (*output)[authzidlen + 1 + authidlen + 1 + passcodelen + 1 +
155 res = GSASL_MECHANISM_CALLED_TOO_MANY_TIMES;
163 _gsasl_securid_client_finish (Gsasl_session * sctx, void *mech_data)
165 int *step = mech_data;