2860
« on: May 13, 2012, 12:43 pm »
here is what I have so far, it only does key generation though. I had it all finished and then my VM fucked up and I had to start over and this is how far back I am done (minus nice formatting too). Will finish it again though, I just wanted to play with TK.
require 'tk'
require 'open3'
require 'securerandom'
root = TkRoot.new do
minsize(600,700)
maxsize(600,700)
end
root.title = "Ruby GPG"
notebook = Tk::Tile::Notebook.new(root) do
place('height' => 700, 'width' => 600, 'x' => 0, 'y' => 0)
end
frame_one = TkFrame.new(notebook)
frame_two = TkFrame.new(notebook)
frame_three = TkFrame.new(notebook)
notebook.add frame_one, :text => 'Generate Keys'
notebook.add frame_two, :text => 'Manage Contacts'
notebook.add frame_three, :text => 'Encryption / Decryption Operations'
perform_operation_button = TkButton.new(frame_three) do
text "Generate Account"
borderwidth 2
state "normal"
font TkFont.new('10')
foreground "black"
background "grey"
activebackground "#bfb7ae"
relief "groove"
command (proc {generate_key_pair})
place('x' => 0, 'y' => 0)
end
@@crypto_io = TkText.new(frame_three) do
self.exportselection = false
self.borderwidth = 0
self.background = "grey"
place('height'=> 350,'width' => 600,'x' => 0, 'y' => 327)
end
@@operation_selection = TkListbox.new(frame_three) do
self.selectmode = "browse"
self.selectbackground = "#c7b6b8"
self.background = "grey"
insert 0, "Decryption", "Asymmetric Encryption", "Symmetric Encryption", "Sign", "Verify Signature"
place('height'=> 80,'width' => 200,'x' => 75, 'y' => 100)
end
@@operation_selection.selection_set 0
@@embed_key_fingerprints_selection = TkListbox.new(frame_three) do
self.exportselection = false
self.selectmode = "browse"
self.selectbackground = "#c7b6b8"
self.background = "grey"
insert 0, "Show recipient key", "Hide recipient key"
end
@@embed_key_fingerprints_selection.selection_set 0
@@pseudonym_entry = TkEntry.new(frame_one) do
place('height'=> 25,'width' => 250,'x' => 50, 'y' => 155)
self.value = "Pseudonym"
end
@@pseudonym_entry.background = "grey"
@@password_entry1 = TkEntry.new(frame_one) do
show '*'
place('height'=> 25,'width' => 250,'x' => 50, 'y' => 185)
self.value = "starslol"
end
@@password_entry1.background = "grey"
@@password_entry2 = TkEntry.new(frame_one) do
show '*'
place('height'=> 25,'width' => 250,'x' => 50, 'y' => 215)
self.value = "password"
end
@@password_entry2.background = "grey"
@@email_entry = TkEntry.new(frame_one) do
place('height'=> 25,'width' => 250,'x' => 50, 'y' => 240)
self.value = "valid format potentially made up E-mail"
end
@@email_entry.background = "grey"
generate_keys_button = TkButton.new(frame_one) do
text "Generate Key pair"
borderwidth 2
state "normal"
font TkFont.new('10')
foreground "black"
background "grey"
activebackground "#bfb7ae"
relief "groove"
command (proc {generate_key_pair})
place('x' => 80, 'y' => 275)
end
@@key_type = TkListbox.new(frame_one) do
self.selectmode = "browse"
self.selectbackground = "#c7b6b8"
self.background = "grey"
insert 0, "RSA and RSA", "DSA and El-Gamal"
place('height'=> 80,'width' => 200,'x' => 340, 'y' => 240)
end
@@key_type.selection_set 0
@@key_strength = TkListbox.new(frame_one) do
self.exportselection = false
self.selectmode = "browse"
self.selectbackground = "#c7b6b8"
self.background = "grey"
insert 0, "1024", "2048", "3072", "4096"
place('height'=> 80,'width' => 200,'x' => 340, 'y' => 155)
end
@@key_strength.selection_set 3
key_generation_explanation = TkText.new(frame_one) do
self.exportselection = false
self.borderwidth = 0
self.background = "grey"
place('height'=> 150,'width' => 600,'x' => 0, 'y' => 0)
self.value = "
To generate a new key you are required to provide the following information. You may choose between RSA/RSA and DSA/ElGamal, both are secure. You also can select a key size. The larger the key size, the more securely encrypted messages sent to you will be 1,024 is not considered to be secure for much longer. 2,046 is the minimum suggested key size, however 4,096 bit keys offer significantly more protection from some realistic attacks. The number of qubits required to break susceptilble asymmetric algorithms grows with the number or bits in the key. After you have filled out the relevant information, click the generate keypair button to begin the process of key generation. "
end
key_generation_explanation.state = "disabled"
@@finished_key = TkText.new(frame_one) do
self.exportselection = false
self.borderwidth = 0
self.background = "grey"
place('height'=> 350,'width' => 600,'x' => 0, 'y' => 327)
end
def generate_key_pair
if @@password_entry1.value != @@password_entry2.value then
passwords_must_match = Tk.messageBox(
'type' => "ok",
'icon' => "warning",
'title' => "Warning!",
'message' => "The provided passwords do not match!"
)
else if @@pseudonym_entry.value.length < 5 then
pseudonym_too_short = Tk.messageBox(
'type' => "ok",
'icon' => "warning",
'title' => "Warning!",
'message' => "The GPG base engine requires your pseudonym to be at least five characters long"
)
elsif @@password_entry1.value.length < 7 then
password_too_short = Tk.messageBox(
'type' => "ok",
'icon' => "warning",
'title' => "Warning!",
'message' => "Your password must be at least eight characters long"
)
elsif not @@email_entry.value.to_s.include?("@") then
invalid_email = Tk.messageBox(
'type' => "ok",
'icon' => "warning",
'title' => "Warning!",
'message' => "This does not appear to be a valid E-mail address (gpg enforced)"
)
else
starting = `gpg --list-keys`.bytesize
stdin, stderr = Open3.popen3('gpg --gen-key --batch')
entropy_explanation = Tk.messageBox(
'type' => "ok",
'icon' => "info",
'title' => "Entropy Gathering Is Required",
'message' => "You must gather entropy to generate your key. Do so by typing randomly into the text box that will pop up momentarily. Gathering sufficient entropy may take a very long time on virtual machines, and depending on the key size selected."
)
selected_algorithms = @@key_type.curselection
selected_key_strength = @@key_strength.curselection
key_type = "RSA" and subkey_type = "RSA" if selected_algorithms[0].to_i == 0
key_type = "DSA" and subkey_type = "ELG-E" if selected_algorithms[0].to_i == 1
puts key_type
key_strength = "1024" if selected_key_strength[0].to_i == 0
key_strength = "2046" if selected_key_strength[0].to_i == 1
key_strength = "3072" if selected_key_strength[0].to_i == 2
key_strength = "4096" if selected_key_strength[0].to_i == 3
puts key_strength
stdin.puts("Key-Type: #{key_type}")
stdin.puts("Key-Length: #{key_strength}")
stdin.puts("Subkey-Type: #{subkey_type}")
stdin.puts("Subkey-Length: #{key_strength}")
stdin.puts("Name-Real: #{@@pseudonym_entry}")
stdin.puts("Name-Email: #{@@email_entry.value.to_s}")
stdin.puts("Expire-Date: 0")
stdin.puts("Passphrase: #{@@password_entry1.value}")
stdin.puts("%commit")
entropy_input_window = TkToplevel.new do
self.title = "gather entropy"
self.height = 500
self.width = 500
end
entropy_input = TkText.new(entropy_input_window) do
self.background = "#e3dede"
place('height'=> 500,'width' => 500,'x' => 0, 'y' => 0)
end
gather_entropy = Thread.new do #this may be insecure way of piping randomness to the GPG engine depending on how they have implemented entropy accumulation
until `gpg --list-keys`.bytesize > starting do
stdin.puts("entropy_input.value")
entropy_input.value = ""
sleep(10)
end
entropy_input_window.destroy
done = Tk.messageBox(
'type' => "ok",
'icon' => "info",
'title' => "Key Generated!",
'message' => "Your key has finished generating!"
)
@@finished_key.value = `gpg -a --export #{@@pseudonym_entry.value}`.to_s
end
end
end
end
Tk.mainloop