使Emacs通过Socks代理访问HTTPS
这个问题让我发疯。我有一个本地SOCKSv5代理,它是系统上所有应用程序的网关。我想让使Emacs通过Socks代理访问HTTPS,emacs,proxy,elisp,socks,Emacs,Proxy,Elisp,Socks,这个问题让我发疯。我有一个本地SOCKSv5代理,它是系统上所有应用程序的网关。我想让url同步检索检查袜子。使用以下设置: (setq socks-noproxy '("127.0.0.1")) (setq socks-server '("Default server" "127.0.0.1" 8010 5)) (setq url-gateway-method 'socks) 通过普通HTTP检索正常: (url-retrieve-synchronously "http://gnu.org"
url同步检索
检查袜子。使用以下设置:
(setq socks-noproxy '("127.0.0.1"))
(setq socks-server '("Default server" "127.0.0.1" 8010 5))
(setq url-gateway-method 'socks)
通过普通HTTP检索正常:
(url-retrieve-synchronously "http://gnu.org")
#<buffer *http www.gnu.org:80*>
它导致:
Debugger entered--Lisp error: (file-error "make client process failed" "connection timed out" :name "gnu.org" :buffer #<buffer *url-http-temp*> :host "gnu.org" :service 443 :nowait nil)
make-network-process(:name "gnu.org" :buffer #<buffer *url-http-temp*> :host "gnu.org" :service 443 :nowait nil)
open-network-stream("gnu.org" #<buffer *url-http-temp*> "gnu.org" 443)
open-gnutls-stream("gnu.org" #<buffer *url-http-temp*> "gnu.org" 443)
network-stream-open-tls("gnu.org" #<buffer *url-http-temp*> "gnu.org" 443 (:type tls :nowait nil))
open-network-stream("gnu.org" #<buffer *url-http-temp*> "gnu.org" 443 :type tls :nowait nil)
byte-code("\306\211\n\307>\203$
调试器已输入--Lisp错误:(文件错误“使客户端进程失败”“连接超时”:名称“gnu.org”:缓冲区:主机“gnu.org”:服务443:nowait nil)
创建网络进程(:name“gnu.org”:buffer#:host“gnu.org”:service 443:nowait nil)
开放网络流(“gnu.org”#“gnu.org”443)
打开gnutls流(“gnu.org”#“gnu.org”443)
网络流开放tls(“gnu.org”#“gnu.org”443(:type tls:nowait nil))
开放网络流(“gnu.org”#“gnu.org”443:type tls:nowait nil)
字节码(“\306\211\n\307>\203$
问题:如何使HTTPS在Emacs中通过socks工作?我的版本是24.2.50/W32
我知道出于某种原因,使用了原始的开放网络流
,而不是socks open network stream
。我试图使用edebug中断url open stream
,但无法理解为什么没有触发断点。有什么想法吗
谢谢。另一种方法是使用程序
proxychains
从命令行启动emacs,proxychains
支持HTTP socks4和socks5代理协议。代码可能是:
proxycarks&
不用说,您必须在proxychains而不是emacs中配置代理设置
PS:别忘了在配置文件(
/etc/proxychains.conf
)中以quiet\u模式设置代理链,否则详细的输出可能会提示您。至少在Fedora上,这不是默认设置。GamerH2o-我从来没有得到过
proxychains emacs &
工作。对我来说,我必须做
proxychains bash-script.sh &
其中bash-script.sh是一个脚本
#!/bin/bash
/path/to/emacs --debug-init --geometry 83X40 --no-splash & ;;
exit 0
它启动了emacs。我的实际脚本比上面稍微复杂一些,因为我包含了各种选项,但这是一般的想法。我现在可以使用w3m或eww作为“emacs internet浏览器”。我通过dns服务器的通道在xterm中回音。(我使用的是tor而不是“免费anon服务器”。创建~/.emacs.d/w3m.sh:
#!/bin/bash
proxychains /usr/bin/w3m "$@"
自定义w3m:
(setq w3m-command "~/.emacs.d/w3m.sh")
然后,只有w3m使用代理。它在emacs当前版本(选中25.2.2)中得到修复。这是emacs 26.3之上的一个bug,在url http
函数中,url http
的签名如下所示:
(defun url-http (url callback cbargs &optional retry-buffer gateway-method) ...)
可选的网关方法
参数试图覆盖url网关方法
,但编码错误:
(connection (url-http-find-free-connection
(url-host url)
(url-port url)
gateway-method))
正确的方法是:
(connection (url-http-find-free-connection
(url-host url)
(url-port url)
(or gateway-method url-gateway-method)))
在Emacs 24版本中,url网关方法
局部变量已硬编码到的tls
(defmacro url-https-create-secure-wrapper (method args)
`(defun ,(intern (format (if method "url-https-%s" "url-https") method)) ,args
,(format "HTTPS wrapper around `%s' call." (or method "url-http"))
(let ((url-gateway-method 'tls))
(,(intern (format (if method "url-http-%s" "url-http") method))
,@(remove '&rest (remove '&optional args))))))
Emacs版本>=25的修复程序:
(defadvice url-http (around url-http-around activate disable)
"Fix the `url-gateway-method' bug in `url-http'."
(if (eq 'socks url-gateway-method)
(let ((gateway-method url-gateway-method))
ad-do-it)
ad-do-it))
Emacs版本<25的修复程序:
(defvar *url-gateway-method* nil
"Alias of `url-gateway-method' used to fix the bug in `url-http'.")
(defadvice url-http (around url-http-around compile)
"Fix the `url-gateway-method' bug in `url-https'."
(let ((url-gateway-method (if (eq *url-gateway-method* 'socks)
'socks
'tls)))
ad-do-it))
最后,您可以在这里查看修复:。我已经跟踪到了问题。Emacs中肯定有一个bug。有一个宏url https create secure wrapper
,它在url http
函数上创建了一个包装器;在包装器中,url gateway method
的值被tls
值覆盖。这导致s跳过使用SOCKS和使用direct gateway进行连接。目前我不知道如何破解/解决此问题。重新定义url https创建安全包装
?将不起作用;至少以我对ELisp的了解而言。如果我重新定义url https创建安全包装
,则连接将通过SOCKS,但会使用plain HTTP协商不是HTTPS。包装器应使用SOCKS代理作为主网络流,但不用于HTTPS。M-x report emacs bug
如果您还没有这样做?(假设尚未修复?)
(defvar *url-gateway-method* nil
"Alias of `url-gateway-method' used to fix the bug in `url-http'.")
(defadvice url-http (around url-http-around compile)
"Fix the `url-gateway-method' bug in `url-https'."
(let ((url-gateway-method (if (eq *url-gateway-method* 'socks)
'socks
'tls)))
ad-do-it))