Skip to content

Instantly share code, notes, and snippets.

@1fabunicorn
Created October 14, 2016 14:25
Show Gist options
  • Save 1fabunicorn/ba310f7f6619611f6056969b802f5796 to your computer and use it in GitHub Desktop.
Save 1fabunicorn/ba310f7f6619611f6056969b802f5796 to your computer and use it in GitHub Desktop.
import os
import gnupg
from subprocess import call
directory_use = str(raw_input("Please specify the directory to make the keys in. Please include the full path. This script will delete everything in this directory so please be carfull\n"))
keyring_name = str(raw_input("please specify the file name you woulk like to name the public key\n"))
secret_name = str(raw_input("please specify the file name you woulk like to name the PRIVATE key\n"))
pub_key_type = str(raw_input("please specify what type of key you want the public key to be. RSA or DSA? This is not case sensitive\n").upper())
pub_length = int(raw_input("please specify how big you want the pubic key to be. between 1024 and 2048 Bytes "))
name = str(raw_input("please specify the name you would like to be associated to these keys\n"))
comment = str(raw_input("Make a comment for the key. If left blank, comment will be 'Generated by gnupg.py' "))
email = str(raw_input("specify the email you want associated with these keys. If left blank, email will be <your username>@<hostname> "))
priv_type = str(raw_input("please specify the signing key/private key, key type. RSA, or ELG-E This is not case sensitive, but is sencitive to (-) ").upper())
priv_length = int(raw_input("please specify the private key/signing key length "))
print "this key will not expire. Please import the key to an actual client to specify when this should expire, then take the necisary steps to get rid of the keys from the directory this script made using 'shred' of something else"
# Deletes whats ever in the pgp_test_dir
os.system('rm -rf' + directory_use)
#tells gnupg whats the home dir for keys, and some other confs
gpg = gnupg.GPG(
gnupghome=directory_use,
keyring=keyring_name,
secret_keyring=secret_name,
#verbose=True
)
gpg.encoding = 'utf-8'
#key configs
input_data = gpg.gen_key_input(
name_real= name,
key_length = pub_length,
key_type = pub_key_type,
subkey_type = priv_type,
name_comment = comment,
name_email = email,
subkey_length = priv_length,
expire_date = 0
)
print "has set key configs"
#executes command to create work on the matine to create more entopathy $ python resorce_heavy.py
print "you now to need to create entropy.\n Please execute this command from the same directory you ran this script \n python resorce_heavy.py"
resorce_heavy_run = raw_input("Have you ran the script(yes, no)? ").lower()
if resorce_heavy_run == "yes":
key = gpg.gen_key(input_data)
#writing pub and priv keys
ascii_armored_public_keys = gpg.export_keys(key)
ascii_armored_private_keys = gpg.export_keys(key, True)
with open('mykeyfile.asc', 'w') as f:
f.write(ascii_armored_public_keys)
f.write(ascii_armored_private_keys)
resorce_heavy.making_keys = False
os.system("kill $(ps aux | grep 'Thunar' | awk ' {print $2 + ' was the pid of the resourse_heavy.py process'}')")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment