2004-06-24 18:01:48 +02: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-06-24 18:01:48 +02: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-06-24 18:01:48 +02: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-06-24 18:01:48 +02: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-06-24 18:01:48 +02:00
|
|
|
* You should have received a copy of the GNU General Public License
|
2013-11-27 20:04:51 +01:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2004-06-24 18:01:48 +02:00
|
|
|
*/
|
|
|
|
|
2008-05-15 23:17:44 +02:00
|
|
|
/**
|
|
|
|
* SECTION:profile
|
|
|
|
* @short_description: Base class for all identity profiles
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
|
2009-03-27 16:04:26 +01:00
|
|
|
#include "../xml/private.h"
|
2004-10-27 11:49:13 +02:00
|
|
|
#include <libxml/xpath.h>
|
|
|
|
#include <libxml/xpathInternals.h>
|
|
|
|
|
2009-08-26 17:14:32 +02:00
|
|
|
#include "../xml/samlp_response.h"
|
|
|
|
#include "../xml/samlp_request.h"
|
|
|
|
#include "../xml/lib_authn_response.h"
|
|
|
|
#include "../xml/lib_status_response.h"
|
2004-06-24 18:01:48 +02:00
|
|
|
|
2009-08-26 17:14:32 +02:00
|
|
|
#include "profile.h"
|
|
|
|
#include "profileprivate.h"
|
|
|
|
#include "providerprivate.h"
|
2011-12-16 14:17:31 +01:00
|
|
|
#include "sessionprivate.h"
|
2004-09-06 14:51:42 +02:00
|
|
|
|
2009-08-26 17:14:32 +02:00
|
|
|
#include "../saml-2.0/profileprivate.h"
|
2010-01-12 16:39:48 +01:00
|
|
|
#include "../xml/saml-2.0/saml2_name_id.h"
|
2010-03-27 17:51:47 +01:00
|
|
|
#include "../xml/saml_name_identifier.h"
|
2010-01-12 16:39:48 +01:00
|
|
|
#include "../xml/saml-2.0/saml2_assertion.h"
|
2010-03-02 12:57:53 +01:00
|
|
|
#include "../xml/soap-1.1/soap_fault.h"
|
Remove use of xmlFreeDoc for lasso_release_doc
- bindings/java/wrapper_top.c, bindings/php4/lasso_php4_helper.c,
bindings/php5/wrapper_source_top.c, bindings/python/wrapper_top.c,
lasso/id-ff/identity.c, lasso/id-ff/lecp.c, lasso/id-ff/login.c,
lasso/id-ff/logout.c, lasso/id-ff/name_registration.c,
lasso/id-ff/profile.c, lasso/id-ff/provider.c, lasso/id-ff/server.c,
lasso/id-ff/session.c, lasso/id-wsf-2.0/data_service.c,
lasso/id-wsf/data_service.c, lasso/id-wsf/discovery.c,
lasso/id-wsf/wsf_profile.c, lasso/saml-2.0/ecp.c,
lasso/saml-2.0/login.c, lasso/saml-2.0/name_id_management.c,
lasso/utils.h, lasso/xml/tools.c, lasso/xml/xml.c, swig/Lasso.i:
Remove use of xmlFreeDoc. Use lasso_release_doc instead.
2008-11-04 02:58:49 +01:00
|
|
|
#include "../utils.h"
|
2009-03-27 16:06:37 +01:00
|
|
|
#include "../debug.h"
|
2010-09-09 01:09:28 +02:00
|
|
|
#ifdef LASSO_WSF_ENABLED
|
|
|
|
#include "../xml/idwsf_strings.h"
|
|
|
|
#include "../xml/id-wsf-2.0/idwsf2_strings.h"
|
|
|
|
#endif
|
2011-01-04 16:43:06 +01:00
|
|
|
#include "../lasso_config.h"
|
2006-11-27 21:12:21 +01:00
|
|
|
|
2014-03-31 10:54:27 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2004-06-24 18:01:48 +02:00
|
|
|
/*****************************************************************************/
|
2004-07-21 18:49:42 +02:00
|
|
|
/* public functions */
|
2004-06-24 18:01:48 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
2010-01-12 16:39:48 +01:00
|
|
|
static LassoNode*
|
|
|
|
_lasso_saml_assertion_get_name_id(LassoSamlAssertion *assertion)
|
|
|
|
{
|
|
|
|
LassoSamlAuthenticationStatement *authn_statement;
|
|
|
|
LassoSamlSubject *subject;
|
|
|
|
|
|
|
|
goto_cleanup_if_fail(LASSO_IS_SAML_ASSERTION(assertion));
|
|
|
|
authn_statement = assertion->AuthenticationStatement;
|
|
|
|
goto_cleanup_if_fail(LASSO_IS_SAML_AUTHENTICATION_STATEMENT(authn_statement));
|
|
|
|
subject = authn_statement->parent.Subject;
|
|
|
|
goto_cleanup_if_fail(LASSO_IS_SAML_SUBJECT(subject));
|
|
|
|
if (LASSO_IS_SAML_NAME_IDENTIFIER(subject->NameIdentifier))
|
|
|
|
return (LassoNode*)subject->NameIdentifier;
|
|
|
|
cleanup:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LassoNode*
|
|
|
|
_lasso_saml2_assertion_get_name_id(LassoSaml2Assertion *assertion)
|
|
|
|
{
|
|
|
|
LassoSaml2Subject *subject;
|
|
|
|
|
|
|
|
goto_cleanup_if_fail(LASSO_SAML2_ASSERTION(assertion));
|
|
|
|
subject = assertion->Subject;
|
|
|
|
goto_cleanup_if_fail(LASSO_SAML2_SUBJECT(subject));
|
|
|
|
if (LASSO_IS_SAML2_NAME_ID(subject->NameID))
|
|
|
|
return (LassoNode*)subject->NameID;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-01-21 11:51:24 +01:00
|
|
|
/**
|
|
|
|
* lasso_profile_get_nameIdentifier:
|
2005-11-21 19:51:52 +01:00
|
|
|
* @profile: a #LassoProfile
|
2005-01-21 11:51:24 +01:00
|
|
|
*
|
|
|
|
* Looks up appropriate federation in object and gets the service provider name
|
2005-11-21 19:51:52 +01:00
|
|
|
* identifier (which is actually a #LassoSamlNameIdentifier in ID-FF 1.2 and
|
|
|
|
* #LassoSaml2NameID in SAML 2.0).
|
2005-01-21 11:51:24 +01:00
|
|
|
*
|
2010-02-17 11:14:56 +01:00
|
|
|
* Return value:(transfer none): the name identifier or NULL if none was found. The #LassoNode
|
2007-11-22 13:30:02 +01:00
|
|
|
* object is internally allocated and must not be freed by the caller.
|
2005-01-21 11:51:24 +01:00
|
|
|
**/
|
2005-11-21 19:51:52 +01:00
|
|
|
LassoNode*
|
2004-12-22 13:48:05 +01:00
|
|
|
lasso_profile_get_nameIdentifier(LassoProfile *profile)
|
2004-10-27 11:49:13 +02:00
|
|
|
{
|
|
|
|
LassoProvider *remote_provider;
|
|
|
|
LassoFederation *federation;
|
2010-02-04 01:02:05 +01:00
|
|
|
const char *name_id_sp_name_qualifier;
|
2004-10-27 11:49:13 +02:00
|
|
|
|
2010-01-12 16:40:06 +01:00
|
|
|
if (!LASSO_IS_PROFILE(profile)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2004-10-27 11:49:13 +02:00
|
|
|
|
2010-01-12 16:39:48 +01:00
|
|
|
if (profile->remote_providerID == NULL)
|
2009-10-30 15:47:19 +01:00
|
|
|
return NULL;
|
|
|
|
|
2010-12-17 17:40:07 +01:00
|
|
|
/* For transient federations, we must look at assertions no federation object exists */
|
|
|
|
if (LASSO_IS_SESSION(profile->session)) {
|
|
|
|
LassoNode *assertion, *name_id;
|
|
|
|
|
|
|
|
assertion = lasso_session_get_assertion(profile->session,
|
|
|
|
profile->remote_providerID);
|
|
|
|
|
|
|
|
name_id = _lasso_saml_assertion_get_name_id((LassoSamlAssertion*)assertion);
|
|
|
|
if (name_id)
|
|
|
|
return name_id;
|
|
|
|
name_id = _lasso_saml2_assertion_get_name_id((LassoSaml2Assertion*)assertion);
|
|
|
|
if (name_id)
|
|
|
|
return name_id;
|
|
|
|
}
|
2010-01-12 16:40:06 +01:00
|
|
|
/* beware, it is not a real loop ! */
|
|
|
|
if (LASSO_IS_IDENTITY(profile->identity)) do {
|
2010-01-12 16:39:48 +01:00
|
|
|
remote_provider = lasso_server_get_provider(profile->server, profile->remote_providerID);
|
|
|
|
if (remote_provider == NULL)
|
2010-01-12 16:40:06 +01:00
|
|
|
break;
|
2010-01-12 16:39:48 +01:00
|
|
|
|
|
|
|
name_id_sp_name_qualifier = lasso_provider_get_sp_name_qualifier(remote_provider);
|
|
|
|
if (name_id_sp_name_qualifier == NULL)
|
2010-01-12 16:40:06 +01:00
|
|
|
break;
|
2010-01-12 16:39:48 +01:00
|
|
|
|
|
|
|
federation = g_hash_table_lookup(
|
|
|
|
profile->identity->federations,
|
|
|
|
name_id_sp_name_qualifier);
|
|
|
|
if (federation == NULL)
|
2010-01-12 16:40:06 +01:00
|
|
|
break;
|
2010-01-12 16:39:48 +01:00
|
|
|
|
|
|
|
if (federation->remote_nameIdentifier)
|
|
|
|
return federation->remote_nameIdentifier;
|
|
|
|
return federation->local_nameIdentifier;
|
2010-01-12 16:40:06 +01:00
|
|
|
} while (FALSE);
|
|
|
|
|
2010-01-12 16:39:48 +01:00
|
|
|
return NULL;
|
2004-10-27 11:49:13 +02:00
|
|
|
}
|
|
|
|
|
2004-12-22 13:48:05 +01:00
|
|
|
/**
|
|
|
|
* lasso_profile_get_request_type_from_soap_msg:
|
|
|
|
* @soap: the SOAP message
|
|
|
|
*
|
|
|
|
* Looks up and return the type of the request in a SOAP message.
|
|
|
|
*
|
|
|
|
* Return value: the type of request
|
|
|
|
**/
|
2004-12-31 19:33:23 +01:00
|
|
|
LassoRequestType
|
2004-10-02 23:49:38 +02:00
|
|
|
lasso_profile_get_request_type_from_soap_msg(const gchar *soap)
|
2004-07-21 18:49:42 +02:00
|
|
|
{
|
2004-10-27 11:49:13 +02:00
|
|
|
xmlDoc *doc;
|
|
|
|
xmlXPathContext *xpathCtx;
|
|
|
|
xmlXPathObject *xpathObj;
|
2004-12-31 19:33:23 +01:00
|
|
|
LassoRequestType type = LASSO_REQUEST_TYPE_INVALID;
|
2004-11-28 21:29:41 +01:00
|
|
|
const char *name = NULL;
|
2005-01-28 11:25:19 +01:00
|
|
|
xmlNs *ns = NULL;
|
2010-02-04 01:02:24 +01:00
|
|
|
xmlError error;
|
2004-10-27 11:49:13 +02:00
|
|
|
|
2010-02-04 01:02:24 +01:00
|
|
|
memset(&error, 0, sizeof(xmlError));
|
2005-02-11 12:23:43 +01:00
|
|
|
if (soap == NULL)
|
|
|
|
return LASSO_REQUEST_TYPE_INVALID;
|
|
|
|
|
2010-02-04 01:02:24 +01:00
|
|
|
doc = lasso_xml_parse_memory_with_error(soap, strlen(soap), &error);
|
|
|
|
if (! doc) {
|
|
|
|
message(G_LOG_LEVEL_WARNING, "Invalid soap message: %s", error.message);
|
|
|
|
type = LASSO_REQUEST_TYPE_INVALID;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2004-10-27 11:49:13 +02:00
|
|
|
xpathCtx = xmlXPathNewContext(doc);
|
2005-07-31 00:36:54 +02:00
|
|
|
xmlXPathRegisterNs(xpathCtx, (xmlChar*)"s", (xmlChar*)LASSO_SOAP_ENV_HREF);
|
|
|
|
xpathObj = xmlXPathEvalExpression((xmlChar*)"//s:Body/*", xpathCtx);
|
2004-10-27 11:49:13 +02:00
|
|
|
|
2005-01-28 11:25:19 +01:00
|
|
|
if (xpathObj && xpathObj->nodesetval && xpathObj->nodesetval->nodeNr) {
|
2005-07-31 00:36:54 +02:00
|
|
|
name = (char*)xpathObj->nodesetval->nodeTab[0]->name;
|
2005-01-28 11:25:19 +01:00
|
|
|
ns = xpathObj->nodesetval->nodeTab[0]->ns;
|
|
|
|
}
|
2004-10-27 11:49:13 +02:00
|
|
|
|
2005-01-28 11:25:19 +01:00
|
|
|
if (name == NULL || ns == NULL) {
|
2004-11-28 21:29:41 +01:00
|
|
|
message(G_LOG_LEVEL_WARNING, "Invalid SOAP request");
|
|
|
|
} else if (strcmp(name, "Request") == 0) {
|
2004-10-27 11:49:13 +02:00
|
|
|
type = LASSO_REQUEST_TYPE_LOGIN;
|
2004-11-28 21:29:41 +01:00
|
|
|
} else if (strcmp(name, "LogoutRequest") == 0) {
|
2004-10-27 11:49:13 +02:00
|
|
|
type = LASSO_REQUEST_TYPE_LOGOUT;
|
2004-11-28 21:29:41 +01:00
|
|
|
} else if (strcmp(name, "FederationTerminationNotification") == 0) {
|
2004-10-27 11:49:13 +02:00
|
|
|
type = LASSO_REQUEST_TYPE_DEFEDERATION;
|
2004-11-28 21:29:41 +01:00
|
|
|
} else if (strcmp(name, "RegisterNameIdentifierRequest") == 0) {
|
2004-10-27 11:49:13 +02:00
|
|
|
type = LASSO_REQUEST_TYPE_NAME_REGISTRATION;
|
2004-11-28 21:29:41 +01:00
|
|
|
} else if (strcmp(name, "NameIdentifierMappingRequest") == 0) {
|
2004-10-27 11:49:13 +02:00
|
|
|
type = LASSO_REQUEST_TYPE_NAME_IDENTIFIER_MAPPING;
|
2004-11-28 21:29:41 +01:00
|
|
|
} else if (strcmp(name, "AuthnRequest") == 0) {
|
2004-10-27 11:49:13 +02:00
|
|
|
type = LASSO_REQUEST_TYPE_LECP;
|
2010-09-29 00:10:09 +02:00
|
|
|
} else if (strcmp(name, "ManageNameIDRequest") == 0) {
|
|
|
|
type = LASSO_REQUEST_TYPE_NAME_ID_MANAGEMENT;
|
2010-09-09 01:09:28 +02:00
|
|
|
#ifdef LASSO_WSF_ENABLED
|
2005-01-28 11:25:19 +01:00
|
|
|
} else if (strcmp(name, "Query") == 0) {
|
2007-06-08 20:16:42 +02:00
|
|
|
if (strcmp((char*)ns->href, LASSO_DISCO_HREF) == 0) {
|
2005-01-28 11:25:19 +01:00
|
|
|
type = LASSO_REQUEST_TYPE_DISCO_QUERY;
|
2010-02-17 11:14:39 +01:00
|
|
|
} else if (strcmp((char*)ns->href, LASSO_IDWSF2_DISCOVERY_HREF) == 0) {
|
2007-06-08 20:16:42 +02:00
|
|
|
type = LASSO_REQUEST_TYPE_IDWSF2_DISCO_QUERY;
|
2005-01-28 11:25:19 +01:00
|
|
|
} else {
|
|
|
|
type = LASSO_REQUEST_TYPE_DST_QUERY;
|
2005-01-28 00:41:05 +01:00
|
|
|
}
|
2005-01-28 11:25:19 +01:00
|
|
|
} else if (strcmp(name, "Modify") == 0) {
|
2005-07-31 00:36:54 +02:00
|
|
|
if (strcmp((char*)ns->href, LASSO_DISCO_HREF) == 0) {
|
2006-11-02 11:23:13 +01:00
|
|
|
type = LASSO_REQUEST_TYPE_DISCO_MODIFY;
|
2005-01-28 11:25:19 +01:00
|
|
|
} else {
|
2008-09-12 17:06:58 +02:00
|
|
|
type = LASSO_REQUEST_TYPE_DST_MODIFY;
|
2005-01-28 00:41:05 +01:00
|
|
|
}
|
2005-03-21 17:51:33 +01:00
|
|
|
} else if (strcmp(name, "SASLRequest") == 0) {
|
|
|
|
type = LASSO_REQUEST_TYPE_SASL_REQUEST;
|
2007-04-25 16:15:25 +02:00
|
|
|
} else if (strcmp(name, "SvcMDRegister") == 0) {
|
|
|
|
type = LASSO_REQUEST_TYPE_IDWSF2_DISCO_SVCMD_REGISTER;
|
|
|
|
} else if (strcmp(name, "SvcMDAssociationAdd") == 0) {
|
|
|
|
type = LASSO_REQUEST_TYPE_IDWSF2_DISCO_SVCMD_ASSOCIATION_ADD;
|
2010-09-09 01:09:28 +02:00
|
|
|
#endif
|
2005-01-28 11:25:19 +01:00
|
|
|
} else {
|
2006-11-06 21:26:06 +01:00
|
|
|
message(G_LOG_LEVEL_WARNING, "Unknown node name : %s", name);
|
2004-10-27 11:49:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
xmlXPathFreeObject(xpathObj);
|
2008-07-22 14:09:06 +02:00
|
|
|
xmlXPathFreeContext(xpathCtx);
|
2010-02-04 01:02:24 +01:00
|
|
|
cleanup:
|
Remove use of xmlFreeDoc for lasso_release_doc
- bindings/java/wrapper_top.c, bindings/php4/lasso_php4_helper.c,
bindings/php5/wrapper_source_top.c, bindings/python/wrapper_top.c,
lasso/id-ff/identity.c, lasso/id-ff/lecp.c, lasso/id-ff/login.c,
lasso/id-ff/logout.c, lasso/id-ff/name_registration.c,
lasso/id-ff/profile.c, lasso/id-ff/provider.c, lasso/id-ff/server.c,
lasso/id-ff/session.c, lasso/id-wsf-2.0/data_service.c,
lasso/id-wsf/data_service.c, lasso/id-wsf/discovery.c,
lasso/id-wsf/wsf_profile.c, lasso/saml-2.0/ecp.c,
lasso/saml-2.0/login.c, lasso/saml-2.0/name_id_management.c,
lasso/utils.h, lasso/xml/tools.c, lasso/xml/xml.c, swig/Lasso.i:
Remove use of xmlFreeDoc. Use lasso_release_doc instead.
2008-11-04 02:58:49 +01:00
|
|
|
lasso_release_doc(doc);
|
2010-02-04 01:02:24 +01:00
|
|
|
xmlResetError(&error);
|
2004-10-27 11:49:13 +02:00
|
|
|
return type;
|
2004-07-21 18:49:42 +02:00
|
|
|
}
|
|
|
|
|
2004-10-02 23:49:38 +02:00
|
|
|
/**
|
2004-12-22 13:48:05 +01:00
|
|
|
* lasso_profile_is_liberty_query:
|
2004-10-02 23:49:38 +02:00
|
|
|
* @query: HTTP query string
|
|
|
|
*
|
|
|
|
* Tests the query string to know if the URL is called as the result of a
|
|
|
|
* Liberty redirect (action initiated elsewhere) or not.
|
|
|
|
*
|
2006-11-02 15:13:19 +01:00
|
|
|
* Return value: TRUE if Liberty query, FALSE otherwise
|
2004-10-02 23:49:38 +02:00
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
lasso_profile_is_liberty_query(const gchar *query)
|
|
|
|
{
|
2004-10-27 11:49:13 +02:00
|
|
|
/* logic is that a lasso query always has some parameters (RequestId,
|
|
|
|
* MajorVersion, MinorVersion, IssueInstant, ProviderID,
|
|
|
|
* NameIdentifier, NameQualifier, Format). If three of them are there;
|
|
|
|
* it's a lasso query, possibly broken, but a lasso query nevertheless.
|
|
|
|
*/
|
|
|
|
gchar *parameters[] = {
|
|
|
|
"RequestId=", "MajorVersion=", "MinorVersion=", "IssueInstant=",
|
|
|
|
"ProviderID=", "NameIdentifier=", "NameQualifier=", "Format=",
|
|
|
|
NULL };
|
|
|
|
gint i, n = 0;
|
|
|
|
|
|
|
|
for (i=0; parameters[i] && n < 3; i++) {
|
|
|
|
if (strstr(query, parameters[i]))
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (n == 3);
|
2004-10-02 23:49:38 +02:00
|
|
|
}
|
|
|
|
|
2004-07-21 18:49:42 +02:00
|
|
|
|
2004-06-24 18:01:48 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* public methods */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
2004-07-08 03:33:39 +02:00
|
|
|
|
2004-12-30 16:21:51 +01:00
|
|
|
/**
|
|
|
|
* lasso_profile_get_identity:
|
|
|
|
* @profile: a #LassoProfile
|
|
|
|
*
|
|
|
|
* Gets the identity bound to @profile.
|
|
|
|
*
|
2010-02-17 11:14:56 +01:00
|
|
|
* Return value:(transfer none): the identity or NULL if it none was found. The #LassoIdentity
|
2004-12-30 16:21:51 +01:00
|
|
|
* object is internally allocated and must not be freed by the caller.
|
|
|
|
**/
|
2004-07-30 15:55:32 +02:00
|
|
|
LassoIdentity*
|
2004-12-22 13:48:05 +01:00
|
|
|
lasso_profile_get_identity(LassoProfile *profile)
|
2004-07-30 15:55:32 +02:00
|
|
|
{
|
2004-12-22 13:48:05 +01:00
|
|
|
if (profile->identity && g_hash_table_size(profile->identity->federations))
|
|
|
|
return profile->identity;
|
2004-10-27 11:49:13 +02:00
|
|
|
return NULL;
|
2004-09-22 12:24:01 +02:00
|
|
|
}
|
|
|
|
|
2004-12-30 16:21:51 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* lasso_profile_get_session:
|
|
|
|
* @profile: a #LassoProfile
|
|
|
|
*
|
|
|
|
* Gets the session bound to @profile.
|
|
|
|
*
|
2010-02-17 11:14:56 +01:00
|
|
|
* Return value:(transfer none): the session or NULL if it none was found. The #LassoSession
|
2004-12-30 16:21:51 +01:00
|
|
|
* object is internally allocated and must not be freed by the caller.
|
|
|
|
**/
|
2004-07-30 15:55:32 +02:00
|
|
|
LassoSession*
|
2004-12-22 13:48:05 +01:00
|
|
|
lasso_profile_get_session(LassoProfile *profile)
|
2004-07-30 15:55:32 +02:00
|
|
|
{
|
2004-12-29 12:00:20 +01:00
|
|
|
if (profile->session == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (lasso_session_is_empty(profile->session))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return profile->session;
|
2004-07-30 15:55:32 +02:00
|
|
|
}
|
|
|
|
|
2004-12-30 16:21:51 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* lasso_profile_is_identity_dirty:
|
|
|
|
* @profile: a #LassoProfile
|
|
|
|
*
|
|
|
|
* Checks whether identity has been modified (and should therefore be saved).
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if identity has changed
|
|
|
|
**/
|
2004-07-30 15:55:32 +02:00
|
|
|
gboolean
|
2004-12-22 13:48:05 +01:00
|
|
|
lasso_profile_is_identity_dirty(LassoProfile *profile)
|
2004-07-30 15:55:32 +02:00
|
|
|
{
|
2004-12-22 13:48:05 +01:00
|
|
|
return (profile->identity && profile->identity->is_dirty);
|
2004-07-30 15:55:32 +02:00
|
|
|
}
|
|
|
|
|
2004-12-30 16:21:51 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* lasso_profile_is_session_dirty:
|
|
|
|
* @profile: a #LassoProfile
|
|
|
|
*
|
|
|
|
* Checks whether session has been modified (and should therefore be saved).
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if session has changed
|
|
|
|
**/
|
2004-07-30 15:55:32 +02:00
|
|
|
gboolean
|
2004-12-22 13:48:05 +01:00
|
|
|
lasso_profile_is_session_dirty(LassoProfile *profile)
|
2004-07-30 15:55:32 +02:00
|
|
|
{
|
2009-11-30 23:58:59 +01:00
|
|
|
return LASSO_IS_SESSION(profile->session) && lasso_session_is_dirty(profile->session);
|
2004-06-24 18:01:48 +02:00
|
|
|
}
|
|
|
|
|
2004-12-30 16:21:51 +01:00
|
|
|
|
2004-06-25 18:44:26 +02:00
|
|
|
void
|
2004-12-22 13:48:05 +01:00
|
|
|
lasso_profile_set_response_status(LassoProfile *profile, const char *statusCodeValue)
|
2004-06-25 18:44:26 +02:00
|
|
|
{
|
2004-10-27 11:49:13 +02:00
|
|
|
LassoSamlpStatus *status;
|
|
|
|
|
2004-12-17 14:57:47 +01:00
|
|
|
/* protocols-schema 1.2 (errata 2.0), page 9
|
|
|
|
*
|
|
|
|
* 3.1.9. Response Status Codes
|
|
|
|
*
|
|
|
|
* All Liberty response messages use <samlp: StatusCode> elements to
|
|
|
|
* indicate the status of a corresponding request. Responders MUST
|
|
|
|
* comply with the rules governing <samlp: StatusCode> elements
|
|
|
|
* specified in [SAMLCore11] regarding the use of nested second-, or
|
|
|
|
* lower-level response codes to provide specific information relating
|
|
|
|
* to particular errors. A number of status codes are defined within
|
|
|
|
* the Liberty namespace for use with this specification.
|
|
|
|
*/
|
|
|
|
|
2004-10-27 11:49:13 +02:00
|
|
|
status = lasso_samlp_status_new();
|
|
|
|
status->StatusCode = lasso_samlp_status_code_new();
|
2004-12-17 14:57:47 +01:00
|
|
|
|
2004-12-20 13:38:41 +01:00
|
|
|
if (strncmp(statusCodeValue, "samlp:", 6) == 0) {
|
2004-12-17 14:57:47 +01:00
|
|
|
status->StatusCode->Value = g_strdup(statusCodeValue);
|
|
|
|
} else {
|
|
|
|
status->StatusCode->Value = g_strdup(LASSO_SAML_STATUS_CODE_RESPONDER);
|
|
|
|
status->StatusCode->StatusCode = lasso_samlp_status_code_new();
|
|
|
|
status->StatusCode->StatusCode->Value = g_strdup(statusCodeValue);
|
|
|
|
}
|
2004-10-27 11:49:13 +02:00
|
|
|
|
2004-12-22 13:48:05 +01:00
|
|
|
if (LASSO_IS_SAMLP_RESPONSE(profile->response)) {
|
|
|
|
LassoSamlpResponse *response = LASSO_SAMLP_RESPONSE(profile->response);
|
2009-04-30 16:58:20 +02:00
|
|
|
lasso_assign_new_gobject(response->Status, status);
|
2004-10-27 11:49:13 +02:00
|
|
|
return;
|
|
|
|
}
|
2004-12-22 13:48:05 +01:00
|
|
|
if (LASSO_IS_LIB_STATUS_RESPONSE(profile->response)) {
|
|
|
|
LassoLibStatusResponse *response = LASSO_LIB_STATUS_RESPONSE(profile->response);
|
2009-04-30 16:58:20 +02:00
|
|
|
lasso_assign_new_gobject(response->Status, status);
|
2004-10-27 11:49:13 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
message(G_LOG_LEVEL_CRITICAL, "Failed to set status");
|
|
|
|
g_assert_not_reached();
|
2008-09-12 17:06:58 +02:00
|
|
|
}
|
2004-06-25 18:44:26 +02:00
|
|
|
|
2007-01-05 14:40:07 +01:00
|
|
|
void
|
|
|
|
lasso_profile_clean_msg_info(LassoProfile *profile)
|
|
|
|
{
|
2009-04-30 16:58:20 +02:00
|
|
|
lasso_release_string(profile->msg_url);
|
|
|
|
lasso_release_string(profile->msg_body);
|
2007-01-05 14:40:07 +01:00
|
|
|
}
|
|
|
|
|
2004-12-30 16:21:51 +01:00
|
|
|
/**
|
|
|
|
* lasso_profile_set_identity_from_dump:
|
|
|
|
* @profile: a #LassoProfile
|
|
|
|
* @dump: XML identity dump
|
|
|
|
*
|
|
|
|
* Builds a new #LassoIdentity object from XML dump and binds it to @profile.
|
|
|
|
*
|
|
|
|
* Return value: 0 on success; or a negative value otherwise.
|
|
|
|
**/
|
2004-07-26 19:38:32 +02:00
|
|
|
gint
|
2004-12-22 13:48:05 +01:00
|
|
|
lasso_profile_set_identity_from_dump(LassoProfile *profile, const gchar *dump)
|
2004-07-26 19:38:32 +02:00
|
|
|
{
|
2004-10-27 11:49:13 +02:00
|
|
|
g_return_val_if_fail(dump != NULL, LASSO_PARAM_ERROR_INVALID_VALUE);
|
2004-07-30 00:25:17 +02:00
|
|
|
|
2009-04-30 16:58:20 +02:00
|
|
|
lasso_assign_new_gobject(profile->identity, lasso_identity_new_from_dump(dump));
|
|
|
|
if (profile->identity == NULL) {
|
2004-12-16 15:04:43 +01:00
|
|
|
return critical_error(LASSO_PROFILE_ERROR_BAD_IDENTITY_DUMP);
|
2009-04-30 16:58:20 +02:00
|
|
|
}
|
2004-07-30 00:25:17 +02:00
|
|
|
|
2004-10-27 11:49:13 +02:00
|
|
|
return 0;
|
2004-07-30 00:25:17 +02:00
|
|
|
}
|
|
|
|
|
2004-12-30 16:21:51 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* lasso_profile_set_session_from_dump:
|
|
|
|
* @profile: a #LassoProfile
|
|
|
|
* @dump: XML session dump
|
|
|
|
*
|
|
|
|
* Builds a new #LassoSession object from XML dump and binds it to @profile.
|
|
|
|
*
|
|
|
|
* Return value: 0 on success; or a negative value otherwise.
|
|
|
|
**/
|
2004-07-30 00:25:17 +02:00
|
|
|
gint
|
2006-11-23 18:44:26 +01:00
|
|
|
lasso_profile_set_session_from_dump(LassoProfile *profile, const gchar *dump)
|
2004-07-30 00:25:17 +02:00
|
|
|
{
|
2004-10-27 11:49:13 +02:00
|
|
|
g_return_val_if_fail(dump != NULL, LASSO_PARAM_ERROR_INVALID_VALUE);
|
2004-09-27 16:52:34 +02:00
|
|
|
|
2009-04-30 16:58:20 +02:00
|
|
|
lasso_assign_new_gobject(profile->session, lasso_session_new_from_dump(dump));
|
2004-12-22 13:48:05 +01:00
|
|
|
if (profile->session == NULL)
|
2004-12-16 15:04:43 +01:00
|
|
|
return critical_error(LASSO_PROFILE_ERROR_BAD_SESSION_DUMP);
|
2008-09-12 17:06:58 +02:00
|
|
|
|
2006-11-23 18:44:26 +01:00
|
|
|
IF_SAML2(profile) {
|
|
|
|
lasso_saml20_profile_set_session_from_dump(profile);
|
|
|
|
}
|
|
|
|
|
2004-11-25 23:51:39 +01:00
|
|
|
return 0;
|
2004-07-30 00:25:17 +02:00
|
|
|
}
|
|
|
|
|
2010-02-17 11:14:59 +01:00
|
|
|
/**
|
|
|
|
* lasso_profile_get_artifact:
|
|
|
|
* @profile: a #LassoProfile object
|
|
|
|
*
|
|
|
|
* Return the artifact token
|
|
|
|
*
|
|
|
|
* Return value:(transfer full)(allow-none): a newly allocated string or NULL.
|
|
|
|
*/
|
2005-11-20 16:38:19 +01:00
|
|
|
char*
|
|
|
|
lasso_profile_get_artifact(LassoProfile *profile)
|
|
|
|
{
|
|
|
|
return g_strdup(profile->private_data->artifact);
|
|
|
|
}
|
|
|
|
|
2010-02-17 11:14:59 +01:00
|
|
|
/**
|
|
|
|
* lasso_profile_get_artifact_message:
|
|
|
|
* @profile: a #LassoProfile object
|
|
|
|
*
|
|
|
|
* Return the artifact message.
|
|
|
|
*
|
|
|
|
* Return value:(transfer full)(allow-none): a newly allocated string or NULL
|
|
|
|
*/
|
2005-11-20 16:38:19 +01:00
|
|
|
char*
|
|
|
|
lasso_profile_get_artifact_message(LassoProfile *profile)
|
|
|
|
{
|
|
|
|
return g_strdup(profile->private_data->artifact_message);
|
|
|
|
}
|
|
|
|
|
2010-02-17 11:14:59 +01:00
|
|
|
/**
|
|
|
|
* lasso_profile_set_artifact_message:
|
|
|
|
* @profile: a #LassoProfile object
|
|
|
|
* @message: the artifact message content
|
|
|
|
*
|
|
|
|
* Set @message as the content for the ArtifactResolve response.
|
|
|
|
*
|
|
|
|
*/
|
2005-11-20 16:38:19 +01:00
|
|
|
void
|
2010-02-17 11:14:59 +01:00
|
|
|
lasso_profile_set_artifact_message(LassoProfile *profile, const char *message)
|
2005-11-20 16:38:19 +01:00
|
|
|
{
|
2010-02-17 11:14:59 +01:00
|
|
|
if (! LASSO_IS_PROFILE(profile)) {
|
|
|
|
message(G_LOG_LEVEL_CRITICAL, "set_artifact_message called on something not a" \
|
|
|
|
"LassoProfile object: %p", profile);
|
|
|
|
return;
|
|
|
|
}
|
2009-04-30 16:58:20 +02:00
|
|
|
lasso_assign_string(profile->private_data->artifact_message, message);
|
2005-11-20 16:38:19 +01:00
|
|
|
}
|
|
|
|
|
2009-04-27 10:19:30 +02:00
|
|
|
/**
|
|
|
|
* lasso_profile_get_server:
|
|
|
|
* @profile: a #LassoProfile object
|
|
|
|
*
|
|
|
|
* Return the #LassoServer linked to this profile object. A profile object should always contains
|
|
|
|
* one. It allows to find metadatas of other providers and to know our own metadatas.
|
|
|
|
*
|
2010-04-16 17:37:17 +02:00
|
|
|
* Return value: (transfer none): a #LassoServer or NULL if profile is not a #LassoProfile or no
|
|
|
|
* #LassoServer object was setup at the creation of this profile.
|
2009-04-27 10:19:30 +02:00
|
|
|
*/
|
|
|
|
LassoServer*
|
|
|
|
lasso_profile_get_server(LassoProfile *profile)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(LASSO_IS_PROFILE(profile), NULL);
|
|
|
|
|
|
|
|
if (profile->server) {
|
|
|
|
if (LASSO_IS_SERVER(profile->server)) {
|
|
|
|
return profile->server;
|
|
|
|
} else {
|
|
|
|
message(G_LOG_LEVEL_WARNING, "profile->server contains a non LassoServer object");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-07-30 00:25:17 +02:00
|
|
|
|
2015-05-28 19:39:20 +02:00
|
|
|
/**
|
|
|
|
* lasso_profile_get_message_id:
|
|
|
|
* @profile: a #LassoProfile object
|
|
|
|
*
|
|
|
|
* Return the messge ID.
|
|
|
|
*
|
|
|
|
* Return value:(transfer full)(allow-none): a newly allocated string or NULL
|
|
|
|
*/
|
|
|
|
char*
|
|
|
|
lasso_profile_get_message_id(LassoProfile *profile)
|
|
|
|
{
|
|
|
|
return g_strdup(profile->private_data->message_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* lasso_profile_set_message_id:
|
|
|
|
* @profile: a #LassoProfile object
|
|
|
|
* @message_id: the message ID
|
|
|
|
*
|
|
|
|
* Set @message_id for the current conversation
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
lasso_profile_set_message_id(LassoProfile *profile, const char *message_id)
|
|
|
|
{
|
|
|
|
if (! LASSO_IS_PROFILE(profile)) {
|
|
|
|
message(G_LOG_LEVEL_CRITICAL, "set_message_id called on something not a" \
|
|
|
|
"LassoProfile object: %p", profile);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
lasso_assign_string(profile->private_data->message_id, message_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* lasso_profile_get_idp_list:
|
|
|
|
* @profile: a #LassoProfile object
|
|
|
|
*
|
|
|
|
* Return the messge ID.
|
|
|
|
*
|
|
|
|
* Return value: a #LassoNode, when using SAML 2.0 a #LassoSamlp2IDPList,
|
|
|
|
* when using ID-FF a #LassoLibIDPList.
|
|
|
|
*/
|
|
|
|
LassoNode*
|
|
|
|
lasso_profile_get_idp_list(LassoProfile *profile)
|
|
|
|
{
|
|
|
|
return profile->private_data->idp_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* lasso_profile_set_idp_list:
|
|
|
|
* @profile: a #LassoProfile object
|
|
|
|
* @idp_list: a #LassoNode, when using SAML 2.0 a #LassoSamlp2IDPList,
|
|
|
|
* when using ID-FF a #LassoLibIDPList.
|
|
|
|
*
|
|
|
|
* Set @idp_list for the current conversation
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
lasso_profile_set_idp_list(LassoProfile *profile, const LassoNode *idp_list)
|
|
|
|
{
|
|
|
|
if (! LASSO_IS_PROFILE(profile)) {
|
|
|
|
message(G_LOG_LEVEL_CRITICAL, "set_idp_list called on something not a" \
|
|
|
|
"LassoProfile object: %p", profile);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
lasso_assign_gobject(profile->private_data->idp_list, idp_list);
|
|
|
|
}
|
|
|
|
|
2004-10-27 11:49:13 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* private methods */
|
|
|
|
/*****************************************************************************/
|
2004-07-30 00:25:17 +02:00
|
|
|
|
2004-12-09 23:32:13 +01:00
|
|
|
static struct XmlSnippet schema_snippets[] = {
|
2009-01-24 10:33:40 +01:00
|
|
|
{ "Request", SNIPPET_NODE_IN_CHILD, G_STRUCT_OFFSET(LassoProfile, request), NULL, NULL, NULL},
|
|
|
|
{ "Response", SNIPPET_NODE_IN_CHILD, G_STRUCT_OFFSET(LassoProfile, response), NULL, NULL, NULL},
|
2004-12-18 19:36:54 +01:00
|
|
|
{ "NameIdentifier", SNIPPET_NODE_IN_CHILD,
|
2009-01-24 10:33:40 +01:00
|
|
|
G_STRUCT_OFFSET(LassoProfile, nameIdentifier), NULL, NULL, NULL},
|
2010-04-16 17:37:17 +02:00
|
|
|
{ "RemoteProviderID", SNIPPET_CONTENT, G_STRUCT_OFFSET(LassoProfile, remote_providerID),
|
|
|
|
NULL, NULL, NULL},
|
2009-01-24 10:33:40 +01:00
|
|
|
{ "MsgUrl", SNIPPET_CONTENT, G_STRUCT_OFFSET(LassoProfile, msg_url), NULL, NULL, NULL},
|
|
|
|
{ "MsgBody", SNIPPET_CONTENT, G_STRUCT_OFFSET(LassoProfile, msg_body), NULL, NULL, NULL},
|
2010-04-16 17:37:17 +02:00
|
|
|
{ "MsgRelayState", SNIPPET_CONTENT, G_STRUCT_OFFSET(LassoProfile, msg_relayState), NULL,
|
|
|
|
NULL, NULL},
|
2006-11-10 16:12:18 +01:00
|
|
|
{ "HttpRequestMethod", SNIPPET_CONTENT | SNIPPET_INTEGER,
|
2009-01-24 10:33:40 +01:00
|
|
|
G_STRUCT_OFFSET(LassoProfile, http_request_method), NULL, NULL, NULL},
|
2011-12-16 11:12:58 +01:00
|
|
|
{ "Artifact", SNIPPET_CONTENT | SNIPPET_PRIVATE, G_STRUCT_OFFSET(LassoProfilePrivate,
|
|
|
|
artifact), NULL, NULL, NULL },
|
|
|
|
{ "ArtifactMessage", SNIPPET_CONTENT | SNIPPET_PRIVATE, G_STRUCT_OFFSET(LassoProfilePrivate,
|
|
|
|
artifact_message), NULL, NULL, NULL },
|
2009-01-24 10:33:40 +01:00
|
|
|
{NULL, 0, 0, NULL, NULL, NULL}
|
2004-12-09 23:32:13 +01:00
|
|
|
};
|
2004-11-09 10:08:47 +01:00
|
|
|
|
2004-12-09 23:32:13 +01:00
|
|
|
static LassoNodeClass *parent_class = NULL;
|
2004-10-27 11:49:13 +02:00
|
|
|
|
2010-01-12 16:39:45 +01:00
|
|
|
/**
|
|
|
|
* lasso_profile_set_signature_hint:
|
|
|
|
* @profile: a #LassoProfile object
|
|
|
|
* @signature_hint: wheter next produced messages should be signed or not (or let Lasso choose from
|
|
|
|
* implicit information).
|
|
|
|
*
|
|
|
|
* By default each profile will choose to sign or not its messages, this method allow to force or
|
|
|
|
* forbid the signature of messages, on a per transaction basis.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
lasso_profile_set_signature_hint(LassoProfile *profile, LassoProfileSignatureHint signature_hint)
|
|
|
|
{
|
2014-06-09 21:29:24 +02:00
|
|
|
if (! LASSO_IS_PROFILE(profile) || ! profile->private_data)
|
2010-01-12 16:39:45 +01:00
|
|
|
return;
|
|
|
|
profile->private_data->signature_hint = signature_hint;
|
|
|
|
}
|
2006-11-13 12:12:59 +01:00
|
|
|
|
2010-01-12 16:39:45 +01:00
|
|
|
/**
|
|
|
|
* lasso_profile_get_signature_hint:
|
|
|
|
* @profile: a #LassoProfile object
|
|
|
|
*
|
|
|
|
* Return the value of the signature hint attribute (see lasso_profile_set_signature_hint()).
|
|
|
|
*
|
|
|
|
* Return value: a value in the enum type #LassoProfileSignatureHint.
|
|
|
|
*/
|
|
|
|
LassoProfileSignatureHint
|
|
|
|
lasso_profile_get_signature_hint(LassoProfile *profile)
|
|
|
|
{
|
2010-04-16 17:37:17 +02:00
|
|
|
LassoProfileSignatureVerifyHint signature_verify_hint;
|
2014-06-09 21:29:24 +02:00
|
|
|
if (! LASSO_IS_PROFILE(profile) || ! profile->private_data)
|
2010-01-12 16:39:45 +01:00
|
|
|
return LASSO_PROFILE_SIGNATURE_HINT_MAYBE;
|
2010-04-16 17:37:17 +02:00
|
|
|
signature_verify_hint = profile->private_data->signature_verify_hint;
|
|
|
|
if (signature_verify_hint >= LASSO_PROFILE_SIGNATURE_VERIFY_HINT_LAST) {
|
|
|
|
message(G_LOG_LEVEL_WARNING, "%u is an invalid signature verify hint",
|
|
|
|
signature_verify_hint);
|
|
|
|
return LASSO_PROFILE_SIGNATURE_HINT_MAYBE;
|
|
|
|
}
|
2010-01-12 16:39:45 +01:00
|
|
|
return profile->private_data->signature_hint;
|
|
|
|
}
|
2006-11-13 12:12:59 +01:00
|
|
|
|
2010-03-27 17:51:34 +01:00
|
|
|
/**
|
|
|
|
* lasso_profile_set_signature_verify_hint:
|
|
|
|
* @profile: a #LassoProfile object
|
|
|
|
* @signature_verify_hint: whether next received message signatures should be checked or not (or let
|
|
|
|
* Lasso choose from implicit information).
|
|
|
|
*
|
2010-04-16 17:37:17 +02:00
|
|
|
* By default each profile will choose to verify or not its messages, this method allow to force or
|
2010-03-27 17:51:34 +01:00
|
|
|
* forbid the signature of messages, on a per transaction basis.
|
|
|
|
*/
|
|
|
|
void
|
2010-04-16 17:37:17 +02:00
|
|
|
lasso_profile_set_signature_verify_hint(LassoProfile *profile,
|
|
|
|
LassoProfileSignatureVerifyHint signature_verify_hint)
|
2010-03-27 17:51:34 +01:00
|
|
|
{
|
2014-06-09 21:29:24 +02:00
|
|
|
if (! LASSO_IS_PROFILE(profile) || ! profile->private_data)
|
2010-03-27 17:51:34 +01:00
|
|
|
return;
|
2010-04-16 17:37:17 +02:00
|
|
|
if (signature_verify_hint >= LASSO_PROFILE_SIGNATURE_VERIFY_HINT_LAST) {
|
|
|
|
message(G_LOG_LEVEL_WARNING, "%i is an invalid argument for " __FUNCTION__,
|
|
|
|
signature_verify_hint);
|
|
|
|
return;
|
|
|
|
}
|
2010-03-27 17:51:34 +01:00
|
|
|
profile->private_data->signature_verify_hint = signature_verify_hint;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* lasso_profile_get_signature_verify_hint:
|
|
|
|
* @profile: a #LassoProfile object
|
|
|
|
*
|
|
|
|
* Return the value of the signature verify hint attribute (see
|
|
|
|
* lasso_profile_set_signature_verify_hint()).
|
|
|
|
*
|
|
|
|
* Return value: a value in the enum type #LassoProfileSignatureVerifyHint.
|
|
|
|
*/
|
|
|
|
LassoProfileSignatureVerifyHint
|
|
|
|
lasso_profile_get_signature_verify_hint(LassoProfile *profile)
|
|
|
|
{
|
2014-06-09 21:29:24 +02:00
|
|
|
if (! LASSO_IS_PROFILE(profile) || ! profile->private_data)
|
2010-03-27 17:51:34 +01:00
|
|
|
return LASSO_PROFILE_SIGNATURE_HINT_MAYBE;
|
|
|
|
return profile->private_data->signature_verify_hint;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-02 12:57:53 +01:00
|
|
|
/**
|
|
|
|
* lasso_profile_set_soap_fault_response:
|
|
|
|
* @profile: a #LassoProfile object
|
|
|
|
* @faultcode: the code for the SOAP fault
|
|
|
|
* @faultstring:(allow-none): the description for the SOAP fault
|
|
|
|
* @details:(element-type LassoNode)(allow-none): a list of nodes to add as details
|
|
|
|
*
|
|
|
|
* Set the response to a SOAP fault, using @faultcode, @faultstring, and @details to initialize it.
|
|
|
|
*
|
|
|
|
* Return value: 0 if successful, an error code otherwise.
|
|
|
|
*/
|
|
|
|
gint
|
|
|
|
lasso_profile_set_soap_fault_response(LassoProfile *profile, const char *faultcode,
|
|
|
|
const char *faultstring, GList *details)
|
|
|
|
{
|
|
|
|
LassoSoapFault *fault;
|
|
|
|
|
|
|
|
if (! LASSO_IS_SOAP_FAULT(profile->response)) {
|
|
|
|
lasso_release_gobject(profile->response);
|
|
|
|
profile->response = (LassoNode*)lasso_soap_fault_new();
|
|
|
|
}
|
|
|
|
fault = (LassoSoapFault*)profile->response;
|
|
|
|
lasso_assign_string(fault->faultcode, faultcode);
|
|
|
|
lasso_assign_string(fault->faultstring, faultstring);
|
|
|
|
if (details) {
|
|
|
|
if (! fault->Detail) {
|
|
|
|
fault->Detail = lasso_soap_detail_new();
|
|
|
|
}
|
|
|
|
lasso_assign_list_of_gobjects(fault->Detail->any, details);
|
|
|
|
} else {
|
|
|
|
lasso_release_gobject(fault->Detail);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-27 17:51:47 +01:00
|
|
|
/**
|
|
|
|
* lasso_profile_sso_role_with:
|
|
|
|
* @profile: a #LassoProfile object
|
|
|
|
* @remote_provider_id: the identifier of a provider
|
|
|
|
*
|
|
|
|
* Returns whether the current provider is a service provider relatively to another provider. It
|
|
|
|
* uses the #LassoProfile.identity to find if a federation qualifier by the given provider exists or
|
|
|
|
* the reverse.
|
|
|
|
*
|
|
|
|
* Return value: #LASSO_PROVIDER_ROLE_NONE if nothing can be said, #LASSO_PROVIDER_ROLE_SP if a
|
|
|
|
* federation qualifier by @remote_provider_id exists or #LASSO_PROVIDER_ROLE_IDP if a federation
|
2011-12-22 18:21:12 +01:00
|
|
|
* qualifier by our own #LassoProvider.ProviderID exists.
|
2010-03-27 17:51:47 +01:00
|
|
|
*/
|
|
|
|
LassoProviderRole lasso_profile_sso_role_with(LassoProfile *profile, const char *remote_provider_id)
|
|
|
|
{
|
|
|
|
LassoFederation *federation = NULL;
|
|
|
|
const char *name_qualifier = NULL;
|
|
|
|
const char *provider_id = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail(LASSO_IS_PROFILE(profile) && remote_provider_id,
|
|
|
|
LASSO_PROVIDER_ROLE_NONE);
|
|
|
|
|
|
|
|
if (profile->server) {
|
|
|
|
provider_id = profile->server->parent.ProviderID;
|
|
|
|
}
|
|
|
|
|
|
|
|
federation = lasso_identity_get_federation(profile->identity, remote_provider_id);
|
|
|
|
if (! federation)
|
|
|
|
return LASSO_PROVIDER_ROLE_NONE;
|
|
|
|
|
|
|
|
/* coherency check */
|
2010-10-01 12:33:24 +02:00
|
|
|
g_return_val_if_fail(lasso_strisequal(federation->remote_providerID,remote_provider_id),
|
2010-03-27 17:51:47 +01:00
|
|
|
LASSO_PROVIDER_ROLE_NONE);
|
|
|
|
|
|
|
|
if (LASSO_IS_SAML2_NAME_ID(federation->local_nameIdentifier)) {
|
|
|
|
LassoSaml2NameID *name_id = (LassoSaml2NameID*)federation->local_nameIdentifier;
|
|
|
|
name_qualifier = name_id->NameQualifier;
|
|
|
|
} else if (LASSO_IS_SAML_NAME_IDENTIFIER(federation->local_nameIdentifier)) {
|
|
|
|
LassoSamlNameIdentifier *name_id;
|
|
|
|
|
|
|
|
name_id = (LassoSamlNameIdentifier*)federation->local_nameIdentifier;
|
|
|
|
name_qualifier = name_id->NameQualifier;
|
|
|
|
} else {
|
|
|
|
message(G_LOG_LEVEL_WARNING, "a federation without a NameID was found");
|
|
|
|
return LASSO_PROVIDER_ROLE_NONE;
|
|
|
|
}
|
2010-10-01 12:33:24 +02:00
|
|
|
if (lasso_strisequal(remote_provider_id,name_qualifier)) {
|
2010-03-27 17:51:47 +01:00
|
|
|
return LASSO_PROVIDER_ROLE_SP;
|
2010-10-01 12:33:24 +02:00
|
|
|
} else if (lasso_strisequal(provider_id,name_qualifier)) {
|
2010-03-27 17:51:47 +01:00
|
|
|
return LASSO_PROVIDER_ROLE_IDP;
|
|
|
|
}
|
|
|
|
return LASSO_PROVIDER_ROLE_NONE;
|
|
|
|
}
|
|
|
|
|
2010-05-01 07:40:31 +02:00
|
|
|
/**
|
|
|
|
* lasso_profile_get_signature_status:
|
|
|
|
* @profile: a #LassoProfile object
|
|
|
|
*
|
|
|
|
* Returns the signature status from the last parsed message.
|
|
|
|
*
|
|
|
|
* Return value: 0 if no error from signature checking occurred, an error code otherwise.
|
|
|
|
*/
|
|
|
|
gint
|
|
|
|
lasso_profile_get_signature_status(LassoProfile *profile)
|
|
|
|
{
|
|
|
|
lasso_bad_param(PROFILE, profile);
|
|
|
|
|
|
|
|
return profile->signature_status;
|
|
|
|
}
|
|
|
|
|
2014-03-31 10:54:27 +02:00
|
|
|
static xmlChar *
|
|
|
|
extract_issuer(xmlTextReader *reader)
|
|
|
|
{
|
|
|
|
const xmlChar *name;
|
|
|
|
const xmlChar *ns_uri;
|
|
|
|
xmlNode *node;
|
|
|
|
|
|
|
|
name = xmlTextReaderConstLocalName(reader);
|
|
|
|
ns_uri = xmlTextReaderConstNamespaceUri(reader);
|
|
|
|
|
|
|
|
if (strcmp((const char*)name, "Issuer"))
|
|
|
|
return NULL;
|
|
|
|
if (strcmp((const char*)ns_uri, LASSO_SAML2_ASSERTION_HREF))
|
|
|
|
return NULL;
|
|
|
|
node = xmlTextReaderExpand(reader);
|
|
|
|
return xmlNodeGetContent(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* lasso_profile_get_issuer:
|
|
|
|
* @message: the HTTP query, POST content or SOAP message
|
|
|
|
*
|
|
|
|
* Extract the issuer of a message.
|
|
|
|
*
|
|
|
|
* Return value:(transfer full): Returns the issuer of the given message.
|
|
|
|
*/
|
|
|
|
char*
|
|
|
|
lasso_profile_get_issuer(const char *message)
|
|
|
|
{
|
|
|
|
xmlTextReader *reader;
|
|
|
|
char *result = NULL;
|
|
|
|
int count = 0, ret;
|
|
|
|
xmlChar *xml_result = NULL;
|
|
|
|
xmlChar *to_free = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
reader = lasso_xmltextreader_from_message(message, &to_free);
|
|
|
|
if (! reader)
|
|
|
|
goto cleanup;
|
|
|
|
ret = xmlTextReaderRead(reader);
|
|
|
|
while (ret == 1) {
|
|
|
|
int node_type = xmlTextReaderNodeType(reader);
|
|
|
|
if (node_type == 1) {
|
|
|
|
count += 1;
|
|
|
|
xml_result = extract_issuer(reader);
|
|
|
|
if (xml_result)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (count == 3) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ret = xmlTextReaderRead(reader);
|
|
|
|
}
|
|
|
|
if (! xml_result)
|
|
|
|
goto cleanup;
|
|
|
|
result = g_strdup((char *)xml_result);
|
|
|
|
cleanup:
|
|
|
|
if (xml_result)
|
|
|
|
lasso_release_xml_string(xml_result);
|
|
|
|
if (reader)
|
|
|
|
xmlFreeTextReader(reader);
|
|
|
|
if (to_free)
|
|
|
|
lasso_release_xml_string(to_free);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* lasso_profile_get_request_id:
|
|
|
|
* @message: the HTTP query, POST content or SOAP message
|
|
|
|
*
|
|
|
|
* Extract the issuer of a message.
|
|
|
|
*
|
|
|
|
* Return value:(transfer full): Returns the issuer of the given message.
|
|
|
|
*/
|
|
|
|
char*
|
|
|
|
lasso_profile_get_in_response_to(const char *message)
|
|
|
|
{
|
|
|
|
xmlTextReader *reader;
|
|
|
|
char *result = NULL;
|
|
|
|
int ret;
|
|
|
|
int node_type = 0;
|
|
|
|
xmlChar *xml_result = NULL;
|
|
|
|
xmlChar *to_free = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
reader = lasso_xmltextreader_from_message(message, &to_free);
|
|
|
|
if (! reader)
|
|
|
|
goto cleanup;
|
|
|
|
ret = xmlTextReaderRead(reader);
|
|
|
|
while (ret == 1) {
|
|
|
|
node_type = xmlTextReaderNodeType(reader);
|
|
|
|
if (node_type == 1) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ret = xmlTextReaderRead(reader);
|
|
|
|
}
|
|
|
|
if (node_type != 1)
|
|
|
|
goto cleanup;
|
|
|
|
xml_result = xmlTextReaderGetAttribute(reader, BAD_CAST "InResponseTo");
|
|
|
|
if (! xml_result)
|
|
|
|
goto cleanup;
|
|
|
|
result = g_strdup((char*)xml_result);
|
|
|
|
cleanup:
|
|
|
|
if (reader)
|
|
|
|
xmlFreeTextReader(reader);
|
|
|
|
if (xml_result)
|
|
|
|
lasso_release_xml_string(xml_result);
|
|
|
|
if (to_free)
|
|
|
|
lasso_release_xml_string(to_free);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2004-07-13 01:25:42 +02:00
|
|
|
/*****************************************************************************/
|
2004-12-10 10:55:27 +01:00
|
|
|
/* overridden parent class methods */
|
2004-07-13 01:25:42 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
static void
|
2004-10-27 11:49:13 +02:00
|
|
|
dispose(GObject *object)
|
2004-07-13 01:25:42 +02:00
|
|
|
{
|
2004-10-27 11:49:13 +02:00
|
|
|
LassoProfile *profile = LASSO_PROFILE(object);
|
2004-07-13 01:25:42 +02:00
|
|
|
|
2004-11-22 17:10:41 +01:00
|
|
|
if (profile->private_data->dispose_has_run) {
|
2004-10-27 11:49:13 +02:00
|
|
|
return;
|
|
|
|
}
|
2004-11-22 17:10:41 +01:00
|
|
|
profile->private_data->dispose_has_run = TRUE;
|
2004-07-13 12:36:32 +02:00
|
|
|
|
2009-03-27 16:06:37 +01:00
|
|
|
|
|
|
|
lasso_mem_debug("LassoProfile", "Server", profile->server);
|
2009-04-30 16:58:20 +02:00
|
|
|
lasso_release_gobject(profile->server);
|
2008-05-20 20:34:09 +02:00
|
|
|
|
2009-03-27 16:06:37 +01:00
|
|
|
lasso_mem_debug("LassoProfile", "Identity", profile->identity);
|
2009-04-30 16:58:20 +02:00
|
|
|
lasso_release_gobject(profile->identity);
|
2008-05-20 20:34:09 +02:00
|
|
|
|
2009-03-27 16:06:37 +01:00
|
|
|
lasso_mem_debug("LassoProfile", "Session", profile->session);
|
2009-04-30 16:58:20 +02:00
|
|
|
lasso_release_gobject(profile->session);
|
2008-05-20 20:34:09 +02:00
|
|
|
|
2009-04-30 16:58:20 +02:00
|
|
|
lasso_release_string(profile->private_data->artifact);
|
|
|
|
lasso_release_string(profile->private_data->artifact_message);
|
2004-07-13 12:36:32 +02:00
|
|
|
|
2004-10-27 11:49:13 +02:00
|
|
|
G_OBJECT_CLASS(parent_class)->dispose(G_OBJECT(profile));
|
2015-11-24 19:19:18 +01:00
|
|
|
|
2015-11-25 03:08:58 +01:00
|
|
|
lasso_release_gobject(profile->private_data->idp_list);
|
2015-11-24 19:19:18 +01:00
|
|
|
lasso_release_string(profile->private_data->message_id);
|
2004-07-13 01:25:42 +02:00
|
|
|
}
|
|
|
|
|
2004-06-24 18:01:48 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* instance and class init functions */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
static void
|
2004-10-27 11:49:13 +02:00
|
|
|
instance_init(LassoProfile *profile)
|
2004-06-24 18:01:48 +02:00
|
|
|
{
|
2011-12-16 11:12:58 +01:00
|
|
|
profile->private_data = LASSO_PROFILE_GET_PRIVATE(profile);
|
2004-11-22 17:10:41 +01:00
|
|
|
profile->private_data->dispose_has_run = FALSE;
|
2005-11-20 16:38:19 +01:00
|
|
|
profile->private_data->artifact = NULL;
|
|
|
|
profile->private_data->artifact_message = NULL;
|
2010-01-12 16:39:45 +01:00
|
|
|
profile->private_data->signature_hint = LASSO_PROFILE_SIGNATURE_HINT_MAYBE;
|
2015-05-28 19:39:20 +02:00
|
|
|
profile->private_data->message_id = NULL;
|
|
|
|
profile->private_data->idp_list = NULL;
|
2004-10-27 11:49:13 +02:00
|
|
|
|
|
|
|
profile->server = NULL;
|
|
|
|
profile->request = NULL;
|
|
|
|
profile->response = NULL;
|
|
|
|
profile->nameIdentifier = NULL;
|
|
|
|
profile->remote_providerID = NULL;
|
|
|
|
profile->msg_url = NULL;
|
|
|
|
profile->msg_body = NULL;
|
|
|
|
profile->msg_relayState = NULL;
|
|
|
|
|
|
|
|
profile->identity = NULL;
|
|
|
|
profile->session = NULL;
|
|
|
|
profile->signature_status = 0;
|
2004-06-24 18:01:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-10-27 11:49:13 +02:00
|
|
|
class_init(LassoProfileClass *klass)
|
2004-06-24 18:01:48 +02:00
|
|
|
{
|
2004-12-09 23:32:13 +01:00
|
|
|
LassoNodeClass *nclass = LASSO_NODE_CLASS(klass);
|
2004-06-24 18:01:48 +02:00
|
|
|
|
2004-12-09 23:32:13 +01:00
|
|
|
parent_class = g_type_class_peek_parent(klass);
|
|
|
|
nclass->node_data = g_new0(LassoNodeClassData, 1);
|
|
|
|
lasso_node_class_set_nodename(nclass, "Profile");
|
|
|
|
lasso_node_class_set_ns(nclass, LASSO_LASSO_HREF, LASSO_LASSO_PREFIX);
|
|
|
|
lasso_node_class_add_snippets(nclass, schema_snippets);
|
2011-12-16 11:12:58 +01:00
|
|
|
g_type_class_add_private(klass, sizeof(LassoProfilePrivate));
|
2004-06-25 18:44:26 +02:00
|
|
|
|
2004-10-27 11:49:13 +02:00
|
|
|
G_OBJECT_CLASS(klass)->dispose = dispose;
|
2004-06-24 18:01:48 +02:00
|
|
|
}
|
|
|
|
|
2004-10-27 11:49:13 +02:00
|
|
|
GType
|
|
|
|
lasso_profile_get_type()
|
|
|
|
{
|
|
|
|
static GType this_type = 0;
|
|
|
|
|
|
|
|
if (!this_type) {
|
|
|
|
static const GTypeInfo this_info = {
|
|
|
|
sizeof(LassoProfileClass),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc) class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof(LassoProfile),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc) instance_init,
|
2009-01-24 10:33:40 +01:00
|
|
|
NULL
|
2004-10-27 11:49:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
this_type = g_type_register_static(LASSO_TYPE_NODE,
|
|
|
|
"LassoProfile", &this_info, 0);
|
|
|
|
}
|
|
|
|
return this_type;
|
2004-06-24 18:01:48 +02:00
|
|
|
}
|
|
|
|
|