2004-03-23 18:00:23 +01:00
|
|
|
/* $Id$
|
|
|
|
*
|
|
|
|
* Lasso - A free implementation of the Liberty Alliance specifications.
|
|
|
|
*
|
2007-05-30 19:17:45 +02:00
|
|
|
* Copyright (C) 2004-2007 Entr'ouvert
|
2004-03-23 18:00:23 +01:00
|
|
|
* http://lasso.entrouvert.org
|
2008-09-12 17:06:58 +02:00
|
|
|
*
|
2005-01-22 16:57:56 +01:00
|
|
|
* Authors: See AUTHORS file in top-level directory.
|
2004-03-23 18:00:23 +01:00
|
|
|
*
|
|
|
|
* 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.
|
2008-09-12 17:06:58 +02:00
|
|
|
*
|
2004-03-23 18:00:23 +01:00
|
|
|
* 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.
|
2008-09-12 17:06:58 +02:00
|
|
|
*
|
2004-03-23 18:00:23 +01:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2008-05-15 23:17:44 +02:00
|
|
|
/**
|
|
|
|
* SECTION:lasso
|
|
|
|
* @short_description: Initialization functions
|
|
|
|
*
|
2010-02-10 01:34:23 +01:00
|
|
|
* <sec2>
|
|
|
|
* <title>Environment variables</title>
|
|
|
|
* <para>
|
2010-02-10 14:58:40 +01:00
|
|
|
* <literal>LASSO_FLAG</literal> is an environment variable containing white-space separated values
|
2010-02-10 01:34:23 +01:00
|
|
|
* which allows to modify the behaviour of lasso. To negate the effect of one of
|
2010-02-10 14:58:40 +01:00
|
|
|
* the value, just add <literal>no-</literal> in front of its name. The flag are also modifiable
|
|
|
|
* using the lasso_set_flag() function. Those values are:
|
|
|
|
*
|
2010-02-10 01:34:23 +01:00
|
|
|
* <informaltable frame="non">
|
|
|
|
* <tgroup cols="2">
|
|
|
|
* <tbody>
|
|
|
|
* <rows>
|
|
|
|
* <entry><literal>no-verify-signature</literal></entry>
|
|
|
|
* <entry><para>Disable the validation of signatures on all message, usually for
|
|
|
|
* debugging pupose</para></entry>
|
|
|
|
* </rows>
|
|
|
|
* <rows>
|
|
|
|
* <entry><literal>memory-debug</literal></entry>
|
|
|
|
* <entry><para>Enable the tracing of nodes allocation, deallocation and initialization.</para></entry>
|
|
|
|
* </rows>
|
|
|
|
* <rows id="strict-checking">
|
|
|
|
* <entry><literal>strict-checking</literal></entry>
|
|
|
|
* <entry><para>Enable checking which were not done in previous version of Lasso, like matching <literal>ResponseTo</literal> attributes of response messages to the identifier of the request.</para></entry>
|
|
|
|
* </rows>
|
|
|
|
* <rows>
|
|
|
|
* <entry><literal>no-add-signature</literal></entry>
|
|
|
|
* <entry><para>Disable all signatures</para></entry>
|
|
|
|
* </rows>
|
|
|
|
* <rows>
|
|
|
|
* <entry><literal>no-sign-messages</literal></entry>
|
|
|
|
* <entry><para>Disable signatures on messages.</para></entry>
|
|
|
|
* </rows>
|
|
|
|
* <rows>
|
|
|
|
* <entry><literal>no-sign-messages</literal></entry>
|
|
|
|
* <entry><para>Disable signatures on messages.</para></entry>
|
|
|
|
* </rows>
|
|
|
|
* </tbody>
|
|
|
|
* </tgroup>
|
|
|
|
* </informaltable>
|
2010-02-10 14:58:40 +01:00
|
|
|
* </para>
|
|
|
|
* </sec2>
|
2008-05-15 23:17:44 +02:00
|
|
|
**/
|
|
|
|
|
2008-10-01 12:31:58 +02:00
|
|
|
#include <stdlib.h> /* getenv */
|
2008-10-16 23:33:25 +02:00
|
|
|
#include <string.h> /* strcmp */
|
2004-07-24 17:47:01 +02:00
|
|
|
#include <xmlsec/xmlsec.h>
|
|
|
|
#include <xmlsec/crypto.h>
|
2004-07-30 17:33:58 +02:00
|
|
|
#include <libxslt/xslt.h>
|
2008-08-01 16:08:54 +02:00
|
|
|
#include <config.h>
|
2010-06-12 02:43:49 +02:00
|
|
|
#include "./lasso.h"
|
|
|
|
#include "./lasso_config.h"
|
|
|
|
#include "./debug.h"
|
|
|
|
#include "./backward_comp.h"
|
|
|
|
#include "./registry-private.h"
|
|
|
|
#include "./xml/private.h"
|
|
|
|
#include "./utils.h"
|
2008-10-01 12:31:58 +02:00
|
|
|
|
|
|
|
/* Set to true, it forces lasso_provider_verify_signature and lasso_query_verify_signature to always
|
|
|
|
* return TRUE. */
|
|
|
|
gboolean lasso_flag_verify_signature = TRUE;
|
|
|
|
/* Set to true, it activates debugging code for LassoNode freeing */
|
|
|
|
gboolean lasso_flag_memory_debug = FALSE;
|
2009-03-27 16:06:40 +01:00
|
|
|
/* set to true, it activates more strict validation of messages */
|
|
|
|
gboolean lasso_flag_strict_checking = FALSE;
|
2010-02-21 13:47:42 +01:00
|
|
|
/* set to false, it does not sign messages */
|
2009-03-27 16:06:43 +01:00
|
|
|
gboolean lasso_flag_add_signature = TRUE;
|
2008-10-01 12:31:58 +02:00
|
|
|
static void lasso_flag_parse_environment_variable();
|
2009-04-27 16:31:48 +02:00
|
|
|
/* do not sign messages */
|
|
|
|
gboolean lasso_flag_sign_messages = TRUE;
|
2008-10-01 12:31:58 +02:00
|
|
|
|
|
|
|
#ifndef LASSO_FLAG_ENV_VAR
|
|
|
|
#define LASSO_FLAG_ENV_VAR "LASSO_FLAG"
|
|
|
|
#endif
|
2004-03-23 18:00:23 +01:00
|
|
|
|
2004-07-16 14:54:43 +02:00
|
|
|
#if defined _MSC_VER
|
2005-02-10 15:56:27 +01:00
|
|
|
HINSTANCE g_hModule = NULL;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DllMain:
|
|
|
|
* @hinstDLL: hnadle to the DLL module
|
|
|
|
* @fdwReason: reason value of the DLL call
|
2010-01-18 11:03:54 +01:00
|
|
|
* @lpvReserved: use is unknown.
|
2004-07-16 14:54:43 +02:00
|
|
|
*
|
2005-02-10 15:56:27 +01:00
|
|
|
* Called when the DLL is attached or detached by a program.
|
2004-07-16 14:54:43 +02:00
|
|
|
*
|
2005-02-10 15:56:27 +01:00
|
|
|
* Return value: %TRUE if everything is OK
|
|
|
|
**/
|
2004-07-16 14:54:43 +02:00
|
|
|
BOOL WINAPI
|
2004-10-27 17:49:43 +02:00
|
|
|
DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
|
2004-07-16 14:54:43 +02:00
|
|
|
{
|
2004-10-27 17:49:43 +02:00
|
|
|
if (fdwReason == DLL_PROCESS_ATTACH)
|
|
|
|
{
|
|
|
|
DisableThreadLibraryCalls(hinstDLL);
|
|
|
|
g_hModule = hinstDLL;
|
|
|
|
}
|
|
|
|
return TRUE;
|
2004-07-16 14:54:43 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-12-04 14:37:53 +01:00
|
|
|
#include "types.c"
|
|
|
|
|
2004-03-23 18:00:23 +01:00
|
|
|
/**
|
|
|
|
* lasso_init:
|
|
|
|
*
|
2005-01-12 16:14:29 +01:00
|
|
|
* Initializes Lasso library.
|
2004-03-23 18:00:23 +01:00
|
|
|
*
|
2005-01-12 16:14:29 +01:00
|
|
|
* Return value: 0 on success; or a negative value otherwise.
|
|
|
|
**/
|
2004-03-23 18:00:23 +01:00
|
|
|
int lasso_init()
|
|
|
|
{
|
2004-12-04 14:37:53 +01:00
|
|
|
int i;
|
|
|
|
|
2004-10-27 17:49:43 +02:00
|
|
|
g_type_init();
|
|
|
|
|
2004-12-04 14:37:53 +01:00
|
|
|
/* Init Lasso classes */
|
|
|
|
for (i=0; functions[i]; i++)
|
|
|
|
functions[i]();
|
|
|
|
|
2004-10-27 17:49:43 +02:00
|
|
|
/* Init libxml and libxslt libraries */
|
|
|
|
xmlInitParser();
|
|
|
|
/*LIBXML_TEST_VERSION*/
|
|
|
|
/* xmlLoadExtDtdDefaultValue = XML_DETECT_IDS | XML_COMPLETE_ATTRS; */
|
|
|
|
/* xmlSubstituteEntitiesDefault(1); */
|
|
|
|
|
|
|
|
/* Init xmlsec library */
|
|
|
|
if (xmlSecInit() < 0) {
|
|
|
|
message(G_LOG_LEVEL_CRITICAL, "XMLSec initialization failed.");
|
2006-11-02 11:51:13 +01:00
|
|
|
return LASSO_ERROR_UNDEFINED;
|
2004-10-27 17:49:43 +02:00
|
|
|
}
|
2004-03-23 18:00:23 +01:00
|
|
|
|
2004-10-27 17:49:43 +02:00
|
|
|
/* Load default crypto engine if we are supporting dynamic
|
|
|
|
* loading for xmlsec-crypto libraries. Use the crypto library
|
2008-09-12 17:06:58 +02:00
|
|
|
* name ("openssl", "nss", etc.) to load corresponding
|
2004-10-27 17:49:43 +02:00
|
|
|
* xmlsec-crypto library.
|
|
|
|
*/
|
2004-03-23 18:00:23 +01:00
|
|
|
#ifdef XMLSEC_CRYPTO_DYNAMIC_LOADING
|
2004-10-27 17:49:43 +02:00
|
|
|
if (xmlSecCryptoDLLoadLibrary(BAD_CAST XMLSEC_CRYPTO) < 0) {
|
|
|
|
message(G_LOG_LEVEL_CRITICAL,
|
|
|
|
"Unable to load default xmlsec-crypto library. Make sure"
|
|
|
|
"that you have it installed and check shared libraries path"
|
|
|
|
"(LD_LIBRARY_PATH) environment variable.");
|
2006-11-02 11:51:13 +01:00
|
|
|
return LASSO_ERROR_UNDEFINED;
|
2004-10-27 17:49:43 +02:00
|
|
|
}
|
2004-03-23 18:00:23 +01:00
|
|
|
#endif /* XMLSEC_CRYPTO_DYNAMIC_LOADING */
|
|
|
|
|
2004-10-27 17:49:43 +02:00
|
|
|
/* Init crypto library */
|
|
|
|
if (xmlSecCryptoAppInit(NULL) < 0) {
|
|
|
|
message(G_LOG_LEVEL_CRITICAL, "Crypto initialization failed.");
|
2006-11-02 11:51:13 +01:00
|
|
|
return LASSO_ERROR_UNDEFINED;
|
2004-10-27 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Init xmlsec-crypto library */
|
|
|
|
if (xmlSecCryptoInit() < 0) {
|
|
|
|
message(G_LOG_LEVEL_CRITICAL, "xmlsec-crypto initialization failed.");
|
2006-11-02 11:51:13 +01:00
|
|
|
return LASSO_ERROR_UNDEFINED;
|
2004-10-27 17:49:43 +02:00
|
|
|
}
|
2008-10-01 12:31:58 +02:00
|
|
|
lasso_flag_parse_environment_variable();
|
2004-10-27 17:49:43 +02:00
|
|
|
return 0;
|
2004-03-23 18:00:23 +01:00
|
|
|
}
|
|
|
|
|
2004-04-02 02:40:22 +02:00
|
|
|
/**
|
|
|
|
* lasso_shutdown:
|
2008-09-12 17:06:58 +02:00
|
|
|
*
|
2005-01-12 16:14:29 +01:00
|
|
|
* Clean ups Lasso library.
|
2008-09-12 17:06:58 +02:00
|
|
|
*
|
2005-01-12 16:14:29 +01:00
|
|
|
* Return value: 0 on success; or a negative value otherwise.
|
2004-04-02 02:40:22 +02:00
|
|
|
**/
|
|
|
|
int lasso_shutdown()
|
2004-03-23 18:00:23 +01:00
|
|
|
{
|
2004-10-27 17:49:43 +02:00
|
|
|
/* Shutdown xmlsec-crypto library */
|
|
|
|
xmlSecCryptoShutdown();
|
|
|
|
|
|
|
|
/* Shutdown crypto library */
|
|
|
|
xmlSecCryptoAppShutdown();
|
|
|
|
|
|
|
|
/* Shutdown xmlsec library */
|
|
|
|
xmlSecShutdown();
|
|
|
|
|
|
|
|
/* Shutdown libxslt/libxml */
|
2004-03-23 18:00:23 +01:00
|
|
|
#ifndef XMLSEC_NO_XSLT
|
2008-09-12 17:06:58 +02:00
|
|
|
xsltCleanupGlobals();
|
2004-03-23 18:00:23 +01:00
|
|
|
#endif /* XMLSEC_NO_XSLT */
|
2004-10-27 17:49:43 +02:00
|
|
|
/* Cleanup function for the XML library */
|
|
|
|
xmlCleanupParser();
|
2009-04-30 16:58:22 +02:00
|
|
|
|
|
|
|
/* Disallocate default registry */
|
|
|
|
lasso_registry_default_shutdown();
|
|
|
|
|
2008-10-01 12:31:58 +02:00
|
|
|
if (lasso_flag_memory_debug == TRUE) {
|
2004-10-27 17:49:43 +02:00
|
|
|
/* this is to debug memory for regression tests */
|
2008-10-01 12:31:58 +02:00
|
|
|
xmlMemoryDump();
|
|
|
|
}
|
2004-10-27 17:49:43 +02:00
|
|
|
return 0;
|
2004-03-23 18:00:23 +01:00
|
|
|
}
|
|
|
|
|
2008-09-12 17:06:58 +02:00
|
|
|
/**
|
2005-01-12 16:14:29 +01:00
|
|
|
* lasso_check_version:
|
|
|
|
* @major: major version numbe
|
|
|
|
* @minor: minor version number
|
|
|
|
* @subminor: subminor version number
|
|
|
|
* @mode: version check mode
|
2004-03-23 18:00:23 +01:00
|
|
|
*
|
|
|
|
* Checks if the loaded version of Lasso library could be used.
|
|
|
|
*
|
2009-01-26 17:42:19 +01:00
|
|
|
* Return value: 1 if the loaded lasso library version is OK to use
|
2005-01-12 16:14:29 +01:00
|
|
|
* 0 if it is not; or a negative value if an error occurs.
|
|
|
|
**/
|
2008-09-12 17:06:58 +02:00
|
|
|
int
|
2005-01-12 16:14:29 +01:00
|
|
|
lasso_check_version(int major, int minor, int subminor, LassoCheckVersionMode mode)
|
2004-04-13 12:15:54 +02:00
|
|
|
{
|
2005-02-17 14:35:15 +01:00
|
|
|
if (mode == LASSO_CHECK_VERSION_NUMERIC) {
|
|
|
|
if (LASSO_VERSION_MAJOR*10000 + LASSO_VERSION_MINOR*100 + LASSO_VERSION_SUBMINOR <
|
|
|
|
major*10000 + minor*100 + subminor)
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
2004-10-27 17:49:43 +02:00
|
|
|
/* we always want to have a match for major version number */
|
|
|
|
if (major != LASSO_VERSION_MAJOR) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode == LASSO_CHECK_VERSION_EXACT) {
|
|
|
|
if (minor != LASSO_VERSION_MINOR || subminor != LASSO_VERSION_SUBMINOR) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2005-02-17 14:35:15 +01:00
|
|
|
|
2004-10-27 17:49:43 +02:00
|
|
|
if (mode == LASSO_CHECK_VERSIONABI_COMPATIBLE) {
|
2008-09-12 17:06:58 +02:00
|
|
|
if (minor < LASSO_VERSION_MINOR || (minor == LASSO_VERSION_MINOR &&
|
2004-10-27 17:49:43 +02:00
|
|
|
subminor < LASSO_VERSION_SUBMINOR)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-17 14:35:15 +01:00
|
|
|
if (mode > LASSO_CHECK_VERSION_NUMERIC)
|
2006-11-02 11:51:13 +01:00
|
|
|
return LASSO_ERROR_UNDEFINED;
|
2005-02-17 14:35:15 +01:00
|
|
|
|
2004-10-27 17:49:43 +02:00
|
|
|
return 1;
|
2004-03-23 18:00:23 +01:00
|
|
|
}
|
2008-10-01 12:31:58 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* lasso_set_flag:
|
|
|
|
* @flag: a string representing a flag name, prefix with 'no-' to disable it.
|
|
|
|
*
|
2010-02-10 14:58:40 +01:00
|
|
|
* Set a debugging flag. You can also use the environment variable LASSO_FLAG
|
|
|
|
* to get the same effect. LASSO_FLAG must contain flag name separated by spaces, commas,
|
2008-10-01 12:31:58 +02:00
|
|
|
* tabulations or colons.
|
|
|
|
*/
|
|
|
|
void lasso_set_flag(char *flag) {
|
|
|
|
gboolean value = TRUE;
|
|
|
|
|
|
|
|
g_return_if_fail(flag);
|
|
|
|
|
|
|
|
/* Handle negative flags */
|
|
|
|
if (flag && strncmp(flag, "no-", 3) == 0) {
|
|
|
|
value = FALSE;
|
|
|
|
flag += 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
2010-10-01 12:33:24 +02:00
|
|
|
if (lasso_strisequal(flag,"verify-signature")) {
|
2008-10-01 12:31:58 +02:00
|
|
|
lasso_flag_verify_signature = value;
|
|
|
|
continue;
|
|
|
|
}
|
2010-10-01 12:33:24 +02:00
|
|
|
if (lasso_strisequal(flag,"memory-debug")) {
|
2008-10-01 12:31:58 +02:00
|
|
|
lasso_flag_memory_debug = value;
|
|
|
|
continue;
|
|
|
|
}
|
2010-10-01 12:33:24 +02:00
|
|
|
if (lasso_strisequal(flag,"strict-checking")) {
|
2009-03-27 16:06:40 +01:00
|
|
|
lasso_flag_strict_checking = value;
|
|
|
|
continue;
|
|
|
|
}
|
2010-10-01 12:33:24 +02:00
|
|
|
if (lasso_strisequal(flag,"add-signature")) {
|
2009-03-27 16:06:43 +01:00
|
|
|
lasso_flag_add_signature = value;
|
|
|
|
continue;
|
|
|
|
}
|
2010-10-01 12:33:24 +02:00
|
|
|
if (lasso_strisequal(flag,"sign-messages")) {
|
2009-04-27 16:31:48 +02:00
|
|
|
lasso_flag_sign_messages = value;
|
|
|
|
continue;
|
|
|
|
}
|
2008-10-01 12:31:58 +02:00
|
|
|
} while (FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void lasso_flag_parse_environment_variable() {
|
|
|
|
char *lasso_flag = getenv(LASSO_FLAG_ENV_VAR);
|
|
|
|
char *save_ptr;
|
|
|
|
char *token;
|
|
|
|
const char delim[] = ", \t:";
|
|
|
|
|
|
|
|
if (lasso_flag) {
|
|
|
|
token = strtok_r(lasso_flag, delim, &save_ptr);
|
|
|
|
do {
|
|
|
|
lasso_set_flag(token);
|
|
|
|
} while ((token = strtok_r(NULL, delim, &save_ptr)) != NULL);
|
|
|
|
}
|
|
|
|
}
|