在需要身份验证的代理后面使用ELPA(Emacs)

时间:2012-05-28 15:32:09

标签: authentication emacs proxy emacs24 elpa

我已阅读thisthis问题。他们都说Emacs可以处理身份验证,但它对我不起作用。

问题是:出了什么问题?

Emacs版本为24.0.97-1,它在64位Linux上运行。

在工作中,我必须使用代理服务器进行任何Internet连接。所以我设置了以下环境变量:

http_proxy="http://username:password@ip:port
https_proxy="https://username:password@ip:port
ftp_proxy="ftp://username:password@ip:port

这很有效。我可以毫无问题地下载软件包。

当我在Emacs中运行M-x package-refresh-contents时,它会要求我提供代理服务器的登录名和密码,但它无法连接到服务器。它甚至不尝试连接,即在我输入密码并按下Enter Emacs 即时报告后: Failed to download 'marmalade' archive

如果我从http_proxy变量删除用户名和密码,或者我在Emacs中设置url-proxy-services(即使我取消设置系统变量),也会发生同样的情况。

4 个答案:

答案 0 :(得分:18)

Emacs仅使用HOST中的PORThttp_proxy部分。

我通过以下方式获得授权而无需用户互动:

(setq url-proxy-services
   '(("no_proxy" . "^\\(localhost\\|10.*\\)")
     ("http" . "proxy.com:8080")
     ("https" . "proxy.com:8080")))

(setq url-http-proxy-basic-auth-storage
    (list (list "proxy.com:8080"
                (cons "Input your LDAP UID !"
                      (base64-encode-string "LOGIN:PASSWORD")))))

这适用于Emacs 24.3。它基于非公共API技巧,因此可能无法使用另一个Emacs版本......

LOGINPASSWORD替换为您的身份验证信息...

还有url-http-proxy-digest-auth-storage。只需填写验证数据提示并检查Emacs使用的var(M-: var RET)...

答案 1 :(得分:6)

看起来Emacs在身份验证方面存在一些问题。所以我已经安装了Squid,现在将它用作外部代理服务器和我所有应用程序之间的中间件。 Squid被配置为没有身份验证的代理,一切都运行良好。

很多人推荐这个解决方案,但没有给出准确的说明。我从另一个为不同目的设计的/etc/squid/squid.conf。可能它包含一些不需要的东西和/或错过它应该拥有的东西。欢迎任何改进:

# only access from localhost is allowed
acl localhost src 127.0.0.1/32
acl all src all
http_access allow localhost
http_access deny all
icp_access deny all

never_direct allow all

# turn off cache
cache_dir null /tmp
cache deny all

# logs
access_log /var/log/squid/access.log squid

# turn off proxy-headers (no idea what is it :))
via off
forwarded_for off

# describe external proxy server
cache_peer <proxy_ip> parent <proxy_port> 0 no-query default proxy-only login=<my_login>:<my_password>
http_port 10000
acl port10000 myport 10000
cache_peer_access <proxy_ip> allow port10000

此代理的地址为127.0.0.1:10000。在Emacs中,我必须执行以下代码:

(setq url-proxy-services '(("http" . "127.0.0.1:10000")))

答案 2 :(得分:4)

这里有两个错误 - 一个在url-http.el中,可以使用我刚发送到http://debbugs.gnu.org/cgi/bugreport.cgi?bug=12069的补丁修复 这将阻止Emacs在每次尝试时提示您输入密码,当它没有提示您时,它应该可以正常工作。

尚未跟踪另一个错误,但似乎当代理服务器请求身份验证时,会提示进行身份验证,然后立即通过程序包代码处理来自代理服务器的身份验证请求。同时,真实的请求在后台继续。

答案 3 :(得分:1)

url-httpurl-https-proxy-connect中的emacs <= 27中还有另一个相关错误,导致通过身份验证代理的所有https调用失败。

请参见https://debbugs.gnu.org/cgi/bugreport.cgi?bug=42422

作为emacs <= 27的解决方法,请使用固定版本覆盖该功能:

(with-eval-after-load 'url-http
  (defun url-https-proxy-connect (connection)
    (setq url-http-after-change-function 'url-https-proxy-after-change-function)
    (process-send-string connection (format (concat "CONNECT %s:%d HTTP/1.1\r\n"
                            "Host: %s\r\n"
                            (let ((proxy-auth (let ((url-basic-auth-storage
                                         'url-http-proxy-basic-auth-storage))
                                    (url-get-authentication url-http-proxy nil 'any nil))))
                              (if proxy-auth (concat "Proxy-Authorization: " proxy-auth "\r\n")))
                            "\r\n")
                        (url-host url-current-object)
                        (or (url-port url-current-object)
                        url-https-default-port)
                        (url-host url-current-object)))))
相关问题