summaryrefslogtreecommitdiffstats
path: root/features/step_definitions/encryption.rb
blob: 404890aec9079248d9a167c6ad3a07932eb4c932 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
Given /^I generate an OpenPGP key named "([^"]+)" with password "([^"]+)"$/ do |name, pwd|
  @passphrase = pwd
  @key_name = name
  next if @skip_steps_while_restoring_background
  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|
    @vm.execute("echo '#{line}' >> /tmp/gpg_key_recipie", $live_user)
  end
  c = @vm.execute("gpg --batch --gen-key < /tmp/gpg_key_recipie", $live_user)
  assert(c.success?, "Failed to generate OpenPGP key:\n#{c.stderr}")
end

When /^I type a message into gedit$/ do
  next if @skip_steps_while_restoring_background
  @screen.wait_and_click("GnomeApplicationsMenu.png", 10)
  @screen.wait_and_click("GnomeApplicationsAccessories.png", 10)
  @screen.wait_and_click("GnomeApplicationsGedit.png", 20)
  @screen.wait_and_click("GeditWindow.png", 10)
  sleep 0.5
  @screen.type("ATTACK AT DAWN")
end

def maybe_deal_with_pinentry
  begin
    @screen.wait_and_click("PinEntryPrompt.png", 3)
    sleep 1
    @screen.type(@passphrase + Sikuli::Key.ENTER)
  rescue FindFailed
    # The passphrase was cached or we wasn't prompted at all (e.g. when
    # only encrypting to a public key)
  end
end

def encrypt_sign_helper
  @screen.wait_and_click("GeditWindow.png", 10)
  @screen.type("a", Sikuli::KeyModifier.CTRL)
  sleep 0.5
  @screen.click("GpgAppletIconNormal.png")
  sleep 2
  @screen.type("k")
  @screen.wait_and_click("GpgAppletChooseKeyWindow.png", 30)
  sleep 0.5
  yield
  maybe_deal_with_pinentry
  @screen.wait_and_click("GeditWindow.png", 10)
  sleep 0.5
  @screen.type("n", Sikuli::KeyModifier.CTRL)
  sleep 0.5
  @screen.type("v", Sikuli::KeyModifier.CTRL)
end

def decrypt_verify_helper(icon)
  @screen.wait_and_click("GeditWindow.png", 10)
  @screen.type("a", Sikuli::KeyModifier.CTRL)
  sleep 0.5
  @screen.click(icon)
  sleep 2
  @screen.type("d")
  maybe_deal_with_pinentry
  @screen.wait("GpgAppletResults.png", 10)
  @screen.wait("GpgAppletResultsMsg.png", 10)
end

When /^I encrypt the message using my OpenPGP key$/ do
  next if @skip_steps_while_restoring_background
  encrypt_sign_helper do
    @screen.type(@key_name + Sikuli::Key.ENTER + Sikuli::Key.ENTER)
  end
end

Then /^I can decrypt the encrypted message$/ do
  next if @skip_steps_while_restoring_background
  decrypt_verify_helper("GpgAppletIconEncrypted.png")
  @screen.wait("GpgAppletResultsEncrypted.png", 10)
end

When /^I sign the message using my OpenPGP key$/ do
  next if @skip_steps_while_restoring_background
  encrypt_sign_helper do
    @screen.type(Sikuli::Key.TAB + Sikuli::Key.DOWN + Sikuli::Key.ENTER)
    @screen.wait("PinEntryPrompt.png", 10)
    @screen.type(@passphrase + Sikuli::Key.ENTER)
  end
end

Then /^I can verify the message's signature$/ do
  next if @skip_steps_while_restoring_background
  decrypt_verify_helper("GpgAppletIconSigned.png")
  @screen.wait("GpgAppletResultsSigned.png", 10)
end

When /^I both encrypt and sign the message using my OpenPGP key$/ do
  next if @skip_steps_while_restoring_background
  encrypt_sign_helper do
    @screen.type(@key_name + Sikuli::Key.ENTER)
    @screen.type(Sikuli::Key.TAB + Sikuli::Key.DOWN + Sikuli::Key.ENTER)
    @screen.wait("PinEntryPrompt.png", 10)
    @screen.type(@passphrase + Sikuli::Key.ENTER)
  end
end

Then /^I can decrypt and verify the encrypted message$/ do
  next if @skip_steps_while_restoring_background
  decrypt_verify_helper("GpgAppletIconEncrypted.png")
  @screen.wait("GpgAppletResultsEncrypted.png", 10)
  @screen.wait("GpgAppletResultsSigned.png", 10)
end

When /^I symmetrically encrypt the message with password "([^"]+)"$/ do |pwd|
  @passphrase = pwd
  next if @skip_steps_while_restoring_background
  @screen.wait_and_click("GeditWindow.png", 10)
  @screen.type("a", Sikuli::KeyModifier.CTRL)
  sleep 0.5
  @screen.click("GpgAppletIconNormal.png")
  sleep 2
  @screen.type("p")
  @screen.wait("PinEntryPrompt.png", 10)
  @screen.type(@passphrase + Sikuli::Key.ENTER)
  sleep 1
  @screen.wait("PinEntryPrompt.png", 10)
  @screen.type(@passphrase + Sikuli::Key.ENTER)
  @screen.wait_and_click("GeditWindow.png", 10)
  sleep 0.5
  @screen.type("n", Sikuli::KeyModifier.CTRL)
  sleep 0.5
  @screen.type("v", Sikuli::KeyModifier.CTRL)
end