Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(xmlsec-core) Fix deprecated functions in LibXML2 2.13.1 including disabling HTTP support by default #813

Merged
merged 4 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
(xmlsec-core) Fix deprecated functions in LibXML2 2.13.1 including di…
…sabling HTTP support by default
  • Loading branch information
lsh123 committed Jul 11, 2024
commit 5afe8f62cff3bdb0f6aa84fef5a10925696bdea8
10 changes: 5 additions & 5 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1918,14 +1918,14 @@ dnl ==========================================================================
dnl See do we need HTTP support
dnl ==========================================================================
AC_MSG_CHECKING(for HTTP support)
AC_ARG_ENABLE([http], [AS_HELP_STRING([--enable-http],[enable HTTP support (yes)])])
if test "z$enable_http" = "zno" ; then
AC_ARG_ENABLE([http], [AS_HELP_STRING([--enable-http],[enable HTTP support (no, deprecated)])])
if test "z$enable_http" = "zyes" ; then
XMLSEC_NO_HTTP="0"
AC_MSG_RESULT([yes])
else
XMLSEC_DEFINES="$XMLSEC_DEFINES -DXMLSEC_NO_HTTP=1"
XMLSEC_NO_HTTP="1"
AC_MSG_RESULT([no])
else
XMLSEC_NO_HTTP="0"
AC_MSG_RESULT([yes])
fi
AM_CONDITIONAL(XMLSEC_NO_HTTP, test "z$XMLSEC_NO_HTTP" = "z1")
AC_SUBST(XMLSEC_NO_HTTP)
Expand Down
158 changes: 156 additions & 2 deletions src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include <xmlsec/keys.h>
#include <xmlsec/io.h>
#include <xmlsec/errors.h>
#include <xmlsec/xmltree.h>

#include "cast_helpers.h"

Expand Down Expand Up @@ -256,6 +257,155 @@ xmlSecIORegisterCallbacks(xmlInputMatchCallback matchFunc,
}


/** File IO **/
static int
xmlSecIOFileExtractFilename(char const* filename, char** out) {
const char* escaped;
char* unescaped = NULL;

xmlSecAssert2(filename != NULL, -1);

if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file://localhost/", 17)) {
escaped = &filename[16];
}
else if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file:///", 8)) {
escaped = &filename[7];
}
else if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file://", 7)) {
/* lots of generators seems to lazy to read RFC 1738 */
escaped = &filename[6];
}
else if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file:/", 6)) {
/* lots of generators seems to lazy to read RFC 1738 */
escaped = &filename[5];
}
else {
(*out) = NULL;
return(0); /* hope for the best */
}

#ifdef _WIN32
/* Ignore slash like in file:///C:/file.txt */
escaped += 1;
#endif

unescaped = xmlURIUnescapeString(escaped, 0, NULL);
if (unescaped == NULL) {
xmlSecXmlError("xmlURIUnescapeString", NULL);
return(-1);
}

/* done */
(*out) = unescaped;
return(0);
}


static int
xmlSecIOFileMatch(char const* filename) {
xmlSecAssert2(filename != NULL, -1);
return(1); /* hope for the best */
}

static void*
xmlSecIOFileOpen(char const* filename) {
char* tmp = NULL;
FILE* fd = NULL;
int ret;

xmlSecAssert2(filename != NULL, NULL);

/* extract the filename */
ret = xmlSecIOFileExtractFilename(filename, &tmp);
if (ret < 0) {
xmlSecInternalError("xmlSecIOFileExtractFilename", NULL);
return(NULL);
}
if (tmp != NULL) {
filename = tmp;
}

/* open file */
#if defined(XMLSEC_WINDOWS) && defined(UNICODE)
{
LPTSTR wpath;
errno_t err;

wpath = xmlSecWin32ConvertUtf8ToTstr(BAD_CAST filename);
if (wpath == NULL) {
xmlSecInternalError("xmlSecWin32ConvertUtf8ToTstr", NULL);
xmlFree(tmp);
return(NULL);
}
err = _wfopen_s(&fd, wpath, L"rb");
if ((err != 0) || (fd == NULL)) {
xmlSecInternalError("_wfopen_s", NULL);
xmlFree(wpath);
xmlFree(tmp);
return(NULL);
}
xmlFree(wpath);
}
#elif defined(XMLSEC_WINDOWS)
{
errno_t err;
err = fopen_s(&fd, filename, "rb");
if ((err != 0) || (fd == NULL)) {
xmlSecInternalError("fopen_s", NULL);
xmlFree(tmp);
return(NULL);
}
}
#else /* defined(XMLSEC_WINDOWS) && defined(UNICODE) */
fd = fopen(filename, "rb");
if (fd == NULL) {
xmlSecInternalError("fopen", NULL);
xmlFree(tmp);
return(NULL);
}
#endif /* defined(XMLSEC_WINDOWS) && defined(UNICODE) */

/* done */
xmlFree(tmp);
return(fd);
}

static int
xmlSecIOFileRead(void* context, char* buffer, int len) {
FILE* fd = (FILE*)context;
size_t szLen, szBytes;
int res;

xmlSecAssert2(fd != NULL, -1);
xmlSecAssert2(buffer != NULL, -1);

XMLSEC_SAFE_CAST_INT_TO_SIZE(len, szLen, return(-1), NULL);

szBytes = fread(buffer, 1, szLen, fd);
if ((szBytes < szLen) && (ferror(fd))) {
xmlSecInternalError("fread", NULL);
return(-1);
}

XMLSEC_SAFE_CAST_SIZE_TO_INT(szBytes, res, return(-1), NULL);
return(res);
}

static int
xmlSecIOFilClose(void* context) {
FILE* fd = (FILE*)context;
int ret;

xmlSecAssert2(fd != NULL, -1);

ret = fclose(fd);
if (ret != 0) {
xmlSecInternalError("fclose", NULL);
return(-1);
}
return(0);
}

/**
* xmlSecIORegisterDefaultCallbacks:
*
Expand All @@ -269,8 +419,12 @@ xmlSecIORegisterDefaultCallbacks(void) {

#ifndef XMLSEC_NO_FILES
/* Callbacks added later are picked up first */
ret = xmlSecIORegisterCallbacks(xmlFileMatch, xmlFileOpen,
xmlFileRead, xmlFileClose);
ret = xmlSecIORegisterCallbacks(
xmlSecIOFileMatch,
xmlSecIOFileOpen,
xmlSecIOFileRead,
xmlSecIOFilClose
);
if(ret < 0) {
xmlSecInternalError("xmlSecIORegisterCallbacks(file)", NULL);
return(-1);
Expand Down
10 changes: 0 additions & 10 deletions tests/testDSig.sh
Original file line number Diff line number Diff line change
Expand Up @@ -474,16 +474,6 @@ execDSigTest $res_success \
"rsa x509" \
"--trusted-$cert_format $topfolder/keys/cacert.$cert_format --enabled-key-data x509 --verification-gmt-time 2014-05-24+00:00:00"


execDSigTest $res_success \
"" \
"aleksey-xmldsig-01/dtd-hmac-91" \
"sha1 hmac-sha1" \
"hmac" \
"--hmackey $topfolder/keys/hmackey.bin --dtd-file $topfolder/aleksey-xmldsig-01/dtd-hmac-91.dtd" \
"--hmackey $topfolder/keys/hmackey.bin --dtd-file $topfolder/aleksey-xmldsig-01/dtd-hmac-91.dtd" \
"--hmackey $topfolder/keys/hmackey.bin --dtd-file $topfolder/aleksey-xmldsig-01/dtd-hmac-91.dtd"

execDSigTest $res_success \
"" \
"aleksey-xmldsig-01/x509data-test" \
Expand Down
Loading