Lines Matching refs:text

453     /* Chris Newman clarified that the following text in DIGEST-MD5 spec
751 static int dec_3des(context_t *text,
758 des_context_t *c = (des_context_t *) text->cipher_dec_context;
791 static int enc_3des(context_t *text,
798 des_context_t *c = (des_context_t *) text->cipher_enc_context;
806 memcpy(output, input, inputlen); /* text */
825 static int init_3des(context_t *text,
833 c = (des_context_t *) text->utils->malloc(2 * sizeof(des_context_t));
846 text->cipher_enc_context = (cipher_context_t *) c;
860 text->cipher_dec_context = (cipher_context_t *) c;
872 static int dec_des(context_t *text,
879 des_context_t *c = (des_context_t *) text->cipher_dec_context;
915 static int enc_des(context_t *text,
922 des_context_t *c = (des_context_t *) text->cipher_enc_context;
930 memcpy(output, input, inputlen); /* text */
952 static int init_des(context_t *text,
960 c = (des_context_t *) text->utils->malloc(2 * sizeof(des_context_t));
969 text->cipher_enc_context = (cipher_context_t *) c;
978 text->cipher_dec_context = (cipher_context_t *) c;
983 static void free_des(context_t *text)
987 if (text->cipher_enc_context) text->utils->free(text->cipher_enc_context);
1001 static void rc4_init(rc4_context_t *text,
1009 text->sbox[i]=i;
1015 j = (j + text->sbox[i] + key[i % keylen]) % 256;
1018 tmp = text->sbox[i];
1019 text->sbox[i] = text->sbox[j];
1020 text->sbox[j] = tmp;
1024 text->i = 0;
1025 text->j = 0;
1028 static void rc4_encrypt(rc4_context_t *text,
1034 int i = text->i;
1035 int j = text->j;
1043 j = (j + text->sbox[i]) % 256;
1046 tmp = text->sbox[i];
1047 text->sbox[i] = text->sbox[j];
1048 text->sbox[j] = tmp;
1050 t = (text->sbox[i] + text->sbox[j]) % 256;
1052 K = text->sbox[t];
1058 text->i = i;
1059 text->j = j;
1062 static void rc4_decrypt(rc4_context_t *text,
1068 int i = text->i;
1069 int j = text->j;
1077 j = (j + text->sbox[i]) % 256;
1080 tmp = text->sbox[i];
1081 text->sbox[i] = text->sbox[j];
1082 text->sbox[j] = tmp;
1084 t = (text->sbox[i] + text->sbox[j]) % 256;
1086 K = text->sbox[t];
1092 text->i = i;
1093 text->j = j;
1096 static void free_rc4(context_t *text)
1100 if(text->cipher_enc_context) text->utils->free(text->cipher_enc_context);
1101 if(text->cipher_dec_context) text->utils->free(text->cipher_dec_context);
1103 text->cipher_enc_context = NULL;
1104 text->cipher_dec_context = NULL;
1108 static int init_rc4(context_t *text,
1118 text->cipher_enc_context=
1119 (cipher_context_t *) text->utils->malloc(sizeof(rc4_context_t));
1120 if (text->cipher_enc_context == NULL) return SASL_NOMEM;
1122 text->cipher_dec_context=
1123 (cipher_context_t *) text->utils->malloc(sizeof(rc4_context_t));
1125 if (text->cipher_dec_context == NULL) {
1126 text->utils->free(text->cipher_enc_context);
1127 text->cipher_enc_context = NULL;
1131 if (text->cipher_dec_context == NULL) return SASL_NOMEM;
1135 rc4_init((rc4_context_t *) text->cipher_enc_context,
1137 rc4_init((rc4_context_t *) text->cipher_dec_context,
1143 static int dec_rc4(context_t *text,
1150 /* decrypt the text part */
1151 rc4_decrypt((rc4_context_t *) text->cipher_dec_context,
1155 rc4_decrypt((rc4_context_t *) text->cipher_dec_context,
1158 /* no padding so we just subtract the HMAC to get the text length */
1164 static int enc_rc4(context_t *text,
1174 /* encrypt the text part */
1175 rc4_encrypt((rc4_context_t *) text->cipher_enc_context,
1181 rc4_encrypt((rc4_context_t *) text->cipher_enc_context,
1255 static int init_uef(context_t *text,
1296 enc_context = text->utils->malloc(sizeof (uef_context_t));
1303 text->utils->free(enc_context);
1305 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1314 text->utils->free(enc_context);
1317 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1323 text->cipher_enc_context = (cipher_context_t *)enc_context;
1329 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1335 dec_context = text->utils->malloc(sizeof(uef_context_t));
1343 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1346 text->utils->free(dec_context);
1366 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1370 text->utils->free(dec_context);
1373 text->cipher_dec_context = (cipher_context_t *)dec_context;
1379 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1388 static int init_rc4_uef(context_t *text,
1392 return init_uef(text, CKK_RC4, CKM_RC4, rc4_slot_id, enckey, deckey);
1395 static int init_des_uef(context_t *text,
1399 return init_uef(text, CKK_DES, CKM_DES_CBC, des_slot_id, enckey, deckey);
1402 static int init_3des_uef(context_t *text,
1406 return init_uef(text, CKK_DES3, CKM_DES3_CBC, des3_slot_id, enckey, deckey);
1410 free_uef(context_t *text)
1413 (uef_context_t *)text->cipher_enc_context;
1415 (uef_context_t *)text->cipher_dec_context;
1425 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1432 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1439 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1443 text->utils->free(enc_context);
1449 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1456 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1464 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1468 text->utils->free(dec_context);
1470 text->cipher_enc_context = NULL;
1471 text->cipher_dec_context = NULL;
1475 dec_rc4_uef(context_t *text,
1484 (uef_context_t *)text->cipher_dec_context;
1492 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1504 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1515 enc_rc4_uef(context_t *text,
1524 (uef_context_t *)text->cipher_enc_context;
1532 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1543 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1556 dec_des_uef(context_t *text,
1565 (uef_context_t *)text->cipher_dec_context;
1573 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1580 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1610 enc_des_uef(context_t *text,
1619 (uef_context_t *)text->cipher_enc_context;
1627 memcpy(output, input, inputlen); /* text */
1637 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1667 static int create_layer_keys(context_t *text,
1676 if (text->i_am == SERVER) {
1687 if (text->i_am != SERVER) {
1699 utils->MD5Update(&Md5Ctx, text->HA1, HASHLEN);
1700 if (text->i_am == SERVER) {
1707 utils->MD5Final(text->Ki_send, &Md5Ctx);
1711 utils->MD5Update(&Md5Ctx, text->HA1, HASHLEN);
1712 if (text->i_am != SERVER) {
1719 utils->MD5Final(text->Ki_receive, &Md5Ctx);
1735 context_t *text = (context_t *) context;
1745 PARAMERROR(text->utils);
1750 ret = _plug_iovec_to_buf(text->utils, invec, numiov, &text->enc_in_buf);
1752 inblob = text->enc_in_buf;
1761 ret = _plug_buf_alloc(text->utils, &(text->encode_buf),
1762 &(text->encode_buf_len),
1772 out = (text->encode_buf)+4;
1776 tmpnum = htonl(text->seqnum);
1777 memcpy(text->encode_buf, &tmpnum, 4);
1778 memcpy(text->encode_buf + 4, inblob->data, inblob->curlen);
1781 text->utils->hmac_md5((const unsigned char *) text->encode_buf,
1783 text->Ki_send, HASHLEN, digest);
1786 text->cipher_enc(text, inblob->data, inblob->curlen,
1798 tmpnum = htonl(text->seqnum);
1805 memcpy(text->encode_buf, &tmp, 4);
1809 *output = text->encode_buf;
1810 text->seqnum++;
1822 context_t *text = (context_t *) context;
1830 if (text->needsize>0) /* 4 bytes for how long message is */
1832 /* if less than 4 bytes just copy those we have into text->size */
1838 if (tocopy>text->needsize)
1839 tocopy=text->needsize;
1841 memcpy(text->sizebuf+4-text->needsize, *input, tocopy);
1842 text->needsize-=tocopy;
1847 if (text->needsize==0) /* got all of size */
1849 memcpy(&(text->size), text->sizebuf, 4);
1850 text->cursize=0;
1851 text->size=ntohl(text->size);
1853 if (text->size > text->in_maxbuf) {
1857 if(!text->buffer)
1858 text->buffer=text->utils->malloc(text->size+5);
1860 text->buffer=text->utils->realloc(text->buffer,
1861 text->size+5);
1862 if (text->buffer == NULL) return SASL_NOMEM;
1870 if (text->size==0) /* should never happen */
1874 diff=text->size - text->cursize; /* bytes need for full message */
1876 if (! text->buffer)
1881 memcpy(text->buffer+text->cursize, *input, *inputlen);
1882 text->cursize+=*inputlen;
1888 memcpy(text->buffer+text->cursize, *input, diff);
1898 result = _plug_buf_alloc(text->utils, &text->decode_once_buf,
1899 &text->decode_once_buf_len,
1900 text->size-6);
1904 *output = text->decode_once_buf;
1907 result=text->cipher_dec(text,text->buffer,text->size-6,digest,
1916 memcpy(&ver, text->buffer+text->size-i,2);
1922 memcpy(&ver, text->buffer+text->size-6, 2);
1927 text->utils->seterror(text->utils->conn, 0,
1930 text->utils->seterror(text->utils->conn, 0, "Wrong Version");
1938 result = _plug_buf_alloc(text->utils, &text->decode_tmp_buf,
1939 &text->decode_tmp_buf_len, *outputlen + 4);
1942 tmpnum = htonl(text->rec_seqnum);
1943 memcpy(text->decode_tmp_buf, &tmpnum, 4);
1944 memcpy(text->decode_tmp_buf + 4, *output, *outputlen);
1947 text->utils->hmac_md5((const unsigned char *) text->decode_tmp_buf,
1949 text->Ki_receive, HASHLEN, checkdigest);
1956 text->utils->log(text->utils->conn, SASL_LOG_ERR,
1960 text->utils->seterror(text->utils->conn, 0,
1967 memcpy(&seqnum, text->buffer+text->size-4,4);
1970 if (seqnum!=text->rec_seqnum)
1973 text->utils->log(text->utils->conn, SASL_LOG_ERR,
1976 text->utils->seterror(text->utils->conn, 0,
1982 text->rec_seqnum++; /* now increment it */
1985 text->needsize=4;
1994 context_t *text = (context_t *) context;
1997 ret = _plug_decode(text->utils, context, input, inputlen,
1998 &text->decode_buf, &text->decode_buf_len, outputlen,
2001 *output = text->decode_buf;
2013 context_t *text = (context_t *) context;
2021 PARAMERROR( text->utils );
2026 ret = _plug_iovec_to_buf(text->utils, invec, numiov,
2027 &text->enc_in_buf);
2029 inblob = text->enc_in_buf;
2040 ret = _plug_buf_alloc(text->utils, &(text->encode_buf),
2041 &(text->encode_buf_len), *outputlen);
2046 tmpnum = htonl(text->seqnum);
2047 memcpy(text->encode_buf, &tmpnum, 4);
2048 memcpy(text->encode_buf + 4, inblob->data, inblob->curlen);
2052 text->utils->hmac_md5((unsigned char *)text->encode_buf,
2054 text->Ki_send, HASHLEN, MAC);
2056 text->utils->hmac_md5(text->encode_buf, inblob->curlen + 4,
2057 text->Ki_send, HASHLEN, MAC);
2064 tmpnum = htonl(text->seqnum);
2071 memcpy(text->encode_buf, &tmpnum, 4);
2072 /* the message text */
2073 memcpy(text->encode_buf + 4, inblob->data, inblob->curlen);
2075 memcpy(text->encode_buf + 4 + inblob->curlen, MAC, 16);
2077 text->seqnum++; /* add one to sequence number */
2079 *output = text->encode_buf;
2085 create_MAC(context_t * text,
2098 ret = _plug_buf_alloc(text->utils, &(text->MAC_buf),
2099 &(text->MAC_buf_len), inputlen + 4);
2104 memcpy(text->MAC_buf, &tmpnum, 4);
2105 memcpy(text->MAC_buf + 4, input, inputlen);
2109 text->utils->hmac_md5((unsigned char *)text->MAC_buf, inputlen + 4,
2110 text->Ki_receive, HASHLEN,
2113 text->utils->hmac_md5(text->MAC_buf, inputlen + 4,
2114 text->Ki_receive, HASHLEN,
2129 check_integrity(context_t * text,
2136 result = create_MAC(text, buf, bufsize - 16, text->rec_seqnum, MAC);
2144 text->utils->log(text->utils->conn, SASL_LOG_ERR,
2148 text->utils->seterror(text->utils->conn, 0, "MAC doesn't match");
2153 text->rec_seqnum++;
2156 result = _plug_buf_alloc(text->utils, &text->decode_once_buf,
2157 &text->decode_once_buf_len,
2162 *output = text->decode_once_buf;
2177 context_t *text = (context_t *) context;
2182 if (text->needsize > 0) { /* 4 bytes for how long message is */
2184 * if less than 4 bytes just copy those we have into text->size
2191 if (tocopy > text->needsize)
2192 tocopy = text->needsize;
2194 memcpy(text->sizebuf + 4 - text->needsize, *input, tocopy);
2195 text->needsize -= tocopy;
2200 if (text->needsize == 0) { /* got all of size */
2201 memcpy(&(text->size), text->sizebuf, 4);
2202 text->cursize = 0;
2203 text->size = ntohl(text->size);
2205 if (text->size > text->in_maxbuf)
2208 if(!text->buffer)
2209 text->buffer=text->utils->malloc(text->size+5);
2211 text->buffer=text->utils->realloc(text->buffer,text->size+5);
2212 if (text->buffer == NULL) return SASL_NOMEM;
2219 if (text->size == 0) /* should never happen */
2222 diff = text->size - text->cursize; /* bytes need for full message */
2224 if(! text->buffer)
2228 memcpy(text->buffer + text->cursize, *input, *inputlen);
2229 text->cursize += *inputlen;
2235 memcpy(text->buffer + text->cursize, *input, diff);
2240 result = check_integrity(text, text->buffer, text->size,
2246 text->needsize = 4;
2255 context_t *text = (context_t *) context;
2258 ret = _plug_decode(text->utils, context, input, inputlen,
2259 &text->decode_buf, &text->decode_buf_len, outputlen,
2262 *output = text->decode_buf;
2270 context_t *text = (context_t *) conn_context;
2272 if (!text || !utils) return;
2274 if (text->authid) utils->free(text->authid);
2275 if (text->realm) utils->free(text->realm);
2276 if (text->nonce) utils->free(text->nonce);
2277 if (text->cnonce) utils->free(text->cnonce);
2279 if (text->cipher_free) text->cipher_free(text);
2282 if (text->response_value) utils->free(text->response_value);
2284 if (text->buffer) utils->free(text->buffer);
2285 if (text->encode_buf) utils->free(text->encode_buf);
2286 if (text->decode_buf) utils->free(text->decode_buf);
2287 if (text->decode_once_buf) utils->free(text->decode_once_buf);
2288 if (text->decode_tmp_buf) utils->free(text->decode_tmp_buf);
2289 if (text->out_buf) utils->free(text->out_buf);
2290 if (text->MAC_buf) utils->free(text->MAC_buf);
2292 if (text->enc_in_buf) {
2293 if (text->enc_in_buf->data) utils->free(text->enc_in_buf->data);
2294 utils->free(text->enc_in_buf);
2346 DigestCalcHA1FromSecret(context_t * text,
2373 memcpy(text->HA1, HA1, sizeof(HASH));
2376 static char *create_response(context_t * text,
2395 DigestCalcHA1FromSecret(text,
2541 context_t *text;
2544 text = sparams->utils->malloc(sizeof(server_context_t));
2545 if (text == NULL)
2547 memset(text, 0, sizeof(server_context_t));
2549 text->state = 1;
2550 text->i_am = SERVER;
2551 text->reauth = glob_context;
2553 *conn_context = text;
2566 context_t *text = (context_t *) stext;
2655 result = _plug_buf_alloc(sparams->utils, &(text->out_buf),
2656 &(text->out_buf_len), resplen);
2666 sprintf(text->out_buf, "nonce=\"%s\"", nonce);
2671 &text->out_buf, &text->out_buf_len, &resplen,
2693 &text->out_buf, &text->out_buf_len, &resplen,
2713 &text->out_buf, &text->out_buf_len, &resplen,
2731 &text->out_buf, &text->out_buf_len, &resplen,
2755 &text->out_buf, &text->out_buf_len, &resplen,
2771 &text->out_buf, &text->out_buf_len, &resplen,
2797 &text->out_buf, &text->out_buf_len, &resplen,
2825 text->authid = NULL;
2826 _plug_strdup(sparams->utils, realm, &text->realm, NULL);
2827 text->nonce = nonce;
2828 text->nonce_count = 1;
2829 text->cnonce = NULL;
2832 *serveroutlen = strlen(text->out_buf);
2833 *serverout = text->out_buf;
2835 text->state = 2;
2849 context_t *text = (context_t *) stext;
3064 if (text->state == 1) {
3065 unsigned val = hash(username) % text->reauth->size;
3068 if (sparams->utils->mutex_lock(text->reauth->mutex) == SASL_OK) { /* LOCK */
3069 if (text->reauth->e[val].authid &&
3070 !strcmp(username, text->reauth->e[val].authid)) {
3072 _plug_strdup(sparams->utils, text->reauth->e[val].realm,
3073 &text->realm, NULL);
3075 _plug_strdup(sparams->utils, (char *)text->reauth->e[val].nonce,
3076 (char **) &text->nonce, NULL);
3078 _plug_strdup(sparams->utils, text->reauth->e[val].nonce,
3079 (char **) &text->nonce, NULL);
3081 text->nonce_count = ++text->reauth->e[val].nonce_count;
3083 _plug_strdup(sparams->utils, (char *)text->reauth->e[val].cnonce,
3084 (char **) &text->cnonce, NULL);
3086 _plug_strdup(sparams->utils, text->reauth->e[val].cnonce,
3087 (char **) &text->cnonce, NULL);
3089 stext->timestamp = text->reauth->e[val].u.s.timestamp;
3091 sparams->utils->mutex_unlock(text->reauth->mutex); /* UNLOCK */
3094 if (!text->nonce) {
3103 if ((realm != NULL && text->realm != NULL &&
3104 strcmp(realm, text->realm) != 0) ||
3105 (realm == NULL && text->realm != NULL) ||
3106 (realm != NULL && text->realm == NULL)) {
3110 if (strcmp(realm, text->realm) != 0) {
3118 if (strcmp((char *)nonce, (char *) text->nonce) != 0) {
3122 if (strcmp(nonce, (char *) text->nonce) != 0) {
3129 if (noncecount != text->nonce_count) {
3141 if (text->cnonce && strcmp((char *)cnonce, (char *)text->cnonce) != 0) {
3145 if (text->cnonce && strcmp(cnonce, text->cnonce) != 0) {
3260 (unsigned char *)text->realm, sec->data,
3264 text->realm, sec->data, sec->len, HA1);
3325 text->cipher_enc = cptr->cipher_enc;
3326 text->cipher_dec = cptr->cipher_dec;
3327 text->cipher_init = cptr->cipher_init;
3328 text->cipher_free = cptr->cipher_free;
3367 serverresponse = create_response(text,
3369 text->nonce,
3370 text->nonce_count,
3376 &text->response_value);
3401 if (text->reauth->timeout &&
3402 time(0) - stext->timestamp > text->reauth->timeout) {
3441 text->seqnum = 0; /* for integrity/privacy */
3442 text->rec_seqnum = 0; /* for integrity/privacy */
3443 text->in_maxbuf =
3445 text->utils = sparams->utils;
3448 text->needsize = 4;
3449 text->buffer = NULL;
3455 create_layer_keys(text, sparams->utils,text->HA1,n,enckey,deckey);
3459 if (text->cipher_init) {
3460 if (text->cipher_free)
3461 text->cipher_free(text);
3462 if ((result = text->cipher_init(text, enckey, deckey)) != SASL_OK) {
3469 if (text->cipher_init)
3470 if (text->cipher_init(text, enckey, deckey) != SASL_OK) {
3495 strlen(text->response_value) + strlen("rspauth") + 3;
3497 result = _plug_buf_alloc(sparams->utils, &(text->out_buf),
3498 &(text->out_buf_len), resplen);
3503 sprintf(text->out_buf, "rspauth=%s", text->response_value);
3506 if (strlen(text->out_buf) > 2048) {
3512 *serveroutlen = strlen(text->out_buf);
3513 *serverout = text->out_buf;
3518 if (text->reauth->timeout &&
3519 sparams->utils->mutex_lock(text->reauth->mutex) == SASL_OK) { /* LOCK */
3520 unsigned val = hash(username) % text->reauth->size;
3525 if (text->nonce_count == 1) {
3527 clear_reauth_entry(&text->reauth->e[val], SERVER, sparams->utils);
3528 text->reauth->e[val].authid = username; username = NULL;
3529 text->reauth->e[val].realm = text->realm; text->realm = NULL;
3530 text->reauth->e[val].nonce = text->nonce; text->nonce = NULL;
3531 text->reauth->e[val].cnonce = cnonce; cnonce = NULL;
3533 if (text->nonce_count <= text->reauth->e[val].nonce_count) {
3535 clear_reauth_entry(&text->reauth->e[val], SERVER, sparams->utils);
3538 text->reauth->e[val].nonce_count = text->nonce_count;
3539 text->reauth->e[val].u.s.timestamp = time(0);
3543 if (text->nonce_count > 1) {
3545 clear_reauth_entry(&text->reauth->e[val], SERVER, sparams->utils);
3551 sparams->utils->mutex_unlock(text->reauth->mutex); /* UNLOCK */
3596 context_t *text = (context_t *) conn_context;
3604 switch (text->state) {
3626 if (clientin && text->reauth->timeout) {
3661 "Invalid DIGEST-MD5 server step %d", text->state);
3664 "Invalid DIGEST-MD5 server step %d\n", text->state);
3816 DigestCalcHA1(context_t * text,
3855 memcpy(text->HA1, HA1, sizeof(HASH));
3859 static char *calculate_response(context_t * text,
3893 DigestCalcHA1(text,
3955 make_client_response(context_t *text,
3959 client_context_t *ctext = (client_context_t *) text;
3978 text->cipher_enc = ctext->cipher->cipher_enc;
3979 text->cipher_dec = ctext->cipher->cipher_dec;
3980 text->cipher_free = ctext->cipher->cipher_free;
3981 text->cipher_init = ctext->cipher->cipher_init;
4015 calculate_response(text,
4022 (unsigned char *) text->realm,
4023 text->nonce,
4024 text->nonce_count,
4025 text->cnonce,
4035 &text->response_value);
4045 result =_plug_buf_alloc(params->utils, &(text->out_buf),
4046 &(text->out_buf_len),
4050 sprintf(text->out_buf, "username=\"%s\"", oparams->authid);
4053 &text->out_buf, &text->out_buf_len, &resplen,
4054 "realm", (unsigned char *) text->realm,
4061 &text->out_buf, &text->out_buf_len, &resplen,
4073 &text->out_buf, &text->out_buf_len, &resplen,
4074 "nonce", text->nonce, TRUE) != SASL_OK) {
4079 &text->out_buf, &text->out_buf_len, &resplen,
4080 "cnonce", text->cnonce, TRUE) != SASL_OK) {
4084 snprintf(ncvalue, sizeof(ncvalue), "%08x", text->nonce_count);
4086 &text->out_buf, &text->out_buf_len, &resplen,
4092 &text->out_buf, &text->out_buf_len, &resplen,
4099 &text->out_buf, &text->out_buf_len, &resplen,
4111 &text->out_buf, &text->out_buf_len, &resplen,
4127 &text->out_buf, &text->out_buf_len, &resplen,
4135 &text->out_buf, &text->out_buf_len, &resplen,
4141 &text->out_buf, &text->out_buf_len, &resplen,
4150 if (strlen(text->out_buf) > 2048) {
4177 text->seqnum = 0; /* for integrity/privacy */
4178 text->rec_seqnum = 0; /* for integrity/privacy */
4179 text->utils = params->utils;
4181 text->in_maxbuf =
4185 text->needsize = 4;
4186 text->buffer = NULL;
4192 create_layer_keys(text, params->utils, text->HA1, nbits,
4197 if (text->cipher_init) {
4198 if (text->cipher_free)
4199 text->cipher_free(text);
4200 if((result = text->cipher_init(text, enckey, deckey)) != SASL_OK) {
4207 if (text->cipher_init)
4208 text->cipher_init(text, enckey, deckey);
4226 context_t *text = (context_t *) ctext;
4262 text->cnonce = create_nonce(params->utils);
4263 if (text->cnonce == NULL) {
4310 _plug_strdup(params->utils, value, (char **) &text->nonce,
4312 text->nonce_count = 1;
4487 if (text->nonce == NULL) {
4623 context_t *text = (context_t *) ctext;
4660 if (text->realm == NULL) {
4769 if (realm && text->realm == NULL) {
4770 _plug_strdup(params->utils, realm, (char **) &text->realm, NULL);
4781 context_t *text;
4784 text = params->utils->malloc(sizeof(client_context_t));
4785 if (text == NULL)
4787 memset(text, 0, sizeof(client_context_t));
4789 text->state = 1;
4790 text->i_am = CLIENT;
4791 text->reauth = glob_context;
4793 *conn_context = text;
4808 context_t *text = (context_t *) ctext;
4819 val = hash(params->serverFQDN) % text->reauth->size;
4820 if (params->utils->mutex_lock(text->reauth->mutex) == SASL_OK) { /* LOCK */
4821 if (text->reauth->e[val].u.c.serverFQDN &&
4822 !strcasecmp(text->reauth->e[val].u.c.serverFQDN,
4824 !strcmp(text->reauth->e[val].authid, oparams->authid)) {
4827 if (text->realm) params->utils->free(text->realm);
4828 if (text->nonce) params->utils->free(text->nonce);
4829 if (text->cnonce) params->utils->free(text->cnonce);
4832 _plug_strdup(params->utils, text->reauth->e[val].realm,
4833 &text->realm, NULL);
4835 _plug_strdup(params->utils, (char *)text->reauth->e[val].nonce,
4836 (char **) &text->nonce, NULL);
4838 _plug_strdup(params->utils, text->reauth->e[val].nonce,
4839 (char **) &text->nonce, NULL);
4841 text->nonce_count = ++text->reauth->e[val].nonce_count;
4843 _plug_strdup(params->utils, (char *)text->reauth->e[val].cnonce,
4844 (char **) &text->cnonce, NULL);
4846 _plug_strdup(params->utils, text->reauth->e[val].cnonce,
4847 (char **) &text->cnonce, NULL);
4849 ctext->protection = text->reauth->e[val].u.c.protection;
4850 ctext->cipher = text->reauth->e[val].u.c.cipher;
4851 ctext->server_maxbuf = text->reauth->e[val].u.c.server_maxbuf;
4853 params->utils->mutex_unlock(text->reauth->mutex); /* UNLOCK */
4856 if (!text->nonce) {
4859 text->state = 2;
4868 result = make_client_response(text, params, oparams);
4871 *clientoutlen = strlen(text->out_buf);
4872 *clientout = text->out_buf;
4874 text->state = 3;
4888 context_t *text = (context_t *) ctext;
4901 if (text->nonce == NULL) {
4908 text->realm = realms[0];
4925 result = make_client_response(text, params, oparams);
4928 *clientoutlen = strlen(text->out_buf);
4929 *clientout = text->out_buf;
4931 text->state = 3;
4959 context_t *text = (context_t *) ctext;
4992 if (strcmp(text->response_value, value) != 0) {
5017 if (params->utils->mutex_lock(text->reauth->mutex) == SASL_OK) { /* LOCK */
5018 unsigned val = hash(params->serverFQDN) % text->reauth->size;
5021 if (text->nonce_count == 1) {
5023 clear_reauth_entry(&text->reauth->e[val], CLIENT, params->utils);
5025 &text->reauth->e[val].authid, NULL);
5026 text->reauth->e[val].realm = text->realm; text->realm = NULL;
5027 text->reauth->e[val].nonce = text->nonce; text->nonce = NULL;
5028 text->reauth->e[val].nonce_count = text->nonce_count;
5029 text->reauth->e[val].cnonce = text->cnonce; text->cnonce = NULL;
5031 &text->reauth->e[val].u.c.serverFQDN, NULL);
5032 text->reauth->e[val].u.c.protection = ctext->protection;
5033 text->reauth->e[val].u.c.cipher = ctext->cipher;
5034 text->reauth->e[val].u.c.server_maxbuf = ctext->server_maxbuf;
5043 if (text->nonce_count > 1) {
5045 clear_reauth_entry(&text->reauth->e[val], CLIENT, params->utils);
5051 params->utils->mutex_unlock(text->reauth->mutex); /* UNLOCK */
5067 context_t *text = (context_t *) conn_context;
5069 unsigned val = hash(params->serverFQDN) % text->reauth->size;
5076 switch (text->state) {
5084 if (params->utils->mutex_lock(text->reauth->mutex) == SASL_OK) { /* LOCK */
5085 reauth = text->reauth->e[val].u.c.serverFQDN &&
5086 !strcasecmp(text->reauth->e[val].u.c.serverFQDN,
5088 params->utils->mutex_unlock(text->reauth->mutex); /* UNLOCK */
5100 text->state = 2;
5117 text->state = 2;
5120 if (params->utils->mutex_lock(text->reauth->mutex) == SASL_OK) { /* LOCK */
5121 clear_reauth_entry(&text->reauth->e[val], CLIENT, params->utils);
5123 params->utils->mutex_unlock(text->reauth->mutex); /* UNLOCK */
5126 if (text->realm) params->utils->free(text->realm);
5127 if (text->nonce) params->utils->free(text->nonce);
5128 if (text->cnonce) params->utils->free(text->cnonce);
5130 text->realm = NULL;
5131 text->nonce = text->cnonce = NULL;
5133 text->realm = text->nonce = text->cnonce = NULL;
5147 "Invalid DIGEST-MD5 client step %d", text->state);
5150 "Invalid DIGEST-MD5 client step %d\n", text->state);