encryption.rb 4.06 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
def seahorse_menu_click_helper(main, sub, verify = nil)
  try_for(60) do
    step "process \"#{verify}\" is running" if verify
    @screen.hide_cursor
    @screen.wait_and_click(main, 10)
    @screen.wait_and_click(sub, 10)
    return
  end
end

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Given /^I generate an OpenPGP key named "([^"]+)" with password "([^"]+)"$/ do |name, pwd|
  @passphrase = pwd
  @key_name = name
  gpg_key_recipie = <<EOF
     Key-Type: RSA
     Key-Length: 4096
     Subkey-Type: RSA
     Subkey-Length: 4096
     Name-Real: #{@key_name}
     Name-Comment: Blah
     Name-Email: #{@key_name}@test.org
     Expire-Date: 0
     Passphrase: #{pwd}
     %commit
EOF
  gpg_key_recipie.split("\n").each do |line|
27
    $vm.execute("echo '#{line}' >> /tmp/gpg_key_recipie", :user => LIVE_USER)
28
  end
29
  c = $vm.execute("gpg --batch --gen-key < /tmp/gpg_key_recipie",
anonym's avatar
anonym committed
30
                  :user => LIVE_USER)
31
32
33
34
  assert(c.success?, "Failed to generate OpenPGP key:\n#{c.stderr}")
end

When /^I type a message into gedit$/ do
anonym's avatar
anonym committed
35
36
37
38
  step 'I start "gedit" via the GNOME "Accessories" applications menu'
  @message = 'ATTACK AT DAWN'
  @gedit = Dogtail::Application.new('gedit')
  @gedit.child(roleName: 'text').typeText(@message)
39
40
41
42
end

def maybe_deal_with_pinentry
  begin
kytv's avatar
kytv committed
43
    @screen.wait_and_click("PinEntryPrompt.png", 10)
44
45
46
47
    # Without this sleep here (and reliable visual indicators) we can sometimes
    # miss keystrokes by typing too soon. This sleep prevents this problem from
    # coming up.
    sleep 5
48
49
    @screen.type(@passphrase + Sikuli::Key.ENTER)
  rescue FindFailed
50
51
52
53
54
    # The passphrase was cached or we wasn't prompted at all (e.g. when
    # only encrypting to a public key)
  end
end

55
def gedit_copy_all_text
56
57
  context_menu_helper('GeditWindow.png', 'GeditStatusBar.png', 'GeditSelectAll.png')
  context_menu_helper('GeditWindow.png', 'GeditStatusBar.png', 'GeditCopy.png')
58
59
end

60
def paste_into_a_new_tab
61
62
  @screen.wait_and_click("GeditNewTab.png", 20)
  context_menu_helper('GeditWindow.png', 'GeditStatusBar.png', 'GeditPaste.png')
63
64
end

65
def encrypt_sign_helper
66
  gedit_copy_all_text
67
  seahorse_menu_click_helper('GpgAppletIconNormal.png', 'GpgAppletSignEncrypt.png')
68
  @screen.wait_and_click("GpgAppletChooseKeyWindow.png", 30)
69
70
71
  # We don't have a good visual indicator for when we can continue without
  # keystrokes being lost.
  sleep 5
72
73
  yield
  maybe_deal_with_pinentry
74
  paste_into_a_new_tab
75
76
77
end

def decrypt_verify_helper(icon)
78
  gedit_copy_all_text
79
  seahorse_menu_click_helper(icon, 'GpgAppletDecryptVerify.png')
80
  maybe_deal_with_pinentry
81
82
  @screen.wait("GpgAppletResults.png", 20)
  @screen.wait("GpgAppletResultsMsg.png", 20)
83
84
85
86
end

When /^I encrypt the message using my OpenPGP key$/ do
  encrypt_sign_helper do
87
    @screen.type(@key_name + Sikuli::Key.ENTER + Sikuli::Key.ENTER)
88
89
90
91
92
  end
end

Then /^I can decrypt the encrypted message$/ do
  decrypt_verify_helper("GpgAppletIconEncrypted.png")
93
  @screen.wait("GpgAppletResultsEncrypted.png", 20)
94
95
96
97
end

When /^I sign the message using my OpenPGP key$/ do
  encrypt_sign_helper do
98
    @screen.type(Sikuli::Key.TAB + Sikuli::Key.DOWN + Sikuli::Key.ENTER)
99
100
101
102
103
  end
end

Then /^I can verify the message's signature$/ do
  decrypt_verify_helper("GpgAppletIconSigned.png")
104
  @screen.wait("GpgAppletResultsSigned.png", 20)
105
106
107
108
end

When /^I both encrypt and sign the message using my OpenPGP key$/ do
  encrypt_sign_helper do
109
110
111
    @screen.wait_and_click('GpgAppletEncryptionKey.png', 20)
    @screen.type(Sikuli::Key.SPACE)
    @screen.wait('GpgAppletKeySelected.png', 10)
112
    @screen.type(Sikuli::Key.TAB + Sikuli::Key.DOWN + Sikuli::Key.ENTER)
113
    @screen.type(Sikuli::Key.ENTER)
114
115
116
117
118
  end
end

Then /^I can decrypt and verify the encrypted message$/ do
  decrypt_verify_helper("GpgAppletIconEncrypted.png")
119
120
  @screen.wait("GpgAppletResultsEncrypted.png", 20)
  @screen.wait("GpgAppletResultsSigned.png", 20)
121
122
123
124
end

When /^I symmetrically encrypt the message with password "([^"]+)"$/ do |pwd|
  @passphrase = pwd
125
  gedit_copy_all_text
126
  seahorse_menu_click_helper('GpgAppletIconNormal.png', 'GpgAppletEncryptPassphrase.png')
127
128
129
  maybe_deal_with_pinentry # enter password
  maybe_deal_with_pinentry # confirm password
  paste_into_a_new_tab
130
end