Merge remote-tracking branch 'flapflap/de-network_configuration'
[tails-test.git] / features / step_definitions / encryption.rb
blob291b7a48af85b6453647d56359ba75d89cd5247f
1 Given /^I generate an OpenPGP key named "([^"]+)" with password "([^"]+)"$/ do |name, pwd|
2   @passphrase = pwd
3   @key_name = name
4   next if @skip_steps_while_restoring_background
5   gpg_key_recipie = <<EOF
6      Key-Type: RSA
7      Key-Length: 4096
8      Subkey-Type: RSA
9      Subkey-Length: 4096
10      Name-Real: #{@key_name}
11      Name-Comment: Blah
12      Name-Email: #{@key_name}@test.org
13      Expire-Date: 0
14      Passphrase: #{pwd}
15      %commit
16 EOF
17   gpg_key_recipie.split("\n").each do |line|
18     @vm.execute("echo '#{line}' >> /tmp/gpg_key_recipie", $live_user)
19   end
20   c = @vm.execute("gpg --batch --gen-key < /tmp/gpg_key_recipie", $live_user)
21   assert(c.success?, "Failed to generate OpenPGP key:\n#{c.stderr}")
22 end
24 When /^I type a message into gedit$/ do
25   next if @skip_steps_while_restoring_background
26   step 'I start "Gedit" via the GNOME "Accessories" applications menu'
27   @screen.wait_and_click("GeditWindow.png", 10)
28   sleep 0.5
29   @screen.type("ATTACK AT DAWN")
30 end
32 def maybe_deal_with_pinentry
33   begin
34     @screen.wait_and_click("PinEntryPrompt.png", 3)
35     sleep 1
36     @screen.type(@passphrase + Sikuli::Key.ENTER)
37   rescue FindFailed
38     # The passphrase was cached or we wasn't prompted at all (e.g. when
39     # only encrypting to a public key)
40   end
41 end
43 def encrypt_sign_helper
44   @screen.wait_and_click("GeditWindow.png", 10)
45   @screen.type("a", Sikuli::KeyModifier.CTRL)
46   sleep 0.5
47   @screen.click("GpgAppletIconNormal.png")
48   sleep 2
49   @screen.type("k")
50   @screen.wait_and_click("GpgAppletChooseKeyWindow.png", 30)
51   sleep 0.5
52   yield
53   maybe_deal_with_pinentry
54   @screen.wait_and_click("GeditWindow.png", 10)
55   sleep 0.5
56   @screen.type("n", Sikuli::KeyModifier.CTRL)
57   sleep 0.5
58   @screen.type("v", Sikuli::KeyModifier.CTRL)
59 end
61 def decrypt_verify_helper(icon)
62   @screen.wait_and_click("GeditWindow.png", 10)
63   @screen.type("a", Sikuli::KeyModifier.CTRL)
64   sleep 0.5
65   @screen.click(icon)
66   sleep 2
67   @screen.type("d")
68   maybe_deal_with_pinentry
69   @screen.wait("GpgAppletResults.png", 10)
70   @screen.wait("GpgAppletResultsMsg.png", 10)
71 end
73 When /^I encrypt the message using my OpenPGP key$/ do
74   next if @skip_steps_while_restoring_background
75   encrypt_sign_helper do
76     @screen.type(@key_name + Sikuli::Key.ENTER + Sikuli::Key.ENTER)
77   end
78 end
80 Then /^I can decrypt the encrypted message$/ do
81   next if @skip_steps_while_restoring_background
82   decrypt_verify_helper("GpgAppletIconEncrypted.png")
83   @screen.wait("GpgAppletResultsEncrypted.png", 10)
84 end
86 When /^I sign the message using my OpenPGP key$/ do
87   next if @skip_steps_while_restoring_background
88   encrypt_sign_helper do
89     @screen.type(Sikuli::Key.TAB + Sikuli::Key.DOWN + Sikuli::Key.ENTER)
90     @screen.wait("PinEntryPrompt.png", 10)
91     @screen.type(@passphrase + Sikuli::Key.ENTER)
92   end
93 end
95 Then /^I can verify the message's signature$/ do
96   next if @skip_steps_while_restoring_background
97   decrypt_verify_helper("GpgAppletIconSigned.png")
98   @screen.wait("GpgAppletResultsSigned.png", 10)
99 end
101 When /^I both encrypt and sign the message using my OpenPGP key$/ do
102   next if @skip_steps_while_restoring_background
103   encrypt_sign_helper do
104     @screen.type(@key_name + Sikuli::Key.ENTER)
105     @screen.type(Sikuli::Key.TAB + Sikuli::Key.DOWN + Sikuli::Key.ENTER)
106     @screen.wait("PinEntryPrompt.png", 10)
107     @screen.type(@passphrase + Sikuli::Key.ENTER)
108   end
111 Then /^I can decrypt and verify the encrypted message$/ do
112   next if @skip_steps_while_restoring_background
113   decrypt_verify_helper("GpgAppletIconEncrypted.png")
114   @screen.wait("GpgAppletResultsEncrypted.png", 10)
115   @screen.wait("GpgAppletResultsSigned.png", 10)
118 When /^I symmetrically encrypt the message with password "([^"]+)"$/ do |pwd|
119   @passphrase = pwd
120   next if @skip_steps_while_restoring_background
121   @screen.wait_and_click("GeditWindow.png", 10)
122   @screen.type("a", Sikuli::KeyModifier.CTRL)
123   sleep 0.5
124   @screen.click("GpgAppletIconNormal.png")
125   sleep 2
126   @screen.type("p")
127   @screen.wait("PinEntryPrompt.png", 10)
128   @screen.type(@passphrase + Sikuli::Key.ENTER)
129   sleep 1
130   @screen.wait("PinEntryPrompt.png", 10)
131   @screen.type(@passphrase + Sikuli::Key.ENTER)
132   @screen.wait_and_click("GeditWindow.png", 10)
133   sleep 0.5
134   @screen.type("n", Sikuli::KeyModifier.CTRL)
135   sleep 0.5
136   @screen.type("v", Sikuli::KeyModifier.CTRL)