00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #if HAVE_CONFIG_H
00024 # include "config.h"
00025 #endif
00026
00027
00028 #include "printer.h"
00029
00030
00031 #include <stdlib.h>
00032
00033
00034 #include <vasprintf.h>
00035
00036
00037 #include "validate.h"
00038
00039
00040
00041
00042 char *
00043 digest_md5_print_challenge (digest_md5_challenge * c)
00044 {
00045 char *out = NULL;
00046 char *realm = NULL, *maxbuf = NULL;
00047 size_t i;
00048
00049
00050
00051 if (digest_md5_validate_challenge (c) != 0)
00052 return NULL;
00053
00054 for (i = 0; i < c->nrealms; i++)
00055 {
00056 char *tmp;
00057 if (asprintf (&tmp, "%s, realm=\"%s\"",
00058 realm ? realm : "", c->realms[i]) < 0)
00059 goto end;
00060 if (realm)
00061 free (realm);
00062 realm = tmp;
00063 }
00064
00065 if (c->servermaxbuf)
00066 if (asprintf (&maxbuf, "maxbuf=%lu", c->servermaxbuf) < 0)
00067 goto end;
00068
00069 if (asprintf (&out, "%s, nonce=\"%s\", %s%s%s%s%s, %s, "
00070 "%s, %s, algorithm=md5-sess, %s%s%s%s%s%s%s%s",
00071 realm ? realm : "",
00072 c->nonce,
00073 c->qops ? "qop=\"" : "",
00074 (c->qops & DIGEST_MD5_QOP_AUTH) ? "auth, " : "",
00075 (c->qops & DIGEST_MD5_QOP_AUTH_INT) ? "auth-int, " : "",
00076 (c->qops & DIGEST_MD5_QOP_AUTH_CONF) ? "auth-conf" : "",
00077 c->qops ? "\"" : "",
00078 c->stale ? "stale=true" : "",
00079 maxbuf ? maxbuf : "",
00080 c->utf8 ? "charset=utf-8" : "",
00081 c->ciphers ? "cipher=\"" : "",
00082 (c->ciphers & DIGEST_MD5_CIPHER_3DES) ? "3des, " : "",
00083 (c->ciphers & DIGEST_MD5_CIPHER_DES) ? "des, " : "",
00084 (c->ciphers & DIGEST_MD5_CIPHER_RC4_40) ? "rc4-40, " : "",
00085 (c->ciphers & DIGEST_MD5_CIPHER_RC4) ? "rc4, " : "",
00086 (c->ciphers & DIGEST_MD5_CIPHER_RC4_56) ? "rc4-56, " : "",
00087 (c->ciphers & DIGEST_MD5_CIPHER_AES_CBC) ? "aes-cbc, " : "",
00088 c->ciphers ? "\"" : "") < 0)
00089 out = NULL;
00090
00091 end:
00092 if (realm)
00093 free (realm);
00094 if (maxbuf)
00095 free (maxbuf);
00096
00097 return out;
00098
00099 }
00100
00101 char *
00102 digest_md5_print_response (digest_md5_response * r)
00103 {
00104 char *out = NULL;
00105 const char *qop = NULL;
00106 const char *cipher = NULL;
00107 char *maxbuf = NULL;
00108
00109
00110
00111 if (digest_md5_validate_response (r) != 0)
00112 return NULL;
00113
00114 if (r->qop & DIGEST_MD5_QOP_AUTH_CONF)
00115 qop = "qop=auth-conf";
00116 else if (r->qop & DIGEST_MD5_QOP_AUTH_INT)
00117 qop = "qop=auth-int";
00118 else if (r->qop & DIGEST_MD5_QOP_AUTH)
00119 qop = "qop=auth";
00120 else
00121 qop = "";
00122
00123 if (r->clientmaxbuf)
00124 if (asprintf (&maxbuf, "maxbuf=%lu", r->clientmaxbuf) < 0)
00125 goto end;
00126
00127 if (r->cipher & DIGEST_MD5_CIPHER_3DES)
00128 cipher = "cipher=3des";
00129 else if (r->cipher & DIGEST_MD5_CIPHER_DES)
00130 cipher = "cipher=des";
00131 else if (r->cipher & DIGEST_MD5_CIPHER_RC4_40)
00132 cipher = "cipher=rc4-40";
00133 else if (r->cipher & DIGEST_MD5_CIPHER_RC4)
00134 cipher = "cipher=rc4";
00135 else if (r->cipher & DIGEST_MD5_CIPHER_RC4_56)
00136 cipher = "cipher=rc4-56";
00137 else if (r->cipher & DIGEST_MD5_CIPHER_AES_CBC)
00138 cipher = "cipher=aes-cbc";
00139 else if (r->cipher & DIGEST_MD5_CIPHER_3DES)
00140 cipher = "cipher=3des";
00141 else
00142 cipher = "";
00143
00144 if (asprintf (&out, "username=\"%s\", %s%s%s, nonce=\"%s\", cnonce=\"%s\", "
00145 "nc=%08lx, %s, digest-uri=\"%s\", response=%s, "
00146 "%s, %s, %s, %s%s%s",
00147 r->username,
00148 r->realm ? "realm=\"" : "",
00149 r->realm ? r->realm : "",
00150 r->realm ? "\"" : "",
00151 r->nonce,
00152 r->cnonce,
00153 r->nc,
00154 qop,
00155 r->digesturi,
00156 r->response,
00157 maxbuf ? maxbuf : "",
00158 r->utf8 ? "charset=utf-8" : "",
00159 cipher,
00160 r->authzid ? "authzid=\"" : "",
00161 r->authzid ? r->authzid : "", r->authzid ? "\"" : "") < 0)
00162 out = NULL;
00163
00164 end:
00165 if (maxbuf)
00166 free (maxbuf);
00167
00168 return out;
00169 }
00170
00171 char *
00172 digest_md5_print_finish (digest_md5_finish * finish)
00173 {
00174 char *out;
00175
00176
00177
00178 if (digest_md5_validate_finish (finish) != 0)
00179 return NULL;
00180
00181 if (asprintf (&out, "rspauth=%s", finish->rspauth) < 0)
00182 return NULL;
00183
00184 return out;
00185 }