49 unescape_authzid (
const char *str,
size_t len,
char **authzid)
53 if (memchr (str,
',', len) != NULL)
56 p = *authzid = malloc (len + 1);
60 while (len > 0 && *str)
62 if (len >= 3 && str[0] ==
'=' && str[1] ==
'2' && str[2] ==
'C')
68 else if (len >= 3 && str[0] ==
'=' && str[1] ==
'3' && str[2] ==
'D')
74 else if (str[0] ==
'=')
98 char **authzid,
size_t *headerlen)
100 char *authzid_endptr;
105 if (strncmp (data,
"n,,", 3) == 0)
110 else if (strncmp (data,
"n,a=", 4) == 0 &&
111 (authzid_endptr = memchr (data + 4,
',', len - 4)))
115 res = unescape_authzid (data + 4, authzid_endptr - (data + 4), authzid);
119 *headerlen = authzid_endptr - data + 1;
131 escape_authzid (
const char *str)
133 char *out = malloc (strlen (str) * 3 + 1);
143 memcpy (p,
"=2C", 3);
146 else if (*str ==
'=')
148 memcpy (p,
"=3D", 3);
167 const char *cbname,
const char *authzid,
168 size_t extralen,
const char *extra,
169 char **gs2h,
size_t *gs2hlen)
176 len = asprintf (&gs2cbflag,
"p=%s", cbname);
177 else if (cbflag ==
'n')
178 len = asprintf (&gs2cbflag,
"n");
179 else if (cbflag ==
'y')
180 len = asprintf (&gs2cbflag,
"y");
185 if (len <= 0 || gs2cbflag == NULL)
190 char *escaped_authzid = escape_authzid (authzid);
192 if (!escaped_authzid)
198 len = asprintf (gs2h,
"%s%s,a=%s,%.*s", nonstd ?
"F," :
"",
199 gs2cbflag, escaped_authzid, elen, extra);
201 free (escaped_authzid);
204 len = asprintf (gs2h,
"%s%s,,%.*s", nonstd ?
"F," :
"", gs2cbflag,
209 if (len <= 0 || *gs2h == NULL)
223 static const char trans[] =
"0123456789abcdef";
227 unsigned char c = *in++;
228 *out++ = trans[(c >> 4) & 0xf];
229 *out++ = trans[c & 0xf];
236 hexdigit_to_char (
char hexdigit)
238 if (hexdigit >=
'0' && hexdigit <=
'9')
239 return hexdigit -
'0';
240 if (hexdigit >=
'a' && hexdigit <=
'f')
241 return hexdigit -
'a' + 10;
246 hex_to_char (
char u,
char l)
248 return (
char) (((
unsigned char) hexdigit_to_char (u)) * 16
249 + hexdigit_to_char (l));
260 *bin = hex_to_char (hexstr[0], hexstr[1]);
270 static const char hexalpha[] =
"0123456789abcdef";
272 for (; *hexstr; hexstr++)
273 if (strchr (hexalpha, *hexstr) == NULL)
301 rc = gc_sha1 (in, inlen, outhash);
303 rc = gc_sha256 (in, inlen, outhash);
330 const char *key,
size_t keylen,
331 const char *in,
size_t inlen,
char *outhash)
336 rc = gc_hmac_sha1 (key, keylen, in, inlen, outhash);
338 rc = gc_hmac_sha256 (key, keylen, in, inlen, outhash);
369 const char *password,
size_t passwordlen,
370 const char *salt,
size_t saltlen,
371 unsigned int c,
char *dk,
size_t dklen)
394 rc = gc_pbkdf2_hmac (gch, password, passwordlen,
395 salt, saltlen, c, dk, dklen);
@ GSASL_MECHANISM_PARSE_ERROR