9
9
from py_vapid import Vapid01 , Vapid02 , b64urlencode
10
10
11
11
12
+ def prompt (prompt ):
13
+ # Not sure why, but python3 throws and exception if you try to
14
+ # monkeypatch for this. It's ugly, but this seems to play nicer.
15
+ try :
16
+ return input (prompt )
17
+ except NameError :
18
+ return raw_input (prompt ) # noqa: F821
19
+
20
+
12
21
def main ():
13
22
parser = argparse .ArgumentParser (description = "VAPID tool" )
14
23
parser .add_argument ('--sign' , '-s' , help = 'claims file to sign' )
15
24
parser .add_argument ('--gen' , '-g' , help = 'generate new key pairs' ,
16
25
default = False , action = "store_true" )
17
- parser .add_argument ('--validate' , '-v' , help = 'dashboard token to validate' )
18
26
parser .add_argument ('--version2' , '-2' , help = "use VAPID spec Draft-02" ,
19
27
default = False , action = "store_true" )
20
28
parser .add_argument ('--version1' , '-1' , help = "use VAPID spec Draft-01" ,
@@ -27,10 +35,6 @@ def main():
27
35
args = parser .parse_args ()
28
36
29
37
# Added to solve 2.7 => 3.* incompatibility
30
- try :
31
- input = raw_input
32
- except NameError :
33
- pass
34
38
Vapid = Vapid01
35
39
if args .version2 :
36
40
Vapid = Vapid02
@@ -39,38 +43,26 @@ def main():
39
43
print ("No private_key.pem file found." )
40
44
answer = None
41
45
while answer not in ['y' , 'n' ]:
42
- answer = input ("Do you want me to create one for you? "
43
- "(Y/n)" )
46
+ answer = prompt ("Do you want me to create one for you? (Y/n)" )
44
47
if not answer :
45
48
answer = 'y'
46
49
answer = answer .lower ()[0 ]
47
50
if answer == 'n' :
48
51
print ("Sorry, can't do much for you then." )
49
52
exit (1 )
53
+ vapid = Vapid ()
54
+ vapid .generate_keys ()
50
55
print ("Generating private_key.pem" )
51
- Vapid ().save_key ('private_key.pem' )
52
- vapid = Vapid .from_file ('private_key.pem' )
53
- if args .gen or not os .path .exists ('public_key.pem' ):
54
- if not args .gen :
55
- print ("No public_key.pem file found. You'll need this to access "
56
- "the developer dashboard." )
57
- answer = None
58
- while answer not in ['y' , 'n' ]:
59
- answer = input ("Do you want me to create one for you? "
60
- "(Y/n)" )
61
- if not answer :
62
- answer = 'y'
63
- answer = answer .lower ()[0 ]
64
- if answer == 'n' :
65
- print ("Exiting..." )
66
- exit (0 )
56
+ vapid .save_key ('private_key.pem' )
67
57
print ("Generating public_key.pem" )
68
58
vapid .save_public_key ('public_key.pem' )
59
+ vapid = Vapid .from_file ('private_key.pem' )
69
60
claim_file = args .sign
70
61
result = dict ()
71
62
if args .applicationServerKey :
63
+ raw_pub = vapid .public_key .public_numbers ().encode_point ()
72
64
print ("Application Server Key = {}\n \n " .format (
73
- b64urlencode (vapid . public_key . to_string () )))
65
+ b64urlencode (raw_pub )))
74
66
if claim_file :
75
67
if not os .path .exists (claim_file ):
76
68
print ("No {} file found." .format (claim_file ))
0 commit comments