Skip to content

Commit db15a67

Browse files
Add gpg-dialog script by Jagadeesh Venugopal [email protected]
1 parent 2c1f363 commit db15a67

File tree

2 files changed

+325
-0
lines changed

2 files changed

+325
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ All these methods generate random text by using the secure /dev/urandom source.
155155
### scripting
156156

157157
* <code>cddo</code>: Run a command in each directory.
158+
* <code>command-is-installed</code>: If a given command installed, then return true.
158159
* <code>keep</code>: Keep running a command every time any file it looks at is changed.
159160
* <code>no</code>: Shorthand to always return "n"
160161
* <code>while-read-do-cd</code>: For each line of input on command line, cd into a path then run a command.
@@ -251,6 +252,11 @@ All these methods generate random text by using the secure /dev/urandom source.
251252
* <code>trackpoint-set-speed-and-sensitivity-to-fastest</code>: Set trackpoint speed and sensitivity to fastest settings.
252253

253254

255+
### Macintosh
256+
257+
* <code>macbook-pro-retina-screen-manufacturer</code>: Show the manfactured id on a Macbook Pro Retina.
258+
259+
254260
### SixArm Setup
255261

256262
* <code>openssl-req-new-key-pem-for-sixarm</code>: OpenSSL script to generate a new key file for SixArm.com

gpg-dialog.pl

Lines changed: 319 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,319 @@
1+
# This program is distributed under the terms of the GNU General Public
2+
# License in effect on August 2001. For further information please see
3+
# http://www.fsf.org
4+
# Copyright (C) 2001 Jagadeesh Venugopal [email protected]
5+
# This program is a simple menu interface to GNUPG 1.0.6. I find myself
6+
# forgetting the command line options, so I created this. You can essentially
7+
# run this script on Windows and Unix systems that have Perl 5.x installed.
8+
# This was meant to be a quick and dirty script, but if you provide feedback
9+
# I will incorporate it. Send all feedback to [email protected]
10+
# To run this script, all you need to do is to type
11+
# perl gpg-dialog.pl
12+
# on your command line.
13+
14+
###########################################################################
15+
# The main routine where the main menu is presented. Depending upon what
16+
# the user selected, the appropriate subroutine is called
17+
###########################################################################
18+
19+
while(1) {
20+
print "\nWelcome to the GNUPG Wizard!\n";
21+
print "============================\n\n";
22+
$value = menu(
23+
24+
"Main Menu",
25+
"Key Management",
26+
"Encryption/Decryption",
27+
"Clear Signature/Verification",
28+
"Detached Signature/Verification",
29+
);
30+
31+
($value == 1) && key_management();
32+
($value == 2) && encrypt_decrypt();
33+
($value == 3) && clear_signature();
34+
($value == 4) && detached_signature();
35+
($value == 0) && exit;
36+
37+
}
38+
39+
###########################################################################
40+
# The submenus
41+
#
42+
###########################################################################
43+
sub key_management {
44+
my $value;
45+
$value = menu(
46+
"Key Management Submenu",
47+
"Generate public and private keypair",
48+
"Export keys",
49+
"Import keys",
50+
"Revoke keys",
51+
"List keys",
52+
"List signatures",
53+
"Show fingerprints",
54+
"Show private keys",
55+
"Delete key",
56+
"Delete private key",
57+
"Edit key",
58+
);
59+
($value == 1) && call_gpg("--gen-key");
60+
($value == 2) && export_keys();
61+
($value == 3) && import_keys();
62+
($value == 4) && revoke_keys();
63+
($value == 5) && list_keys();
64+
($value == 6) && list_signatures();
65+
($value == 7) && show_fingerprints();
66+
($value == 8) && show_private_keys();
67+
($value == 9) && delete_key();
68+
($value == 10) && delete_private_key();
69+
($value == 11) && edit_key();
70+
($value == 0) && return;
71+
}
72+
73+
sub encrypt_decrypt{
74+
my $value;
75+
$value = menu(
76+
"Encryption/Decryption Submenu",
77+
"Encrypt and sign file",
78+
"Decrypt file and verify signature",
79+
"Conventional encrypt file",
80+
"Conventional decrypt file"
81+
);
82+
83+
($value == 1) && encrypt_and_sign();
84+
($value == 2) && decrypt_and_verify();
85+
($value == 3) && conventional_encrypt();
86+
($value == 4) && conventional_decrypt();
87+
($value == 0) && return;
88+
89+
}
90+
91+
sub clear_signature {
92+
my $value;
93+
$value = menu(
94+
"Clear Signature/Verification Menu",
95+
"Clear sign a file",
96+
"Verify a clearsigned file"
97+
);
98+
99+
($value == 1) && create_clear_signature();
100+
($value == 2) && verify_clear_signature();
101+
($value == 0) && return;
102+
}
103+
104+
sub detached_signature {
105+
my $value;
106+
$value = menu(
107+
"Detached Signature/Verification Menu",
108+
"Detached sign a file",
109+
"Verify a detached signature"
110+
);
111+
112+
($value == 1) && create_detached_signature();
113+
($value == 2) && verify_detached_signature();
114+
($value == 0) && return;
115+
}
116+
117+
sub create_detached_signature {
118+
$input_file =
119+
file_dialog("input", "Enter input file to sign");
120+
$output_file =
121+
file_dialog("output",
122+
"Enter output signature file name");
123+
call_gpg("-o $output_file --armor --detach-sig $input_file");
124+
125+
}
126+
127+
sub verify_detached_signature {
128+
$sig_file = file_dialog("input", "Enter signature file name");
129+
$signed_file = file_dialog("input", "Enter signed file name");
130+
call_gpg("--verify $sig_file $signed_file");
131+
132+
}
133+
134+
sub create_clear_signature{
135+
$input_file = file_dialog("input",
136+
"Enter input file to clearsign");
137+
$output_file = file_dialog("output", "Enter output file name");
138+
call_gpg("-o $output_file --clearsign $input_file");
139+
}
140+
141+
sub verify_clear_signature {
142+
$input_file = file_dialog("input",
143+
"Enter input file to verify");
144+
call_gpg("$input_file");
145+
}
146+
147+
sub export_keys {
148+
149+
$output_file = file_dialog("output", "Enter output file");
150+
$username = accept_string(
151+
"Enter optional username [none exports all users]");
152+
call_gpg("--export -a -o $output_file $username");
153+
}
154+
sub import_keys {
155+
$input_file = file_dialog("input", "Enter key file name");
156+
call_gpg("--import $input_file");
157+
}
158+
159+
sub revoke_keys {
160+
$output_file = file_dialog("input",
161+
"Enter revocation certificate file name");
162+
$username = accept_string("Enter user name to revoke");
163+
call_gpg(" -a -o $output_file --gen-revoke $username");
164+
}
165+
166+
sub list_keys {
167+
call_gpg("--list-keys");
168+
}
169+
170+
sub list_signatures {
171+
call_gpg("--list-sigs");
172+
}
173+
174+
sub show_fingerprints {
175+
call_gpg("--fingerprint");
176+
}
177+
178+
sub show_private_keys {
179+
call_gpg("--list-secret-keys");
180+
}
181+
182+
sub delete_key {
183+
$username = accept_string("Enter username to be deleted");
184+
call_gpg(" --delete-key $username");
185+
}
186+
187+
sub delete_private_key {
188+
$username = accept_string("Enter username to be deleted");
189+
call_gpg(" --delete-secret-key $username");
190+
}
191+
192+
sub edit_key {
193+
$username = accept_string("Enter username to be edited");
194+
call_gpg("--edit-key $username");
195+
}
196+
197+
sub encrypt_and_sign {
198+
199+
$input_file = file_dialog("input",
200+
"Enter input file to encrypt");
201+
$output_file = file_dialog("output",
202+
"Enter encrypted file name");
203+
$recipient = accept_string("Enter recipient\'s username");
204+
call_gpg("-o $output_file --armor --recipient $recipient --sign --encrypt $input_file");
205+
206+
}
207+
208+
sub decrypt_and_verify {
209+
$input_file = file_dialog("input", "Enter input file to decrypt");
210+
$output_file = file_dialog("output", "Enter decrypted file name");
211+
call_gpg("-o $output_file --decrypt $input_file");
212+
213+
}
214+
215+
sub conventional_encrypt {
216+
$input_file = file_dialog("input", "Enter input file to encrypt");
217+
$output_file = file_dialog("output", "Enter encrypted file name");
218+
call_gpg("-o $output_file --armor --symmetric $input_file");
219+
220+
}
221+
222+
sub conventional_decrypt {
223+
decrypt_and_verify();
224+
}
225+
226+
227+
sub call_gpg {
228+
my $arg = $_[0];
229+
print "gpg $arg\n";
230+
$output = `gpg $arg`;
231+
print "$output";
232+
}
233+
234+
sub menu {
235+
my @options;
236+
my $title;
237+
238+
($title, @options) = @_;
239+
my $title_length = length($title);
240+
while(1) {
241+
my $count = 0;
242+
print "\n$title\n" . "-" x $title_length . "\n\n";
243+
244+
my $option;
245+
foreach $option (@options) {
246+
$count++;
247+
print "$count: " . $options[$count-1] . "\n";
248+
}
249+
print "0: Return";
250+
print "\n\nSelect an option(0-$count): ";
251+
252+
my $input_number;
253+
$input_number = <STDIN>;
254+
chomp($input_number);
255+
if(($input_number < 0) or ($input_number > $count)) {
256+
print "\nError. Choose a number from 0 to $count\n";
257+
} else {
258+
return $input_number;
259+
}
260+
}
261+
}
262+
sub menu_test {
263+
my @menu_opts = ("Choose only one option",
264+
"First", "Second", "Third", "Fourth",
265+
"Fifth");
266+
print "You selected: " . $menu_opts[menu(@menu_opts)] . "\n";
267+
}
268+
#&menu_test;
269+
270+
sub file_dialog {
271+
my $mode = shift; #should be "input" or "output"
272+
my $prompt = shift;
273+
274+
if($mode eq "input") {
275+
#input mode; just check that the file exists and return the file
276+
#name. If the file does not exist, then loop endlessly
277+
my $input_file_name = "";
278+
while(1) {
279+
print "$prompt: ";
280+
$input_file_name = <STDIN>;
281+
chomp($input_file_name);
282+
if(-r $input_file_name) {
283+
return $input_file_name;
284+
} else {
285+
print "Error. File $input_file_name is not readable\n";
286+
}
287+
}
288+
} else {
289+
my $output_file_name = "";
290+
while(1) {
291+
print "$prompt: ";
292+
$output_file_name = <STDIN>;
293+
chomp($output_file_name);
294+
if((! -e $output_file_name)
295+
or ((-e $output_file_name) and (-w $output_file_name))){
296+
return $output_file_name;
297+
} else {
298+
print "Error. File $output_file_name is not writeable\n";
299+
}
300+
}
301+
}
302+
}
303+
304+
sub file_dialog_test {
305+
my $input_file = file_dialog("input", "Enter a file name for input");
306+
print "You entered $input_file for read\n";
307+
my $output_file = file_dialog("output", "Enter a file name for output");
308+
print "You entered $output_file for write\n";
309+
}
310+
#&file_dialog_test;
311+
312+
sub accept_string {
313+
my $prompt = $_[0];
314+
print "$prompt: ";
315+
$choice = <STDIN>;
316+
chomp($choice);
317+
return($choice);
318+
}
319+
1;

0 commit comments

Comments
 (0)