Lines Matching defs:text
452 /* Chris Newman clarified that the following text in DIGEST-MD5 spec
749 static int dec_3des(context_t *text,
756 des_context_t *c = (des_context_t *) text->cipher_dec_context;
789 static int enc_3des(context_t *text,
796 des_context_t *c = (des_context_t *) text->cipher_enc_context;
804 memcpy(output, input, inputlen); /* text */
823 static int init_3des(context_t *text,
831 c = (des_context_t *) text->utils->malloc(2 * sizeof(des_context_t));
844 text->cipher_enc_context = (cipher_context_t *) c;
858 text->cipher_dec_context = (cipher_context_t *) c;
870 static int dec_des(context_t *text,
877 des_context_t *c = (des_context_t *) text->cipher_dec_context;
913 static int enc_des(context_t *text,
920 des_context_t *c = (des_context_t *) text->cipher_enc_context;
928 memcpy(output, input, inputlen); /* text */
950 static int init_des(context_t *text,
958 c = (des_context_t *) text->utils->malloc(2 * sizeof(des_context_t));
967 text->cipher_enc_context = (cipher_context_t *) c;
976 text->cipher_dec_context = (cipher_context_t *) c;
981 static void free_des(context_t *text)
985 if (text->cipher_enc_context) text->utils->free(text->cipher_enc_context);
999 static void rc4_init(rc4_context_t *text,
1007 text->sbox[i]=i;
1013 j = (j + text->sbox[i] + key[i % keylen]) % 256;
1016 tmp = text->sbox[i];
1017 text->sbox[i] = text->sbox[j];
1018 text->sbox[j] = tmp;
1022 text->i = 0;
1023 text->j = 0;
1026 static void rc4_encrypt(rc4_context_t *text,
1032 int i = text->i;
1033 int j = text->j;
1041 j = (j + text->sbox[i]) % 256;
1044 tmp = text->sbox[i];
1045 text->sbox[i] = text->sbox[j];
1046 text->sbox[j] = tmp;
1048 t = (text->sbox[i] + text->sbox[j]) % 256;
1050 K = text->sbox[t];
1056 text->i = i;
1057 text->j = j;
1060 static void rc4_decrypt(rc4_context_t *text,
1066 int i = text->i;
1067 int j = text->j;
1075 j = (j + text->sbox[i]) % 256;
1078 tmp = text->sbox[i];
1079 text->sbox[i] = text->sbox[j];
1080 text->sbox[j] = tmp;
1082 t = (text->sbox[i] + text->sbox[j]) % 256;
1084 K = text->sbox[t];
1090 text->i = i;
1091 text->j = j;
1094 static void free_rc4(context_t *text)
1098 if(text->cipher_enc_context) text->utils->free(text->cipher_enc_context);
1099 if(text->cipher_dec_context) text->utils->free(text->cipher_dec_context);
1101 text->cipher_enc_context = NULL;
1102 text->cipher_dec_context = NULL;
1106 static int init_rc4(context_t *text,
1116 text->cipher_enc_context=
1117 (cipher_context_t *) text->utils->malloc(sizeof(rc4_context_t));
1118 if (text->cipher_enc_context == NULL) return SASL_NOMEM;
1120 text->cipher_dec_context=
1121 (cipher_context_t *) text->utils->malloc(sizeof(rc4_context_t));
1123 if (text->cipher_dec_context == NULL) {
1124 text->utils->free(text->cipher_enc_context);
1125 text->cipher_enc_context = NULL;
1129 if (text->cipher_dec_context == NULL) return SASL_NOMEM;
1133 rc4_init((rc4_context_t *) text->cipher_enc_context,
1135 rc4_init((rc4_context_t *) text->cipher_dec_context,
1141 static int dec_rc4(context_t *text,
1148 /* decrypt the text part */
1149 rc4_decrypt((rc4_context_t *) text->cipher_dec_context,
1153 rc4_decrypt((rc4_context_t *) text->cipher_dec_context,
1156 /* no padding so we just subtract the HMAC to get the text length */
1162 static int enc_rc4(context_t *text,
1172 /* encrypt the text part */
1173 rc4_encrypt((rc4_context_t *) text->cipher_enc_context,
1179 rc4_encrypt((rc4_context_t *) text->cipher_enc_context,
1250 static int init_uef(context_t *text,
1291 enc_context = text->utils->malloc(sizeof (uef_context_t));
1298 text->utils->free(enc_context);
1300 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1309 text->utils->free(enc_context);
1312 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1318 text->cipher_enc_context = (cipher_context_t *)enc_context;
1324 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1330 dec_context = text->utils->malloc(sizeof(uef_context_t));
1338 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1341 text->utils->free(dec_context);
1361 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1365 text->utils->free(dec_context);
1368 text->cipher_dec_context = (cipher_context_t *)dec_context;
1374 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1383 static int init_rc4_uef(context_t *text,
1387 return init_uef(text, CKK_RC4, CKM_RC4, rc4_slot_id, enckey, deckey);
1390 static int init_des_uef(context_t *text,
1394 return init_uef(text, CKK_DES, CKM_DES_CBC, des_slot_id, enckey, deckey);
1397 static int init_3des_uef(context_t *text,
1401 return init_uef(text, CKK_DES3, CKM_DES3_CBC, des3_slot_id, enckey, deckey);
1405 free_uef(context_t *text)
1408 (uef_context_t *)text->cipher_enc_context;
1410 (uef_context_t *)text->cipher_dec_context;
1420 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1427 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1434 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1438 text->utils->free(enc_context);
1444 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1451 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1459 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1463 text->utils->free(dec_context);
1465 text->cipher_enc_context = NULL;
1466 text->cipher_dec_context = NULL;
1470 dec_rc4_uef(context_t *text,
1479 (uef_context_t *)text->cipher_dec_context;
1487 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1499 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1510 enc_rc4_uef(context_t *text,
1519 (uef_context_t *)text->cipher_enc_context;
1527 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1538 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1551 dec_des_uef(context_t *text,
1560 (uef_context_t *)text->cipher_dec_context;
1568 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1575 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1605 enc_des_uef(context_t *text,
1614 (uef_context_t *)text->cipher_enc_context;
1622 memcpy(output, input, inputlen); /* text */
1632 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1662 static int create_layer_keys(context_t *text,
1671 if (text->i_am == SERVER) {
1682 if (text->i_am != SERVER) {
1694 utils->MD5Update(&Md5Ctx, text->HA1, HASHLEN);
1695 if (text->i_am == SERVER) {
1702 utils->MD5Final(text->Ki_send, &Md5Ctx);
1706 utils->MD5Update(&Md5Ctx, text->HA1, HASHLEN);
1707 if (text->i_am != SERVER) {
1714 utils->MD5Final(text->Ki_receive, &Md5Ctx);
1730 context_t *text = (context_t *) context;
1740 PARAMERROR(text->utils);
1745 ret = _plug_iovec_to_buf(text->utils, invec, numiov, &text->enc_in_buf);
1747 inblob = text->enc_in_buf;
1756 ret = _plug_buf_alloc(text->utils, &(text->encode_buf),
1757 &(text->encode_buf_len),
1767 out = (text->encode_buf)+4;
1771 tmpnum = htonl(text->seqnum);
1772 memcpy(text->encode_buf, &tmpnum, 4);
1773 memcpy(text->encode_buf + 4, inblob->data, inblob->curlen);
1776 text->utils->hmac_md5((const unsigned char *) text->encode_buf,
1778 text->Ki_send, HASHLEN, digest);
1781 text->cipher_enc(text, inblob->data, inblob->curlen,
1793 tmpnum = htonl(text->seqnum);
1800 memcpy(text->encode_buf, &tmp, 4);
1804 *output = text->encode_buf;
1805 text->seqnum++;
1817 context_t *text = (context_t *) context;
1825 if (text->needsize>0) /* 4 bytes for how long message is */
1827 /* if less than 4 bytes just copy those we have into text->size */
1833 if (tocopy>text->needsize)
1834 tocopy=text->needsize;
1836 memcpy(text->sizebuf+4-text->needsize, *input, tocopy);
1837 text->needsize-=tocopy;
1842 if (text->needsize==0) /* got all of size */
1844 memcpy(&(text->size), text->sizebuf, 4);
1845 text->cursize=0;
1846 text->size=ntohl(text->size);
1848 if (text->size > text->in_maxbuf) {
1852 if(!text->buffer)
1853 text->buffer=text->utils->malloc(text->size+5);
1855 text->buffer=text->utils->realloc(text->buffer,
1856 text->size+5);
1857 if (text->buffer == NULL) return SASL_NOMEM;
1865 if (text->size==0) /* should never happen */
1869 diff=text->size - text->cursize; /* bytes need for full message */
1871 if (! text->buffer)
1876 memcpy(text->buffer+text->cursize, *input, *inputlen);
1877 text->cursize+=*inputlen;
1883 memcpy(text->buffer+text->cursize, *input, diff);
1893 result = _plug_buf_alloc(text->utils, &text->decode_once_buf,
1894 &text->decode_once_buf_len,
1895 text->size-6);
1899 *output = text->decode_once_buf;
1902 result=text->cipher_dec(text,text->buffer,text->size-6,digest,
1911 memcpy(&ver, text->buffer+text->size-i,2);
1917 memcpy(&ver, text->buffer+text->size-6, 2);
1922 text->utils->seterror(text->utils->conn, 0,
1925 text->utils->seterror(text->utils->conn, 0, "Wrong Version");
1933 result = _plug_buf_alloc(text->utils, &text->decode_tmp_buf,
1934 &text->decode_tmp_buf_len, *outputlen + 4);
1937 tmpnum = htonl(text->rec_seqnum);
1938 memcpy(text->decode_tmp_buf, &tmpnum, 4);
1939 memcpy(text->decode_tmp_buf + 4, *output, *outputlen);
1942 text->utils->hmac_md5((const unsigned char *) text->decode_tmp_buf,
1944 text->Ki_receive, HASHLEN, checkdigest);
1951 text->utils->log(text->utils->conn, SASL_LOG_ERR,
1955 text->utils->seterror(text->utils->conn, 0,
1962 memcpy(&seqnum, text->buffer+text->size-4,4);
1965 if (seqnum!=text->rec_seqnum)
1968 text->utils->log(text->utils->conn, SASL_LOG_ERR,
1971 text->utils->seterror(text->utils->conn, 0,
1977 text->rec_seqnum++; /* now increment it */
1980 text->needsize=4;
1989 context_t *text = (context_t *) context;
1992 ret = _plug_decode(text->utils, context, input, inputlen,
1993 &text->decode_buf, &text->decode_buf_len, outputlen,
1996 *output = text->decode_buf;
2008 context_t *text = (context_t *) context;
2016 PARAMERROR( text->utils );
2021 ret = _plug_iovec_to_buf(text->utils, invec, numiov,
2022 &text->enc_in_buf);
2024 inblob = text->enc_in_buf;
2035 ret = _plug_buf_alloc(text->utils, &(text->encode_buf),
2036 &(text->encode_buf_len), *outputlen);
2041 tmpnum = htonl(text->seqnum);
2042 memcpy(text->encode_buf, &tmpnum, 4);
2043 memcpy(text->encode_buf + 4, inblob->data, inblob->curlen);
2047 text->utils->hmac_md5((unsigned char *)text->encode_buf,
2049 text->Ki_send, HASHLEN, MAC);
2051 text->utils->hmac_md5(text->encode_buf, inblob->curlen + 4,
2052 text->Ki_send, HASHLEN, MAC);
2059 tmpnum = htonl(text->seqnum);
2066 memcpy(text->encode_buf, &tmpnum, 4);
2067 /* the message text */
2068 memcpy(text->encode_buf + 4, inblob->data, inblob->curlen);
2070 memcpy(text->encode_buf + 4 + inblob->curlen, MAC, 16);
2072 text->seqnum++; /* add one to sequence number */
2074 *output = text->encode_buf;
2080 create_MAC(context_t * text,
2093 ret = _plug_buf_alloc(text->utils, &(text->MAC_buf),
2094 &(text->MAC_buf_len), inputlen + 4);
2099 memcpy(text->MAC_buf, &tmpnum, 4);
2100 memcpy(text->MAC_buf + 4, input, inputlen);
2104 text->utils->hmac_md5((unsigned char *)text->MAC_buf, inputlen + 4,
2105 text->Ki_receive, HASHLEN,
2108 text->utils->hmac_md5(text->MAC_buf, inputlen + 4,
2109 text->Ki_receive, HASHLEN,
2124 check_integrity(context_t * text,
2131 result = create_MAC(text, buf, bufsize - 16, text->rec_seqnum, MAC);
2139 text->utils->log(text->utils->conn, SASL_LOG_ERR,
2143 text->utils->seterror(text->utils->conn, 0, "MAC doesn't match");
2148 text->rec_seqnum++;
2151 result = _plug_buf_alloc(text->utils, &text->decode_once_buf,
2152 &text->decode_once_buf_len,
2157 *output = text->decode_once_buf;
2172 context_t *text = (context_t *) context;
2177 if (text->needsize > 0) { /* 4 bytes for how long message is */
2179 * if less than 4 bytes just copy those we have into text->size
2186 if (tocopy > text->needsize)
2187 tocopy = text->needsize;
2189 memcpy(text->sizebuf + 4 - text->needsize, *input, tocopy);
2190 text->needsize -= tocopy;
2195 if (text->needsize == 0) { /* got all of size */
2196 memcpy(&(text->size), text->sizebuf, 4);
2197 text->cursize = 0;
2198 text->size = ntohl(text->size);
2200 if (text->size > text->in_maxbuf)
2203 if(!text->buffer)
2204 text->buffer=text->utils->malloc(text->size+5);
2206 text->buffer=text->utils->realloc(text->buffer,text->size+5);
2207 if (text->buffer == NULL) return SASL_NOMEM;
2214 if (text->size == 0) /* should never happen */
2217 diff = text->size - text->cursize; /* bytes need for full message */
2219 if(! text->buffer)
2223 memcpy(text->buffer + text->cursize, *input, *inputlen);
2224 text->cursize += *inputlen;
2230 memcpy(text->buffer + text->cursize, *input, diff);
2235 result = check_integrity(text, text->buffer, text->size,
2241 text->needsize = 4;
2250 context_t *text = (context_t *) context;
2253 ret = _plug_decode(text->utils, context, input, inputlen,
2254 &text->decode_buf, &text->decode_buf_len, outputlen,
2257 *output = text->decode_buf;
2265 context_t *text = (context_t *) conn_context;
2267 if (!text || !utils) return;
2269 if (text->authid) utils->free(text->authid);
2270 if (text->realm) utils->free(text->realm);
2271 if (text->nonce) utils->free(text->nonce);
2272 if (text->cnonce) utils->free(text->cnonce);
2274 if (text->cipher_free) text->cipher_free(text);
2277 if (text->response_value) utils->free(text->response_value);
2279 if (text->buffer) utils->free(text->buffer);
2280 if (text->encode_buf) utils->free(text->encode_buf);
2281 if (text->decode_buf) utils->free(text->decode_buf);
2282 if (text->decode_once_buf) utils->free(text->decode_once_buf);
2283 if (text->decode_tmp_buf) utils->free(text->decode_tmp_buf);
2284 if (text->out_buf) utils->free(text->out_buf);
2285 if (text->MAC_buf) utils->free(text->MAC_buf);
2287 if (text->enc_in_buf) {
2288 if (text->enc_in_buf->data) utils->free(text->enc_in_buf->data);
2289 utils->free(text->enc_in_buf);
2341 DigestCalcHA1FromSecret(context_t * text,
2368 memcpy(text->HA1, HA1, sizeof(HASH));
2371 static char *create_response(context_t * text,
2390 DigestCalcHA1FromSecret(text,
2536 context_t *text;
2539 text = sparams->utils->malloc(sizeof(server_context_t));
2540 if (text == NULL)
2542 memset(text, 0, sizeof(server_context_t));
2544 text->state = 1;
2545 text->i_am = SERVER;
2546 text->reauth = glob_context;
2548 *conn_context = text;
2561 context_t *text = (context_t *) stext;
2650 result = _plug_buf_alloc(sparams->utils, &(text->out_buf),
2651 &(text->out_buf_len), resplen);
2661 sprintf(text->out_buf, "nonce=\"%s\"", nonce);
2666 &text->out_buf, &text->out_buf_len, &resplen,
2688 &text->out_buf, &text->out_buf_len, &resplen,
2708 &text->out_buf, &text->out_buf_len, &resplen,
2726 &text->out_buf, &text->out_buf_len, &resplen,
2750 &text->out_buf, &text->out_buf_len, &resplen,
2766 &text->out_buf, &text->out_buf_len, &resplen,
2792 &text->out_buf, &text->out_buf_len, &resplen,
2820 text->authid = NULL;
2821 _plug_strdup(sparams->utils, realm, &text->realm, NULL);
2822 text->nonce = nonce;
2823 text->nonce_count = 1;
2824 text->cnonce = NULL;
2827 *serveroutlen = strlen(text->out_buf);
2828 *serverout = text->out_buf;
2830 text->state = 2;
2844 context_t *text = (context_t *) stext;
3059 if (text->state == 1) {
3060 unsigned val = hash(username) % text->reauth->size;
3063 if (sparams->utils->mutex_lock(text->reauth->mutex) == SASL_OK) { /* LOCK */
3064 if (text->reauth->e[val].authid &&
3065 !strcmp(username, text->reauth->e[val].authid)) {
3067 _plug_strdup(sparams->utils, text->reauth->e[val].realm,
3068 &text->realm, NULL);
3070 _plug_strdup(sparams->utils, (char *)text->reauth->e[val].nonce,
3071 (char **) &text->nonce, NULL);
3073 _plug_strdup(sparams->utils, text->reauth->e[val].nonce,
3074 (char **) &text->nonce, NULL);
3076 text->nonce_count = ++text->reauth->e[val].nonce_count;
3078 _plug_strdup(sparams->utils, (char *)text->reauth->e[val].cnonce,
3079 (char **) &text->cnonce, NULL);
3081 _plug_strdup(sparams->utils, text->reauth->e[val].cnonce,
3082 (char **) &text->cnonce, NULL);
3084 stext->timestamp = text->reauth->e[val].u.s.timestamp;
3086 sparams->utils->mutex_unlock(text->reauth->mutex); /* UNLOCK */
3089 if (!text->nonce) {
3098 if ((realm != NULL && text->realm != NULL &&
3099 strcmp(realm, text->realm) != 0) ||
3100 (realm == NULL && text->realm != NULL) ||
3101 (realm != NULL && text->realm == NULL)) {
3105 if (strcmp(realm, text->realm) != 0) {
3113 if (strcmp((char *)nonce, (char *) text->nonce) != 0) {
3117 if (strcmp(nonce, (char *) text->nonce) != 0) {
3124 if (noncecount != text->nonce_count) {
3136 if (text->cnonce && strcmp((char *)cnonce, (char *)text->cnonce) != 0) {
3140 if (text->cnonce && strcmp(cnonce, text->cnonce) != 0) {
3255 (unsigned char *)text->realm, sec->data,
3259 text->realm, sec->data, sec->len, HA1);
3320 text->cipher_enc = cptr->cipher_enc;
3321 text->cipher_dec = cptr->cipher_dec;
3322 text->cipher_init = cptr->cipher_init;
3323 text->cipher_free = cptr->cipher_free;
3362 serverresponse = create_response(text,
3364 text->nonce,
3365 text->nonce_count,
3371 &text->response_value);
3396 if (text->reauth->timeout &&
3397 time(0) - stext->timestamp > text->reauth->timeout) {
3436 text->seqnum = 0; /* for integrity/privacy */
3437 text->rec_seqnum = 0; /* for integrity/privacy */
3438 text->in_maxbuf =
3440 text->utils = sparams->utils;
3443 text->needsize = 4;
3444 text->buffer = NULL;
3450 create_layer_keys(text, sparams->utils,text->HA1,n,enckey,deckey);
3454 if (text->cipher_init) {
3455 if (text->cipher_free)
3456 text->cipher_free(text);
3457 if ((result = text->cipher_init(text, enckey, deckey)) != SASL_OK) {
3464 if (text->cipher_init)
3465 if (text->cipher_init(text, enckey, deckey) != SASL_OK) {
3490 strlen(text->response_value) + strlen("rspauth") + 3;
3492 result = _plug_buf_alloc(sparams->utils, &(text->out_buf),
3493 &(text->out_buf_len), resplen);
3498 sprintf(text->out_buf, "rspauth=%s", text->response_value);
3501 if (strlen(text->out_buf) > 2048) {
3507 *serveroutlen = strlen(text->out_buf);
3508 *serverout = text->out_buf;
3513 if (text->reauth->timeout &&
3514 sparams->utils->mutex_lock(text->reauth->mutex) == SASL_OK) { /* LOCK */
3515 unsigned val = hash(username) % text->reauth->size;
3520 if (text->nonce_count == 1) {
3522 clear_reauth_entry(&text->reauth->e[val], SERVER, sparams->utils);
3523 text->reauth->e[val].authid = username; username = NULL;
3524 text->reauth->e[val].realm = text->realm; text->realm = NULL;
3525 text->reauth->e[val].nonce = text->nonce; text->nonce = NULL;
3526 text->reauth->e[val].cnonce = cnonce; cnonce = NULL;
3528 if (text->nonce_count <= text->reauth->e[val].nonce_count) {
3530 clear_reauth_entry(&text->reauth->e[val], SERVER, sparams->utils);
3533 text->reauth->e[val].nonce_count = text->nonce_count;
3534 text->reauth->e[val].u.s.timestamp = time(0);
3538 if (text->nonce_count > 1) {
3540 clear_reauth_entry(&text->reauth->e[val], SERVER, sparams->utils);
3546 sparams->utils->mutex_unlock(text->reauth->mutex); /* UNLOCK */
3591 context_t *text = (context_t *) conn_context;
3599 switch (text->state) {
3621 if (clientin && text->reauth->timeout) {
3656 "Invalid DIGEST-MD5 server step %d", text->state);
3659 "Invalid DIGEST-MD5 server step %d\n", text->state);
3803 DigestCalcHA1(context_t * text,
3842 memcpy(text->HA1, HA1, sizeof(HASH));
3846 static char *calculate_response(context_t * text,
3880 DigestCalcHA1(text,
3942 make_client_response(context_t *text,
3946 client_context_t *ctext = (client_context_t *) text;
3965 text->cipher_enc = ctext->cipher->cipher_enc;
3966 text->cipher_dec = ctext->cipher->cipher_dec;
3967 text->cipher_free = ctext->cipher->cipher_free;
3968 text->cipher_init = ctext->cipher->cipher_init;
4002 calculate_response(text,
4009 (unsigned char *) text->realm,
4010 text->nonce,
4011 text->nonce_count,
4012 text->cnonce,
4022 &text->response_value);
4032 result =_plug_buf_alloc(params->utils, &(text->out_buf),
4033 &(text->out_buf_len),
4037 sprintf(text->out_buf, "username=\"%s\"", oparams->authid);
4040 &text->out_buf, &text->out_buf_len, &resplen,
4041 "realm", (unsigned char *) text->realm,
4048 &text->out_buf, &text->out_buf_len, &resplen,
4060 &text->out_buf, &text->out_buf_len, &resplen,
4061 "nonce", text->nonce, TRUE) != SASL_OK) {
4066 &text->out_buf, &text->out_buf_len, &resplen,
4067 "cnonce", text->cnonce, TRUE) != SASL_OK) {
4071 snprintf(ncvalue, sizeof(ncvalue), "%08x", text->nonce_count);
4073 &text->out_buf, &text->out_buf_len, &resplen,
4079 &text->out_buf, &text->out_buf_len, &resplen,
4086 &text->out_buf, &text->out_buf_len, &resplen,
4098 &text->out_buf, &text->out_buf_len, &resplen,
4114 &text->out_buf, &text->out_buf_len, &resplen,
4122 &text->out_buf, &text->out_buf_len, &resplen,
4128 &text->out_buf, &text->out_buf_len, &resplen,
4137 if (strlen(text->out_buf) > 2048) {
4164 text->seqnum = 0; /* for integrity/privacy */
4165 text->rec_seqnum = 0; /* for integrity/privacy */
4166 text->utils = params->utils;
4168 text->in_maxbuf =
4172 text->needsize = 4;
4173 text->buffer = NULL;
4179 create_layer_keys(text, params->utils, text->HA1, nbits,
4184 if (text->cipher_init) {
4185 if (text->cipher_free)
4186 text->cipher_free(text);
4187 if((result = text->cipher_init(text, enckey, deckey)) != SASL_OK) {
4194 if (text->cipher_init)
4195 text->cipher_init(text, enckey, deckey);
4213 context_t *text = (context_t *) ctext;
4249 text->cnonce = create_nonce(params->utils);
4250 if (text->cnonce == NULL) {
4297 _plug_strdup(params->utils, value, (char **) &text->nonce,
4299 text->nonce_count = 1;
4474 if (text->nonce == NULL) {
4610 context_t *text = (context_t *) ctext;
4647 if (text->realm == NULL) {
4756 if (realm && text->realm == NULL) {
4757 _plug_strdup(params->utils, realm, (char **) &text->realm, NULL);
4768 context_t *text;
4771 text = params->utils->malloc(sizeof(client_context_t));
4772 if (text == NULL)
4774 memset(text, 0, sizeof(client_context_t));
4776 text->state = 1;
4777 text->i_am = CLIENT;
4778 text->reauth = glob_context;
4780 *conn_context = text;
4795 context_t *text = (context_t *) ctext;
4806 val = hash(params->serverFQDN) % text->reauth->size;
4807 if (params->utils->mutex_lock(text->reauth->mutex) == SASL_OK) { /* LOCK */
4808 if (text->reauth->e[val].u.c.serverFQDN &&
4809 !strcasecmp(text->reauth->e[val].u.c.serverFQDN,
4811 !strcmp(text->reauth->e[val].authid, oparams->authid)) {
4814 if (text->realm) params->utils->free(text->realm);
4815 if (text->nonce) params->utils->free(text->nonce);
4816 if (text->cnonce) params->utils->free(text->cnonce);
4819 _plug_strdup(params->utils, text->reauth->e[val].realm,
4820 &text->realm, NULL);
4822 _plug_strdup(params->utils, (char *)text->reauth->e[val].nonce,
4823 (char **) &text->nonce, NULL);
4825 _plug_strdup(params->utils, text->reauth->e[val].nonce,
4826 (char **) &text->nonce, NULL);
4828 text->nonce_count = ++text->reauth->e[val].nonce_count;
4830 _plug_strdup(params->utils, (char *)text->reauth->e[val].cnonce,
4831 (char **) &text->cnonce, NULL);
4833 _plug_strdup(params->utils, text->reauth->e[val].cnonce,
4834 (char **) &text->cnonce, NULL);
4836 ctext->protection = text->reauth->e[val].u.c.protection;
4837 ctext->cipher = text->reauth->e[val].u.c.cipher;
4838 ctext->server_maxbuf = text->reauth->e[val].u.c.server_maxbuf;
4840 params->utils->mutex_unlock(text->reauth->mutex); /* UNLOCK */
4843 if (!text->nonce) {
4846 text->state = 2;
4855 result = make_client_response(text, params, oparams);
4858 *clientoutlen = strlen(text->out_buf);
4859 *clientout = text->out_buf;
4861 text->state = 3;
4875 context_t *text = (context_t *) ctext;
4888 if (text->nonce == NULL) {
4895 text->realm = realms[0];
4912 result = make_client_response(text, params, oparams);
4915 *clientoutlen = strlen(text->out_buf);
4916 *clientout = text->out_buf;
4918 text->state = 3;
4946 context_t *text = (context_t *) ctext;
4979 if (strcmp(text->response_value, value) != 0) {
5004 if (params->utils->mutex_lock(text->reauth->mutex) == SASL_OK) { /* LOCK */
5005 unsigned val = hash(params->serverFQDN) % text->reauth->size;
5008 if (text->nonce_count == 1) {
5010 clear_reauth_entry(&text->reauth->e[val], CLIENT, params->utils);
5012 &text->reauth->e[val].authid, NULL);
5013 text->reauth->e[val].realm = text->realm; text->realm = NULL;
5014 text->reauth->e[val].nonce = text->nonce; text->nonce = NULL;
5015 text->reauth->e[val].nonce_count = text->nonce_count;
5016 text->reauth->e[val].cnonce = text->cnonce; text->cnonce = NULL;
5018 &text->reauth->e[val].u.c.serverFQDN, NULL);
5019 text->reauth->e[val].u.c.protection = ctext->protection;
5020 text->reauth->e[val].u.c.cipher = ctext->cipher;
5021 text->reauth->e[val].u.c.server_maxbuf = ctext->server_maxbuf;
5030 if (text->nonce_count > 1) {
5032 clear_reauth_entry(&text->reauth->e[val], CLIENT, params->utils);
5038 params->utils->mutex_unlock(text->reauth->mutex); /* UNLOCK */
5054 context_t *text = (context_t *) conn_context;
5056 unsigned val = hash(params->serverFQDN) % text->reauth->size;
5063 switch (text->state) {
5071 if (params->utils->mutex_lock(text->reauth->mutex) == SASL_OK) { /* LOCK */
5072 reauth = text->reauth->e[val].u.c.serverFQDN &&
5073 !strcasecmp(text->reauth->e[val].u.c.serverFQDN,
5075 params->utils->mutex_unlock(text->reauth->mutex); /* UNLOCK */
5087 text->state = 2;
5104 text->state = 2;
5107 if (params->utils->mutex_lock(text->reauth->mutex) == SASL_OK) { /* LOCK */
5108 clear_reauth_entry(&text->reauth->e[val], CLIENT, params->utils);
5110 params->utils->mutex_unlock(text->reauth->mutex); /* UNLOCK */
5113 if (text->realm) params->utils->free(text->realm);
5114 if (text->nonce) params->utils->free(text->nonce);
5115 if (text->cnonce) params->utils->free(text->cnonce);
5117 text->realm = NULL;
5118 text->nonce = text->cnonce = NULL;
5120 text->realm = text->nonce = text->cnonce = NULL;
5134 "Invalid DIGEST-MD5 client step %d", text->state);
5137 "Invalid DIGEST-MD5 client step %d\n", text->state);