mirror of
				https://github.com/ergochat/ergo.git
				synced 2025-10-30 21:37:23 +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 | ||||
| 
 | ||||
| import re | ||||
| import binascii | ||||
| import json | ||||
| import logging | ||||
| import re | ||||
| import sys | ||||
| from collections import defaultdict, namedtuple | ||||
| 
 | ||||
| @ -83,6 +84,19 @@ ANOPE_MODENAME_TO_MODE = { | ||||
|     '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): | ||||
|     out = { | ||||
|         'version': 1, | ||||
| @ -99,6 +113,9 @@ def convert(infile): | ||||
|         if obj.type == 'NickCore': | ||||
|             username = obj.kv['display'] | ||||
|             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 | ||||
|         elif obj.type == 'NickAlias': | ||||
|             username = obj.kv['nc'] | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 GitHub
							GitHub