-
Notifications
You must be signed in to change notification settings - Fork 0
/
otr.py
61 lines (54 loc) · 1.75 KB
/
otr.py
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
#!/usr/bin/python
import commondns
import hashlib
dnssec_status = {
"GETDNS_DNSSEC_SECURE" : 400,
"GETDNS_DNSSEC_BOGUS" : 401,
"GETDNS_DNSSEC_INDETERMINATE" : 402,
"GETDNS_DNSSEC_INSECURE" : 403,
"GETDNS_DNSSEC_NOT_PERFORMED" : 404
}
def buildOtrFingerprintHostname(jid):
"""
Build the hostname where the OTR fingerprint should be stored in a
text record if it has been published. Don't forget, it's always
possible that the name will not exist.
"""
parts = jid.split('@')
hostname = hashlib.sha224(parts[0]).hexdigest()
hostname += "._otrfingerprint."
hostname += parts[1]
hostname += ".iain.getdnsapi.net"
return hostname
def lookupOtrFingerprintRecords(hostname):
"""
TODO: Update
"""
records = []
for record, dnssec_valid in commondns.lookupTextRecords(hostname):
if record[0:7] == "v=otr1 ":
records.append((record, dnssec_valid))
return records
def parseOtrFingerprintRecord(value):
"""
Extract fingerprints from an OTR fingerprint record's value.
"""
parts = value.split(" ")
fingerprints = []
for part in parts:
if part[0:2] == "f:":
fingerprints.append(part[2:])
return fingerprints
def getOtrFingerprints(jid):
"""
Returns a list of tuples containing OTR fingerprints published in
DNS for a Jabber ID and whether or not DNSSEC validation was
successfully performed for each fingerprint.
"""
hostname = buildOtrFingerprintHostname(jid)
records = lookupOtrFingerprintRecords(hostname)
fingerprints = []
for record, dnssec_valid in records:
for fingerprint in parseOtrFingerprintRecord(record):
fingerprints.append((fingerprint, dnssec_valid))
return fingerprints