SatoshiPortal / cyphernode

Modular Bitcoin full-node microservices API server architecture and utilities toolkit to build scalable, secure and featureful apps and services without trusted third parties
MIT License
363 stars 68 forks source link

Tor bypass cause curl error when not torified #179

Closed Tomtibo closed 4 years ago

Tomtibo commented 4 years ago

I had hard time finding out why I can't receive curl callbacks. Now I found out why ! In notifier docker, the web.sh script at line 36, torbypass shoud be true.

  torbypass=$(echo ${msg} | jq -e ".torbypass")
  # jq -e will have a return code of 1 if the supplied tag is null.
  if [ "$?" -ne "0" ]; then
    # torbypass tag null
    torbypass=false
  torbypass=$(echo ${msg} | jq -e ".torbypass")
  # jq -e will have a return code of 1 if the supplied tag is null.
  if [ "$?" -ne "0" ]; then
    # torbypass tag null
    torbypass=true

I not shure how to properly send PR

FrancisPouliot commented 4 years ago

thanks for reporting this.

By the way feel free to join our slack here https://join.slack.com/t/cyphernode/shared_invite/zt-6o33efer-JJXE9Fox~k_DAJY6u3c79A

Kexkey commented 4 years ago

Hi @Tomtibo ,

During setup, did you select to Torify the different callbacks? If your Cyphernode client is local/not accessible on the Internet, you should not Torify the callbacks.

What is the "curl error" exactly?

Can you have a look at the file .../.cyphernodeconf/installer/config.sh ? What are the values for:

FEATURE_TOR=true
TOR_OTS_WEBHOOKS=true
TOR_ADDR_WATCH_WEBHOOKS=true
TOR_TXID_WATCH_WEBHOOKS=true

Thanks!

Tomtibo commented 4 years ago

For now, nothing is torified, here is my config.sh


FEATURE_TOR=true
TOR_DATAPATH=/home/tom/cyphernode/tor
TOR_OTS_WEBHOOKS=false
TOR_ADDR_WATCH_WEBHOOKS=false
TOR_TXID_WATCH_WEBHOOKS=false
TOR_TRAEFIK=false
TOR_BITCOIN=false
TOR_LIGHTNING=false

edit : Remove not tor related settings.

Tomtibo commented 4 years ago

The reason why I refer to the web.sh, is that the logic seem wrong to me.

  torbypass=$(echo ${msg} | jq -e ".torbypass")
  # jq -e will have a return code of 1 if the supplied tag is null.
  if [ "$?" -ne "0" ]; then    ## if return not equal to  0 (so not torified)
    # torbypass tag null
    torbypass=false    ## torbypass should be true
Tomtibo commented 4 years ago

Here is the notifier logging, with fake info of course.:


2020-03-31T22:45:10+0000 10 [web] torbypass=false
2020-03-31T22:45:10+0000 10 Entering curl_it()...
1+0 records in
1+0 records out
2020-03-31T22:45:10+0000 10 [curl_it] curl --socks5-hostname tor:9050 -o webresponse-92427f4682 -m 20 -w "%{http_code}" -H "Content-Type: application/json" -H "X-Forwarded-Proto: https" -d "{"id":"314","address":"1CZUA9dq3WitJZZbZQpeAD6bqwrgT32D2T","hash":"70ee9e267947564a4a86492c78b18f50cd478925be5c98571ebf68495372d2ae","vout_n":0,"sent_amount":0.00003535,"confirmations":1,"received":"2020-01-30T18:00:03+0000","size":225,"vsize":144,"fees":0.00003180,"is_replaceable":0,"blockhash":"0000000000000000000167e89e563ffb5599db2602736c78b1615e184b8aaf58","blocktime":"2020-01-30T18:01:45+0000","blockheight":656639,"pub32":"xpub0489C17E4FC32DC1CB1BAF3C27C726D887D31F1447C3B62CEEAE37A47AAF5F33FE2CD0B389780859A9635A2B1103E7EA8ECDD9799D4CC4E7BE1985D262F0AD8231","pub32_label":"Electrum_receiving","pub32_derivation_path":"0/20","eventMessage":""}" -k 192.168.0.55:1111
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (7) Can't complete SOCKS5 connection to 0.0.0.0:0. (1)
2020-03-31T22:45:10+0000 10 [curl_it] HTTP return code=000
2020-03-31T22:45:10+0000 10 Last return code: 7
Kexkey commented 4 years ago

Thanks! I will install an instance of cyphernode with the same setup: Tor enabled but nothing torified. I think that's the setup you have?

It's indeed strange to see the callbacks trying to go through Tor when you actually disabled it.

BTW, it makes sense to "bypass Tor" (torbypass=true) when not using Tor. In this case, torbypass should have a value of true. However, if Tor is enabled, torbypass should be false or null or absent from the call to notify. That's why I assign it to false in this case.

We are using this setup at Bull Bitcoin in prod, bypassing Tor for our callbacks. It works well.

Kexkey commented 4 years ago

Reading the logs, it looks like the tor container is not found by the notifier container. I will try to reproduce that. Thanks again!

Kexkey commented 4 years ago

Hi @Tomtibo ! Just a followup to let you know that there's indeed something not right somewhere. I can reproduce the problem. I am on it and I will let you know when it is fixed.

Thanks again for the issue!

Kexkey commented 4 years ago

Can you give a try to latest dev branch version? Commit ed06a00380908b500b2cb1494879e1778e31274b should have fixed the issue.

Kexkey commented 4 years ago

Fix is now released. You can find it in master. Thanks again @Tomtibo !