]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/auth/digest/file/digest_file_auth.cc
2 * Copyright (C) 1996-2022 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
10 * AUTHOR: Robert Collins.
12 * Based on ncsa_auth.c by Arjan de Vet <Arjan.deVet@adv.iae.nl>
14 * LDAP backend extension by Flavio Pescuma,
15 * MARA Systems AB <flavio@marasystems.com>
17 * Example digest authentication program for Squid, based on the original
18 * proxy_auth code from client_side.c, written by
19 * Jon Thackray <jrmt@uk.gdscorp.com>.
21 * - comment lines are possible and should start with a '#';
22 * - empty or blank lines are possible;
23 * - file format is username:password
25 * To build a directory integrated backend, you need to be able to
26 * calculate the HA1 returned to squid. To avoid storing a plaintext
27 * password you can calculate MD5(username:realm:password) when the
28 * user changes their password, and store the tuple username:realm:HA1.
29 * then find the matching username:realm when squid asks for the
32 * This implementation could be improved by using such a triple for
33 * the file format. However storing such a triple does little to
34 * improve security: If compromised the username:realm:HA1 combination
35 * is "plaintext equivalent" - for the purposes of digest authentication
36 * they allow the user access. Password synchronization is not tackled
37 * by digest - just preventing on the wire compromise.
39 * Copyright (c) 2003 Robert Collins <robertc@squid-cache.org>
43 #include "auth/digest/file/digest_common.h"
44 #include "auth/digest/file/text_backend.h"
45 #include "helper/protocol_defines.h"
48 GetHHA1(RequestData
* requestData
)
50 TextHHA1(requestData
);
54 ParseBuffer(char *buf
, RequestData
* requestData
)
57 requestData
->parsed
= 0;
58 if ((p
= strchr(buf
, '\n')) != nullptr)
59 *p
= '\0'; /* strip \n */
62 requestData
->channelId
= strtoll(buf
, &p
, 10);
63 if (*p
!= ' ') // not a channel-ID
64 requestData
->channelId
= -1;
68 if ((requestData
->user
= strtok(buf
, "\"")) == nullptr)
70 if ((requestData
->realm
= strtok(nullptr, "\"")) == nullptr)
72 if ((requestData
->realm
= strtok(nullptr, "\"")) == nullptr)
74 requestData
->parsed
= -1;
78 OutputHHA1(RequestData
* requestData
)
80 requestData
->error
= 0;
82 if (requestData
->channelId
>= 0)
83 printf("%u ", requestData
->channelId
);
84 if (requestData
->error
) {
85 SEND_ERR("message=\"No such user\"");
88 printf("OK ha1=\"%s\"\n", requestData
->HHA1
);
92 DoOneRequest(char *buf
)
94 RequestData requestData
;
95 ParseBuffer(buf
, &requestData
);
96 if (!requestData
.parsed
) {
97 if (requestData
.channelId
>= 0)
98 printf("%u ", requestData
.channelId
);
99 SEND_BH("message=\"Invalid line received\"");
102 OutputHHA1(&requestData
);
106 ProcessArguments(int argc
, char **argv
)
108 TextArguments(argc
, argv
);
112 main(int argc
, char **argv
)
114 char buf
[HELPER_INPUT_BUFFER
];
115 setbuf(stdout
, nullptr);
116 ProcessArguments(argc
, argv
);
117 while (fgets(buf
, HELPER_INPUT_BUFFER
, stdin
) != nullptr)