Philip P. Moltmann | 25aee82 | 2016-12-15 12:16:46 -0800 | [diff] [blame] | 1 | /* |
Bryan Ferris | 5fb2ccd | 2019-06-21 10:49:26 -0700 | [diff] [blame] | 2 | * MD5 password support for CUPS (deprecated). |
Philip P. Moltmann | 25aee82 | 2016-12-15 12:16:46 -0800 | [diff] [blame] | 3 | * |
Bryan Ferris | 5fb2ccd | 2019-06-21 10:49:26 -0700 | [diff] [blame] | 4 | * Copyright 2007-2017 by Apple Inc. |
Philip P. Moltmann | 25aee82 | 2016-12-15 12:16:46 -0800 | [diff] [blame] | 5 | * Copyright 1997-2005 by Easy Software Products. |
| 6 | * |
| 7 | * These coded instructions, statements, and computer programs are the |
| 8 | * property of Apple Inc. and are protected by Federal copyright |
| 9 | * law. Distribution and use rights are outlined in the file "LICENSE.txt" |
| 10 | * which should have been included with this file. If this file is |
Philip P. Moltmann | 2447373 | 2017-05-11 09:37:47 -0700 | [diff] [blame] | 11 | * missing or damaged, see the license at "http://www.cups.org/". |
Philip P. Moltmann | 25aee82 | 2016-12-15 12:16:46 -0800 | [diff] [blame] | 12 | * |
| 13 | * This file is subject to the Apple OS-Developed Software exception. |
| 14 | */ |
| 15 | |
| 16 | /* |
| 17 | * Include necessary headers... |
| 18 | */ |
| 19 | |
Bryan Ferris | 5fb2ccd | 2019-06-21 10:49:26 -0700 | [diff] [blame] | 20 | #include <cups/cups.h> |
Philip P. Moltmann | 25aee82 | 2016-12-15 12:16:46 -0800 | [diff] [blame] | 21 | #include "http-private.h" |
| 22 | #include "string-private.h" |
| 23 | |
| 24 | |
| 25 | /* |
| 26 | * 'httpMD5()' - Compute the MD5 sum of the username:group:password. |
Bryan Ferris | 5fb2ccd | 2019-06-21 10:49:26 -0700 | [diff] [blame] | 27 | * |
| 28 | * @deprecated@ |
Philip P. Moltmann | 25aee82 | 2016-12-15 12:16:46 -0800 | [diff] [blame] | 29 | */ |
| 30 | |
| 31 | char * /* O - MD5 sum */ |
| 32 | httpMD5(const char *username, /* I - User name */ |
| 33 | const char *realm, /* I - Realm name */ |
| 34 | const char *passwd, /* I - Password string */ |
| 35 | char md5[33]) /* O - MD5 string */ |
| 36 | { |
Philip P. Moltmann | 25aee82 | 2016-12-15 12:16:46 -0800 | [diff] [blame] | 37 | unsigned char sum[16]; /* Sum data */ |
| 38 | char line[256]; /* Line to sum */ |
| 39 | |
| 40 | |
| 41 | /* |
| 42 | * Compute the MD5 sum of the user name, group name, and password. |
| 43 | */ |
| 44 | |
| 45 | snprintf(line, sizeof(line), "%s:%s:%s", username, realm, passwd); |
Bryan Ferris | 5fb2ccd | 2019-06-21 10:49:26 -0700 | [diff] [blame] | 46 | cupsHashData("md5", (unsigned char *)line, strlen(line), sum, sizeof(sum)); |
Philip P. Moltmann | 25aee82 | 2016-12-15 12:16:46 -0800 | [diff] [blame] | 47 | |
| 48 | /* |
| 49 | * Return the sum... |
| 50 | */ |
| 51 | |
Bryan Ferris | 5fb2ccd | 2019-06-21 10:49:26 -0700 | [diff] [blame] | 52 | return ((char *)cupsHashString(sum, sizeof(sum), md5, 33)); |
Philip P. Moltmann | 25aee82 | 2016-12-15 12:16:46 -0800 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | |
| 56 | /* |
| 57 | * 'httpMD5Final()' - Combine the MD5 sum of the username, group, and password |
| 58 | * with the server-supplied nonce value, method, and |
| 59 | * request-uri. |
Bryan Ferris | 5fb2ccd | 2019-06-21 10:49:26 -0700 | [diff] [blame] | 60 | * |
| 61 | * @deprecated@ |
Philip P. Moltmann | 25aee82 | 2016-12-15 12:16:46 -0800 | [diff] [blame] | 62 | */ |
| 63 | |
| 64 | char * /* O - New sum */ |
| 65 | httpMD5Final(const char *nonce, /* I - Server nonce value */ |
| 66 | const char *method, /* I - METHOD (GET, POST, etc.) */ |
| 67 | const char *resource, /* I - Resource path */ |
| 68 | char md5[33]) /* IO - MD5 sum */ |
| 69 | { |
Philip P. Moltmann | 25aee82 | 2016-12-15 12:16:46 -0800 | [diff] [blame] | 70 | unsigned char sum[16]; /* Sum data */ |
| 71 | char line[1024]; /* Line of data */ |
| 72 | char a2[33]; /* Hash of method and resource */ |
| 73 | |
| 74 | |
| 75 | /* |
| 76 | * First compute the MD5 sum of the method and resource... |
| 77 | */ |
| 78 | |
| 79 | snprintf(line, sizeof(line), "%s:%s", method, resource); |
Bryan Ferris | 5fb2ccd | 2019-06-21 10:49:26 -0700 | [diff] [blame] | 80 | cupsHashData("md5", (unsigned char *)line, strlen(line), sum, sizeof(sum)); |
| 81 | cupsHashString(sum, sizeof(sum), a2, sizeof(a2)); |
Philip P. Moltmann | 25aee82 | 2016-12-15 12:16:46 -0800 | [diff] [blame] | 82 | |
| 83 | /* |
| 84 | * Then combine A1 (MD5 of username, realm, and password) with the nonce |
| 85 | * and A2 (method + resource) values to get the final MD5 sum for the |
| 86 | * request... |
| 87 | */ |
| 88 | |
| 89 | snprintf(line, sizeof(line), "%s:%s:%s", md5, nonce, a2); |
Bryan Ferris | 5fb2ccd | 2019-06-21 10:49:26 -0700 | [diff] [blame] | 90 | cupsHashData("md5", (unsigned char *)line, strlen(line), sum, sizeof(sum)); |
Philip P. Moltmann | 25aee82 | 2016-12-15 12:16:46 -0800 | [diff] [blame] | 91 | |
Bryan Ferris | 5fb2ccd | 2019-06-21 10:49:26 -0700 | [diff] [blame] | 92 | return ((char *)cupsHashString(sum, sizeof(sum), md5, 33)); |
Philip P. Moltmann | 25aee82 | 2016-12-15 12:16:46 -0800 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | |
| 96 | /* |
| 97 | * 'httpMD5String()' - Convert an MD5 sum to a character string. |
Bryan Ferris | 5fb2ccd | 2019-06-21 10:49:26 -0700 | [diff] [blame] | 98 | * |
| 99 | * @deprecated@ |
Philip P. Moltmann | 25aee82 | 2016-12-15 12:16:46 -0800 | [diff] [blame] | 100 | */ |
| 101 | |
| 102 | char * /* O - MD5 sum in hex */ |
| 103 | httpMD5String(const unsigned char *sum, /* I - MD5 sum data */ |
| 104 | char md5[33]) |
| 105 | /* O - MD5 sum in hex */ |
| 106 | { |
Bryan Ferris | 5fb2ccd | 2019-06-21 10:49:26 -0700 | [diff] [blame] | 107 | return ((char *)cupsHashString(sum, 16, md5, 33)); |
Philip P. Moltmann | 25aee82 | 2016-12-15 12:16:46 -0800 | [diff] [blame] | 108 | } |