Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "curl_setup.h"
00024
00025 #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_CRYPTO_AUTH)
00026
00027 #include "urldata.h"
00028 #include "strcase.h"
00029 #include "vauth/vauth.h"
00030 #include "http_digest.h"
00031
00032 #include "curl_printf.h"
00033 #include "curl_memory.h"
00034 #include "memdebug.h"
00035
00036
00037
00038
00039
00040
00041
00042
00043 CURLcode Curl_input_digest(struct connectdata *conn,
00044 bool proxy,
00045 const char *header)
00046
00047 {
00048 struct Curl_easy *data = conn->data;
00049
00050
00051 struct digestdata *digest;
00052
00053 if(proxy) {
00054 digest = &data->state.proxydigest;
00055 }
00056 else {
00057 digest = &data->state.digest;
00058 }
00059
00060 if(!checkprefix("Digest", header))
00061 return CURLE_BAD_CONTENT_ENCODING;
00062
00063 header += strlen("Digest");
00064 while(*header && ISSPACE(*header))
00065 header++;
00066
00067 return Curl_auth_decode_digest_http_message(header, digest);
00068 }
00069
00070 CURLcode Curl_output_digest(struct connectdata *conn,
00071 bool proxy,
00072 const unsigned char *request,
00073 const unsigned char *uripath)
00074 {
00075 CURLcode result;
00076 struct Curl_easy *data = conn->data;
00077 unsigned char *path = NULL;
00078 char *tmp = NULL;
00079 char *response;
00080 size_t len;
00081 bool have_chlg;
00082
00083
00084
00085 char **allocuserpwd;
00086
00087
00088 const char *userp;
00089 const char *passwdp;
00090
00091
00092 struct digestdata *digest;
00093 struct auth *authp;
00094
00095 if(proxy) {
00096 digest = &data->state.proxydigest;
00097 allocuserpwd = &conn->allocptr.proxyuserpwd;
00098 userp = conn->http_proxy.user;
00099 passwdp = conn->http_proxy.passwd;
00100 authp = &data->state.authproxy;
00101 }
00102 else {
00103 digest = &data->state.digest;
00104 allocuserpwd = &conn->allocptr.userpwd;
00105 userp = conn->user;
00106 passwdp = conn->passwd;
00107 authp = &data->state.authhost;
00108 }
00109
00110 Curl_safefree(*allocuserpwd);
00111
00112
00113 if(!userp)
00114 userp = "";
00115
00116 if(!passwdp)
00117 passwdp = "";
00118
00119 #if defined(USE_WINDOWS_SSPI)
00120 have_chlg = digest->input_token ? TRUE : FALSE;
00121 #else
00122 have_chlg = digest->nonce ? TRUE : FALSE;
00123 #endif
00124
00125 if(!have_chlg) {
00126 authp->done = FALSE;
00127 return CURLE_OK;
00128 }
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 if(authp->iestyle) {
00144 tmp = strchr((char *)uripath, '?');
00145 if(tmp) {
00146 size_t urilen = tmp - (char *)uripath;
00147 path = (unsigned char *) aprintf("%.*s", urilen, uripath);
00148 }
00149 }
00150 if(!tmp)
00151 path = (unsigned char *) strdup((char *) uripath);
00152
00153 if(!path)
00154 return CURLE_OUT_OF_MEMORY;
00155
00156 result = Curl_auth_create_digest_http_message(data, userp, passwdp, request,
00157 path, digest, &response, &len);
00158 free(path);
00159 if(result)
00160 return result;
00161
00162 *allocuserpwd = aprintf("%sAuthorization: Digest %s\r\n",
00163 proxy ? "Proxy-" : "",
00164 response);
00165 free(response);
00166 if(!*allocuserpwd)
00167 return CURLE_OUT_OF_MEMORY;
00168
00169 authp->done = TRUE;
00170
00171 return CURLE_OK;
00172 }
00173
00174 void Curl_digest_cleanup(struct Curl_easy *data)
00175 {
00176 Curl_auth_digest_cleanup(&data->state.digest);
00177 Curl_auth_digest_cleanup(&data->state.proxydigest);
00178 }
00179
00180 #endif