Getting bitcoind to accept https Requests
Can bitcoind accept https requests?
The JSON-RPC server requires basic HTTP authentication. For example, to send a request using curl
:
curl --user av:mypassword \
--data-binary '{"jsonrpc":"1.0","id":"curltext","method":"listunspent","params":[]}' \
-H 'content-type:text/plain;' http://192.168.blah.blah:18443/ \
Authentication (Basic HTTP) Data is basically Plaintext
Authentication data (user name and password) is sent as base 64 encoded plaintext (which can be decoded online)
To avoid this plaintext send, our only option is to use SSH between the client machine and the bitcoind server.
Computer to Computer SSH
If the VM hosting yourbitcoind
software has a way to SSH to the client sending the HTTP request.
- Set up SSH local port forwarding on the client machine – i.e. the computer that will send HTTP requests to the RPC server
ssh -v -fNL 5555:192.168.client.IP:18443 remote_user@192.168.client.IP
To use the tunnel, send traffic to localhost – i.e.
127.0.0.1:5555
host:port
Step 1 – Add rpcssl = 1 to the- bitcoin.conf
config file:
rpcuser = myUsername rpcpassword = myPassword rpcallowip = ipAddressWhitelisteddHost rpcssl = 1 2.
Generate a Self Signed Cert.. Navigate to your data directory.bitcoin
and generate a self-signed certificate. Do not enter a password when it prompts you for one.
openssl genrsa -out server.pem 2048
openssl req -new -x509 -nodes -sha1 -days 3650 -key server.pem > server.cert
Restart bitcoind and test the SSL functionality.
You should see the certificate details. Pressing enter twice will return – HTTP/1.0 401 Authorization Required
.
openssl s_client -connect localhost:8332
bitcoind will now accept RPC-JSON commands through through HTTPS.
Appendix B
Python code for setting up the SSH tunnel
Leave a Reply