mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-21 19:39:43 +01:00
anope2json certfp support (#1867)
* Advanced certfp support Signed-off-by: Georg <georg@lysergic.dev> * Moving certfp logic Signed-off-by: Georg <georg@lysergic.dev> * Cleaning up certfp logic Signed-off-by: Georg <georg@lysergic.dev>
This commit is contained in:
parent
0483e3f6ad
commit
15f5f2e9b0
@ -1,8 +1,9 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import re
|
import binascii
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
from collections import defaultdict, namedtuple
|
from collections import defaultdict, namedtuple
|
||||||
|
|
||||||
@ -83,6 +84,19 @@ ANOPE_MODENAME_TO_MODE = {
|
|||||||
'SECRET': 's',
|
'SECRET': 's',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# verify that a certfp appears to be a hex-encoded SHA-256 fingerprint;
|
||||||
|
# if it's anything else, silently ignore it
|
||||||
|
def validate_certfps(certobj):
|
||||||
|
certfps = []
|
||||||
|
for fingerprint in certobj.split():
|
||||||
|
try:
|
||||||
|
dec = binascii.unhexlify(fingerprint)
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
if len(dec) == 32:
|
||||||
|
certfps.append(fingerprint)
|
||||||
|
return certfps
|
||||||
|
|
||||||
def convert(infile):
|
def convert(infile):
|
||||||
out = {
|
out = {
|
||||||
'version': 1,
|
'version': 1,
|
||||||
@ -99,6 +113,9 @@ def convert(infile):
|
|||||||
if obj.type == 'NickCore':
|
if obj.type == 'NickCore':
|
||||||
username = obj.kv['display']
|
username = obj.kv['display']
|
||||||
userdata = {'name': username, 'hash': obj.kv['pass'], 'email': obj.kv['email']}
|
userdata = {'name': username, 'hash': obj.kv['pass'], 'email': obj.kv['email']}
|
||||||
|
certobj = obj.kv.get('cert')
|
||||||
|
if certobj:
|
||||||
|
userdata['certfps'] = validate_certfps(certobj)
|
||||||
out['users'][username] = userdata
|
out['users'][username] = userdata
|
||||||
elif obj.type == 'NickAlias':
|
elif obj.type == 'NickAlias':
|
||||||
username = obj.kv['nc']
|
username = obj.kv['nc']
|
||||||
|
Loading…
Reference in New Issue
Block a user