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

Mak*_*dev 20 authentication emacs proxy elpa emacs24

我已经读过这个这个问题.他们都说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
Run Code Online (Sandbox Code Playgroud)

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

当我M-x package-refresh-contents在Emacs中运行时,它会询问我代理服务器的登录名和密码,但它无法连接到服务器.它甚至不尝试连接,即在我输入密码后立即EnterEmacs 报告: Failed to download 'marmalade' archive

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

gav*_*koa 18

Emacs仅使用HOSTPORT部分来自http_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")))))
Run Code Online (Sandbox Code Playgroud)

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

替换LOGINPASSWORD使用您的身份信息...

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


Mak*_*dev 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
Run Code Online (Sandbox Code Playgroud)

这个代理有地址127.0.0.1:10000.在Emacs中,我必须执行以下代码:

(setq url-proxy-services '(("http" . "127.0.0.1:10000")))
Run Code Online (Sandbox Code Playgroud)


mos*_*net 6

url-httpemacs < 28.1 中的function存在另一个相关错误url-https-proxy-connect,导致通过身份验证代理的所有 https 调用失败。

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

作为 emacs < 28.1 的解决方法,使用固定版本覆盖该函数:

(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)))))
Run Code Online (Sandbox Code Playgroud)


JSO*_*SON 5

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

另一个bug还没有被追查到,不过好像代理服务器请求认证的时候,会提示认证,然后代理服务器的认证请求马上就被包代码处理了。同时,真正的请求在后台继续。