~ubuntu-branches/ubuntu/precise/topal/precise

« back to all changes in this revision

Viewing changes to externals-gpg.adb

  • Committer: Bazaar Package Importer
  • Author(s): Phil Brooke
  • Date: 2008-07-18 07:57:38 UTC
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20080718075738-i1szqvmxz0evz32p
Tags: upstream-62
ImportĀ upstreamĀ versionĀ 62

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
--
2
 
--
3
 
--
4
 
--
 
1
-- Topal: GPG/GnuPG and Alpine/Pine integration
 
2
-- Copyright (C) 2001--2008  Phillip J. Brooke
 
3
--
 
4
-- This program is free software: you can redistribute it and/or modify
 
5
-- it under the terms of the GNU General Public License version 3 as
 
6
-- published by the Free Software Foundation.
 
7
--
 
8
-- This program is distributed in the hope that it will be useful,
 
9
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
-- GNU General Public License for more details.
 
12
--
 
13
-- You should have received a copy of the GNU General Public License
 
14
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
5
15
 
6
16
with Ada.Text_IO;
7
17
with Externals.Simple;
27
24
   begin
28
25
      -- Clean up the error file to remove
29
26
      -- `gpg: Invalid passphrase; please try again ...' messages.
30
 
      if ForkExec_Out(Value_Nonempty(Config.Grep_Binary),
 
27
      if ForkExec_Out(Value_Nonempty(Config.Binary(Grep)),
31
28
                      UBS_Array'(0 => ToUBS("grep"),
32
29
                                 1 => ToUBS("-v"),
33
30
                                 2 => ToUBS("gpg: Invalid passphrase; please try again ..."),
41
38
                     Output_File : String;
42
39
                     Err_File    : String) return Integer is
43
40
      GPG_Return_Value, Tee_Return_Value : Integer;
44
 
      Orig_Err_File                      : String := Temp_File_Name("origerr");
 
41
      Orig_Err_File                      : constant String
 
42
        := Temp_File_Name("origerr");
45
43
   begin
46
 
      ForkExec2(Value_Nonempty(Config.Gpg_Binary),
 
44
      ForkExec2(Value_Nonempty(Config.Binary(GPGOP)),
47
45
                ToUBS("gpg "
48
46
                      & ToStr(Config.Gpg_Options)
49
47
                      & " --output "
55
53
                      & " "
56
54
                      & Input_File),
57
55
                GPG_Return_Value,
58
 
                Value_Nonempty(Config.Tee_Binary),
 
56
                Value_Nonempty(Config.Binary(Tee)),
59
57
                ToUBS("tee "
60
58
                      & Orig_Err_File),
61
59
                Tee_Return_Value,
79
77
                            Output_File : String;
80
78
                            Err_File    : String) return Integer is
81
79
      GPG_Return_Value, Tee_Return_Value : Integer;
82
 
      Orig_Err_File                      : String := Temp_File_Name("origerr");
 
80
      Orig_Err_File                      : constant String
 
81
        := Temp_File_Name("origerr");
83
82
   begin
84
 
      ForkExec2(Value_Nonempty(Config.Gpg_Binary),
 
83
      ForkExec2(Value_Nonempty(Config.Binary(GPGOP)),
85
84
                ToUBS("gpg "
86
85
                      & ToStr(Config.Gpg_Options)
87
86
                      & " --output "
95
94
                      & " "
96
95
                      & Input_File),
97
96
                GPG_Return_Value,
98
 
                Value_Nonempty(Config.Tee_Binary),
 
97
                Value_Nonempty(Config.Binary(Tee)),
99
98
                ToUBS("tee "
100
99
                      & Orig_Err_File),
101
100
                Tee_Return_Value,
114
113
         raise;
115
114
   end GPG_Verify_Tee;
116
115
 
 
116
   function GPGSM_Verify_Tee (Input_File  : String;
 
117
                              Sig_File    : String;
 
118
                              Output_File : String;
 
119
                              Err_File    : String) return Integer is
 
120
      GPG_Return_Value, Tee_Return_Value : Integer;
 
121
      Orig_Err_File                      : constant String
 
122
        := Temp_File_Name("origerr");
 
123
   begin
 
124
      -- FIXME: gpgsm should be in config
 
125
      ForkExec2(Value_Nonempty(Config.Binary(GPGSM)),
 
126
                ToUBS("gpgsm "
 
127
                      & " --disable-crl-checks --output "
 
128
                      & Output_File
 
129
                      & " --verify "
 
130
                      & Sig_File
 
131
                      & " "
 
132
                      & Input_File),
 
133
                GPG_Return_Value,
 
134
                Value_Nonempty(Config.Binary(Tee)),
 
135
                ToUBS("tee "
 
136
                      & Orig_Err_File),
 
137
                Tee_Return_Value,
 
138
                Merge_StdErr1 => True,
 
139
                Report => True);
 
140
      if Tee_Return_Value /= 0 then
 
141
         Error("Tee failed! (ff1)");
 
142
      end if;
 
143
      Clean_GPG_Errors(Orig_Err_File, Err_File);
 
144
      -- Let the caller sort out the GPG return value.
 
145
      return GPG_Return_Value;
 
146
   exception
 
147
      when others =>
 
148
         Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
 
149
                              "Exception raised in Externals.GPG.GPGSM_Verify_Tee");
 
150
         raise;
 
151
   end GPGSM_Verify_Tee;
 
152
 
117
153
   function Grep_Sigfile_Digest (Sigfile : in String;
118
154
                                 Number  : in String)
119
155
                                 return Integer is
120
156
      E1, E2 : Integer;
121
157
   begin
122
 
      ForkExec2(Value_Nonempty(Config.GPG_Binary),
 
158
      ForkExec2(Value_Nonempty(Config.Binary(GPGOP)),
123
159
                UBS_Array'(0 => ToUBS("gpg"),
124
160
                           1 => ToUBS("--list-packets"),
125
161
                           2 => ToUBS(Sigfile)),
126
162
                E1,
127
 
                Value_Nonempty(Config.Grep_Binary),
 
163
                Value_Nonempty(Config.Binary(Grep)),
128
164
                UBS_Array'(0 => ToUBS("grep"),
129
165
                           1 => ToUBS("-q"),
130
166
                           2 => ToUBS("digest algo " & Number)),
191
227
      R : Integer;  -- The return code from GPG.
192
228
   begin
193
229
      Ada.Text_IO.Put_Line("About to run `gpg " & Args & "'...");
194
 
      R := ForkExec(Value_Nonempty(Config.Gpg_Binary),
 
230
      R := ForkExec(Value_Nonempty(Config.Binary(GPGOP)),
195
231
                    ToUBS("gpg " & Args));
196
232
      if R = 0 then
197
233
         Ada.Text_IO.Put_Line("GPG exited successfully...");
222
258
                      Target : in String) is
223
259
      E1, E2, E3 : Integer;
224
260
   begin
225
 
      ForkExec3_Out(Value_Nonempty(Config.Gpg_Binary),
 
261
      ForkExec3_Out(Value_Nonempty(Config.Binary(GPGOP)),
226
262
                    ToUBS("gpg "
227
263
                          & ToStr(Config.Gpg_Options)
228
 
                          & " --fingerprint " & Key),
 
264
                          & " --with-colons --with-fingerprint --list-keys " & Key),
229
265
                    E1,
230
 
                    Value_Nonempty(Config.Grep_binary),
 
266
                    Value_Nonempty(Config.Binary(Grep)),
231
267
                    UBS_Array'(0 => ToUBS("grep"),
232
 
                               1 => ToUBS("Key fingerprint")),
 
268
                               1 => ToUBS("^fpr")),
233
269
                    E2,
234
 
                    Value_Nonempty(Config.Sed_binary),
 
270
                    Value_Nonempty(Config.Binary(Sed)),
235
271
                    UBS_Array'(0 => ToUBS("sed"),
236
 
                               1 => ToUBS("-e"),
237
 
                               2 => ToUBS("s/.*= //"),
238
 
                               3 => ToUBS("-e"),
239
 
                               4 => ToUBS("s/ //g"),
240
 
                               5 => ToUBS("-e"),
241
 
                               6 => ToUBS("s/^/0x/")),
 
272
                               1 => ToUBS("s/^fpr:*://; s/:*$//")),
242
273
                    E3,
243
274
                    Target => Target);
244
275
      Debug("Add_Keys_By_Fingerprint: Finished exec's");
261
292
                             Target : in String) is
262
293
      E1, E2, E3 : Integer;
263
294
   begin
264
 
      ForkExec3_Out(Value_Nonempty(Config.Gpg_Binary),
 
295
      ForkExec3_Out(Value_Nonempty(Config.Binary(GPGOP)),
265
296
                    ToUBS("gpg "
266
297
                          & ToStr(Config.Gpg_Options)
267
 
                          & " --list-secret-keys "
268
 
                          & Key),
 
298
                          & " --with-colons --with-fingerprint --list-secret-keys " & Key),
269
299
                    E1,
270
 
                    Value_Nonempty(Config.Grep_Binary),
 
300
                    Value_Nonempty(Config.Binary(Grep)),
271
301
                    UBS_Array'(0 => ToUBS("grep"),
272
 
                               1 => ToUBS("^sec")),
 
302
                               1 => ToUBS("^fpr")),
273
303
                    E2,
274
 
                    Value_Nonempty(Config.Sed_Binary),
 
304
                    Value_Nonempty(Config.Binary(Sed)),
275
305
                    UBS_Array'(0 => ToUBS("sed"),
276
 
                               1 => ToUBS("-e"),
277
 
                               2 => ToUBS("s/^sec *//"),
278
 
                               3 => ToUBS("-e"),
279
 
                               4 => ToUBS("s/ .*$//"),
280
 
                               5 => ToUBS("-e"),
281
 
                               6 => ToUBS("sx^.*/xx")),
 
306
                               1 => ToUBS("s/^fpr:*://; s/:*$//")),
282
307
                    E3,
283
308
                    Target => Target);
284
309
      if E1 /= 0 then
297
322
 
298
323
   procedure Listkey (Key    : in String;
299
324
                      Target : in String) is
 
325
      E1, E2 : Integer;
300
326
   begin
301
 
      if ForkExec_Out(Value_Nonempty(Config.Gpg_Binary),
302
 
                      ToUBS("gpg "
303
 
                            & ToStr(Config.Gpg_Options)
304
 
                            & " --list-keys "
305
 
                            & Key),
306
 
                      Target => Target) /= 0 then
307
 
         Error("Problem generating keylist, GPG barfed (ff7)");
 
327
      ForkExec2_Out(File1 => Value_Nonempty(Config.Binary(GPGOP)),
 
328
                    Argv1 => ToUBS("gpg "
 
329
                                   & ToStr(Config.Gpg_Options)
 
330
                                   & " --with-colons --with-fingerprint --with-fingerprint  --list-keys "
 
331
                                   & Key),
 
332
                    Exit1 => E1,
 
333
                    File2 => Value_Nonempty(Config.Binary(Grep)),
 
334
                    Argv2 => UBS_Array'(0 => ToUBS("grep"),
 
335
                                        1 => ToUBS("^pub")),
 
336
                    Exit2 => E2,
 
337
                    Target => Target);
 
338
      if E1 /= 0 then
 
339
         Error("Problem generating keylist, GPG barfed (ff7a)");
 
340
      end if;
 
341
      if E2 /= 0 then
 
342
         Error("Problem generating keylist, grep barfed (ff7b)");
308
343
      end if;
309
344
   exception
310
345
      when others =>
329
364
                    & " --list-keys "
330
365
                    & Key);
331
366
      end if;
332
 
      ForkExec2(Value_Nonempty(Config.Gpg_binary),
 
367
      ForkExec2(Value_Nonempty(Config.Binary(GPGOP)),
333
368
                U,
334
369
                E1,
335
 
                Value_Nonempty(Config.Less_Binary),
 
370
                Value_Nonempty(Config.Binary(Less)),
336
371
                ToUBS("less"),
337
372
                E2);
338
373
      if E1 /= 0 then