Skip to content

Commit

Permalink
Namecoin: Add support for SSHFP DNS records
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyRand committed Dec 12, 2019
1 parent 65e87c9 commit f1d6ad1
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
23 changes: 23 additions & 0 deletions electrum_nmc/electrum/gui/qt/configure_dns_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def __init__(self, value, parent):
self.ui.btnNSCreate.clicked.connect(self.create_ns_record)
self.ui.btnDSCreate.clicked.connect(self.create_ds_record)
self.ui.btnTLSCreate.clicked.connect(self.create_tls_record)
self.ui.btnSSHFPCreate.clicked.connect(self.create_sshfp_record)
self.ui.btnTXTCreate.clicked.connect(self.create_txt_record)

self.ui.dialogButtons.accepted.connect(self.accept)
Expand Down Expand Up @@ -227,6 +228,25 @@ def create_tls_record(self):

self.insert_record(idx, record)

def create_sshfp_record(self):
model = self.ui.listDNSRecords.model()
idx = model.rowCount()

domain = self.get_selected_domain()
try:
data = [
int(self.ui.editSSHFPAlgorithm.text()),
int(self.ui.editSSHFPFingerprintType.text()),
self.ui.editSSHFPFingerprint.text(),
]
except ValueError:
self.show_error(_("The Algorithm and Fingerprint Type must be integers."))
return

record = [domain, "sshfp", data]

self.insert_record(idx, record)

def create_txt_record(self):
model = self.ui.listDNSRecords.model()
idx = model.rowCount()
Expand Down Expand Up @@ -298,6 +318,9 @@ def insert_record(self, idx, record):
elif record_type == "tls":
formatted_record_type = "TLS"
formatted_data = json.dumps(data)
elif record_type == "sshfp":
formatted_record_type = "SSHFP"
formatted_data = json.dumps(data)
elif record_type == "txt":
formatted_record_type = "TXT"
formatted_data = json.dumps(data)
Expand Down
48 changes: 48 additions & 0 deletions electrum_nmc/electrum/names.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,12 @@ def get_domain_records(domain, value):
if value["tls"] == []:
del value["tls"]

if "sshfp" in value:
new_records, value["sshfp"] = get_domain_records_sshfp(domain, value["sshfp"])
records.extend(new_records)
if value["sshfp"] == []:
del value["sshfp"]

if "txt" in value:
new_records, value["txt"] = get_domain_records_txt(domain, value["txt"])
records.extend(new_records)
Expand Down Expand Up @@ -835,6 +841,38 @@ def get_domain_records_tls_single(domain, value, protocol, port):

return [domain, "tls", [protocol, port, value]], None

def get_domain_records_sshfp(domain, value):
# Must be array
if type(value) != list:
return [], value

# Parse each array item
records = []
remaining = []
for raw_address in value:
single_record, single_remaining = get_domain_records_sshfp_single(domain, raw_address)
if single_record is not None:
records.append(single_record)
if single_remaining is not None:
remaining.append(single_remaining)

return records, remaining

def get_domain_records_sshfp_single(domain, value):
# Must be array
if type(value) != list:
return None, value

# Must be length 3
if len(value) != 3:
return None, value

# Check value types
if type(value[0]) != int or type(value[1]) != int or type(value[2]) != str:
return None, value

return [domain, "sshfp", value], None

def get_domain_records_txt(domain, value):
# Process Tor specially
if domain.startswith("_tor."):
Expand Down Expand Up @@ -942,6 +980,8 @@ def add_domain_record(base_domain, value, record):
add_domain_record_ds(subdomain_value, data)
elif record_type == "tls":
add_domain_record_tls(subdomain_value, data)
elif record_type == "sshfp":
add_domain_record_sshfp(subdomain_value, data)
elif record_type == "txt":
add_domain_record_txt(subdomain_value, data)

Expand Down Expand Up @@ -1051,6 +1091,14 @@ def add_domain_record_tls(value, data):
# Add the record
value["tls"].append(data)

def add_domain_record_sshfp(value, data):
# Make sure the field exists
if "sshfp" not in value:
value["sshfp"] = []

# Add the record
value["sshfp"].append(data)

def add_domain_record_txt(value, data):
# Make sure the field exists
if "txt" not in value:
Expand Down

0 comments on commit f1d6ad1

Please sign in to comment.