Generate a digest reply, according to RFC 2617. */
| 135 | |
| 136 | /* Generate a digest reply, according to RFC 2617. */ |
| 137 | static char *make_digest_auth(HTTPAuthState *state, const char *username, |
| 138 | const char *password, const char *uri, |
| 139 | const char *method) |
| 140 | { |
| 141 | DigestParams *digest = &state->digest_params; |
| 142 | int len; |
| 143 | uint32_t cnonce_buf[2]; |
| 144 | char cnonce[17]; |
| 145 | char nc[9]; |
| 146 | int i; |
| 147 | char A1hash[33], A2hash[33], response[33]; |
| 148 | struct AVMD5 *md5ctx; |
| 149 | uint8_t hash[16]; |
| 150 | char *authstr; |
| 151 | |
| 152 | digest->nc++; |
| 153 | snprintf(nc, sizeof(nc), "%08x", digest->nc); |
| 154 | |
| 155 | /* Generate a client nonce. */ |
| 156 | for (i = 0; i < 2; i++) |
| 157 | cnonce_buf[i] = av_get_random_seed(); |
| 158 | ff_data_to_hex(cnonce, (const uint8_t*) cnonce_buf, sizeof(cnonce_buf), 1); |
| 159 | |
| 160 | md5ctx = av_md5_alloc(); |
| 161 | if (!md5ctx) |
| 162 | return NULL; |
| 163 | |
| 164 | av_md5_init(md5ctx); |
| 165 | update_md5_strings(md5ctx, username, ":", state->realm, ":", password, NULL); |
| 166 | av_md5_final(md5ctx, hash); |
| 167 | ff_data_to_hex(A1hash, hash, 16, 1); |
| 168 | |
| 169 | if (!strcmp(digest->algorithm, "") || !strcmp(digest->algorithm, "MD5")) { |
| 170 | } else if (!strcmp(digest->algorithm, "MD5-sess")) { |
| 171 | av_md5_init(md5ctx); |
| 172 | update_md5_strings(md5ctx, A1hash, ":", digest->nonce, ":", cnonce, NULL); |
| 173 | av_md5_final(md5ctx, hash); |
| 174 | ff_data_to_hex(A1hash, hash, 16, 1); |
| 175 | } else { |
| 176 | /* Unsupported algorithm */ |
| 177 | av_free(md5ctx); |
| 178 | return NULL; |
| 179 | } |
| 180 | |
| 181 | av_md5_init(md5ctx); |
| 182 | update_md5_strings(md5ctx, method, ":", uri, NULL); |
| 183 | av_md5_final(md5ctx, hash); |
| 184 | ff_data_to_hex(A2hash, hash, 16, 1); |
| 185 | |
| 186 | av_md5_init(md5ctx); |
| 187 | update_md5_strings(md5ctx, A1hash, ":", digest->nonce, NULL); |
| 188 | if (!strcmp(digest->qop, "auth") || !strcmp(digest->qop, "auth-int")) { |
| 189 | update_md5_strings(md5ctx, ":", nc, ":", cnonce, ":", digest->qop, NULL); |
| 190 | } |
| 191 | update_md5_strings(md5ctx, ":", A2hash, NULL); |
| 192 | av_md5_final(md5ctx, hash); |
| 193 | ff_data_to_hex(response, hash, 16, 1); |
| 194 |
no test coverage detected