Skip to content

Commit e847a02

Browse files
committed
gpg
1 parent 4d3dd20 commit e847a02

13 files changed

Lines changed: 1247 additions & 0 deletions

File tree

debian/gpg/ChangeLog.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# ChangeLog
2+
3+
*Version 1*
4+
5+
Simple script
6+
7+
8+
*Version 2*
9+
10+
No password needed any more also mail or name is optional
11+
12+
13+
*Version 3*
14+
15+
Auto detection of the new key pair and sign it with a "CA" like key pair

debian/gpg/LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

debian/gpg/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# GPG Scripts
2+
3+
To autogenerate gpg keys and performs signing of the new keys (version 3).
4+
5+
# Known Bugs
6+
7+
If you set *name* and *email* to none it will fail.
8+
9+
You need to set name or email or both!
10+
11+
# Related work:
12+
13+
The Script based on the information taken from
14+
15+
*https://www.gnupg.org/documentation/manuals/gnupg/Unattended-GPG-key-generation.html*
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# KeyGenGPG
2+
Generates a gpg key.
3+
4+
# Requirements:
5+
gpg2
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
Copyright (C) 2017 Georg Schmidt <gs-develop@gs-sys.de>
3+
This program is free software: you can redistribute it and/or modify
4+
it under the terms of the GNU General Public License as published by
5+
the Free Software Foundation, either version 3 of the License, or
6+
(at your option) any later version.
7+
This program is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU General Public License for more details.
11+
You should have received a copy of the GNU General Public License
12+
along with this program. If not, see <http://www.gnu.org/licenses/>.
13+
*/
14+
15+
package de.gs_sys.basics.data;
16+
17+
import java.io.InputStream;
18+
import java.util.Scanner;
19+
20+
/**
21+
* Created by Georg Schmidt on 30.04.2017.
22+
*/
23+
public class InputStreamToString {
24+
25+
public static String toString(InputStream inputStream) {
26+
Scanner s = new Scanner(inputStream).useDelimiter("\\A");
27+
return s.hasNext() ? s.next() : "";
28+
}
29+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
Copyright (C) 2017 Georg Schmidt <gs-develop@gs-sys.de>
3+
This program is free software: you can redistribute it and/or modify
4+
it under the terms of the GNU General Public License as published by
5+
the Free Software Foundation, either version 3 of the License, or
6+
(at your option) any later version.
7+
This program is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU General Public License for more details.
11+
You should have received a copy of the GNU General Public License
12+
along with this program. If not, see <http://www.gnu.org/licenses/>.
13+
*/
14+
15+
package de.gs_sys.basics.file;
16+
17+
import java.io.File;
18+
import java.nio.charset.StandardCharsets;
19+
import java.nio.file.Files;
20+
import java.nio.file.Paths;
21+
import java.nio.file.StandardOpenOption;
22+
23+
/**
24+
* Created by Georg Schmidt on 30.04.2017.
25+
*/
26+
public class StringAndFiles {
27+
28+
public static String getString(String filename) {
29+
// Load password length from file
30+
if (new File(filename).exists()) {
31+
try {
32+
return new String(Files.readAllBytes(Paths.get(filename)));
33+
} catch (Exception ignored) {}
34+
}
35+
return null;
36+
}
37+
38+
public static boolean toFile(String filename, String content) {
39+
if (content != null && !content.isEmpty()) {
40+
try {
41+
Files.write(
42+
Paths.get(filename),
43+
content.getBytes(StandardCharsets.UTF_8),
44+
StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE
45+
);
46+
return true;
47+
} catch (Exception ignored) {}
48+
}
49+
return false;
50+
}
51+
52+
}
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
/*
2+
Copyright (C) 2017 Georg Schmidt <gs-develop@gs-sys.de>
3+
This program is free software: you can redistribute it and/or modify
4+
it under the terms of the GNU General Public License as published by
5+
the Free Software Foundation, either version 3 of the License, or
6+
(at your option) any later version.
7+
This program is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU General Public License for more details.
11+
You should have received a copy of the GNU General Public License
12+
along with this program. If not, see <http://www.gnu.org/licenses/>.
13+
*/
14+
15+
package de.gs_sys.gpg.gui;
16+
17+
import de.gs_sys.basics.data.InputStreamToString;
18+
import de.gs_sys.basics.file.StringAndFiles;
19+
20+
import javax.swing.*;
21+
import java.awt.*;
22+
import java.awt.event.ActionEvent;
23+
import java.awt.event.ActionListener;
24+
import java.io.File;
25+
import java.io.IOException;
26+
27+
/**
28+
* @author Georg Schmidt
29+
* @version 1.0 vom 30.04.2017
30+
*/
31+
32+
public class KeyGen extends JFrame {
33+
private JTextField tf_name = new JTextField();
34+
private JLabel jLabel1 = new JLabel();
35+
private JLabel jLabel2 = new JLabel();
36+
private JTextField tf_mail = new JTextField();
37+
private JLabel jLabel3 = new JLabel();
38+
private JTextField tf_password = new JTextField();
39+
private JLabel jLabel4 = new JLabel();
40+
private JLabel jLabel5 = new JLabel();
41+
private JComboBox<String> cb_keysize = new JComboBox<String>();
42+
private DefaultComboBoxModel<String> cb_keysizeModel = new DefaultComboBoxModel<String>();
43+
private JButton b_save = new JButton();
44+
private JButton b_exit = new JButton();
45+
private JLabel jLabel6 = new JLabel();
46+
private JTextArea ta_log = new JTextArea("");
47+
private JScrollPane ta_logScrollPane = new JScrollPane(ta_log);
48+
49+
public KeyGen() {
50+
super();
51+
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
52+
int frameWidth = 300;
53+
int frameHeight = 295;
54+
setSize(frameWidth, frameHeight);
55+
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
56+
int x = (d.width - getSize().width) / 2;
57+
int y = (d.height - getSize().height) / 2;
58+
setLocation(x, y);
59+
setTitle("Generate a GPG Key");
60+
setResizable(false);
61+
Container cp = getContentPane();
62+
cp.setLayout(null);
63+
64+
tf_name.setBounds(80, 16, 193, 25);
65+
cp.add(tf_name);
66+
jLabel1.setBounds(8, 16, 67, 25);
67+
jLabel1.setText("Name");
68+
cp.add(jLabel1);
69+
jLabel2.setBounds(8, 48, 67, 25);
70+
jLabel2.setText("E-Mail");
71+
cp.add(jLabel2);
72+
tf_mail.setBounds(80, 48, 193, 25);
73+
cp.add(tf_mail);
74+
jLabel3.setBounds(8, 80, 67, 25);
75+
jLabel3.setText("Password");
76+
cp.add(jLabel3);
77+
tf_password.setBounds(80, 80, 193, 25);
78+
cp.add(tf_password);
79+
jLabel4.setBounds(8, 112, 67, 25);
80+
jLabel4.setText("Key size");
81+
cp.add(jLabel4);
82+
83+
jLabel5.setBounds(200, 112, 43, 25);
84+
jLabel5.setText("bits");
85+
cp.add(jLabel5);
86+
cb_keysize.setModel(cb_keysizeModel);
87+
cb_keysize.setBounds(80, 112, 113, 25);
88+
cp.add(cb_keysize);
89+
b_save.setBounds(72, 216, 145, 25);
90+
b_save.setText("Generate");
91+
b_save.setMargin(new Insets(2, 2, 2, 2));
92+
b_save.addActionListener(new ActionListener() {
93+
public void actionPerformed(ActionEvent evt) {
94+
b_save_ActionPerformed(evt);
95+
}
96+
});
97+
cp.add(b_save);
98+
b_exit.setBounds(224, 216, 49, 25);
99+
b_exit.setText("Exit");
100+
b_exit.setMargin(new Insets(2, 2, 2, 2));
101+
b_exit.addActionListener(new ActionListener() {
102+
public void actionPerformed(ActionEvent evt) {
103+
b_exit_ActionPerformed(evt);
104+
}
105+
});
106+
cp.add(b_exit);
107+
jLabel6.setBounds(8, 216, 51, 25);
108+
jLabel6.setText("Ver 1.0");
109+
cp.add(jLabel6);
110+
ta_logScrollPane.setBounds(8, 144, 265, 65);
111+
cp.add(ta_logScrollPane);
112+
113+
cb_keysize.addItem("1024");
114+
cb_keysize.addItem("2048");
115+
cb_keysize.addItem("4096");
116+
/*
117+
cb_keysize.addItem("8192");
118+
cb_keysize.addItem("16384");
119+
cb_keysize.addItem("32768");
120+
cb_keysize.addItem("65536");
121+
*/
122+
123+
setVisible(true);
124+
} // end of public KeyGen
125+
126+
public static void main(String[] args) {
127+
new KeyGen();
128+
} // end of main
129+
130+
public void b_save_ActionPerformed(ActionEvent evt) {
131+
132+
String keysize = cb_keysize.getSelectedItem().toString();
133+
134+
String name = tf_name.getText();
135+
if (!name.isEmpty())
136+
name = " Name-Real: " + name + "\n";
137+
138+
String mail = tf_mail.getText();
139+
if (!mail.isEmpty())
140+
mail = " Name-Email: " + mail + "\n";
141+
142+
String password = tf_password.getText();
143+
if (!password.isEmpty()) {
144+
password = " Passphrase: " + password + "\n";
145+
} else {
146+
password = "%no-protection\n%no-ask-passphrase\n";
147+
}
148+
149+
if (name.isEmpty() && mail.isEmpty()) {
150+
ta_log.append("Name or Mail must be set! Try again!\n");
151+
return;
152+
}
153+
154+
String config = "%echo Generating a basic OpenPGP key\n" +
155+
" Key-Type: RSA\n" +
156+
" Key-Length: " + keysize + "\n" +
157+
" Subkey-Type: RSA\n" +
158+
" Subkey-Length: " + keysize + "\n" +
159+
" Preferences: SHA512 SHA384 SHA256 SHA224 AES256 AES192 AES CAST5 ZLIB BZIP2 ZIP Uncompressed\n" +
160+
name +
161+
mail +
162+
" Expire-Date: 10y\n" +
163+
password +
164+
" # Do a commit here, so that we can later print \"done\"\n" +
165+
" %commit\n" +
166+
" %echo done";
167+
168+
try {
169+
StringAndFiles.toFile("tmp5456.del", config);
170+
171+
Process p = Runtime.getRuntime().exec("gpg2 --batch --gen-key tmp5456.del");
172+
173+
while (p.isAlive()) ;
174+
175+
if (p.exitValue() == 0)
176+
ta_log.append("Key for " + tf_name.getText() + " " + tf_mail.getText() + " successfully generated!\n");
177+
else
178+
ta_log.append("Key for " + tf_name.getText() + " " + tf_mail.getText() + " failed!\n" + InputStreamToString.toString(p.getErrorStream()) + "\n");
179+
180+
181+
new File("tmp5456.del").delete();
182+
} catch (IOException e) {
183+
e.printStackTrace();
184+
}
185+
} // end of b_save_ActionPerformed
186+
187+
public void b_exit_ActionPerformed(ActionEvent evt) {
188+
System.exit(0);
189+
} // end of b_exit_ActionPerformed
190+
} // end of class KeyGen
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@echo off
2+
gpg2 --export-secret-key -a>priv_keys.asc
3+
pause
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@echo off
2+
gpg2 --export -a>pub_keys.asc
3+
pause
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
%echo Generating a basic OpenPGP key
2+
Key-Type: RSA
3+
Key-Length: 4096
4+
Subkey-Type: RSA
5+
Subkey-Length: 4096
6+
Preferences: SHA512 SHA384 SHA256 SHA224 AES256 AES192 AES CAST5 ZLIB BZIP2 ZIP Uncompressed
7+
Name-Real: <name>
8+
Name-Email: <mail>
9+
Expire-Date: 10y
10+
Passphrase: <pw>
11+
# %no-ask-passphrase
12+
# %no-protection
13+
# Do a commit here, so that we can later print "done" :-)
14+
%commit
15+
%echo done

0 commit comments

Comments
 (0)