-
Notifications
You must be signed in to change notification settings - Fork 6
/
pem-to-png
executable file
·98 lines (88 loc) · 5.29 KB
/
pem-to-png
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#! /usr/bin/env bash
# IMPORTANT: pem-to-png is the old version, kept for reference
# cert-card is the new version
# entr bash -c "./pem-to-png <foo.crt" <<<$'pem-to-png\n'
set -euo pipefail
echo "Reading PEM from stdin..." >&2
cat >/tmp/crt
# When printing to the Brother QL-820WNB, the width of the image (as opposed to
# the height) is scaled to the 6.2 cm of the label tape's width. In the
# following, e.g., 984 x 696 px, means height x width. So the "second" number is
# the one scaled to 6.2 cm.
#
# For example, with a portrait-mode image of 696 x 232 px, the "top" if the
# image is scaled to the width of the paper roll (6.2 cm). If the "top" is 696
# px, which the the nominal pixel width, then no scaling is neededd.
#
# 696 x 232 px
# ^^^ ^^^
# width height
# (6.2 cm)
#
# - - - - - - - - - - +--------------+ ^
# | RIGHT | |
# | | |
# PAPER UNROLLS THIS WAY | TOP | | width
# --------------------> | | | 696 px
# | (normal | | (6.2 cm)
# | orienta.) | |
# - - - - - - - - - - +--------------+ v
# <-------------->
# height 232 px (2.9 cm)
#
#
# If I want the "right" of the image to scale to the 6.2 cm of the paper roll,
# I need to --rotate 90. Since the "right" of the image is now scaled to the
# width of the paper roll, I need to have an image with a in which case the size
# is 696 x 984 px:
#
# 696 x 984 px (rotated 90 degrees)
# ^^^ ^^^
# width height
# (6.2 cm)
#
# - - - - - - - - - - +------------------------------+ ^
# | TOP | |
# | | |
# PAPER UNROLLS THIS WAY | | | width
# --------------------> | RIGHT | | 696 px
# | | | (6.2 cm)
# | (rotated 90) | |
# - - - - - - - - - - +------------------------------+ v
# <------------------------------>
# height 984 px (8.4 cm)
#
#
# Format 1: 984 x 696 px (8.7 x 6.2 cm), requires --rotate 90 so that "696 px"
# (the height) coincides with the the width of the paper roll.
#
# Format 2: 696 x 492 px (6.2 x 4.4 cm), requires no rotation.
line1=$(
cat <<EOF
Thank you for visiting the cert-manager
booth! We hope you are enjoying
your time in Salt Lake City.
EOF
)
line2=$(
cat <<EOF
This card is proof that you
were there! On the back of
the card, the QR code
links to your certificate.
EOF
)
# \( -gravity NorthEast logo.png -resize 160 -background white -alpha remove -alpha off -monochrome \) -geometry +40+20 -composite \
# \( -gravity East kubecon-eu-2022-logo.png -resize 280 -background white -alpha remove -alpha off -monochrome \) -geometry +80+10 \
convert -size 696x492 canvas:white \
\( -gravity NorthWest -font Open-Sans-Regular -pointsize 22 -fill black -annotate +0-0 "$line1" \) -geometry +0+0 \
\( -gravity NorthWest -font Open-Sans-Regular -pointsize 22 -fill black -annotate +0+115 "$line2" \) -geometry +0+0 \
\( -gravity SouthWest -font DejaVu-Sans-Mono -pointsize 22 -fill black -annotate +0+0 "$(step certificate inspect --short /tmp/crt | sed -e 's/\[\(.*\)\]/\n\1/' -e 's/Certificate (\(.*\))/Certificate\nAlgorithm: \1/' | sed 's/^ //')" \) -geometry +0+0 \
-background None -layers Flatten front.png
# See js/x509.js to understand the format expected by the asn1 query parameter.
url=$(grep -v 'CERTIFICATE' /tmp/crt | tr -d '$\n' | python3 -c "import urllib.parse; print(urllib.parse.quote_plus(open(0).read()))")
echo "https://cert-manager.github.io/print-your-cert?asn1=$url" >&2
echo "https://cert-manager.github.io/print-your-cert?asn1=$url" | qrencode --type PNG --margin 0 -o - | convert -size 696x492 canvas:white \
\( -gravity Center -monochrome -filter point -interpolate nearest - -resize 492 \) -composite back.png
# Example:
# https://cert-manager.github.io/print-your-cert?asn1=MIICXDCCAgOgAwIBAgIQdPaTuGSUDeosii4dbdLBgTAKBggqhkjOPQQDAjAnMSUwIwYDVQQDExxUaGUgY2VydC1tYW5hZ2VyIG1haW50YWluZXJzMB4XDTIyMDUxNjEzMDkwMFoXDTIyMDgxNDEzMDkwMFowLDEqMCgGA1UEAwwhZm9vIGJhciBmb28gYmFyIDxmb28uYmFyQGJhci5mb28%2BMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtmGM5lil9Vw%2Fy5LhpgO8t5gSb5oUo%2BDp5vWw0Z5C7rjvifi0%2FeD9MbVFkxb%2B%2BhmOaaNCVgqDUio1OBOZyL90KzdnGW7nz1fRM2KCNrDF5Y1mO7uv1ZTZa8cVBjF67KjFuNkvvHp74m65bKwXeCHXJBmO3Z1FH8hudICU74%2BNl6tyjlMOsTHv%2BLY0jPfmAtO6eR%2BEf%2FHvgzwsjKds12vdlRCdHSS6u5zlrZZxF3zTO7YuAM7mN8Wbjq94YcpgsJ5ssNOtMu9FwZtPGQDHPaQyVQ86FfjhmMi1IUOUAAGwh%2FQRv8ksX%2BOupHTNdH06WmIDCaGBjWFgPkwicavMZgZG3QIDAQABo0EwPzAOBgNVHQ8BAf8EBAMCBaAwDAYDVR0TAQH%2FBAIwADAfBgNVHSMEGDAWgBQG5XQnDhOUa748L9H7TWZN2avluTAKBggqhkjOPQQDAgNHADBEAiBXmyJ24PTG76pEyq6AQtCo6TXEidqJhsmK9O5WjGBw7wIgaPbcFI5iMMgfPGEATH2AGGutZ6MlxBmwhEO7pAkqhQc%3D