gpgv.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. /* ######################################################################
  4. Helpers to deal with gpgv better and more easily
  5. ##################################################################### */
  6. /*}}}*/
  7. #ifndef CONTRIB_GPGV_H
  8. #define CONTRIB_GPGV_H
  9. #include <apt-pkg/macros.h>
  10. #include <string>
  11. #include <vector>
  12. #ifndef APT_10_CLEANER_HEADERS
  13. #include <apt-pkg/fileutl.h>
  14. #endif
  15. class FileFd;
  16. /** \brief generates and run the command to verify a file with gpgv
  17. *
  18. * If File and FileSig specify the same file it is assumed that we
  19. * deal with a clear-signed message. Note that the method will accept
  20. * and validate files which include additional (unsigned) messages
  21. * without complaining. Do NOT open files accepted by this method
  22. * for reading. Use #OpenMaybeClearSignedFile to access the message
  23. * instead to ensure you are only reading signed data.
  24. *
  25. * The method does not return, but has some notable exit-codes:
  26. * 111 signals an internal error like the inability to execute gpgv,
  27. * 112 indicates a clear-signed file which doesn't include a message,
  28. * which can happen if APT is run while on a network requiring
  29. * authentication before usage (e.g. in hotels)
  30. * All other exit-codes are passed-through from gpgv.
  31. *
  32. * @param File is the message (unsigned or clear-signed)
  33. * @param FileSig is the signature (detached or clear-signed)
  34. * @param statusfd is the fd given to gpgv as --status-fd
  35. * @param fd is used as a pipe for the standard output of gpgv
  36. * @param key is the specific one to be used instead of using all
  37. */
  38. void ExecGPGV(std::string const &File, std::string const &FileSig,
  39. int const &statusfd, int fd[2], std::string const &Key = "") APT_NORETURN;
  40. inline APT_NORETURN void ExecGPGV(std::string const &File, std::string const &FileSig,
  41. int const &statusfd = -1) {
  42. int fd[2];
  43. ExecGPGV(File, FileSig, statusfd, fd);
  44. }
  45. /** \brief Split an inline signature into message and signature
  46. *
  47. * Takes a clear-signed message and puts the first signed message
  48. * in the content file and all signatures following it into the
  49. * second. Unsigned messages, additional messages as well as
  50. * whitespaces are discarded. The resulting files are suitable to
  51. * be checked with gpgv.
  52. *
  53. * If a FileFd pointers is NULL it will not be used and the content
  54. * which would have been written to it is silently discarded.
  55. *
  56. * The content of the split files is undefined if the splitting was
  57. * unsuccessful.
  58. *
  59. * Note that trying to split an unsigned file will fail, but
  60. * not generate an error message.
  61. *
  62. * @param InFile is the clear-signed file
  63. * @param ContentFile is the FileFd the message will be written to
  64. * @param ContentHeader is a list of all required Amored Headers for the message
  65. * @param SignatureFile is the FileFd all signatures will be written to
  66. * @return true if the splitting was successful, false otherwise
  67. */
  68. bool SplitClearSignedFile(std::string const &InFile, FileFd * const ContentFile,
  69. std::vector<std::string> * const ContentHeader, FileFd * const SignatureFile);
  70. /** \brief open a file which might be clear-signed
  71. *
  72. * This method tries to extract the (signed) message of a file.
  73. * If the file isn't signed it will just open the given filename.
  74. * Otherwise the message is extracted to a temporary file which
  75. * will be opened instead.
  76. *
  77. * @param ClearSignedFileName is the name of the file to open
  78. * @param[out] MessageFile is the FileFd in which the file will be opened
  79. * @return true if opening was successful, otherwise false
  80. */
  81. bool OpenMaybeClearSignedFile(std::string const &ClearSignedFileName, FileFd &MessageFile);
  82. #endif