summaryrefslogtreecommitdiff
path: root/src/rexmpp_openpgp.h
blob: 74703473c06c831768b4e532a70a2854c71c3f4f (plain)
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
99
100
101
102
/**
   @file rexmpp_openpgp.h
   @brief XEP-0373 routines
   @author defanor <defanor@uberspace.net>
   @date 2020--2021
   @copyright MIT license.
*/
#ifndef REXMPP_OPENPGP_H
#define REXMPP_OPENPGP_H

#include "rexmpp.h"

/**
   @brief A mode corresponding to XEP-0373's OpenPGP content element.
 */
enum rexmpp_ox_mode {
  REXMPP_OX_SIGN,
  REXMPP_OX_CRYPT,
  REXMPP_OX_SIGNCRYPT
};

/**
   @brief Checks whether we have all the keys from the list of known
   keys for a given JID, requests missing ones.
   @param[in] s ::rexmpp
   @param[in] jid A JID.
   @param[in] items An <items> element with <public-keys-list> in it.
*/
rexmpp_err_t
rexmpp_openpgp_check_keys (rexmpp_t *s,
                           const char *jid,
                           xmlNodePtr items);

/**
   @brief Publishes a key via PEP/pubsub.
   @param[in] s ::rexmpp
   @param[in] fp The fingerprint of a key that should be published.
   @returns ::REXMPP_SUCCESS or an error code.
*/
rexmpp_err_t rexmpp_openpgp_publish_key (rexmpp_t *s, const char *fp);

/**
   @brief Retracts a key from PEP/pubsub.
   @param[in] s ::rexmpp
   @param[in] fp The fingerprint of a key that should be deleted.
*/
void rexmpp_openpgp_retract_key (rexmpp_t *s, const char *fp);

/**
   @brief Tries to decrypt and/or verify an OpenPGP message.
   @param[in] s ::rexmpp
   @param[in] cipher_base64 An OpenPGP ciphertext.
   @returns A plaintext message body.
*/
xmlNodePtr
rexmpp_openpgp_decrypt_verify (rexmpp_t *s,
                               const char *cipher_base64);

/**
   @brief Tries to decrypt and/or verify an OpenPGP message from a
   <message> element, taking into account its attributes.
   @param[in] s ::rexmpp
   @param[in] message A <message> element.
   @param[out] valid Will be set to 1 if the message appears to be
   valid.
   @returns A decrypted message body.
*/
xmlNodePtr
rexmpp_openpgp_decrypt_verify_message (rexmpp_t *s,
                                       xmlNodePtr message,
                                       int *valid);

/**
   @brief Encodes a message, producing a signed and/or encrypted
   payload.
   @param[in] s ::rexmpp
   @param[in] payload XML payload.
   @param[in] recipients A NULL-terminated list of recipient JIDs.
   @param[in] signers A NULL-terminated list of fingerprints of the
   keys to sign with. Can be NULL to sign with all the available
   published keys.
   @param[in] mode ::rexmpp_ox_mode
   @returns An encoded <openpgp> payload.
*/
char *rexmpp_openpgp_payload (rexmpp_t *s,
                              xmlNodePtr payload,
                              const char **recipients,
                              const char **signers,
                              enum rexmpp_ox_mode mode);


/**
   @brief An utility function for setting GPG home directory. An
   appropriate time to call it is right after rexmpp_init.
   @param[in] s ::rexmpp
   @param[in] home_dir Path to the home directory.
   @returns ::REXMPP_E_PGP or ::REXMPP_SUCCESS
*/
rexmpp_err_t rexmpp_openpgp_set_home_dir (rexmpp_t *s, const char *home_dir);


#endif