Replace xmlSecSoap functions with lasso implementations

xmlsec has removed support for SOAP. The missing xmlSecSoap* functions
and their dependent utiliity functions were added to Lasso following
the model of the existing xmlSec implmentations.

Note: Lasso tried to accommodate both SOAP 1.1 and SOAP 1.2 but SAML2
*only* uses SOAP 1.1 thus the SOAP 1.2 support was superfluous and
confused matters. Therefire the SOAP 1.2 support was removed.

The following new functions were added to Lasso to support SOAP:

* lasso_xml_next_element_node
* lasso_xml_get_node_ns_href
* lasso_xml_is_element_node
* lasso_xml_soap11_get_header
* lasso_xml_soap11_get_body

The following is the mapping from the deprecated xmlSecSoap symbols
to the new Lasso symbols:

xmlSecSoap11Ns -> LASSO_SOAP_ENV_HREF
xmlSecGetNextElementNode -> lasso_xml_next_element_node
xmlSecGetNodeNsHref -> lasso_xml_get_node_ns_href
xmlSecCheckNodeName -> lasso_xml_is_element_node
xmlSecSoap11GetHeader -> lasso_xml_soap11_get_header
xmlSecSoap11GetBody -> lasso_xml_soap11_get_body

This patch also extends the automake version support in autogen.sh to the
current 1.16 version.

License: MIT
Signed-off-by: John Dennis <jdennis@redhat.com>
This commit is contained in:
John Dennis 2018-04-03 19:49:31 -04:00 committed by Benjamin Dauvergne
parent 39ca2d4833
commit 760eb947ab
6 changed files with 153 additions and 128 deletions

View File

@ -27,7 +27,10 @@ cd "$srcdir"
DIE=1
}
if automake-1.15 --version < /dev/null > /dev/null 2>&1; then
if automake-1.16 --version < /dev/null > /dev/null 2>&1; then
AUTOMAKE=automake-1.16
ACLOCAL=aclocal-1.16
elif automake-1.15 --version < /dev/null > /dev/null 2>&1; then
AUTOMAKE=automake-1.15
ACLOCAL=aclocal-1.15
elif automake-1.14 --version < /dev/null > /dev/null 2>&1; then

View File

@ -59,7 +59,6 @@
#include "../id-ff/providerprivate.h"
#include "../id-ff/sessionprivate.h"
#include "../xml/misc_text_node.h"
#include <../xml/xmlsec_soap.h>
/**
* SECTION:wsf_profile
@ -1369,7 +1368,7 @@ lasso_wsf_profile_add_saml_signature(LassoWsfProfile *wsf_profile, xmlDoc *doc)
/* Lookup all referenced node and their Ids */
envelope = xmlDocGetRootElement(doc);
header = xmlSecSoap11GetHeader(envelope);
header = lasso_xml_soap11_get_header(envelope);
provider = xmlSecFindNode(header, (xmlChar*) "Provider",
(xmlChar*) LASSO_SOAP_BINDING_HREF);
@ -1377,7 +1376,7 @@ lasso_wsf_profile_add_saml_signature(LassoWsfProfile *wsf_profile, xmlDoc *doc)
(xmlChar*) LASSO_SOAP_BINDING_HREF);
interaction = xmlSecFindNode(header, (xmlChar*) "UserInteraction",
(xmlChar*) LASSO_IS_HREF);
body = xmlSecSoap11GetBody(envelope);
body = lasso_xml_soap11_get_body(envelope);
xmlSecAddIDs(doc, envelope, ids);
goto_cleanup_if_fail_with_rc(header != NULL, LASSO_XML_ERROR_NODE_NOT_FOUND);
goto_cleanup_if_fail_with_rc(provider != NULL, LASSO_XML_ERROR_NODE_NOT_FOUND);

View File

@ -243,7 +243,6 @@ liblassoinclude_HEADERS = \
samlp_status_code.h \
xml_enc.h \
tools.h \
xmlsec_soap.h \
$(WSF_H_FILES)
lasso_private_h_sources = \

View File

@ -265,8 +265,19 @@ xmlDocPtr lasso_xml_parse_memory(const char *buffer, int size);
xmlNode* lasso_xml_get_soap_content(xmlNode *root);
xmlNodePtr lasso_xml_next_element_node(xmlNodePtr node);
const xmlChar* lasso_xml_get_node_ns_href(const xmlNodePtr node);
gboolean lasso_xml_is_element_node(const xmlNodePtr node,
const xmlChar *name, const xmlChar *ns);
gboolean lasso_xml_is_soap(xmlNode *root);
xmlNodePtr lasso_xml_soap11_get_header(xmlNodePtr envelope_node);
xmlNodePtr lasso_xml_soap11_get_body(xmlNodePtr envelope_node);
gboolean lasso_eval_xpath_expression(xmlXPathContextPtr xpath_ctx, const char *expression,
xmlXPathObjectPtr *xpath_object_ptr, int *xpath_error_code);

View File

@ -70,7 +70,6 @@
#include <stdarg.h>
#include <ctype.h>
#include "../lasso_config.h"
#include <lasso/xml/xmlsec_soap.h>
/**
* SECTION:tools
@ -1677,30 +1676,156 @@ cleanup:
return rc;
}
/**
* lasso_xml_next_element_node:
* @node: the pointer to an XML node.
*
* Seraches for the next element node.
*
* Returns: the pointer to next element node or NULL if it is not found.
*/
xmlNodePtr
lasso_xml_next_element_node(xmlNodePtr node)
{
for (; node != NULL && node->type != XML_ELEMENT_NODE; node = node->next);
return node;
}
/**
* lasso_xml_get_node_ns_href:
* @node: the pointer to node.
*
* Get's node's namespace href.
*
* Returns: node's namespace href.
*/
const xmlChar*
lasso_xml_get_node_ns_href(const xmlNodePtr node)
{
xmlNsPtr ns;
if (node == NULL) {
return NULL;
}
/* do we have a namespace in the node? */
if (node->ns != NULL) {
return node->ns->href;
}
/* search for default namespace */
ns = xmlSearchNs(node->doc, node, NULL);
if (ns != NULL) {
return ns->href;
}
return NULL;
}
/**
* lasso_xml_is_element_node:
* @node: the pointer to an XML node.
* @name: the name,
* @ns: the namespace href.
*
* Checks that the node has a given name and a given namespace href.
*
* Returns: true if the node matches false otherwise.
*/
gboolean
lasso_xml_is_element_node(const xmlNodePtr node,
const xmlChar *name, const xmlChar *ns)
{
if (node == NULL) {
return FALSE;
}
return (node->type == XML_ELEMENT_NODE &&
xmlStrEqual(node->name, name) &&
xmlStrEqual(lasso_xml_get_node_ns_href(node), ns));
}
gboolean
lasso_xml_is_soap(xmlNode *root)
{
return xmlSecCheckNodeName(root, xmlSecNodeEnvelope, xmlSecSoap11Ns) ||
xmlSecCheckNodeName(root, xmlSecNodeEnvelope, xmlSecSoap12Ns);
return lasso_xml_is_element_node(root, BAD_CAST "Envelope",
BAD_CAST LASSO_SOAP_ENV_HREF);
}
/**
* lasso_xml_soap11_get_header:
* @envelope_node: the pointer to <soap:Envelope> node.
*
* Gets pointer to the <soap:Header> node.
*
* Returns: pointer to <soap:Header> node or NULL if an error occurs.
*/
xmlNodePtr
lasso_xml_soap11_get_header(xmlNodePtr envelope_node)
{
xmlNodePtr node;
if (envelope_node == NULL) {
return NULL;
}
/* optional Header node is first */
node = lasso_xml_next_element_node(envelope_node->children);
if (lasso_xml_is_element_node(node, BAD_CAST "Header",
BAD_CAST LASSO_SOAP_ENV_HREF)) {
return node;
}
return NULL;
}
/**
* lasso_xml_soap11_get_body:
* @envelope_node: the pointer to <soap:Envelope> node.
*
* Gets pointer to the <soap:Body> node.
*
* Returns: pointer to <soap:Body> node or NULL if an error occurs.
*/
xmlNodePtr
lasso_xml_soap11_get_body(xmlNodePtr envelope_node)
{
xmlNodePtr node;
if (envelope_node == NULL) {
return NULL;
}
/* optional Header node first */
node = lasso_xml_next_element_node(envelope_node->children);
if (lasso_xml_is_element_node(node, BAD_CAST "Header",
BAD_CAST LASSO_SOAP_ENV_HREF)) {
node = lasso_xml_next_element_node(node->next);
}
/* Body node is next */
if (!lasso_xml_is_element_node(node, BAD_CAST "Body",
BAD_CAST LASSO_SOAP_ENV_HREF)) {
return NULL;
}
return node;
}
xmlNode*
lasso_xml_get_soap_content(xmlNode *root)
{
gboolean is_soap11 = FALSE;
gboolean is_soap12 = FALSE;
xmlNode *content = NULL;
is_soap11 = xmlSecCheckNodeName(root, xmlSecNodeEnvelope, xmlSecSoap11Ns);
is_soap12 = xmlSecCheckNodeName(root, xmlSecNodeEnvelope, xmlSecSoap12Ns);
if (is_soap11 || is_soap12) {
is_soap11 = lasso_xml_is_element_node(root, BAD_CAST "Envelope",
BAD_CAST LASSO_SOAP_ENV_HREF);
if (is_soap11) {
xmlNode *body;
if (is_soap11) {
body = xmlSecSoap11GetBody(root);
} else {
body = xmlSecSoap12GetBody(root);
body = lasso_xml_soap11_get_body(root);
}
if (body) {
content = xmlSecGetNextElementNode(body->children);

View File

@ -1,112 +0,0 @@
/* $Id$
*
* Lasso - A free implementation of the Liberty Alliance specifications.
*
* Copyright (C) 2004-2007 Entr'ouvert
* http://lasso.entrouvert.org
*
* Authors: See AUTHORS file in top-level directory.
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __LASSO_XMLSEC_SOAP_H__
#define __LASSO_XMLSEC_SOAP_H__
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include <libxml/tree.h>
#include <xmlsec/xmlsec.h>
#include <xmlsec/xmltree.h>
#include <xmlsec/errors.h>
/** Replacement for xmlsec/soap.h */
#define xmlSecSoap11Ns ((xmlChar*)"http://schemas.xmlsoap.org/soap/envelope/")
#define xmlSecSoap12Ns ((xmlChar*)"http://www.w3.org/2003/05/soap-envelope")
static inline xmlNodePtr
xmlSecSoap11GetHeader(xmlNodePtr envNode) {
xmlNodePtr cur;
xmlSecAssert2(envNode != NULL, NULL);
/* optional Header node is first */
cur = xmlSecGetNextElementNode(envNode->children);
if((cur != NULL) && xmlSecCheckNodeName(cur, xmlSecNodeHeader, xmlSecSoap11Ns)) {
return(cur);
}
return(NULL);
}
static inline xmlNodePtr
xmlSecSoap11GetBody(xmlNodePtr envNode) {
xmlNodePtr cur;
xmlSecAssert2(envNode != NULL, NULL);
/* optional Header node first */
cur = xmlSecGetNextElementNode(envNode->children);
if((cur != NULL) && xmlSecCheckNodeName(cur, xmlSecNodeHeader, xmlSecSoap11Ns)) {
cur = xmlSecGetNextElementNode(cur->next);
}
/* Body node is next */
if((cur == NULL) || !xmlSecCheckNodeName(cur, xmlSecNodeBody, xmlSecSoap11Ns)) {
xmlSecError(XMLSEC_ERRORS_HERE,
NULL,
xmlSecErrorsSafeString(xmlSecNodeBody),
XMLSEC_ERRORS_R_NODE_NOT_FOUND,
XMLSEC_ERRORS_NO_MESSAGE);
return(NULL);
}
return(cur);
}
static inline xmlNodePtr
xmlSecSoap12GetBody(xmlNodePtr envNode) {
xmlNodePtr cur;
xmlSecAssert2(envNode != NULL, NULL);
/* optional Header node first */
cur = xmlSecGetNextElementNode(envNode->children);
if((cur != NULL) && xmlSecCheckNodeName(cur, xmlSecNodeHeader, xmlSecSoap12Ns)) {
cur = xmlSecGetNextElementNode(cur->next);
}
/* Body node is next */
if((cur == NULL) || !xmlSecCheckNodeName(cur, xmlSecNodeBody, xmlSecSoap12Ns)) {
xmlSecError(XMLSEC_ERRORS_HERE,
NULL,
xmlSecErrorsSafeString(xmlSecNodeBody),
XMLSEC_ERRORS_R_NODE_NOT_FOUND,
XMLSEC_ERRORS_NO_MESSAGE);
return(NULL);
}
return(cur);
}
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __LASSO_XMLSEC_SOAP_H__ */