def parse(settingsdir=None): if settingsdir == None: settingsdir = JitsiProperties.path p = Properties() p.load(open(os.path.join(settingsdir, JitsiProperties.propertiesfile))) keydict = dict() for item in p.items(): propkey = item[0] name = "" if re.match("net\.java\.sip\.communicator\.impl\.protocol\.jabber\.acc[0-9]+\.ACCOUNT_UID", propkey): name = JitsiProperties._parse_account_uid(item[1]) if name in keydict: key = keydict[name] else: key = dict() key["name"] = name key["protocol"] = "prpl-jabber" keydict[name] = key propkey_base = "net.java.sip.communicator.plugin.otr." + re.sub("[^a-zA-Z0-9_]", "_", item[1]) private_key = p.getProperty(propkey_base + "_privateKey").strip() public_key = p.getProperty(propkey_base + "_publicKey").strip() numdict = util.ParsePkcs8(private_key) key["x"] = numdict["x"] numdict = util.ParseX509(public_key) for num in ("y", "g", "p", "q"): key[num] = numdict[num] key["fingerprint"] = util.fingerprint((key["y"], key["g"], key["p"], key["q"])) verifiedkey = ( "net.java.sip.communicator.plugin.otr." + re.sub("[^a-zA-Z0-9_]", "_", key["name"]) + "_publicKey_verified" ) if p.getProperty(verifiedkey).strip() == "true": key["verification"] = "verified" elif re.match("net\.java\.sip\.communicator\.plugin\.otr\..*_publicKey_verified", propkey): name, protocol = JitsiProperties._parse_account_from_propkey(settingsdir, propkey) if name != None: if name not in keydict: key = dict() key["name"] = name keydict[name] = key if protocol and "protocol" not in keydict[name]: keydict[name]["protocol"] = protocol keydict[name]["verification"] = "verified" # if the protocol name is included in the property name, its a local account with private key elif re.match("net\.java\.sip\.communicator\.plugin\.otr\..*_publicKey", propkey) and not re.match( "net\.java\.sip\.communicator\.plugin\.otr\.(Jabber_|Google_Talk_)", propkey ): name, ignored = JitsiProperties._parse_account_from_propkey(settingsdir, propkey) if name not in keydict: key = dict() key["name"] = name key["protocol"] = "prpl-jabber" keydict[name] = key numdict = util.ParseX509(item[1]) for num in ("y", "g", "p", "q"): key[num] = numdict[num] key["fingerprint"] = util.fingerprint((key["y"], key["g"], key["p"], key["q"])) return keydict
def parse(settingsdir=None): if settingsdir == None: settingsdir = JitsiProperties.path p = Properties() p.load(open(os.path.join(settingsdir, JitsiProperties.propertiesfile))) keydict = dict() for item in p.items(): propkey = item[0] name = '' if re.match('net\.java\.sip\.communicator\.impl\.protocol\.jabber\.acc[0-9]+\.ACCOUNT_UID', propkey): name = JitsiProperties._parse_account_uid(item[1]) if name in keydict: key = keydict[name] else: key = dict() key['name'] = name key['protocol'] = 'prpl-jabber' keydict[name] = key propkey_base = ('net.java.sip.communicator.plugin.otr.' + re.sub('[^a-zA-Z0-9_]', '_', item[1])) private_key = p.getProperty(propkey_base + '_privateKey').strip() public_key = p.getProperty(propkey_base + '_publicKey').strip() numdict = util.ParsePkcs8(private_key) key['x'] = numdict['x'] numdict = util.ParseX509(public_key) for num in ('y', 'g', 'p', 'q'): key[num] = numdict[num] key['fingerprint'] = util.fingerprint((key['y'], key['g'], key['p'], key['q'])) verifiedkey = ('net.java.sip.communicator.plugin.otr.' + re.sub('[^a-zA-Z0-9_]', '_', key['name']) + '_publicKey_verified') if p.getProperty(verifiedkey).strip() == 'true': key['verification'] = 'verified' elif (re.match('net\.java\.sip\.communicator\.plugin\.otr\..*_publicKey_verified', propkey)): name, protocol = JitsiProperties._parse_account_from_propkey(settingsdir, propkey) if name != None: if name not in keydict: key = dict() key['name'] = name keydict[name] = key if protocol and 'protocol' not in keydict[name]: keydict[name]['protocol'] = protocol keydict[name]['verification'] = 'verified' # if the protocol name is included in the property name, its a local account with private key elif (re.match('net\.java\.sip\.communicator\.plugin\.otr\..*_publicKey', propkey) and not re.match('net\.java\.sip\.communicator\.plugin\.otr\.(Jabber_|Google_Talk_)', propkey)): name, ignored = JitsiProperties._parse_account_from_propkey(settingsdir, propkey) if name not in keydict: key = dict() key['name'] = name key['protocol'] = 'prpl-jabber' keydict[name] = key numdict = util.ParseX509(item[1]) for num in ('y', 'g', 'p', 'q'): key[num] = numdict[num] key['fingerprint'] = util.fingerprint((key['y'], key['g'], key['p'], key['q'])) return keydict
def parse(filename): '''parse the given file into the standard keydict''' # the parsing and generation is done in separate passes so that # multiple properties are combined into a single keydict per account, # containing all of the fields p = pyjavaproperties.Properties() p.load(open(filename)) parsed = [] for item in p.items(): propkey = item[0] if propkey.endswith('.publicKey'): id = '.'.join(propkey.split('.')[0:-1]) parsed.append(('public-key', id, item[1])) elif propkey.endswith('.publicKey.verified'): keylist = propkey.split('.') fingerprint = keylist[-3] id = '.'.join(keylist[0:-3]) parsed.append(('verified', id, fingerprint)) elif propkey.endswith('.privateKey'): id = '.'.join(propkey.split('.')[0:-1]) parsed.append(('private-key', id, item[1])) # create blank keys for all IDs keydict = dict() for keydata in parsed: name = keydata[1] if not name in keydict: keydict[name] = dict() keydict[name]['name'] = name keydict[name]['protocol'] = 'prpl-jabber' if keydata[0] == 'private-key': cleaned = keydata[2].replace('\\n', '') numdict = util.ParsePkcs8(cleaned) for num in ('g', 'p', 'q', 'x'): keydict[name][num] = numdict[num] elif keydata[0] == 'verified': keydict[name]['verification'] = 'verified' fingerprint = keydata[2].lower() util.check_and_set(keydict[name], 'fingerprint', fingerprint) elif keydata[0] == 'public-key': cleaned = keydata[2].replace('\\n', '') numdict = util.ParseX509(cleaned) for num in ('y', 'g', 'p', 'q'): keydict[name][num] = numdict[num] fingerprint = util.fingerprint( (numdict['y'], numdict['g'], numdict['p'], numdict['q'])) util.check_and_set(keydict[name], 'fingerprint', fingerprint) return keydict
def parse(filename): '''parse the given file into the standard keydict''' # the parsing and generation is done in separate passes so that # multiple properties are combined into a single keydict per account, # containing all of the fields p = pyjavaproperties.Properties() p.load(open(filename)) parsed = [] for item in p.items(): propkey = item[0] if propkey.endswith('.publicKey'): id = '.'.join(propkey.split('.')[0:-1]) parsed.append(('public-key', id, item[1])) elif propkey.endswith('.publicKey.verified'): keylist = propkey.split('.') fingerprint = keylist[-3] id = '.'.join(keylist[0:-3]) parsed.append(('verified', id, fingerprint)) elif propkey.endswith('.privateKey'): id = '.'.join(propkey.split('.')[0:-1]) parsed.append(('private-key', id, item[1])) # create blank keys for all IDs keydict = dict() for keydata in parsed: name = keydata[1] if not name in keydict: keydict[name] = dict() keydict[name]['name'] = name keydict[name]['protocol'] = 'prpl-jabber' if keydata[0] == 'private-key': cleaned = keydata[2].replace('\\n', '') numdict = util.ParsePkcs8(cleaned) for num in ('g', 'p', 'q', 'x'): keydict[name][num] = numdict[num] elif keydata[0] == 'verified': keydict[name]['verification'] = 'verified' fingerprint = keydata[2].lower() util.check_and_set(keydict[name], 'fingerprint', fingerprint) elif keydata[0] == 'public-key': cleaned = keydata[2].replace('\\n', '') numdict = util.ParseX509(cleaned) for num in ('y', 'g', 'p', 'q'): keydict[name][num] = numdict[num] fingerprint = util.fingerprint((numdict['y'], numdict['g'], numdict['p'], numdict['q'])) util.check_and_set(keydict[name], 'fingerprint', fingerprint) return keydict
def parse(filename): """parse the otr.private_key S-Expression and return an OTR dict""" f = open(filename, "r") data = "" for line in f.readlines(): data += line f.close() sexplist = OtrPrivateKeys.parse_sexp(data) keydict = dict() for sexpkey in sexplist: if sexpkey[0] == "account": key = dict() name = "" for element in sexpkey: # 'name' must be the first element in the sexp or BOOM! if element[0] == "name": if element[1].find("/") > -1: name, resource = element[1].split("/") else: name = element[1].strip() resource = "" key = dict() key["name"] = name.strip() key["resource"] = resource.strip() if element[0] == "protocol": key["protocol"] = element[1] elif element[0] == "private-key": if element[1][0] == "dsa": key["type"] = "dsa" for num in element[1][1:6]: key[num[0]] = num[1] keytuple = (key["y"], key["g"], key["p"], key["q"]) key["fingerprint"] = util.fingerprint(keytuple) keydict[name] = key return keydict
def parse(filename): '''parse the otr.private_key S-Expression and return an OTR dict''' f = open(filename, 'r') data = "" for line in f.readlines(): data += line f.close() sexplist = OtrPrivateKeys.parse_sexp(data) keydict = dict() for sexpkey in sexplist: if sexpkey[0] == "account": key = dict() name = '' for element in sexpkey: # 'name' must be the first element in the sexp or BOOM! if element[0] == "name": if element[1].find('/') > -1: name, resource = element[1].split('/') else: name = element[1].strip() resource = '' key = dict() key['name'] = name.strip() key['resource'] = resource.strip() if element[0] == "protocol": key['protocol'] = element[1] elif element[0] == "private-key": if element[1][0] == 'dsa': key['type'] = 'dsa' for num in element[1][1:6]: key[num[0]] = num[1] keytuple = (key['y'], key['g'], key['p'], key['q']) key['fingerprint'] = util.fingerprint(keytuple) keydict[name] = key return keydict
def parse(settingsdir=None): if settingsdir == None: settingsdir = JitsiProperties.path p = Properties() p.load(open(os.path.join(settingsdir, JitsiProperties.propertiesfile))) keydict = dict() for item in p.items(): propkey = item[0] name = '' if re.match( 'net\.java\.sip\.communicator\.impl\.protocol\.jabber\.acc[0-9]+\.ACCOUNT_UID', propkey): name = JitsiProperties._parse_account_uid(item[1]) if name in keydict: key = keydict[name] else: key = dict() key['name'] = name key['protocol'] = 'prpl-jabber' keydict[name] = key propkey_base = ('net.java.sip.communicator.plugin.otr.' + re.sub('[^a-zA-Z0-9_]', '_', item[1])) private_key = p.getProperty(propkey_base + '_privateKey').strip() public_key = p.getProperty(propkey_base + '_publicKey').strip() numdict = util.ParsePkcs8(private_key) key['x'] = numdict['x'] numdict = util.ParseX509(public_key) for num in ('y', 'g', 'p', 'q'): key[num] = numdict[num] key['fingerprint'] = util.fingerprint( (key['y'], key['g'], key['p'], key['q'])) verifiedkey = ('net.java.sip.communicator.plugin.otr.' + re.sub('[^a-zA-Z0-9_]', '_', key['name']) + '_publicKey_verified') if p.getProperty(verifiedkey).strip() == 'true': key['verification'] = 'verified' elif (re.match( 'net\.java\.sip\.communicator\.plugin\.otr\..*_publicKey_verified', propkey)): name, protocol = JitsiProperties._parse_account_from_propkey( settingsdir, propkey) if name != None: if name not in keydict: key = dict() key['name'] = name keydict[name] = key if protocol and 'protocol' not in keydict[name]: keydict[name]['protocol'] = protocol keydict[name]['verification'] = 'verified' # if the protocol name is included in the property name, its a local account with private key elif (re.match( 'net\.java\.sip\.communicator\.plugin\.otr\..*_publicKey', propkey ) and not re.match( 'net\.java\.sip\.communicator\.plugin\.otr\.(Jabber_|Google_Talk_)', propkey)): name, ignored = JitsiProperties._parse_account_from_propkey( settingsdir, propkey) if name not in keydict: key = dict() key['name'] = name key['protocol'] = 'prpl-jabber' keydict[name] = key numdict = util.ParseX509(item[1]) for num in ('y', 'g', 'p', 'q'): key[num] = numdict[num] key['fingerprint'] = util.fingerprint( (key['y'], key['g'], key['p'], key['q'])) return keydict