diff --git a/README.md b/README.md index 93dc7a6..209fb55 100644 --- a/README.md +++ b/README.md @@ -8,17 +8,38 @@ At the ending of [documentation](https://github.com/Tribler/trustchain-superapp/ The server uses Letsencrypt to retrieve a certificate for HTTPS. This certificate is automatically renewed via cronjob (crontab of root user) which runs on the first day of the month. To receive the signature ACME identification is needed, while this could be done via DNS, HTTP was easier for us. So also you will find code in the python server that performs the response to an ACME challenge. The code for server (and bash history for help) is all on this github. This github contains all of our scripts, which are fully documented. In addition, our own library, as well as all other code, is fully documented. Please check out the code with the documentation to understand the flow in the app and how everything works together. ## Bitcoin commands -- Start: ./home/bitcoin/bitcoin-0.21.0/bin/bitcoind -conf=/home/bitcoin/bitcoin-node/bitcoin.conf -- Stop: ./home/bitcoin/bitcoin-0.21.0/bin/bitcoin-cli -conf=/home/bitcoin/bitcoin-node/bitcoin.conf stop +- Start: ./home/bitcoin/bitcoin-0.26.1/bin/bitcoind -conf=[Absolute path to the config, it is located in home/bitcoin/bitcoin-node/bitcoin.conf] +- Stop: ./home/bitcoin/bitcoin-0.26.1/bin/bitcoin-cli -conf=[Absolute path to the config, it is located in home/bitcoin/bitcoin-node/bitcoin.conf] stop - For more commands see: https://chainquery.com/bitcoin-cli +## Creating a key and cert file +This approach uses OpenSSL. The following commands were used to create a private key and a self signed certificate. +- 'openssl genrsa -out key.pem 2048' generates a 2048 bit RSA private key +- 'openssl req -new -sha256 -key privkey.pem -out csr.csr' creates a Certificate Signing Request (CSR) +- 'openssl req -x509 -sha256 -days 365 -key privkey.pem -in csr.csr -out fullchain.pem' generates a self-signed x509 certificate + +In order for this server to work locally with the android application we need to create custom config file for SAN. This file looks as follows +subjectKeyIdentifier = hash +authorityKeyIdentifier = keyid:always,issuer:always +basicConstraints = CA:TRUE +keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment, keyAgreement, keyCertSign +subjectAltName = DNS:example.com, DNS:*.example.com +issuerAltName = issuer:copy + +In our case we need to include an IP subjectAltName for the IP '10.0.2.2'. We do this by assigning the value IP:10.0.2.2 to subjectAltName in the SAN config file. +- touch san_config.ext (to create the SAN config file) + +In order to include this config in the cert file, the third command mentioned before needs to be changed slightly to: +- 'openssl x509 -req -in csr.csr -signkey privkey.pem -out fullchain.pem -days 365 -sha256 -extfile san_config.ext' generates a self-signed x509 certificate + ## Reset bitcoin server - delete everything in the .bitcoin folder -- restart bitcoind -- create a new wallet -- load the new wallet -- generate a new address for the wallet +- restart bitcoind (bitcoind -conf='CONF FILE PATH') +- create a new wallet (bitcoin-cli createwallet "NAME_OF_WALLET") +- load the new wallet (done by default if the wallet is newly created, you can skip this step. Otherwise you can use: bitcoin-cli loadwallet "filename_of_wallet.dat") +- generate a new address for the wallet (bitcoin-cli getnewaddress "label") - copy this address to the python server and the crontab job +- mine some btc to newly created address (bitcoin-cli generatetoaddress nblocks "address") NOTE: this cannot be done on the testnet - make sure all devices connected to the network are reset as well (otherwise they do not have matching blockchains) ## Reset python server diff --git a/home/bitcoin/bitcoin-0.21.0/README.md b/home/bitcoin/bitcoin-0.26.1/README.md similarity index 100% rename from home/bitcoin/bitcoin-0.21.0/README.md rename to home/bitcoin/bitcoin-0.26.1/README.md diff --git a/home/bitcoin/bitcoin-0.21.0/bin/bitcoin-cli b/home/bitcoin/bitcoin-0.26.1/bin/bitcoin-cli similarity index 100% rename from home/bitcoin/bitcoin-0.21.0/bin/bitcoin-cli rename to home/bitcoin/bitcoin-0.26.1/bin/bitcoin-cli diff --git a/home/bitcoin/bitcoin-0.21.0/bin/bitcoin-qt b/home/bitcoin/bitcoin-0.26.1/bin/bitcoin-qt similarity index 67% rename from home/bitcoin/bitcoin-0.21.0/bin/bitcoin-qt rename to home/bitcoin/bitcoin-0.26.1/bin/bitcoin-qt index 3b623a1..604e2c0 100644 Binary files a/home/bitcoin/bitcoin-0.21.0/bin/bitcoin-qt and b/home/bitcoin/bitcoin-0.26.1/bin/bitcoin-qt differ diff --git a/home/bitcoin/bitcoin-0.21.0/bin/bitcoin-tx b/home/bitcoin/bitcoin-0.26.1/bin/bitcoin-tx similarity index 100% rename from home/bitcoin/bitcoin-0.21.0/bin/bitcoin-tx rename to home/bitcoin/bitcoin-0.26.1/bin/bitcoin-tx diff --git a/home/bitcoin/bitcoin-0.21.0/bin/bitcoin-wallet b/home/bitcoin/bitcoin-0.26.1/bin/bitcoin-wallet similarity index 100% rename from home/bitcoin/bitcoin-0.21.0/bin/bitcoin-wallet rename to home/bitcoin/bitcoin-0.26.1/bin/bitcoin-wallet diff --git a/home/bitcoin/bitcoin-0.21.0/bin/bitcoind b/home/bitcoin/bitcoin-0.26.1/bin/bitcoind similarity index 53% rename from home/bitcoin/bitcoin-0.21.0/bin/bitcoind rename to home/bitcoin/bitcoin-0.26.1/bin/bitcoind index 5b0c4b9..a7b43a8 100644 Binary files a/home/bitcoin/bitcoin-0.21.0/bin/bitcoind and b/home/bitcoin/bitcoin-0.26.1/bin/bitcoind differ diff --git a/home/bitcoin/bitcoin-0.21.0/bin/test_bitcoin b/home/bitcoin/bitcoin-0.26.1/bin/test_bitcoin similarity index 100% rename from home/bitcoin/bitcoin-0.21.0/bin/test_bitcoin rename to home/bitcoin/bitcoin-0.26.1/bin/test_bitcoin diff --git a/home/bitcoin/bitcoin-0.21.0/include/bitcoinconsensus.h b/home/bitcoin/bitcoin-0.26.1/include/bitcoinconsensus.h similarity index 100% rename from home/bitcoin/bitcoin-0.21.0/include/bitcoinconsensus.h rename to home/bitcoin/bitcoin-0.26.1/include/bitcoinconsensus.h diff --git a/home/bitcoin/bitcoin-0.21.0/lib/libbitcoinconsensus.so b/home/bitcoin/bitcoin-0.26.1/lib/libbitcoinconsensus.so similarity index 100% rename from home/bitcoin/bitcoin-0.21.0/lib/libbitcoinconsensus.so rename to home/bitcoin/bitcoin-0.26.1/lib/libbitcoinconsensus.so diff --git a/home/bitcoin/bitcoin-0.21.0/lib/libbitcoinconsensus.so.0 b/home/bitcoin/bitcoin-0.26.1/lib/libbitcoinconsensus.so.0 similarity index 100% rename from home/bitcoin/bitcoin-0.21.0/lib/libbitcoinconsensus.so.0 rename to home/bitcoin/bitcoin-0.26.1/lib/libbitcoinconsensus.so.0 diff --git a/home/bitcoin/bitcoin-0.21.0/lib/libbitcoinconsensus.so.0.0.0 b/home/bitcoin/bitcoin-0.26.1/lib/libbitcoinconsensus.so.0.0.0 similarity index 100% rename from home/bitcoin/bitcoin-0.21.0/lib/libbitcoinconsensus.so.0.0.0 rename to home/bitcoin/bitcoin-0.26.1/lib/libbitcoinconsensus.so.0.0.0 diff --git a/home/bitcoin/bitcoin-0.21.0/share/man/man1/bitcoin-cli.1 b/home/bitcoin/bitcoin-0.26.1/share/man/man1/bitcoin-cli.1 similarity index 100% rename from home/bitcoin/bitcoin-0.21.0/share/man/man1/bitcoin-cli.1 rename to home/bitcoin/bitcoin-0.26.1/share/man/man1/bitcoin-cli.1 diff --git a/home/bitcoin/bitcoin-0.21.0/share/man/man1/bitcoin-qt.1 b/home/bitcoin/bitcoin-0.26.1/share/man/man1/bitcoin-qt.1 similarity index 100% rename from home/bitcoin/bitcoin-0.21.0/share/man/man1/bitcoin-qt.1 rename to home/bitcoin/bitcoin-0.26.1/share/man/man1/bitcoin-qt.1 diff --git a/home/bitcoin/bitcoin-0.21.0/share/man/man1/bitcoin-tx.1 b/home/bitcoin/bitcoin-0.26.1/share/man/man1/bitcoin-tx.1 similarity index 100% rename from home/bitcoin/bitcoin-0.21.0/share/man/man1/bitcoin-tx.1 rename to home/bitcoin/bitcoin-0.26.1/share/man/man1/bitcoin-tx.1 diff --git a/home/bitcoin/bitcoin-0.21.0/share/man/man1/bitcoin-wallet.1 b/home/bitcoin/bitcoin-0.26.1/share/man/man1/bitcoin-wallet.1 similarity index 100% rename from home/bitcoin/bitcoin-0.21.0/share/man/man1/bitcoin-wallet.1 rename to home/bitcoin/bitcoin-0.26.1/share/man/man1/bitcoin-wallet.1 diff --git a/home/bitcoin/bitcoin-0.21.0/share/man/man1/bitcoind.1 b/home/bitcoin/bitcoin-0.26.1/share/man/man1/bitcoind.1 similarity index 100% rename from home/bitcoin/bitcoin-0.21.0/share/man/man1/bitcoind.1 rename to home/bitcoin/bitcoin-0.26.1/share/man/man1/bitcoind.1 diff --git a/home/bitcoin/bitcoin-node/bitcoin.conf b/home/bitcoin/bitcoin-node/bitcoin.conf index 7ba7589..936ec62 100644 --- a/home/bitcoin/bitcoin-node/bitcoin.conf +++ b/home/bitcoin/bitcoin-node/bitcoin.conf @@ -2,23 +2,25 @@ ## bitcoin.conf configuration file. Lines beginning with # are comments. ## +# Change the datadir value to the path of your .bitcoin directory datadir=/home/bitcoin/bitcoin-node/.bitcoin daemon=1 peerbloomfilters=1 + # Network-related settings: # Note that if you use testnet, signet or regtest, particularly with the options # addnode, connect, port, bind, rpcport, rpcbind or wallet, you will also # want to read "[Sections]" further down. -# Run on the testnet network -#testnet=0 +# Run on the testnet network by changing the value to 1 (active) or 0 (inactive) +testnet=1 -# Run on a signet network +# Run on a signet network by changing the value to 1 (active) or 0 (inactive) #signet=0 -# Run a regression test network -regtest=1 +# Run a regression test network by changing the value to 1 (active) or 0 (inactive) +# regtest=0 # Connect via a SOCKS5 proxy #proxy=127.0.0.1:9050 @@ -170,6 +172,9 @@ rpcallowip=0.0.0.0/0 # Options only for testnet [test] +rpcport=18443 +rpcbind=0.0.0.0 +fallbackfee=0.00000002 # Options only for signet [signet] diff --git a/home/bitcoin/server.py b/home/bitcoin/server.py index 960252d..1981f36 100644 --- a/home/bitcoin/server.py +++ b/home/bitcoin/server.py @@ -7,14 +7,18 @@ import ssl import re import copy +import os -amount = 10 +# set the amount as you please (for testnest it is recommended to use a small amount) +amount = 0.00001 address_regex = r"[a-km-zA-HJ-NP-Z1-9]{25,50}$" transaction_regex = r"[0-1]{5,11}[a-fA-F0-9]{100,800}" -command_start = ['/home/bitcoin/bitcoin-0.21.0/bin/bitcoin-cli', '-conf=/home/bitcoin/bitcoin-node/bitcoin.conf'] +command_start = ['/home/bitcoin/bitcoin-0.26.1/bin/bitcoin-cli', '-conf=/home/bitcoin/bitcoin-node/bitcoin.conf'] challenge_response = "Aegfote4P6GXJZrEtpl4LrV2bhCPYskHWmtNghJ7mrc" -address_stored_btc = 'bcrt1qz7n0np33ukt05q3f7h59pg9kch7gaqhfkg54vl' + +# change the address to the address of the wallet you created (see readme for instructions) +address_stored_btc = 'tb1qfpd4u746w6m8305mzuwfy6494m402cjurkeprr' def valid_hex(result): @@ -68,6 +72,7 @@ def add_btc(self, query_params): command = copy.deepcopy(command_start) command.extend(['sendtoaddress', address, f'{amount}']) + logging.info(f'COMMAND IS: {command}') result = subprocess.run(command, stdout=subprocess.PIPE) logging.info(f'Result is: {result}') @@ -150,8 +155,8 @@ def run(server_class=HTTPServer, handler_class=S, port=443): logging.basicConfig(level=logging.INFO) server_address = ('', port) httpd = server_class(server_address, handler_class) - httpd.socket = ssl.wrap_socket(httpd.socket, keyfile="/etc/letsencrypt/live/taproot.tribler.org/privkey.pem", - certfile='/etc/letsencrypt/live/taproot.tribler.org/fullchain.pem', server_side=True) + httpd.socket = ssl.wrap_socket(httpd.socket, keyfile="/PATH_TO_YOUR/privkey.pem", + certfile='/PATH_TO_YOUR/fullchain1.pem', server_side=True) logging.info('Starting server...\n') try: httpd.serve_forever()