Subject: Re: bug#53941: 27.2; socks + tor dont work with https

From: "J.P." <[email-masked]>
Date: Sat, 05 Mar 2022 18:58:55 -0800

Jacobo <[email-masked]> writes:

> "J.P." <[email-masked]> writes:
>
>> v3. Passing around an opener function was clunky, so I've opted for
>> passing around contact params instead. I've also gone back to explicitly
>> setting the coding to binary because folks may not be using
>> `url-open-stream' (which does this indirectly by let-binding
>> `coding-system-for-{read,write}').
>
> Emacs 28.0.91 compiled with this patches, dont work, connections dont
> use the proxy

As I tried to explain up thread, the patches only get you half way
there. But perhaps that wasn't clear. You still need to do something
like the following, which is what I MemoServ'd you about (but I guess
you didn't get it). Quoting from there:

  ;; This works with eww. Try https://check.torproject.org

  (require 'socks)
  (require 'gnutls)
  (require 'nsm)

  (setq socks-server '("tor" "127.0.0.1" 9050 5)
        socks-username "user"
        socks-password ""
        url-gateway-method 'socks)

  (defun my-socks-open-https (orig name buffer host service &rest params)
    (let ((proc (apply orig name buffer host service params)))
      (advice-add 'network-lookup-address-info :override #'socks-tor-resolve)
      (unwind-protect
          (when (eq service 443)
            (gnutls-negotiate :process proc :hostname host)
            (unless (string-suffix-p ".onion" host)
              (nsm-verify-connection proc host service)))
        (advice-remove 'network-lookup-address-info #'socks-tor-resolve))
      proc))

  (defun my-url-open-stream (args)
    (pcase-let ((`(,name ,buffer ,host ,service ,gateway-method) args))
      (when (and (eq url-gateway-method 'socks)
                 (eq gateway-method 'tls))
        (setq gateway-method nil))
      (list name buffer host service gateway-method)))

  (advice-add 'socks-open-network-stream :around #'my-socks-open-https)
  (advice-add 'url-open-stream :filter-args #'my-url-open-stream)

The above is an example of what I was getting at in my initial reply
about mimicking the recipe in the last patch (the ERT test). If you have
questions about how to use it, I can help you in real time on Libera, as
we did with applying the patches. Also, please try this with emacs -Q.
Thanks.