[new] vdirsyncer_update_fingerprints.py
This commit is contained in:
parent
e663b7d7c4
commit
cbaa5cf408
55
vdirsyncer_update_fingerprints.py
Executable file
55
vdirsyncer_update_fingerprints.py
Executable file
@ -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()
|
Loading…
Reference in New Issue
Block a user