File: pinentry-clearpassphrase

package info (click to toggle)
schleuder 3.6.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,820 kB
  • sloc: ruby: 10,886; sh: 211; makefile: 8
file content (72 lines) | stat: -rwxr-xr-x 1,360 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/env ruby

# This file can be deleted once we cease to support gnupg 2.0.

require 'fileutils'
require 'cgi'
require 'openssl'

def respond(msg, flush=true)
  $stdout.puts msg
  if flush
    $stdout.flush
  end
end

def send_ok(flush=true)
  respond 'OK', flush
end

def send_password
  if File.exist?(OLDPWDSENTFILE)
    pwd = ''
    if File.exist?(EMPTYPWDSENTFILE1)
      FileUtils.touch(EMPTYPWDSENTFILE2)
    else
      FileUtils.touch(EMPTYPWDSENTFILE1)
    end
  else
    pwd = OLDPASSWD
    FileUtils.touch(OLDPWDSENTFILE)
  end
  respond "D #{pwd}"
end

def do_exit
  if File.exist?(EMPTYPWDSENTFILE2)
    FileUtils.rm_rf(TMPDIR)
  end
  exit 0
end

OLDPASSWD = CGI.escape(ENV['PINENTRY_USER_DATA'].to_s)
if OLDPASSWD.empty?
  respond "Fatal error: passed PINENTRY_USER_DATA was empty, cannot continue"
  exit 1
end

# We need a static directory name to maintain the state across invocations of
# this file.
TMPDIR = File.join(ENV['GNUPGHOME'], '.tmp-pinentry-clearpassphrase')
OLDPWDSENTFILE = File.join(TMPDIR, '1')
EMPTYPWDSENTFILE1 = File.join(TMPDIR, '2')
EMPTYPWDSENTFILE2 = File.join(TMPDIR, '3')
if ! Dir.exist?(TMPDIR)
  Dir.mkdir(TMPDIR)
end

respond "OK - what's up?"

while line = $stdin.gets do
  case line
  when /^GETPIN/
    send_password
    send_ok
  when /^BYE/
    send_ok false
    do_exit
  else
    send_ok
  end
end