From cbaa5cf408b6cb0d6787e53921d2b3add53303f6 Mon Sep 17 00:00:00 2001 From: masq Date: Tue, 11 Mar 2025 08:20:49 +0100 Subject: [PATCH] [new] vdirsyncer_update_fingerprints.py --- vdirsyncer_update_fingerprints.py | 55 +++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100755 vdirsyncer_update_fingerprints.py diff --git a/vdirsyncer_update_fingerprints.py b/vdirsyncer_update_fingerprints.py new file mode 100755 index 0000000..a2f4a17 --- /dev/null +++ b/vdirsyncer_update_fingerprints.py @@ -0,0 +1,55 @@ +#!/usr/bin/python3 + +import sys +import os +from configparser import ConfigParser +from urllib.parse import urlparse +import subprocess + +def get_fingerprint(url): + return subprocess.run(['ssl_get_fingerprint.sh', url], + capture_output=True).stdout.decode().strip() + + +def main(): + cp = ConfigParser() + + conf_file = os.path.join( + os.environ.get('HOME'), + '.config', + 'vdirsyncer', + 'config' + ) + + cp.read(conf_file) + + storage_flt = lambda x: x.split(' ').pop(0) == 'storage' + + urls_sects = {} + + for sect in filter(storage_flt, cp.sections()): + if 'url' not in cp[sect]: + continue + + url = urlparse(eval(cp[sect]['url'])) + if url.scheme != 'https': + continue + + if url.netloc not in urls_sects: + urls_sects[url.netloc] = set() + + urls_sects[url.netloc].add(sect) + + for url in urls_sects.keys(): + + fp = get_fingerprint(url) + for sect in urls_sects[url]: + cp.set(sect, 'verify_fingerprint', f'"{fp}"') + + with open(conf_file, 'w') as fh: + cp.write(fh) + + + +if __name__ == '__main__': + main()