| 1312 | */ |
| 1313 | |
| 1314 | int /* O - 1 on success, 0 on failure */ |
| 1315 | _httpSetDigestAuthString( |
| 1316 | http_t *http, /* I - HTTP connection */ |
| 1317 | const char *nonce, /* I - Nonce value */ |
| 1318 | const char *method, /* I - HTTP method */ |
| 1319 | const char *resource) /* I - HTTP resource path */ |
| 1320 | { |
| 1321 | char kd[65], /* Final MD5/SHA-256 digest */ |
| 1322 | ha1[65], /* Hash of username:realm:password */ |
| 1323 | ha2[65], /* Hash of method:request-uri */ |
| 1324 | username[HTTP_MAX_VALUE], |
| 1325 | /* username:password */ |
| 1326 | *password, /* Pointer to password */ |
| 1327 | temp[1024], /* Temporary string */ |
| 1328 | digest[1024]; /* Digest auth data */ |
| 1329 | unsigned char hash[32]; /* Hash buffer */ |
| 1330 | size_t hashsize; /* Size of hash */ |
| 1331 | _cups_globals_t *cg = _cupsGlobals(); /* Per-thread globals */ |
| 1332 | |
| 1333 | |
| 1334 | DEBUG_printf(("2_httpSetDigestAuthString(http=%p, nonce=\"%s\", method=\"%s\", resource=\"%s\")", (void *)http, nonce, method, resource)); |
| 1335 | |
| 1336 | if (nonce && *nonce && strcmp(nonce, http->nonce)) |
| 1337 | { |
| 1338 | strlcpy(http->nonce, nonce, sizeof(http->nonce)); |
| 1339 | |
| 1340 | if (nonce == http->nextnonce) |
| 1341 | http->nextnonce[0] = '\0'; |
| 1342 | |
| 1343 | http->nonce_count = 1; |
| 1344 | } |
| 1345 | else |
| 1346 | http->nonce_count ++; |
| 1347 | |
| 1348 | strlcpy(username, http->userpass, sizeof(username)); |
| 1349 | if ((password = strchr(username, ':')) != NULL) |
| 1350 | *password++ = '\0'; |
| 1351 | else |
| 1352 | return (0); |
| 1353 | |
| 1354 | if (http->algorithm[0]) |
| 1355 | { |
| 1356 | /* |
| 1357 | * Follow RFC 2617/7616... |
| 1358 | */ |
| 1359 | |
| 1360 | int i; /* Looping var */ |
| 1361 | char cnonce[65]; /* cnonce value */ |
| 1362 | const char *hashalg; /* Hashing algorithm */ |
| 1363 | |
| 1364 | for (i = 0; i < 64; i ++) |
| 1365 | cnonce[i] = "0123456789ABCDEF"[CUPS_RAND() & 15]; |
| 1366 | cnonce[64] = '\0'; |
| 1367 | |
| 1368 | if (!_cups_strcasecmp(http->algorithm, "MD5")) |
| 1369 | { |
| 1370 | /* |
| 1371 | * RFC 2617 Digest with MD5 |