oa8verify 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #!/usr/bin/env sh
  2. # vim: filetype=sh:tabstop=4:tw=80
  3. set -e > /dev/null 2>&1
  4. set -u > /dev/null 2>&1
  5. me=oa8verify
  6. vers=1.1.1
  7. osl=openssl
  8. a85=ascii85
  9. # shellcheck disable=SC2097,SC2098
  10. if ! PATH="$(command -p env -i \
  11. getconf PATH)" \
  12. command -p env -i TMPDIR="${TMPDIR:-}" PATH="${PATH:-}" \
  13. rm -f \
  14. "$(command -p env -i TMPDIR="${TMPDIR:-}" mktemp)"; then
  15. printf '%s\n' \
  16. "Error: Misbehaving shell or environment; aborting" >&2
  17. exit 1
  18. fi
  19. cleanup() {
  20. command -p env -i \
  21. rm -f \
  22. "${tmpfile:-}" ||
  23. true
  24. }
  25. filename=${1:-}
  26. signature=${2:-}
  27. publickey=${3:-}
  28. exitstatus=""
  29. if ! command -p env \
  30. "${osl:?}" version > /dev/null 2>&1; then
  31. printf '%s\n' \
  32. "Error: ${osl:?} could not be executed" >&2
  33. exit 1
  34. fi
  35. exitstatus=""
  36. if ! command -p env \
  37. "${a85:?}" -h > /dev/null 2>&1; then
  38. exitstatus="${?:?Error: exitstatus undefined}"
  39. if [ "${exitstatus:-}" -eq 126 ]; then
  40. printf '%s\n' \
  41. "Error: ${a85:?} could not be executed" >&2
  42. exit 1
  43. elif [ "${exitstatus:-}" -eq 127 ]; then
  44. printf '%s\n' \
  45. "Error: ${a85:?} could not be found" >&2
  46. printf '\t%s\n' \
  47. 'Suggestion: "gem install Ascii85"' >&2
  48. exit 1
  49. else
  50. printf '%s\n' \
  51. "Error: ${a85:?} failure ${exitstatus:-}" >&2
  52. exit 1
  53. fi
  54. fi
  55. if [ ${#} -lt 3 ]; then
  56. printf '%s\n' \
  57. "*** ${me:?Error: me undefined} (v${vers:?Error: vers undefined})"
  58. printf '\t%s\n' \
  59. "Usage: ${me:?} <file> <signature.oa8> <public.oa8>"
  60. exit 1
  61. fi
  62. tmpfile=""
  63. tmpfile="$(command -p env -i TMPDIR="${TMPDIR:-}" \
  64. mktemp)" ||
  65. {
  66. printf '%s\n' \
  67. "Error: mktemp failure" >&2
  68. exit 1
  69. }
  70. exitstatus=""
  71. command -p env \
  72. "${a85:?}" -d \
  73. < "${signature:?Error: signature undefined}" \
  74. > "${tmpfile:?Error: tmpfile undefined}" ||
  75. {
  76. exitstatus="${?:?Error: exitstatus undefined}"
  77. if [ "${exitstatus:-}" -eq 126 ]; then
  78. printf '%s\n' \
  79. "Error: ${a85:?} could not be executed" >&2
  80. cleanup
  81. exit 1
  82. elif [ "${exitstatus:-}" -eq 127 ]; then
  83. printf '%s\n' \
  84. "Error: ${a85:?} could not be found" >&2
  85. printf '\t%s\n' \
  86. 'Suggestion: "gem install Ascii85"' >&2
  87. cleanup
  88. exit 1
  89. else
  90. printf '%s\n' \
  91. "Error: signature parsing failure ${exitstatus:-}" \
  92. >&2
  93. cleanup
  94. exit 3
  95. fi
  96. }
  97. exitstatus=""
  98. command -p env \
  99. "${osl:?}" dgst -sha3-512 \
  100. -verify "${publickey:?Error: publickey undefined}" \
  101. -signature "${tmpfile:?Error: tmpfile undefined}" \
  102. "${filename:?Error filename undefined}" ||
  103. {
  104. exitstatus="${?:?Error: exitstatus undefined}"
  105. if [ "${exitstatus:-}" -eq 126 ]; then
  106. printf '%s\n' \
  107. "Error: ${osl:?} could not be executed" >&2
  108. cleanup
  109. exit 1
  110. elif [ "${exitstatus:-}" -eq 127 ]; then
  111. printf '%s\n' \
  112. "Error: ${osl:?} could not be found" >&2
  113. cleanup
  114. exit 1
  115. else
  116. printf '%s\n' \
  117. "Error: ${me:?} failure ${exitstatus:-}" \
  118. >&2
  119. cleanup
  120. exit 2
  121. fi
  122. }
  123. cleanup
  124. # Local Variables:
  125. # mode: sh
  126. # sh-shell: sh
  127. # sh-indentation: 4
  128. # sh-basic-offset: 4
  129. # tab-width: 4
  130. # End: