@@ -7,41 +7,44 @@ var yargs = require('yargs')
7
7
8
8
var metadata = require ( './package' )
9
9
10
- var args = parseArgs ( )
11
- var fileToSign = args . argv . _ [ 0 ]
12
- if ( ! fileToSign ) {
13
- args . showHelp ( )
14
- process . exit ( 1 )
15
- }
16
- fileToSign = path . resolve ( fileToSign )
10
+ processCommand ( )
11
+
12
+ function sign ( argv ) {
13
+ var options = {
14
+ cert : path . resolve ( argv . cert ) ,
15
+ hash : [ 'sha1' , 'sha256' ] ,
16
+ key : argv . key ? path . resolve ( argv . key ) : argv . key ,
17
+ name : argv . name ,
18
+ overwrite : true ,
19
+ password : argv . password ,
20
+ path : path . resolve ( argv . file_to_sign ) ,
21
+ site : argv . url
22
+ }
17
23
18
- var options = {
19
- cert : path . resolve ( args . argv . cert ) ,
20
- hash : [ 'sha1' , 'sha256' ] ,
21
- key : args . argv . key ? path . resolve ( args . argv . key ) : args . argv . key ,
22
- name : args . argv . name ,
23
- overwrite : true ,
24
- password : args . argv . password ,
25
- path : fileToSign ,
26
- site : args . argv . url
24
+ if ( argv . prompt ) {
25
+ promptForPassword ( function ( password ) {
26
+ options . password = password
27
+ signcode . sign ( options , exitIfError )
28
+ } )
29
+ } else {
30
+ signcode . sign ( options , exitIfError )
31
+ }
27
32
}
28
33
29
- if ( args . argv . prompt ) {
30
- promptForPassword ( function ( password ) {
31
- options . password = password
32
- sign ( options )
33
- } )
34
- } else {
35
- sign ( options )
34
+ function verify ( argv ) {
35
+ var options = {
36
+ path : path . resolve ( argv . file_to_verify ) ,
37
+ hash : argv . hash
38
+ }
39
+
40
+ signcode . verify ( options , exitIfError )
36
41
}
37
42
38
- function sign ( options ) {
39
- signcode . sign ( options , function ( error ) {
40
- if ( error ) {
41
- console . error ( error . message || error )
42
- process . exit ( 1 )
43
- }
44
- } )
43
+ function exitIfError ( error ) {
44
+ if ( error ) {
45
+ console . error ( error . message || error )
46
+ process . exit ( 1 )
47
+ }
45
48
}
46
49
47
50
function promptForPassword ( callback ) {
@@ -56,45 +59,53 @@ function promptForPassword (callback) {
56
59
}
57
60
prompt . start ( )
58
61
prompt . get ( promptConfig , function ( error , result ) {
59
- if ( error ) {
60
- console . error ( error . message || error )
61
- process . exit ( 1 )
62
- }
62
+ exitIfError ( error )
63
63
callback ( result . password )
64
64
} )
65
65
}
66
66
67
- function parseArgs ( ) {
68
- return yargs
69
- . usage ( metadata . name + ' file_to_sign [args]\n\nSign Windows executables from a Mac.\nVersion ' + metadata . version )
70
- . option ( 'cert' , {
71
- alias : 'c' ,
72
- demand : true ,
73
- describe : 'Path to a .pem, .pfx, or .p12 certificate file' ,
74
- type : 'string'
75
- } )
76
- . option ( 'key' , {
77
- alias : 'k' ,
78
- describe : 'Path to .pem key file' ,
79
- type : 'string'
80
- } )
81
- . option ( 'name' , {
82
- alias : 'n' ,
83
- describe : 'Application name' ,
84
- type : 'string'
85
- } )
86
- . option ( 'password' , {
87
- describe : 'Password to use for certificate/key pair' ,
88
- type : 'string'
89
- } )
90
- . option ( 'prompt' , {
91
- describe : 'Prompt for a password' ,
92
- type : 'boolean'
93
- } )
94
- . option ( 'url' , {
95
- alias : 'u' ,
96
- describe : 'Application URL' ,
97
- type : 'string'
98
- } )
67
+ function processCommand ( ) {
68
+ yargs
69
+ . usage ( metadata . name + ' <command> path_to_executable [args]\n\nSign Windows executables from a Mac.\nVersion ' + metadata . version )
70
+ . command ( 'sign <file_to_sign>' , 'sign an executable' , {
71
+ cert : {
72
+ alias : 'c' ,
73
+ demand : true ,
74
+ describe : 'Path to a .pem, .pfx, or .p12 certificate file' ,
75
+ type : 'string'
76
+ } ,
77
+ key : {
78
+ alias : 'k' ,
79
+ describe : 'Path to .pem key file' ,
80
+ type : 'string'
81
+ } ,
82
+ name : {
83
+ alias : 'n' ,
84
+ describe : 'Application name' ,
85
+ type : 'string'
86
+ } ,
87
+ password : {
88
+ describe : 'Password to use for certificate/key pair' ,
89
+ type : 'string'
90
+ } ,
91
+ prompt : {
92
+ describe : 'Prompt for a password' ,
93
+ type : 'boolean'
94
+ } ,
95
+ url : {
96
+ alias : 'u' ,
97
+ describe : 'Application URL' ,
98
+ type : 'string'
99
+ }
100
+ } , sign )
101
+ . command ( 'verify <file_to_verify> [args]' , 'verify the signature on an executable' , {
102
+ hash : {
103
+ alias : 'h' ,
104
+ describe : 'Certificate fingerprint to expect on executable' ,
105
+ type : 'string'
106
+ }
107
+ } , verify )
108
+ . demandCommand ( )
99
109
. help ( 'help' )
110
+ . argv
100
111
}
0 commit comments