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