about summary refs log tree commit diff stats
path: root/src/xmpp/ox.c
blob: 195cdedd6f4d37bb744613f348833f839f30e26d (plain) (blame)
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#ifndef ELF_H
#define ELF_H

#include "common.h"

/*
 * ELF HEADER
 */
typedef struct {
    unsigned char e_ident[16];	/* ELF identification */
    uint16 e_type;		/* 2 (exec file) */
    uint16 e_machine;		/* 3 (intel architecture) */
    uint32 e_version;		/* 1 */
    uint32 e_entry;		/* starting point */
    uint32 e_phoff;		/* program header table offset */
    uint32 e_shoff;		/* section header table offset */
    uint32 e_flags;		/* various flags */
    uint16 e_ehsize;		/* ELF header (this) size */

    uint16 e_phentsize;	/* program header table entry size */
    uint16 e_phnum;		/* number of entries */

    uint16 e_shentsize;	/* section header table entry size */
    uint16 e_shnum;		/* number of entries */

    uint16 e_shstrndx;		/* index of the section name string table */
} Elf32_Ehdr;

/*
 * ELF identification
 */
#define	EI_MAG0		0
#define	EI_MAG1		1
#define	EI_MAG2		2
#define	EI_MAG3		3
#
/*
 * ox.c
 * vim: expandtab:ts=4:sts=4:sw=4
 *
 * Copyright (C) 2020 Stefan Kropp <stefan@debxwoody.de>
 *
 * This file is part of Profanity.
 *
 * Profanity is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Profanity is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Profanity.  If not, see <https://www.gnu.org/licenses/>.
 *
 * In addition, as a special exception, the copyright holders give permission to
 * link the code of portions of this program with the OpenSSL library under
 * certain conditions as described in each individual source file, and
 * distribute linked combinations including the two.
 *
 * You must obey the GNU General Public License in all respects for all of the
 * code used other than OpenSSL. If you modify file(s) with this exception, you
 * may extend this exception to your version of the file(s), but you are not
 * obligated to do so. If you do not wish to do so, delete this exception
 * statement from your version. If you delete this exception statement from all
 * source files in the program, then also delete it here.
 *
 */

#include "config.h"

#include <glib.h>
#include <assert.h>

#include "log.h"
#include "ui/ui.h"
#include "xmpp/connection.h"
#include "xmpp/stanza.h"
#include "pgp/gpg.h"

#ifdef HAVE_LIBGPGME

#define KEYID_LENGTH 40

static void _ox_metadata_node__public_key(const char* const fingerprint);
static int _ox_metadata_result(xmpp_conn_t* const conn, xmpp_stanza_t* const stanza, void* const userdata);

static void _ox_request_public_key(const char* const jid, const char* const fingerprint);
static int _ox_public_key_result(xmpp_conn_t* const conn, xmpp_stanza_t* const stanza, void* const userdata);

/*!
 * \brief Current Date and Time.
 *
 * XEP-0082: XMPP Date and Time Profiles
 * https://xmpp.org/extensions/xep-0082.html
 *
 * \return YYYY-MM-DDThh:mm:ssZ
 *
 */

static char* _gettimestamp();

/*!
 *
<pre>
<iq type='set' from='juliet@example.org/balcony' id='publish1'>
  <pubsub xmlns='http://jabber.org/protocol/pubsub'>
    <publish node='urn:xmpp:openpgp:0:public-keys:123456789ABCDEF1234567891238484848484848'>
      <item id='2020-01-21T10:46:21Z'>
        <pubkey xmlns='urn:xmpp:openpgp:0'>
           <data>
             BASE64_OPENPGP_PUBLIC_KEY
           </data>
        </pubkey>
      </item>
    </publish>
  </pubsub>
</iq>
</pre>
 *
 */

gboolean
ox_announce_public_key(const char* const filename)
{
    assert(filename);

    cons_show("Annonuce OpenPGP Key for OX %s ...", filename);
    log_info("[OX] Annonuce OpenPGP Key of OX: %s", filename);

    // key the key and the fingerprint via GnuPG from file
    char* key = NULL;
    char* fp = NULL;
    p_ox_gpg_readkey(filename, &key, &fp);

    if (!(key && fp)) {
        cons_show("Error during OpenPGP OX announce. See log file for more information");
        return FALSE;
    } else {
        log_info("[OX] Annonuce OpenPGP Key for Fingerprint: %s", fp);
        xmpp_ctx_t* const ctx = connection_get_ctx();
        char* id = xmpp_uuid_gen(ctx);
        xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
        xmpp_stanza_set_from(iq, xmpp_conn_get_jid(connection_get_conn()));

        xmpp_stanza_t* pubsub = xmpp_stanza_new(ctx);
        xmpp_stanza_set_name(pubsub, STANZA_NAME_PUBSUB);
        xmpp_stanza_set_ns(pubsub, XMPP_FEATURE_PUBSUB);

        GString* node_name = g_string_new(STANZA_NS_OPENPGP_0_PUBLIC_KEYS);
        g_string_append(node_name, ":");
        g_string_append(node_name, fp);

        xmpp_stanza_t* publish = xmpp_stanza_new(ctx);
        xmpp_stanza_set_name(publish, STANZA_NAME_PUBLISH);
        xmpp_stanza_set_attribute(publish, STANZA_ATTR_NODE, node_name->str);

        xmpp_stanza_t* item = xmpp_stanza_new(ctx);
        xmpp_stanza_set_name(item, STANZA_NAME_ITEM);
        char *timestamp = _gettimestamp();
        xmpp_stanza_set_attribute(item, STANZA_ATTR_ID, timestamp);
        free(timestamp);

        xmpp_stanza_t* pubkey = xmpp_stanza_new(ctx);
        xmpp_stanza_set_name(pubkey, STANZA_NAME_PUPKEY);
        xmpp_stanza_set_ns(pubkey, STANZA_NS_OPENPGP_0);

        xmpp_stanza_t* data = xmpp_stanza_new(ctx);
        xmpp_stanza_set_name(data, STANZA_NAME_DATA);
        xmpp_stanza_t* keydata = xmpp_stanza_new(ctx);
        xmpp_stanza_set_text(keydata, key);

        xmpp_stanza_add_child(data, keydata);
        xmpp_stanza_add_child(pubkey, data);
        xmpp_stanza_add_child(item, pubkey);
        xmpp_stanza_add_child(publish, item);
        xmpp_stanza_add_child(pubsub, publish);
        xmpp_stanza_add_child(iq, pubsub);
        xmpp_send(connection_get_conn(), iq);

        _ox_metadata_node__public_key(fp);
    }
    return TRUE;
}

/*!
 * <pre>

<iq from='romeo@example.org/orchard'
    to='juliet@example.org'
    type='get'
    id='getmeta'>
  <pubsub xmlns='http://jabber.org/protocol/pubsub'>
    <items node='urn:xmpp:openpgp:0:public-keys'/>
  </pubsub>
</iq>

 * </pre>
 *
*/

void
ox_discover_public_key(const char* const jid)
{
    assert(jid && strlen(jid) > 0);
    log_info("[OX] Discovering Public Key for %s", jid);
    cons_show("Discovering Public Key for %s", jid);
    // iq
    xmpp_ctx_t* const ctx = connection_get_ctx();
    char* id = xmpp_uuid_gen(ctx);
    xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_GET, id);
    xmpp_stanza_set_from(iq, xmpp_conn_get_jid(connection_get_conn()));
    xmpp_stanza_set_to(iq, jid);
    // pubsub
    xmpp_stanza_t* pubsub = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(pubsub, STANZA_NAME_PUBSUB);
    xmpp_stanza_set_ns(pubsub, XMPP_FEATURE_PUBSUB);
    // items
    xmpp_stanza_t* items = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(items, STANZA_NAME_ITEMS);
    xmpp_stanza_set_attribute(items, STANZA_ATTR_NODE, STANZA_NS_OPENPGP_0_PUBLIC_KEYS);

    xmpp_stanza_add_child(pubsub, items);
    xmpp_stanza_add_child(iq, pubsub);

    xmpp_id_handler_add(connection_get_conn(), _ox_metadata_result, id, strdup(jid));
    xmpp_send(connection_get_conn(), iq);
    xmpp_stanza_release(iq);
}

void
ox_request_public_key(const char* const jid, const char* const fingerprint)
{
    _ox_request_public_key(jid, fingerprint);
}

/*!
 *
 *
 *
<pre>
<iq type='set' from='juliet@example.org/balcony' id='publish1'>
  <pubsub xmlns='http://jabber.org/protocol/pubsub'>
    <publish node='urn:xmpp:openpgp:0:public-keys'>
      <item>
        <public-keys-list xmlns='urn:xmpp:openpgp:0'>
          <pubkey-metadata
            v4-fingerprint='1234512345678122ABCDE2222222222222222222'
            date='2018-03-01T15:26:12Z'
            />
          <pubkey-metadata
            v4-fingerprint='1234ABCD1234409865ABCD234482728939483472'
            date='1953-05-16T12:00:00Z'
            />
        </public-keys-list>
      </item>
    </publish>
  </pubsub>
</iq>    
</pre>
 *
 */

void
_ox_metadata_node__public_key(const char* const fingerprint)
{
    log_info("Annonuce OpenPGP metadata: %s", fingerprint);
    assert(fingerprint);
    assert(strlen(fingerprint) == KEYID_LENGTH);
    // iq
    xmpp_ctx_t* const ctx = connection_get_ctx();
    char* id = xmpp_uuid_gen(ctx);
    xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
    xmpp_stanza_set_from(iq, xmpp_conn_get_jid(connection_get_conn()));
    // pubsub
    xmpp_stanza_t* pubsub = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(pubsub, STANZA_NAME_PUBSUB);
    xmpp_stanza_set_ns(pubsub, XMPP_FEATURE_PUBSUB);
    // publish
    xmpp_stanza_t* publish = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(publish, STANZA_NAME_PUBLISH);
    xmpp_stanza_set_attribute(publish, STANZA_ATTR_NODE, STANZA_NS_OPENPGP_0_PUBLIC_KEYS);
    // item
    xmpp_stanza_t* item = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(item, STANZA_NAME_ITEM);
    // public-keys-list
    xmpp_stanza_t* publickeyslist = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(publickeyslist, STANZA_NAME_PUBLIC_KEYS_LIST);
    xmpp_stanza_set_ns(publickeyslist, STANZA_NS_OPENPGP_0);
    // pubkey-metadata
    xmpp_stanza_t* pubkeymetadata = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(pubkeymetadata, STANZA_NAME_PUBKEY_METADATA);
    xmpp_stanza_set_attribute(pubkeymetadata, STANZA_ATTR_V4_FINGERPRINT, fingerprint);
    xmpp_stanza_set_attribute(pubkeymetadata, STANZA_ATTR_DATE, _gettimestamp());

    xmpp_stanza_add_child(publickeyslist, pubkeymetadata);
    xmpp_stanza_add_child(item, publickeyslist);
    xmpp_stanza_add_child(publish, item);
    xmpp_stanza_add_child(pubsub, publish);
    xmpp_stanza_add_child(iq, pubsub);
    xmpp_send(connection_get_conn(), iq);
}

static int
_ox_metadata_result(xmpp_conn_t* const conn, xmpp_stanza_t* const stanza, void* const userdata)
{
    log_debug("[OX] Processing result %s's metadata.", (char*)userdata);

    if (g_strcmp0(xmpp_stanza_get_type(stanza), "result") != 0) {
        log_debug("[OX] Error: Unable to load metadata of user %s - Not a stanza result type", (char*)userdata);
        return FALSE;
    }
    // pubsub
    xmpp_stanza_t* pubsub = xmpp_stanza_get_child_by_name_and_ns(stanza, STANZA_NAME_PUBSUB, XMPP_FEATURE_PUBSUB);
    if (!pubsub) {
        cons_show("[OX] Error: No pubsub");
        return FALSE;
    }

    xmpp_stanza_t* items = xmpp_stanza_get_child_by_name(pubsub, STANZA_NAME_ITEMS);
    if (!items) {
        cons_show("[OX] Error: No items");
        return FALSE;
    }

    xmpp_stanza_t* item = xmpp_stanza_get_child_by_name(items, STANZA_NAME_ITEM);
    if (!item) {
        cons_show("[OX] Error: No item");
        return FALSE;
    }

    xmpp_stanza_t* publickeyslist = xmpp_stanza_get_child_by_name_and_ns(item, STANZA_NAME_PUBLIC_KEYS_LIST, STANZA_NS_OPENPGP_0);
    if (!publickeyslist) {
        cons_show("[OX] Error: No publickeyslist");
        return FALSE;
    }

    xmpp_stanza_t* pubkeymetadata = xmpp_stanza_get_children(publickeyslist);

    while (pubkeymetadata) {
        const char* fingerprint = xmpp_stanza_get_attribute(pubkeymetadata, STANZA_ATTR_V4_FINGERPRINT);
        if ( strlen( fingerprint ) == KEYID_LENGTH ) {
            cons_show(fingerprint);
        } else {
            cons_show("OX: Wrong char size of public key");
            log_error("[OX] Wrong chat size of public key %s", fingerprint);
        }
        pubkeymetadata = xmpp_stanza_get_next(pubkeymetadata);
    }

    return FALSE;
}

/*!
 *
 * <pre>

<iq from='romeo@example.org/orchard'
    to='juliet@example.org'
    type='get'
    id='getpub'>
  <pubsub xmlns='http://jabber.org/protocol/pubsub'>
    <items node='urn:xmpp:openpgp:0:public-keys:1234567890ABCDF12349ABCD1293848292983833'
           max_items='1'/>
  </pubsub>
</iq>

 * </pre>
 */

void
_ox_request_public_key(const char* const jid, const char* const fingerprint)
{
    assert(jid);
    assert(fingerprint);
    assert(strlen(fingerprint) == KEYID_LENGTH);
    cons_show("Requesting Public Key %s for %s", fingerprint, jid);
    log_info("[OX] Request %s's public key %s.", jid, fingerprint);
    // iq
    xmpp_ctx_t* const ctx = connection_get_ctx();
    char* id = xmpp_uuid_gen(ctx);
    xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_GET, id);
    xmpp_stanza_set_from(iq, xmpp_conn_get_jid(connection_get_conn()));
    xmpp_stanza_set_to(iq, jid);
    // pubsub
    xmpp_stanza_t* pubsub = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(pubsub, STANZA_NAME_PUBSUB);
    xmpp_stanza_set_ns(pubsub, XMPP_FEATURE_PUBSUB);
    // items
    GString* node_name = g_string_new(STANZA_NS_OPENPGP_0_PUBLIC_KEYS);
    g_string_append(node_name, ":");
    g_string_append(node_name, fingerprint);

    xmpp_stanza_t* items = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(items, STANZA_NAME_ITEMS);
    xmpp_stanza_set_attribute(items, STANZA_ATTR_NODE, node_name->str);
    xmpp_stanza_set_attribute(items, "max_items", "1");

    xmpp_stanza_add_child(pubsub, items);
    xmpp_stanza_add_child(iq, pubsub);

    xmpp_id_handler_add(connection_get_conn(), _ox_public_key_result, id, NULL);

    xmpp_send(connection_get_conn(), iq);
}

/*!
 *
 * <pre>

<iq from='juliet@example.org'
    to='romeo@example.org/orchard'
    type='result'
    id='getpub'>
  <pubsub xmlns='http://jabber.org/protocol/pubsub'>
    <items node='urn:xmpp:openpgp:0:public-keys:123454678819283823ABCDEF1234566789001234'>
      <item id='2020-01-21T10:46:21Z'>
        <pubkey xmlns='urn:xmpp:openpgp:0'>
          <data>
            BASE64_OPENPGP_PUBLIC_KEY
          </data>
        </pubkey>
      </item>
    </items>
  </pubsub>
</iq>

 * </pre>
 */

int
_ox_public_key_result(xmpp_conn_t* const conn, xmpp_stanza_t* const stanza, void* const userdata)
{
    log_debug("[OX] Processing result public key");

    if (g_strcmp0(xmpp_stanza_get_type(stanza), "result") != 0) {
        cons_show("Public Key import failed. Check log for details.");
        log_error("[OX] Public Key response type is wrong");
        return FALSE;
    }
    // pubsub
    xmpp_stanza_t* pubsub = xmpp_stanza_get_child_by_name_and_ns(stanza, STANZA_NAME_PUBSUB, XMPP_FEATURE_PUBSUB);
    if (!pubsub) {
        cons_show("Public Key import failed. Check log for details.");
        log_error("[OX] Public key request response failed: No <pubsub/>");
        return FALSE;
    }

    xmpp_stanza_t* items = xmpp_stanza_get_child_by_name(pubsub, STANZA_NAME_ITEMS);
    if (!items) {
        cons_show("Public Key import failed. Check log for details.");
        log_error("[OX] Public key request response failed: No <items/>");
        return FALSE;
    }

    xmpp_stanza_t* item = xmpp_stanza_get_child_by_name(items, STANZA_NAME_ITEM);
    if (!item) {
        cons_show("Public Key import failed. Check log for details.");
        log_error("[OX] Public key request response failed: No <item/>");
        return FALSE;
    }

    xmpp_stanza_t* pubkey = xmpp_stanza_get_child_by_name_and_ns(item, STANZA_NAME_PUPKEY, STANZA_NS_OPENPGP_0);
    if (!pubkey) {
        cons_show("Public Key import failed. Check log for details.");
        log_error("[OX] Public key request response failed: No <pubkey/>");
        return FALSE;
    }

    xmpp_stanza_t* data = xmpp_stanza_get_child_by_name(pubkey, STANZA_NAME_DATA);
    if (!data) {
        log_error("[OX] No data");
    }

    char* base64_data = xmpp_stanza_get_text(data);
    if (base64_data) {
        log_debug("Key data: %s", base64_data);

        if (p_ox_gpg_import(base64_data)) {
            cons_show("Public Key imported");
        } else {
            cons_show("Public Key import failed. Check log for details.");
        }

        free(base64_data);
    }

    return FALSE;
}

// Date and Time (XEP-0082)
char*
_gettimestamp()
{
    time_t now = time(NULL);
    struct tm* tm = localtime(&now);
    char buf[255];
    strftime(buf, sizeof(buf), "%FT%T", tm);
    GString* d = g_string_new(buf);
    g_string_append(d, "Z");
    return strdup(d->str);
}

#endif // HAVE_LIBGPGME