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>
102 lines
2.4 KiB
C
102 lines
2.4 KiB
C
/* SPDX-License-Identifier: MIT OR GPL-3.0-only */
|
|
/* test_sasl.c
|
|
** libstrophe XMPP client library -- test routines for the SASL implementation
|
|
**
|
|
** Copyright (C) 2005-2009 Collecta, Inc.
|
|
**
|
|
** 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 <stdio.h>
|
|
#include <string.h>
|
|
|
|
#include "strophe.h"
|
|
#include "common.h"
|
|
#include "sasl.h"
|
|
|
|
static const unsigned char jid[] = "foo@bar.com";
|
|
static const char password[] = "secret";
|
|
static const char response_plain[] = "AGZvb0BiYXIuY29tAHNlY3JldA==";
|
|
|
|
static const char challenge_md5[] =
|
|
"cmVhbG09InNvbWVyZWFsbSIsbm9uY2U9Ik9BNk1HOXRFUUdtMmhoIixxb3A9ImF1dGgi"
|
|
"LGNoYXJzZXQ9dXRmLTgsYWxnb3JpdGhtPW1kNS1zZXNzCg==";
|
|
static const char response_md5[] =
|
|
"dXNlcm5hbWU9InNvbWVub2RlIixyZWFsbT0ic29tZXJlYWxtIixub25jZT0i"
|
|
"T0E2TUc5dEVRR20yaGgiLGNub25jZT0iMDBERUFEQkVFRjAwIixuYz0wMDAw"
|
|
"MDAwMSxxb3A9YXV0aCxkaWdlc3QtdXJpPSJ4bXBwL3NvbWVyZWFsbSIscmVz"
|
|
"cG9uc2U9NGVhNmU4N2JjMDkzMzUwNzQzZGIyOGQ3MDIwOGNhZmIsY2hhcnNl"
|
|
"dD11dGYtOA==";
|
|
|
|
int test_plain(xmpp_ctx_t *ctx)
|
|
{
|
|
char *result;
|
|
|
|
result = sasl_plain(ctx, jid, password);
|
|
if (result == NULL) {
|
|
/* SASL PLAIN internal failure! */
|
|
return 1;
|
|
}
|
|
if (strncmp(response_plain, result, strlen(response_plain))) {
|
|
/* SASL PLAIN returned incorrect string! */
|
|
return 2;
|
|
}
|
|
strophe_free(ctx, result);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int test_digest_md5(xmpp_ctx_t *ctx)
|
|
{
|
|
char *result;
|
|
|
|
result =
|
|
sasl_digest_md5(ctx, challenge_md5, "somenode@somerealm", "secret");
|
|
printf("response:\n%s\n", result);
|
|
if (strcmp(response_md5, result)) {
|
|
/* generated incorrect response to challenge */
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int main()
|
|
{
|
|
xmpp_ctx_t *ctx;
|
|
int ret;
|
|
|
|
printf("allocating context... ");
|
|
ctx = xmpp_ctx_new(NULL, NULL);
|
|
if (ctx == NULL)
|
|
printf("failed to create context\n");
|
|
if (ctx == NULL)
|
|
return -1;
|
|
printf("ok.\n");
|
|
|
|
printf("testing SASL PLAIN... ");
|
|
ret = test_plain(ctx);
|
|
if (ret)
|
|
printf("failed!\n");
|
|
if (ret)
|
|
return ret;
|
|
printf("ok.\n");
|
|
|
|
printf("testing SASL DIGEST-MD5... ");
|
|
ret = test_digest_md5(ctx);
|
|
if (ret)
|
|
printf("failed!\n");
|
|
if (ret)
|
|
return ret;
|
|
printf("ok.\n");
|
|
|
|
printf("freeing context... ");
|
|
xmpp_ctx_free(ctx);
|
|
printf("ok.\n");
|
|
|
|
return ret;
|
|
}
|