a0618961b16b8e2230ec1de99f5bd1ec3a47ee8d
[mirror/dsa-puppet.git] / modules / roles / files / signing / pesign-wrap
1 #!/usr/bin/expect -f
2
3 if {[llength $argv] != 4} {
4     puts stderr "Usage: $argv0 certdir token cert filename"
5     exit 2
6 }
7
8 lassign $argv certdir token cert filename
9
10 set pin $::env(PESIGN_PIN)
11
12 file tempfile output efi.sig
13
14 log_user 0
15 spawn pesign --certdir "$certdir" -t "$token" -c "$cert" --sign -d sha256 -i "$filename" --export-signature "$output" --force
16 expect {
17         "Enter Password *:" {
18                 send "$pin\n"
19                 exp_continue
20         }
21         "Enter passphrase *:" {
22                 send "$pin\n"
23                 exp_continue
24         }
25         timeout {close}
26 }
27 lassign [wait] wait_pid spawn_id exec_rc wait_code childkilled
28 # couldn't exec pesign
29 if {$exec_rc != 0} {
30         file delete $output
31         exit 1
32 }
33 # killed by signal (e.g. timeout)
34 if {$childkilled == "CHILDKILLED"} {
35         file delete $output
36         exit 1
37 }
38 # all good?
39 if {$wait_code == 0} {system cat $output}
40 file delete $output
41 exit $wait_code