clevis-luks-askpass 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/bash -e
  2. # vim: set tabstop=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80:
  3. #
  4. # Copyright (c) 2016 Red Hat, Inc.
  5. # Author: Harald Hoyer <harald@redhat.com>
  6. # Author: Nathaniel McCallum <npmccallum@redhat.com>
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. UUID=cb6e8904-81ff-40da-a84a-07ab9ab5715e
  22. shopt -s nullglob
  23. for question in /run/systemd/ask-password/ask.*; do
  24. d=
  25. s=
  26. while read line; do
  27. case "$line" in
  28. Id=cryptsetup:*) d="${line##Id=cryptsetup:}";;
  29. Socket=*) s="${line##Socket=}";;
  30. esac
  31. done < "$question"
  32. [ -z "$d" -o -z "$s" ] && continue
  33. luksmeta show -d "$d" | while read -r slot state uuid; do
  34. [ "$state" != "active" ] && continue
  35. [ "$uuid" != "$UUID" ] && continue
  36. if pt="`luksmeta load -d $d -s $slot -u $UUID | clevis decrypt`"; then
  37. echo -n "+$pt" | nc -U -u --send-only "$s"
  38. break
  39. fi
  40. done
  41. done