-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsop-openpgp.js
executable file
·254 lines (252 loc) · 7.08 KB
/
sop-openpgp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#!/usr/bin/env node
const yargs = require('yargs');
const encrypt = require('./src/commands/encrypt');
const decrypt = require('./src/commands/decrypt');
const sign = require('./src/commands/sign');
const verify = require('./src/commands/verify');
const inlineSign = require('./src/commands/inlineSign');
const inlineVerify = require('./src/commands/inlineVerify');
const inlineDetach = require('./src/commands/inlineDetach');
const generate = require('./src/commands/generate');
const extract = require('./src/commands/extract');
const armor = require('./src/commands/armor');
const dearmor = require('./src/commands/dearmor');
const listProfiles = require('./src/commands/listProfiles');
const version = require('./src/commands/version');
const { getProfileOptions } = require('./src/utils');
yargs
.command({
command: 'encrypt [certfiles..]',
describe: 'Encrypt a Message',
builder: {
profile: {
describe: 'specify profile to use',
type: 'string'
},
'with-password': {
describe: 'symmetric encryption',
type: 'string'
},
'sign-with': {
describe: 'sign with key',
},
'with-key-password': {
describe: 'unlock signing key with the given password file',
type: 'string'
},
as: {
describe: 'the type of data to encrypt',
choices: ['binary', 'text'],
default: 'binary'
},
armor: {
describe: 'armor the output',
type: 'boolean',
default: true
}
},
handler: async (argv) => {
const signWith =
Array.isArray(argv.signWith) ? argv.signWith :
argv.signWith ? [argv.signWith] :
[];
const profileOptions = getProfileOptions('encrypt', argv.profile);
encrypt(argv.withPassword, signWith, argv.withKeyPassword, argv.certfiles, argv.as, argv.armor, profileOptions);
}
})
.command({
command: 'decrypt [keyfiles..]',
describe: 'Decrypt a Message',
builder: {
'session-key-out': {
describe: 'session key of encrypted message',
},
'with-session-key': {
describe: 'decrypt using provided session key',
},
'with-password': {
describe: 'symmetric encryption',
type: 'string'
},
'with-key-password': {
describe: 'unlock key with the given password file',
type: 'string'
},
'verify-with': {
describe: 'verify with key',
},
'verifications-out': {
describe: 'save verifications to file',
alias: 'verify-out'
}
},
handler: async (argv) => {
const verifyWith =
Array.isArray(argv.verifyWith) ? argv.verifyWith :
argv.verifyWith ? [argv.verifyWith] :
[];
decrypt(argv.withPassword, argv.sessionKeyOut, argv.withSessionKey, verifyWith, argv.verificationsOut, argv.keyfiles, argv.withKeyPassword);
}
})
.command({
command: 'sign <keyfiles..>',
describe: 'Create Detached Signatures',
builder: {
'with-key-password': {
describe: 'unlock key with the given password file',
type: 'string'
},
as: {
describe: 'the type of data to sign',
choices: ['binary', 'text'],
default: 'binary'
},
armor: {
describe: 'armor the output',
type: 'boolean',
default: true
}
},
handler: async (argv) => { sign(argv.keyfiles, argv.withKeyPassword, argv.as, argv.armor); }
})
.command({
command: 'verify <signature> <certfiles..>',
describe: 'Verify Detached Signatures',
handler: async (argv) => { verify(argv.signature, argv.certfiles); }
})
.command({
command: 'inline-sign <keyfiles..>',
describe: 'Create an Inline-Signed Message',
builder: {
'with-key-password': {
describe: 'unlock key with the given password file',
type: 'string'
},
as: {
describe: 'the type of data to sign',
choices: ['binary', 'text', 'clearsigned'],
default: 'binary'
},
armor: {
describe: 'armor the output',
type: 'boolean',
default: true
}
},
handler: async (argv) => { inlineSign(argv.keyfiles, argv.withKeyPassword, argv.as, argv.armor); }
})
.command({
command: 'inline-verify <certfiles..>',
describe: 'Verify an Inline-Signed Message',
builder: {
'verifications-out': {
describe: 'save verifications to file',
}
},
handler: async (argv) => { inlineVerify(argv.certfiles, argv.verificationsOut); }
})
.command({
command: 'inline-detach',
describe: 'Split Signatures from an Inline-Signed Message',
builder: {
'signatures-out': {
describe: 'save signatures to file',
},
armor: {
describe: 'armor the signatures',
type: 'boolean'
}
},
handler: async (argv) => {
const armor = argv.armor != false;
inlineDetach(argv.signaturesOut, armor);
}
})
.command({
command: 'extract-cert',
describe: 'Extract a Certificate from a Secret Key',
builder: {
armor: {
describe: 'armor the output',
type: 'boolean'
}
},
handler: async (argv) => {
const armor = argv.armor != false;
extract(armor);
}
})
.command({
command: 'generate-key [userids..]',
describe: 'Generate a Secret Key',
builder: {
profile: {
describe: 'specify profile to use',
type: 'string'
},
'with-key-password': {
describe: 'lock key with the given password file',
type: 'string'
},
armor: {
describe: 'armor the output',
type: 'boolean'
},
userids: {
describe: 'some user ids',
type: 'string'
}
},
handler: async (argv) => {
const armor = argv.armor != false;
const userids = argv.userids || [];
const profileOptions = getProfileOptions('generate-key', argv.profile);
generate(argv.withKeyPassword, armor, userids, profileOptions);
}
})
.command({
command: 'armor',
describe: 'Convert Binary to ASCII',
handler: armor
})
.command({
command: 'dearmor',
describe: 'Convert ASCII to Binary',
handler: dearmor
})
.command({
command: 'list-profiles <subcommand>',
describe: 'List custom profiles supported by the given subcommand',
handler: async (argv) => {
listProfiles(argv.subcommand);
}
})
.command({
command: 'version',
describe: 'Version Information',
builder: {
backend: {
describe: 'display OpenPGP.js version',
type: 'boolean'
},
extended: {
describe: 'display extended version information',
type: 'boolean'
},
'sop-spec': {
describe: 'display supported sop specification version',
type: 'boolean'
},
sopv: {
describe: 'display supported sopv specification version',
type: 'boolean'
}
},
handler: version
})
.version(false) // Disable --version option as we have our own version command.
.help()
.alias('help', 'h')
.demandCommand(1)
.strict()
.argv;