diff options
Diffstat (limited to 'lasso')
-rw-r--r-- | lasso/id-ff/lecp.c | 24 | ||||
-rw-r--r-- | lasso/id-ff/session.c | 23 | ||||
-rw-r--r-- | lasso/key.c | 6 | ||||
-rw-r--r-- | lasso/saml-2.0/ecp.c | 25 | ||||
-rw-r--r-- | lasso/xml/tools.c | 39 |
5 files changed, 34 insertions, 83 deletions
diff --git a/lasso/id-ff/lecp.c b/lasso/id-ff/lecp.c index f175691d..cdff0314 100644 --- a/lasso/id-ff/lecp.c +++ b/lasso/id-ff/lecp.c @@ -58,8 +58,6 @@ lasso_lecp_build_authn_request_envelope_msg(LassoLecp *lecp) LassoProfile *profile; gchar *assertionConsumerServiceURL; xmlNode *msg; - xmlOutputBuffer *buf; - xmlCharEncodingHandler *handler; g_return_val_if_fail(LASSO_IS_LECP(lecp), LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ); @@ -89,16 +87,7 @@ lasso_lecp_build_authn_request_envelope_msg(LassoLecp *lecp) LASSO_PROFILE(lecp)->server->certificate; msg = lasso_node_get_xmlNode(LASSO_NODE(lecp->authnRequestEnvelope), FALSE); - /* msg is not SOAP but straight XML */ - handler = xmlFindCharEncodingHandler("utf-8"); - buf = xmlAllocOutputBuffer(handler); - xmlNodeDumpOutput(buf, NULL, msg, 0, 0, "utf-8"); - xmlOutputBufferFlush(buf); - - lasso_assign_string(profile->msg_body, - (char*)(buf->conv ? buf->conv->content : buf->buffer->content)); - xmlOutputBufferClose(buf); - xmlFreeNode(msg); + lasso_assign_new_string(profile->msg_body, lasso_xmlnode_to_string(msg, 0, 0)) if (profile->msg_body == NULL) { return LASSO_PROFILE_ERROR_BUILDING_REQUEST_FAILED; @@ -299,8 +288,6 @@ lasso_lecp_process_authn_request_envelope_msg(LassoLecp *lecp, const char *reque xmlXPathContext *xpathCtx; xmlXPathObject *xpathObj; xmlNode *soap_envelope, *soap_body, *authn_request; - xmlOutputBuffer *buf; - xmlCharEncodingHandler *handler; g_return_val_if_fail(LASSO_IS_LECP(lecp), LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ); g_return_val_if_fail(request_msg != NULL, LASSO_PARAM_ERROR_INVALID_VALUE); @@ -337,13 +324,8 @@ lasso_lecp_process_authn_request_envelope_msg(LassoLecp *lecp, const char *reque soap_body = xmlNewTextChild(soap_envelope, NULL, (xmlChar*)"Body", NULL); xmlAddChild(soap_body, authn_request); - handler = xmlFindCharEncodingHandler("utf-8"); - buf = xmlAllocOutputBuffer(handler); - xmlNodeDumpOutput(buf, NULL, soap_envelope, 0, 0, "utf-8"); - xmlOutputBufferFlush(buf); - LASSO_PROFILE(lecp)->msg_body = g_strdup( (char*)( - buf->conv ? buf->conv->content : buf->buffer->content)); - xmlOutputBufferClose(buf); + lasso_assign_new_string(LASSO_PROFILE(lecp)->msg_body, + lasso_xmlnode_to_string(soap_envelope, 0, 0)); xmlFreeNode(soap_envelope); diff --git a/lasso/id-ff/session.c b/lasso/id-ff/session.c index d5294ff3..67b0147f 100644 --- a/lasso/id-ff/session.c +++ b/lasso/id-ff/session.c @@ -723,27 +723,12 @@ add_assertion_childnode(gchar *key, LassoLibAssertion *value, DumpContext *conte xmlChar * xmlNode_to_base64(xmlNode *node) { - xmlOutputBufferPtr buf = NULL; - xmlCharEncodingHandlerPtr handler = NULL; - xmlChar *buffer = NULL; + gchar *buffer = NULL; xmlChar *ret = NULL; - handler = xmlFindCharEncodingHandler("utf-8"); - if (! handler) - goto cleanup; - buf = xmlAllocOutputBuffer(handler); - if (! buf) - goto cleanup; - xmlNodeDumpOutput(buf, NULL, node, 0, 0, "utf-8"); - xmlOutputBufferFlush(buf); - buffer = buf->conv ? buf->conv->content : buf->buffer->content; - - ret = xmlSecBase64Encode(buffer, strlen((char*)buffer), 0); - -cleanup: - if (buf) - xmlOutputBufferClose(buf); - + buffer = lasso_xmlnode_to_string(node, 0, 0); + ret = xmlSecBase64Encode(BAD_CAST buffer, strlen((char*)buffer), 0); + lasso_release_string(buffer); return ret; } diff --git a/lasso/key.c b/lasso/key.c index 2f6dcecc..747492c6 100644 --- a/lasso/key.c +++ b/lasso/key.c @@ -134,7 +134,7 @@ lasso_key_new_for_signature_from_context(LassoSignatureContext context) { } /** - * lasso_key_new_for_signature_from_file; + * lasso_key_new_for_signature_from_file: * @filename_or_buffer: a file path of a string containing the key PEM or Base64 encoded * @password: an eventual password to decoded the private key contained in @buffer * @signature_method: the signature method to associate to this key @@ -159,7 +159,7 @@ lasso_key_new_for_signature_from_file(char *filename_or_buffer, } /** - * lasso_key_new_for_signature_from_memory; + * lasso_key_new_for_signature_from_memory: * @buffer: a byte buffer of size @size * @size: the size of @buffer * @password: an eventual password to decoded the private key contained in @buffer @@ -188,7 +188,7 @@ lasso_key_new_for_signature_from_memory(const void *buffer, } /** - * lasso_key_new_for_signature_from_base64_string; + * lasso_key_new_for_signature_from_base64_string: * @base64_string: a NULL-terminated string containing a base64 encode representation of the key * @password: an eventual password to decoded the private key contained in @buffer * @signature_method: the signature method to associate to this key diff --git a/lasso/saml-2.0/ecp.c b/lasso/saml-2.0/ecp.c index 06dfff21..52c909bd 100644 --- a/lasso/saml-2.0/ecp.c +++ b/lasso/saml-2.0/ecp.c @@ -132,8 +132,6 @@ lasso_ecp_process_authn_request_msg(LassoEcp *ecp, const char *authn_request_msg xmlXPathContext *xpathCtx; xmlXPathObject *xpathObj; xmlNode *xmlnode; - xmlOutputBuffer *buf; - xmlCharEncodingHandler *handler; LassoProfile *profile; LassoProvider *remote_provider; @@ -174,13 +172,8 @@ lasso_ecp_process_authn_request_msg(LassoEcp *ecp, const char *authn_request_msg xpathObj = NULL; xmlnode = xmlDocGetRootElement(doc); - handler = xmlFindCharEncodingHandler("utf-8"); - buf = xmlAllocOutputBuffer(handler); - xmlNodeDumpOutput(buf, NULL, xmlnode, 0, 0, "utf-8"); - xmlOutputBufferFlush(buf); - LASSO_PROFILE(ecp)->msg_body = g_strdup( - (char*)(buf->conv ? buf->conv->content : buf->buffer->content)); - xmlOutputBufferClose(buf); + lasso_assign_new_string(LASSO_PROFILE(ecp)->msg_body, + lasso_xmlnode_to_string(xmlnode, 0, 0)) lasso_release_doc(doc); profile->remote_providerID = lasso_server_get_first_providerID_by_role(profile->server, LASSO_PROVIDER_ROLE_IDP); @@ -210,8 +203,6 @@ lasso_ecp_process_response_msg(LassoEcp *ecp, const char *response_msg) xmlXPathObject *xpathObj; xmlNode *new_envelope, *header, *paos_response, *ecp_relay_state; xmlNode *body = NULL; - xmlOutputBuffer *buf; - xmlCharEncodingHandler *handler; xmlNs *soap_env_ns, *ecp_ns; g_return_val_if_fail(LASSO_IS_ECP(ecp), LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ); @@ -274,17 +265,9 @@ lasso_ecp_process_response_msg(LassoEcp *ecp, const char *response_msg) } xmlAddChild(new_envelope, body); - - handler = xmlFindCharEncodingHandler("utf-8"); - buf = xmlAllocOutputBuffer(handler); - xmlNodeDumpOutput(buf, NULL, new_envelope, 0, 0, "utf-8"); - xmlOutputBufferFlush(buf); - LASSO_PROFILE(ecp)->msg_body = g_strdup( - (char*)(buf->conv ? buf->conv->content : buf->buffer->content)); - xmlOutputBufferClose(buf); - + lasso_assign_new_string(LASSO_PROFILE(ecp)->msg_body, + lasso_xmlnode_to_string(new_envelope, 0, 0)) lasso_release_doc(doc); - return 0; } diff --git a/lasso/xml/tools.c b/lasso/xml/tools.c index 83db2d2c..08c3eb1a 100644 --- a/lasso/xml/tools.c +++ b/lasso/xml/tools.c @@ -36,6 +36,7 @@ #include <libxml/uri.h> #include <libxml/parser.h> #include <libxml/parserInternals.h> +#include <libxml/xmlIO.h> #include <openssl/pem.h> #include <openssl/sha.h> @@ -1023,9 +1024,9 @@ lasso_node_build_deflated_query(LassoNode *node) gchar* lasso_xmlnode_build_deflated_query(xmlNode *xmlnode) { - xmlOutputBufferPtr buf; + xmlOutputBuffer *output_buffer; + xmlBuffer *buffer; xmlCharEncodingHandlerPtr handler = NULL; - xmlChar *buffer; xmlChar *ret, *b64_ret; char *rret; unsigned long in_len; @@ -1033,18 +1034,19 @@ lasso_xmlnode_build_deflated_query(xmlNode *xmlnode) z_stream stream; handler = xmlFindCharEncodingHandler("utf-8"); - buf = xmlAllocOutputBuffer(handler); - xmlNodeDumpOutput(buf, NULL, xmlnode, 0, 0, "utf-8"); - xmlOutputBufferFlush(buf); - buffer = buf->conv ? buf->conv->content : buf->buffer->content; + buffer = xmlBufferCreate(); + output_buffer = xmlOutputBufferCreateBuffer(buffer, handler); + xmlNodeDumpOutput(output_buffer, NULL, xmlnode, 0, 0, NULL); + xmlOutputBufferClose(output_buffer); + xmlBufferAdd(buffer, BAD_CAST "", 1); - in_len = strlen((char*)buffer); + in_len = strlen((char*)xmlBufferContent(buffer)); ret = g_malloc(in_len * 2); /* deflating should never increase the required size but we are * more conservative than that. Twice the size should be * enough. */ - stream.next_in = buffer; + stream.next_in = (xmlChar*)xmlBufferContent(buffer); stream.avail_in = in_len; stream.next_out = ret; stream.avail_out = in_len * 2; @@ -1067,6 +1069,7 @@ lasso_xmlnode_build_deflated_query(xmlNode *xmlnode) rc = deflateEnd(&stream); } } + xmlBufferFree(buffer); if (rc != Z_OK) { lasso_release(ret); message(G_LOG_LEVEL_CRITICAL, "Failed to deflate"); @@ -1074,7 +1077,6 @@ lasso_xmlnode_build_deflated_query(xmlNode *xmlnode) } b64_ret = xmlSecBase64Encode(ret, stream.total_out, 0); - xmlOutputBufferClose(buf); lasso_release(ret); ret = xmlURIEscapeStr(b64_ret, NULL); @@ -2246,22 +2248,21 @@ cleanup: char* lasso_xmlnode_to_string(xmlNode *node, gboolean format, int level) { - xmlOutputBufferPtr buf; - xmlCharEncodingHandlerPtr handler = NULL; - xmlChar *buffer; + xmlOutputBufferPtr output_buffer; + xmlBuffer *buffer; char *str; if (! node) return NULL; - handler = xmlFindCharEncodingHandler("utf-8"); - buf = xmlAllocOutputBuffer(handler); - xmlNodeDumpOutput(buf, NULL, node, level, format ? 1 : 0, "utf-8"); - xmlOutputBufferFlush(buf); - buffer = buf->conv ? buf->conv->content : buf->buffer->content; + buffer = xmlBufferCreate(); + output_buffer = xmlOutputBufferCreateBuffer(buffer, NULL); + xmlNodeDumpOutput(output_buffer, NULL, node, level, format ? 1 : 0, NULL); + xmlOutputBufferClose(output_buffer); + xmlBufferAdd(buffer, BAD_CAST "", 1); /* do not mix XML and GLib strings, so we must copy */ - str = g_strdup((char*)buffer); - xmlOutputBufferClose(buf); + str = g_strdup((char*)xmlBufferContent(buffer)); + xmlBufferFree(buffer); return str; } |