{"id":28,"date":"2007-03-27T21:03:44","date_gmt":"2007-03-27T21:03:44","guid":{"rendered":"http:\/\/patchlog.com\/general\/squid-digest-authentication\/"},"modified":"2008-05-19T05:40:07","modified_gmt":"2008-05-19T02:40:07","slug":"squid-digest-authentication","status":"publish","type":"post","link":"https:\/\/patchlog.com\/security\/squid-digest-authentication\/","title":{"rendered":"squid digest authentication"},"content":{"rendered":"<p><a id=\"more-28\"><\/a><br \/>\nIf you use authentication in squid you have several mechanisms ( authenticators )  to chose  from.  The Basic   authenticator is the easiest to set up and the most insecure because the client sends the username and password in plain text to the proxy server.<\/p>\n<p>Instead of using the basic you would consider using the digest authenticator.  This authenticator does not require the client to send the user and password in plain text but encoded in an MD5 hash so that an attacker that captures the data between the client and proxy server will not be able to use the user and password.<\/p>\n<p><!--more-->To use the digest authenticator you have to specifically compile it if you are compiling squid from sources. Before you compile just add  --enable-auth=\"basic digest\" to the .\/configure line or after you compile squid, go to  helpers\/digest_auth\/ and do :<\/p>\n<blockquote><p>make<br \/>\nmake install<\/p><\/blockquote>\n<p>If you are using Fedora then the digest authenticator is already compiled and the program is located at \/usr\/lib\/squid\/digest_pw_auth<\/p>\n<p>If you are using squid from ports on freebsd then the program will be compiled by default and installed at   \/usr\/local\/libexec\/squid\/digest_pw_auth<\/p>\n<p>If you emerge squid on gentoo the program will be compiled by default and installed at  \/usr\/libexec\/squid\/digest_pw_auth<\/p>\n<p>Now for the configuration part the default squid.conf gives  almost all the info we need. I say almost because it does not say much about the format of the file where you have to store the passwords:<\/p>\n<blockquote><p>#\"program\" cmdline<br \/>\n#       Specify the command for the external authenticator.  Such a program<br \/>\n#       reads a line containing \"username\":\"realm\" and replies with the<br \/>\n#       appropriate H(A1) value hex encoded or ERR if the user (or his H(A1)<br \/>\n#       hash) does not exists.  See RFC 2616 for the definition of H(A1).<br \/>\n#       \"ERR\" responses may optionally be followed by a error description<br \/>\n#       available as %m in the returned error page.<\/p><\/blockquote>\n<p>I did not want to read the whole RFC 2616 just to find the definition of H(A1) so I looked in squid source at digest_pw_auth.c right in the header :<\/p>\n<blockquote><p> * To avoid storing a plaintext<br \/>\n* password you can calculate MD5(username:realm:password) when the<br \/>\n* user changes their password, and store the tuple username:realm:HA1.<br \/>\n* then find the matching username:realm when squid asks for the<br \/>\n* HA1.<\/p><\/blockquote>\n<p>Storing encrypted ( hashed ) passwords will not really help the security that much, the part that helps security is that plain text passwords are not sent over the net,  but we will store encrypted passwords anyway. HA1 is really just MD5(username:realm:password) and you have to pass the \"-c\" parameter to digest_pw_auth if you want to not store the plain text passwords in the file and the format to be username:realm:HA1.<\/p>\n<p>The final configuration for the digest authenticator :<\/p>\n<blockquote><\/blockquote>\n<blockquote><p>auth_param digest program \/usr\/lib\/squid\/digest_pw_auth -c \/etc\/squid\/digest_passwd<br \/>\nauth_param digest children 5<br \/>\nauth_param digest realm Squid proxy-caching web server<br \/>\nauth_param digest nonce_garbage_interval 5 minutes<br \/>\nauth_param digest nonce_max_duration 30 minutes<br \/>\nauth_param digest nonce_max_count 50<\/p><\/blockquote>\n<p>I created a small script to help me add users to \/etc\/squid\/digest_passwd :<\/p>\n<blockquote><p> cat digest_user.sh<\/p>\n<pre><ol><li style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;\"><div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\">&nbsp;<\/div><\/li><\/ol><\/pre>\n<\/blockquote>\n<p>To add a user named test with the password 1234 to the file specified in our config I would just do :<\/p>\n<pre>.\/digest_user.sh test 1234 'Squid proxy-caching web server' &gt;&gt;\/etc\/squid\/digest_passwd<\/pre>\n<p>Now all that's left to do is to set up the proper acls and http_access directives to allow the authenticated users to use the proxy server.  I'm using this acl to match any user that can authenticate:<\/p>\n<blockquote><p>acl  authenticated  proxy_auth  REQUIRED<\/p><\/blockquote>\n<p>And then this http_access directive before any other  http_access directive:<\/p>\n<blockquote><p>http_access allow authenticated<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>If you use authentication in squid you have several mechanisms ( authenticators ) to chose from. The Basic authenticator is the easiest to set up and the most insecure because the client sends the username and password in plain text to the proxy server. Instead of using the basic you would consider using the digest &hellip; <a href=\"https:\/\/patchlog.com\/security\/squid-digest-authentication\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">squid digest authentication<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[5],"tags":[34,35,33,354,32],"class_list":["post-28","post","type-post","status-publish","format-standard","hentry","category-security","tag-authentication","tag-digest","tag-proxy","tag-security","tag-squid"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pofPh-s","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/patchlog.com\/wp-json\/wp\/v2\/posts\/28","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/patchlog.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/patchlog.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/patchlog.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/patchlog.com\/wp-json\/wp\/v2\/comments?post=28"}],"version-history":[{"count":0,"href":"https:\/\/patchlog.com\/wp-json\/wp\/v2\/posts\/28\/revisions"}],"wp:attachment":[{"href":"https:\/\/patchlog.com\/wp-json\/wp\/v2\/media?parent=28"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/patchlog.com\/wp-json\/wp\/v2\/categories?post=28"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/patchlog.com\/wp-json\/wp\/v2\/tags?post=28"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}