gpgv.h 3.5 KB

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