It has been pointed out that the wording of the license of this library is not entirely clear. The term "dual licensing" usually refers to a licence choice of two licenses "LICENSE1 _or_ LICENSE2. Instead the license of this library claimed "LICENSE1 _and_ LICENSE2". After an internal discussion with @metajack and @pasis it was made clear that the initial idea was to dual license the library in the usual way. This was also made clear by jack on the ML in the past [0]. As of jack, these licensing terms originated from jquery, which also used the 'and' version in the past and has since been corrected [1]. This patch changes the license terms to 'MIT or GPLv3' and also adds SPDX headers [2]. [0] https://groups.google.com/g/libstrophe/c/JkFgr601JQc [1] https://stackoverflow.com/q/2758409 [2] https://spdx.org Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
122 lines
3.1 KiB
C
122 lines
3.1 KiB
C
/* SPDX-License-Identifier: MIT OR GPL-3.0-only */
|
|
/* test_xmppaddr.c
|
|
** libstrophe XMPP client library -- test routines for the xmppaddr
|
|
** certificate API's
|
|
**
|
|
** Copyright (C) 2021 Steffen Jaeckel
|
|
**
|
|
** This software is provided AS-IS with no warranty, either express
|
|
** or implied.
|
|
**
|
|
** This program is dual licensed under the MIT or GPLv3 licenses.
|
|
*/
|
|
|
|
#include <assert.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <sys/param.h>
|
|
|
|
#include "strophe.h"
|
|
|
|
#include "test.h"
|
|
|
|
static int
|
|
password_callback(char *pw, size_t pw_max, xmpp_conn_t *conn, void *userdata)
|
|
{
|
|
(void)pw_max;
|
|
(void)userdata;
|
|
(void)conn;
|
|
memcpy(pw, "abc123", 7);
|
|
return 6;
|
|
}
|
|
|
|
int main()
|
|
{
|
|
xmpp_ctx_t *ctx;
|
|
xmpp_conn_t *conn;
|
|
xmpp_log_t *log;
|
|
struct {
|
|
int needs_callback;
|
|
char *pem, *key;
|
|
} client_cert[] = {
|
|
{0, "tests/cert.pem", "tests/key.pem"},
|
|
{1, "tests/cert.pem", "tests/key_encrypted.pem"},
|
|
{0, NULL, "tests/cert.emptypass.pfx"},
|
|
{0, NULL, "tests/cert.nopass.pfx"},
|
|
{1, NULL, "tests/cert.pfx"},
|
|
{0, "tests/cert.emptypass.pfx", NULL},
|
|
{0, "tests/cert.nopass.pfx", NULL},
|
|
{1, "tests/cert.pfx", NULL},
|
|
};
|
|
|
|
const char *srcdir;
|
|
char *certbuf, *keybuf;
|
|
char xmppaddr_num[] = "0";
|
|
unsigned int m, n;
|
|
|
|
xmpp_initialize();
|
|
log = xmpp_get_default_logger(XMPP_LEVEL_DEBUG);
|
|
ctx = xmpp_ctx_new(NULL, log);
|
|
|
|
srcdir = getenv("srcdir");
|
|
|
|
certbuf = malloc(MAXPATHLEN);
|
|
keybuf = malloc(MAXPATHLEN);
|
|
|
|
for (m = 0; m < sizeof(client_cert) / sizeof(client_cert[0]); ++m) {
|
|
char *certfile = certbuf, *keyfile = keybuf;
|
|
conn = xmpp_conn_new(ctx);
|
|
|
|
if (client_cert[m].pem)
|
|
snprintf(certfile, MAXPATHLEN, "%s/%s", srcdir, client_cert[m].pem);
|
|
else
|
|
certfile = NULL;
|
|
|
|
if (client_cert[m].key)
|
|
snprintf(keyfile, MAXPATHLEN, "%s/%s", srcdir, client_cert[m].key);
|
|
else
|
|
keyfile = NULL;
|
|
|
|
if (client_cert[m].needs_callback)
|
|
xmpp_conn_set_password_callback(conn, password_callback, NULL);
|
|
|
|
xmpp_conn_set_client_cert(conn, certfile, keyfile);
|
|
|
|
xmppaddr_num[0] = '0' + xmpp_conn_cert_xmppaddr_num(conn);
|
|
|
|
COMPARE("2", xmppaddr_num);
|
|
|
|
for (n = 0; n < 3; ++n) {
|
|
char *r = xmpp_conn_cert_xmppaddr(conn, n);
|
|
switch (n) {
|
|
case 0:
|
|
COMPARE(
|
|
"very.long.username@so.the.asn1.length.is.a.valid.ascii."
|
|
"character",
|
|
r);
|
|
break;
|
|
case 1:
|
|
COMPARE("second@xmpp.jid", r);
|
|
break;
|
|
default:
|
|
if (r != NULL) {
|
|
printf("\nThere shall only be two id-on-xmppAddr SANs!\n"
|
|
"Found another one: %s\n",
|
|
r);
|
|
exit(1);
|
|
}
|
|
break;
|
|
}
|
|
free(r);
|
|
}
|
|
xmpp_conn_release(conn);
|
|
}
|
|
free(certbuf);
|
|
free(keybuf);
|
|
|
|
xmpp_ctx_free(ctx);
|
|
xmpp_shutdown();
|
|
|
|
return 0;
|
|
}
|