-
Notifications
You must be signed in to change notification settings - Fork 10
/
ssh-print.rb
executable file
·69 lines (57 loc) · 2.02 KB
/
ssh-print.rb
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
#!/usr/bin/env ruby
# Copyright 2018, Raphael Reitzig
#
# pdfinvert is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# pdfinvert is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pdfinvert. If not, see <http://www.gnu.org/licenses/>.
# A simple script that creates a printable PDF backup of an SSH key.
#
# Does currently not include any error handling.
require 'tmpdir'
if ARGV.size < 4
puts "Usage: ssh-print.rb name passphrase key_file out_file"
Process.exit(0)
end
name = ARGV[0]
pass = ARGV[1]
key = ARGV[2]
out = ARGV[3]
out += ".pdf" unless out.end_with?(".pdf")
Dir.mktmpdir { |tmpdir|
wd = Dir.pwd
fingerprint = `ssh-keygen -lf "#{key}"`
`cat "#{key}" | qrencode -o "#{tmpdir}"/qr.png`
key_content = `cat "#{key}"`
latex = <<~TEX
\\documentclass{article}
\\pagestyle{empty}
\\setlength{\\parindent}{0pt}
\\usepackage[margin=2cm]{geometry}
\\usepackage{graphicx}
\\begin{document}
\\section*{#{name}}
\\begin{description}
\\item[Fingerprint:] \\texttt{#{fingerprint}}
\\item[Passphrase:] \\texttt{#{pass}}
\\end{description}
\\includegraphics[width=\\linewidth]{qr.png}
\\clearpage\\centering\\begin{verbatim}#{key_content}
\\end{verbatim}
\\end{document}
TEX
File.open("#{tmpdir}/bak.tex", "w") { |texfile|
texfile.write(latex)
}
Dir.chdir(tmpdir)
`pdflatex -file-line-error -interaction=nonstopmode bak.tex`
FileUtils.cp("bak.pdf", "#{wd}/#{out}")
}