]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
7ec11630 | 2 | * MD5 password support for CUPS (deprecated). |
ef416fc2 | 3 | * |
7ec11630 | 4 | * Copyright 2007-2017 by Apple Inc. |
503b54c9 | 5 | * Copyright 1997-2005 by Easy Software Products. |
ef416fc2 | 6 | * |
e3101897 | 7 | * Licensed under Apache License v2.0. See the file "LICENSE" for more information. |
ef416fc2 | 8 | */ |
9 | ||
10 | /* | |
11 | * Include necessary headers... | |
12 | */ | |
13 | ||
7ec11630 | 14 | #include <cups/cups.h> |
f7deaa1a | 15 | #include "http-private.h" |
71e16022 | 16 | #include "string-private.h" |
ef416fc2 | 17 | |
18 | ||
19 | /* | |
20 | * 'httpMD5()' - Compute the MD5 sum of the username:group:password. | |
7ec11630 MS |
21 | * |
22 | * @deprecated@ | |
ef416fc2 | 23 | */ |
24 | ||
25 | char * /* O - MD5 sum */ | |
26 | httpMD5(const char *username, /* I - User name */ | |
27 | const char *realm, /* I - Realm name */ | |
28 | const char *passwd, /* I - Password string */ | |
29 | char md5[33]) /* O - MD5 string */ | |
30 | { | |
ef416fc2 | 31 | unsigned char sum[16]; /* Sum data */ |
32 | char line[256]; /* Line to sum */ | |
33 | ||
34 | ||
35 | /* | |
36 | * Compute the MD5 sum of the user name, group name, and password. | |
37 | */ | |
38 | ||
39 | snprintf(line, sizeof(line), "%s:%s:%s", username, realm, passwd); | |
7ec11630 | 40 | cupsHashData("md5", (unsigned char *)line, strlen(line), sum, sizeof(sum)); |
ef416fc2 | 41 | |
42 | /* | |
43 | * Return the sum... | |
44 | */ | |
45 | ||
7ec11630 | 46 | return ((char *)cupsHashString(sum, sizeof(sum), md5, 33)); |
ef416fc2 | 47 | } |
48 | ||
49 | ||
50 | /* | |
51 | * 'httpMD5Final()' - Combine the MD5 sum of the username, group, and password | |
52 | * with the server-supplied nonce value, method, and | |
53 | * request-uri. | |
7ec11630 MS |
54 | * |
55 | * @deprecated@ | |
ef416fc2 | 56 | */ |
57 | ||
58 | char * /* O - New sum */ | |
59 | httpMD5Final(const char *nonce, /* I - Server nonce value */ | |
60 | const char *method, /* I - METHOD (GET, POST, etc.) */ | |
61 | const char *resource, /* I - Resource path */ | |
62 | char md5[33]) /* IO - MD5 sum */ | |
63 | { | |
ef416fc2 | 64 | unsigned char sum[16]; /* Sum data */ |
65 | char line[1024]; /* Line of data */ | |
66 | char a2[33]; /* Hash of method and resource */ | |
67 | ||
68 | ||
69 | /* | |
70 | * First compute the MD5 sum of the method and resource... | |
71 | */ | |
72 | ||
73 | snprintf(line, sizeof(line), "%s:%s", method, resource); | |
7ec11630 | 74 | cupsHashData("md5", (unsigned char *)line, strlen(line), sum, sizeof(sum)); |
e22f464e | 75 | cupsHashString(sum, sizeof(sum), a2, sizeof(a2)); |
ef416fc2 | 76 | |
77 | /* | |
78 | * Then combine A1 (MD5 of username, realm, and password) with the nonce | |
79 | * and A2 (method + resource) values to get the final MD5 sum for the | |
80 | * request... | |
81 | */ | |
82 | ||
83 | snprintf(line, sizeof(line), "%s:%s:%s", md5, nonce, a2); | |
7ec11630 | 84 | cupsHashData("md5", (unsigned char *)line, strlen(line), sum, sizeof(sum)); |
ef416fc2 | 85 | |
7ec11630 | 86 | return ((char *)cupsHashString(sum, sizeof(sum), md5, 33)); |
ef416fc2 | 87 | } |
88 | ||
89 | ||
90 | /* | |
91 | * 'httpMD5String()' - Convert an MD5 sum to a character string. | |
7ec11630 MS |
92 | * |
93 | * @deprecated@ | |
ef416fc2 | 94 | */ |
95 | ||
96 | char * /* O - MD5 sum in hex */ | |
97 | httpMD5String(const unsigned char *sum, /* I - MD5 sum data */ | |
98 | char md5[33]) | |
99 | /* O - MD5 sum in hex */ | |
100 | { | |
7ec11630 | 101 | return ((char *)cupsHashString(sum, 16, md5, 33)); |
ef416fc2 | 102 | } |