-
Notifications
You must be signed in to change notification settings - Fork 0
/
BTCpaylink
80 lines (62 loc) · 3.16 KB
/
BTCpaylink
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python3
import os
import subprocess
def check_tls_fingerprint():
try:
# Get the absolute path to the tls.cert file
tls_cert_path = os.path.expanduser('~/.lnd/tls.cert')
# Execute the OpenSSL command with the absolute path
result = subprocess.run(['openssl', 'x509', '-noout', '-fingerprint', '-sha256', '-inform', 'pem', '-in', tls_cert_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
# Extract the fingerprint and remove colons
fingerprint = result.stdout.strip().replace(":", "")
print(f"TLS Fingerprint: {fingerprint}") # Print the fingerprint
return fingerprint
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
print(e.stderr)
return None
def update_config_with_fingerprint(fingerprint):
if fingerprint is not None:
# Define the path to the settings.config file
config_file_path = os.path.expanduser("~/.btcpayserver/Main/settings.config")
# Read the current content of the configuration file
with open(config_file_path, "r") as file:
config_lines = file.readlines()
# Find and update the line with the certthumbprint
updated_lines = []
for line in config_lines:
if line.strip().startswith("#BTC.lightning="):
line = f'BTC.lightning=type=lnd-rest;server=https://127.0.0.1:8080/;macaroonfilepath=/home/humble/.lnd/data/chain/bitcoin/mainnet/admin.macaroon;certthumbprint="{fingerprint}">\n'
updated_lines.append(line)
# Write the updated content back to the configuration file
with open(config_file_path, "w") as file:
file.writelines(updated_lines)
print("Configuration file updated.")
if __name__ == '__main__':
fingerprint = check_tls_fingerprint()
update_config_with_fingerprint(fingerprint)
def check_tls_fingerprint():
try:
# Get the absolute path to the tls.cert file
tls_cert_path = os.path.expanduser('~/.lnd/tls.cert')
# Execute the OpenSSL command with the absolute path
result = subprocess.run(['openssl', 'x509', '-noout', '-fingerprint', '-sha256', '-inform', 'pem', '-in', tls_cert_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
# Check if the subprocess had an error
if result.returncode != 0:
print(f"Error: {result.stderr.strip()}")
return None
# Extract the fingerprint and remove unwanted text
output_lines = result.stdout.strip().split('\n')
fingerprint_line = [line for line in output_lines if 'Fingerprint=' in line][0]
fingerprint = fingerprint_line.split('=', 1)[1].replace(":", "")
return fingerprint
except Exception as e:
print(f"Error: {e}")
return None
if __name__ == '__main__':
fingerprint = check_tls_fingerprint()
if fingerprint is not None:
lightning_config = f'type=lnd-rest;server=https://localhost:8080/;macaroonfilepath=/home/humble/.lnd/data/chain/bitcoin/mainnet/admin.macaroon;certthumbprint={fingerprint}'
print(lightning_config)
else:
print("TLS fingerprint retrieval failed.")