]> Raphaƫl G. Git Repositories - youtubedl/blob - devscripts/gh-pages/sign-versions.py
Imported Upstream version 2014.08.05
[youtubedl] / devscripts / gh-pages / sign-versions.py
1 #!/usr/bin/env python3
2
3 import rsa
4 import json
5 from binascii import hexlify
6
7 try:
8 input = raw_input
9 except NameError:
10 pass
11
12 versions_info = json.load(open('update/versions.json'))
13 if 'signature' in versions_info:
14 del versions_info['signature']
15
16 print('Enter the PKCS1 private key, followed by a blank line:')
17 privkey = b''
18 while True:
19 try:
20 line = input()
21 except EOFError:
22 break
23 if line == '':
24 break
25 privkey += line.encode('ascii') + b'\n'
26 privkey = rsa.PrivateKey.load_pkcs1(privkey)
27
28 signature = hexlify(rsa.pkcs1.sign(json.dumps(versions_info, sort_keys=True).encode('utf-8'), privkey, 'SHA-256')).decode()
29 print('signature: ' + signature)
30
31 versions_info['signature'] = signature
32 json.dump(versions_info, open('update/versions.json', 'w'), indent=4, sort_keys=True)