diff options
author | Damien Laniel <Damien Laniel@localhost> | 2007-04-03 13:38:04 +0000 |
---|---|---|
committer | Damien Laniel <Damien Laniel@localhost> | 2007-04-03 13:38:04 +0000 |
commit | a559d3fe94844afa898e7bd59b6df32f61f157dd (patch) | |
tree | d5ad5b8887a7038cffe6bdf3eff02123949d55fa /lasso/id-wsf-2.0 | |
parent | 0497774d47f0809528577395299543f51df1f827 (diff) | |
download | lasso-a559d3fe94844afa898e7bd59b6df32f61f157dd.tar.gz lasso-a559d3fe94844afa898e7bd59b6df32f61f157dd.tar.xz lasso-a559d3fe94844afa898e7bd59b6df32f61f157dd.zip |
ID-WSF 2.0 Discovery Query : not yet working classes
Diffstat (limited to 'lasso/id-wsf-2.0')
-rw-r--r-- | lasso/id-wsf-2.0/discovery.c | 1147 | ||||
-rw-r--r-- | lasso/id-wsf-2.0/discovery.h | 128 | ||||
-rw-r--r-- | lasso/id-wsf-2.0/wsf2_profile.c | 1524 | ||||
-rw-r--r-- | lasso/id-wsf-2.0/wsf2_profile.h | 133 | ||||
-rw-r--r-- | lasso/id-wsf-2.0/wsf2_profile_private.h | 47 |
5 files changed, 2979 insertions, 0 deletions
diff --git a/lasso/id-wsf-2.0/discovery.c b/lasso/id-wsf-2.0/discovery.c new file mode 100644 index 00000000..efb15b75 --- /dev/null +++ b/lasso/id-wsf-2.0/discovery.c @@ -0,0 +1,1147 @@ +/* $Id: discovery.c,v 1.75 2007/01/03 23:35:17 fpeters Exp $ + * + * Lasso - A free implementation of the Liberty Alliance specifications. + * + * Copyright (C) 2004, 2005 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include <libxml/xpath.h> +#include <libxml/xpathInternals.h> + +#include <xmlsec/xmltree.h> + +#include <lasso/xml/soap_binding_correlation.h> +#include <lasso/xml/saml_assertion.h> +#include <lasso/xml/saml_attribute_value.h> +//#include <lasso/xml/disco_modify.h> +#include <lasso/xml/ds_key_info.h> +#include <lasso/xml/ds_key_value.h> +#include <lasso/xml/ds_rsa_key_value.h> + + +#include <lasso/id-ff/server.h> +#include <lasso/id-ff/provider.h> +#include <lasso/id-ff/providerprivate.h> + +#include <lasso/id-wsf-2.0/discovery.h> +//#include <lasso/id-wsf/identity.h> +//#include <lasso/id-wsf/data_service.h> +//#include <lasso/id-wsf/personal_profile_service.h> +#include <lasso/id-wsf-2.0/wsf2_profile_private.h> + +struct _LassoIdwsf2DiscoveryPrivate +{ + gboolean dispose_has_run; + GList *new_entry_ids; + char *security_mech_id; +}; + +/*****************************************************************************/ +/* static methods/functions */ +/*****************************************************************************/ + +//static gchar* lasso_discovery_build_credential(LassoDiscovery *discovery, const gchar *providerId); +// +//static gchar* +//lasso_discovery_build_credential(LassoDiscovery *discovery, const gchar *providerId) +//{ +// LassoSoapHeader *header; +// LassoSoapBindingProvider *provider; +// LassoDiscoQueryResponse *response; +// LassoDiscoCredentials *credentials; +// GList *iter; +// +// LassoSamlAssertion *assertion; +// +// LassoSamlAuthenticationStatement *authentication_statement; +// +// LassoSamlSubject *subject; +// LassoSamlNameIdentifier *identifier; +// +// LassoSamlSubjectConfirmation *subject_confirmation; +// +// /* Init assertion informations */ +// assertion = lasso_saml_assertion_new(); +// assertion->AssertionID = lasso_build_unique_id(32); +// assertion->MajorVersion = LASSO_SAML_MAJOR_VERSION_N; +// assertion->MinorVersion = LASSO_SAML_MINOR_VERSION_N; +// assertion->IssueInstant = lasso_get_current_time(); +// assertion->Issuer = \ +// g_strdup(LASSO_PROVIDER(LASSO_WSF_PROFILE(discovery)->server)->ProviderID); +// +// /* Add AuthenticationStatement */ +// authentication_statement = LASSO_SAML_AUTHENTICATION_STATEMENT( +// lasso_saml_authentication_statement_new()); +// authentication_statement->AuthenticationInstant = lasso_get_current_time(); +// subject = LASSO_SAML_SUBJECT(lasso_saml_subject_new()); +// LASSO_SAML_SUBJECT_STATEMENT_ABSTRACT(authentication_statement)->Subject = subject; +// +// /* NameIdentifier */ +// identifier = lasso_saml_name_identifier_new(); +// identifier->NameQualifier = g_strdup( +// LASSO_PROVIDER(LASSO_WSF_PROFILE(discovery)->server)->ProviderID); +// header = LASSO_WSF_PROFILE(discovery)->soap_envelope_request->Header; +// iter = header->Other; +// while (iter) { +// if (LASSO_IS_SOAP_BINDING_PROVIDER(iter->data) == TRUE) { +// provider = LASSO_SOAP_BINDING_PROVIDER(iter->data); +// break; +// } +// iter = iter->next; +// } +// if (provider) { +// identifier->Format = g_strdup(LASSO_LIB_NAME_IDENTIFIER_FORMAT_ENTITYID); +// identifier->content = g_strdup(provider->providerID); +// } else { +// identifier->Format = g_strdup(LASSO_LIB_NAME_IDENTIFIER_FORMAT_FEDERATED); +// } +// subject->NameIdentifier = identifier; +// +// /* SubjectConfirmation */ +// subject_confirmation = lasso_saml_subject_confirmation_new(); +// subject_confirmation->ConfirmationMethod = \ +// g_list_append(subject_confirmation->ConfirmationMethod, +// g_strdup(LASSO_SAML_CONFIRMATION_METHOD_HOLDER_OF_KEY)); +// +// /* Add public key value in credential */ +// { +// LassoDsKeyInfo *key_info; +// LassoDsRsaKeyValue *rsa_key_value; +// LassoDsKeyValue *key_value; +// +// LassoProvider *lasso_provider; +// +// xmlSecKeyInfoCtx *ctx; +// xmlSecKey *public_key; +// xmlSecKeyData *public_key_data; +// +// xmlDoc *doc; +// xmlNode *key_info_node, *xmlnode; +// +// xmlXPathContext *xpathCtx = NULL; +// xmlXPathObject *xpathObj; +// +// lasso_provider = lasso_server_get_provider(LASSO_WSF_PROFILE(discovery)->server, +// (char *) provider->providerID); +// public_key = lasso_provider_get_public_key(lasso_provider); +// public_key_data = xmlSecKeyGetValue(public_key); +// ctx = xmlSecKeyInfoCtxCreate(NULL); +// xmlSecKeyInfoCtxInitialize(ctx, NULL); +// ctx->mode = xmlSecKeyInfoModeWrite; +// ctx->keyReq.keyType = xmlSecKeyDataTypePublic; +// +// doc = xmlSecCreateTree((xmlChar*)"KeyInfo", +// (xmlChar*)"http://www.w3.org/2000/09/xmldsig#"); +// key_info_node = xmlDocGetRootElement(doc); +// xmlSecAddChild(key_info_node, (xmlChar*)"KeyValue", +// (xmlChar*)"http://www.w3.org/2000/09/xmldsig#"); +// +// xmlSecKeyInfoNodeWrite(key_info_node, public_key, ctx); +// +// xpathCtx = xmlXPathNewContext(doc); +// xmlXPathRegisterNs(xpathCtx, (xmlChar*)"ds", +// (xmlChar*)"http://www.w3.org/2000/09/xmldsig#"); +// +// rsa_key_value = lasso_ds_rsa_key_value_new(); +// xpathObj = xmlXPathEvalExpression((xmlChar*)"//ds:Modulus", xpathCtx); +// if (xpathObj->nodesetval && xpathObj->nodesetval->nodeNr) { +// xmlnode = xpathObj->nodesetval->nodeTab[0]; +// rsa_key_value->Modulus = (gchar *) xmlNodeGetContent(xmlnode); +// } +// xmlXPathFreeObject(xpathObj); +// +// xpathObj = xmlXPathEvalExpression((xmlChar*)"//ds:Exponent", xpathCtx); +// if (xpathObj->nodesetval && xpathObj->nodesetval->nodeNr) { +// xmlnode = xpathObj->nodesetval->nodeTab[0]; +// rsa_key_value->Exponent = (gchar *) xmlNodeGetContent(xmlnode); +// } +// xmlXPathFreeObject(xpathObj); +// +// key_value = lasso_ds_key_value_new(); +// key_value->RSAKeyValue = rsa_key_value; +// key_info = lasso_ds_key_info_new(); +// key_info->KeyValue = key_value; +// subject_confirmation->KeyInfo = key_info; +// +// xmlXPathFreeContext(xpathCtx); +// xmlFreeDoc(doc); +// } +// +// subject->SubjectConfirmation = subject_confirmation; +// assertion->AuthenticationStatement = authentication_statement; +// +// /* Add credential to disco:QueryResponse */ +// response = LASSO_DISCO_QUERY_RESPONSE(LASSO_WSF_PROFILE(discovery)->response); +// credentials = lasso_disco_credentials_new(); +// response->Credentials = credentials; +// credentials->any = g_list_append(credentials->any, LASSO_NODE(assertion)); +// +// return g_strdup(assertion->AssertionID); +//} +// +///** +// * lasso_discovery_init_request: +// * @discovery: a LassoDiscovery +// * @resourceOffering: a LassoDiscoResourceOffering +// * @description: a LassoDiscoDescription +// * +// * Generic static method used by lasso_discovery_init_modify() and +// * lasso_discovery_init_query() +// * +// * Return value: 0 on success and a negative value if an error occurs. +// **/ +//static gint +//lasso_discovery_init_request(LassoDiscovery *discovery, +// LassoDiscoResourceOffering *resourceOffering, +// LassoDiscoDescription *description) +//{ +// LassoWsfProfile *profile = LASSO_WSF_PROFILE(discovery); +// +// /* verify that description is present in resourceOffering->ServiceInstance->Description */ +// if (g_list_find(resourceOffering->ServiceInstance->Description, description) == NULL) { +// message(G_LOG_LEVEL_CRITICAL, lasso_strerror(LASSO_PARAM_ERROR_INVALID_VALUE)); +// } +// /* get ResourceID/EncryptedResourceID in description */ +// /* ResourceID and EncryptedResourceID are owned by resourceOffering, +// so increment reference count */ +// if (resourceOffering->ResourceID != NULL) { +// g_object_ref(resourceOffering->ResourceID); +// if (LASSO_IS_DISCO_MODIFY(profile->request)) { +// LASSO_DISCO_MODIFY(profile->request)->ResourceID = \ +// resourceOffering->ResourceID; +// } else if (LASSO_IS_DISCO_QUERY(profile->request)) { +// LASSO_DISCO_QUERY(profile->request)->ResourceID = \ +// resourceOffering->ResourceID; +// } +// } else if (resourceOffering->EncryptedResourceID != NULL) { +// g_object_ref(resourceOffering->EncryptedResourceID); +// if (LASSO_IS_DISCO_MODIFY(profile->request)) { +// LASSO_DISCO_MODIFY(profile->request)->EncryptedResourceID = \ +// resourceOffering->EncryptedResourceID; +// } else if (LASSO_IS_DISCO_QUERY(profile->request)) { +// LASSO_DISCO_QUERY(profile->request)->EncryptedResourceID = \ +// resourceOffering->EncryptedResourceID; +// } +// } +// +// if (description->Endpoint != NULL) { +// profile->msg_url = g_strdup(description->Endpoint); +// } else if (description->WsdlURI != NULL) { +// /* TODO: get Endpoint at WsdlURI */ +// } +// +// return 0; +//} +// +//LassoDiscoInsertEntry* +//lasso_discovery_add_insert_entry(LassoDiscovery *discovery, +// LassoDiscoServiceInstance *serviceInstance, +// LassoDiscoResourceID *resourceId) +//{ +// LassoDiscoModify *modify; +// LassoDiscoInsertEntry *insertEntry; +// LassoDiscoResourceOffering *resourceOffering; +// +// g_return_val_if_fail(LASSO_IS_DISCOVERY(discovery), NULL); +// g_return_val_if_fail(LASSO_IS_DISCO_SERVICE_INSTANCE(serviceInstance), NULL); +// g_return_val_if_fail(LASSO_IS_DISCO_RESOURCE_ID(resourceId), NULL); +// +// modify = LASSO_DISCO_MODIFY(LASSO_WSF_PROFILE(discovery)->request); +// +// /* ResourceOffering elements being inserted MUST NOT contain entryID attributes. */ +// serviceInstance = serviceInstance ? g_object_ref(serviceInstance) : serviceInstance; +// resourceOffering = lasso_disco_resource_offering_new(serviceInstance); +// +// resourceId = resourceId ? g_object_ref(resourceId) : resourceId; +// resourceOffering->ResourceID = resourceId; +// +// insertEntry = lasso_disco_insert_entry_new(resourceOffering); +// +// modify->InsertEntry = g_list_append(modify->InsertEntry, insertEntry); +// +// return insertEntry; +//} +// +//gint +//lasso_discovery_add_remove_entry(LassoDiscovery *discovery, +// const gchar *entryID) +//{ +// LassoDiscoModify *modify; +// +// g_return_val_if_fail(LASSO_IS_DISCOVERY(discovery), LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ); +// g_return_val_if_fail(entryID != NULL, LASSO_PARAM_ERROR_INVALID_VALUE); +// +// modify = LASSO_DISCO_MODIFY(LASSO_WSF_PROFILE(discovery)->request); +// +// /* add RemoveEntry */ +// modify->RemoveEntry = g_list_append(modify->RemoveEntry, +// lasso_disco_remove_entry_new(entryID)); +// +// return 0; +//} +// +///** +// * lasso_discovery_add_requested_service_type: +// * @discovery: a #LassoDiscovery +// * @service_type: requested service type +// * @option: option to the requested service +// * +// * Adds a request for service of @service_type to the disco:Query being built. +// * +// * Return value: a newly created #LassoDiscoRequestedServiceType with the +// * request. Note that it is internally allocated and shouldn't be freed +// * by the caller. +// **/ +//LassoDiscoRequestedServiceType* +//lasso_discovery_add_requested_service_type(LassoDiscovery *discovery, +// const gchar *service_type, +// const gchar *option) +//{ +// LassoDiscoQuery *query; +// LassoDiscoRequestedServiceType *rst; +// LassoDiscoOptions *opts = NULL; +// +// g_return_val_if_fail(LASSO_IS_DISCOVERY(discovery), NULL); +// g_return_val_if_fail(service_type != NULL, NULL); +// /* option is optional */ +// +// query = LASSO_DISCO_QUERY(LASSO_WSF_PROFILE(discovery)->request); +// if (query == NULL) { +// /* missing request */ +// return NULL; +// } +// +// rst = lasso_disco_requested_service_type_new(service_type); +// +// /* optionals data */ +// if (option != NULL) { +// opts = lasso_disco_options_new(); +// opts->Option = g_list_append(opts->Option, (gpointer)option); +// rst->Options = opts; +// } +// +// /* add RequestedServiceType */ +// query->RequestedServiceType = g_list_append(query->RequestedServiceType, (gpointer)rst); +// +// return rst; +//} + +/** + * lasso_discovery_destroy: + * @discovery: a LassoDiscovery + * + * Destroys LassoDiscovery objects created with lasso_discovery_new() or + * lasso_discovery_new_from_dump(). + **/ +void +lasso_idwsf2_discovery_destroy(LassoIdwsf2Discovery *discovery) +{ + g_object_unref(G_OBJECT(discovery)); +} + +//gint +//lasso_discovery_init_modify(LassoDiscovery *discovery, +// LassoDiscoResourceOffering *resourceOffering, +// LassoDiscoDescription *description) +//{ +// LassoSoapEnvelope *envelope; +// LassoDiscoModify *modify; +// +// g_return_val_if_fail(LASSO_IS_DISCOVERY(discovery), LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ); +// g_return_val_if_fail(LASSO_IS_DISCO_RESOURCE_OFFERING(resourceOffering), +// LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ); +// g_return_val_if_fail(LASSO_IS_DISCO_DESCRIPTION(description), +// LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ); +// +// modify = lasso_disco_modify_new(); +// LASSO_WSF_PROFILE(discovery)->request = LASSO_NODE(modify); +// +// envelope = lasso_wsf_profile_build_soap_envelope(NULL, NULL); +// LASSO_WSF_PROFILE(discovery)->soap_envelope_request = envelope; +// envelope->Body->any = g_list_append(envelope->Body->any, modify); +// +// return lasso_discovery_init_request(discovery, resourceOffering, description); +//} +// +//static LassoDiscoResourceOffering* +//lasso_discovery_get_resource_offering_auto(LassoDiscovery *discovery, const gchar *service_type) +//{ +// LassoSession *session; +// GList *assertions, *iter, *iter2, *iter3, *iter4; +// LassoDiscoResourceOffering *resource_offering = NULL; +// +// if (LASSO_WSF_PROFILE(discovery)->session == NULL) { +// return NULL; +// } +// +// session = LASSO_WSF_PROFILE(discovery)->session; +// assertions = lasso_session_get_assertions(session, NULL); +// iter = assertions; +// while (iter) { +// LassoSamlAssertion *assertion = iter->data; +// iter = g_list_next(iter); +// if (assertion->AttributeStatement == NULL) +// continue; +// iter2 = assertion->AttributeStatement->Attribute; +// while (iter2) { +// LassoSamlAttribute *attribute = iter2->data; +// iter2 = g_list_next(iter2); +// if (strcmp(attribute->attributeName, "DiscoveryResourceOffering") != 0) +// continue; +// iter3 = attribute->AttributeValue; +// while (iter3) { +// LassoSamlAttributeValue *attribute_value = iter3->data; +// iter3 = g_list_next(iter3); +// iter4 = attribute_value->any; +// while (iter4) { +// LassoDiscoResourceOffering *v = iter4->data; +// iter4 = g_list_next(iter4); +// if (! LASSO_IS_DISCO_RESOURCE_OFFERING(v)) +// continue; +// if (v->ServiceInstance == NULL) +// continue; +// if (strcmp(v->ServiceInstance->ServiceType, +// service_type) == 0) { +// resource_offering = v; +// goto end; +// } +// } +// } +// } +// } +// +//end: +// +// g_list_free(assertions); +// +// if (resource_offering) { +// return g_object_ref(resource_offering); +// } +// +// return NULL; +//} +// +///** +// * lasso_discovery_get_description_auto: +// * +// * +// * +// * Return value: internally allocated, don't free +// **/ +//LassoDiscoDescription* +//lasso_discovery_get_description_auto(LassoDiscoResourceOffering *offering, +// const gchar *security_mech) +//{ +// GList *iter, *iter2; +// LassoDiscoDescription *description; +// +// iter = offering->ServiceInstance->Description; +// while (iter) { +// description = iter->data; +// iter = g_list_next(iter); +// iter2 = description->SecurityMechID; +// while (iter2) { +// if (strcmp((char*)iter2->data, security_mech) == 0) { +// return description; +// } +// iter2 = g_list_next(iter2); +// } +// } +// return NULL; +//} +// +// +///** +// * lasso_discovery_init_insert +// * @discovery: a #LassoDiscovery +// * @new_offering: the new service offered +// * @security_mech_id: the security mechanism identifier +// * +// * Initializes a disco Modify/InsertEntry +// * +// * Return value: 0 on success; or a negative value otherwise. +// **/ +//gint +//lasso_discovery_init_insert(LassoDiscovery *discovery, +// LassoDiscoResourceOffering *new_offering, const char *security_mech_id) +//{ +// LassoDiscoModify *modify; +// LassoDiscoResourceOffering *offering; +// LassoDiscoDescription *description = NULL; +// +// modify = lasso_disco_modify_new(); +// lasso_wsf_profile_init_soap_request(LASSO_WSF_PROFILE(discovery), LASSO_NODE(modify)); +// +// /* get discovery service resource id from principal assertion */ +// offering = lasso_discovery_get_resource_offering_auto(discovery, LASSO_DISCO_HREF); +// if (offering == NULL) { +// return LASSO_PROFILE_ERROR_MISSING_RESOURCE_OFFERING; +// } +// if (security_mech_id) { +// description = lasso_discovery_get_description_auto(offering, security_mech_id); +// } else { +// description = LASSO_DISCO_DESCRIPTION(offering->ServiceInstance->Description->data); +// } +// if (!description) { +// return LASSO_PROFILE_ERROR_MISSING_SERVICE_DESCRIPTION; +// } +// lasso_wsf_profile_set_description(LASSO_WSF_PROFILE(discovery), description); +// +// /* XXX: EncryptedResourceID support */ +// modify->ResourceID = g_object_ref(offering->ResourceID); +// lasso_node_destroy(LASSO_NODE(offering)); +// +// modify->InsertEntry = g_list_append(modify->InsertEntry, +// lasso_disco_insert_entry_new(new_offering)); +// LASSO_WSF_PROFILE(discovery)->request = LASSO_NODE(modify); +// +// if (description->Endpoint != NULL) { +// LASSO_WSF_PROFILE(discovery)->msg_url = g_strdup(description->Endpoint); +// } /* XXX: else, description->WsdlURLI, get endpoint automatically */ +// +// return 0; +//} +// +// +///** +// * lasso_discovery_init_remove +// * @discovery: a #LassoDiscovery +// * @entry_id: entry id of the resource offering to remove +// * +// * Initializes a disco Modify/RemoveEntry +// * +// * Return value: 0 on success; or a negative value otherwise. +// **/ +//gint +//lasso_discovery_init_remove(LassoDiscovery *discovery, const char *entry_id) +//{ +// LassoDiscoModify *modify; +// LassoDiscoResourceOffering *offering; +// LassoDiscoDescription *description; +// +// modify = lasso_disco_modify_new(); +// lasso_wsf_profile_init_soap_request(LASSO_WSF_PROFILE(discovery), LASSO_NODE(modify)); +// +// /* get discovery service resource id from principal assertion */ +// offering = lasso_discovery_get_resource_offering_auto(discovery, LASSO_DISCO_HREF); +// if (offering == NULL) { +// return LASSO_PROFILE_ERROR_MISSING_RESOURCE_OFFERING; +// } +// description = lasso_discovery_get_description_auto(offering, +// LASSO_SECURITY_MECH_NULL); +// +// /* XXX: EncryptedResourceID support */ +// modify->ResourceID = g_object_ref(offering->ResourceID); +// lasso_node_destroy(LASSO_NODE(offering)); +// +// modify->RemoveEntry = g_list_append(modify->RemoveEntry, +// lasso_disco_remove_entry_new(entry_id)); +// LASSO_WSF_PROFILE(discovery)->request = LASSO_NODE(modify); +// +// if (description->Endpoint != NULL) { +// LASSO_WSF_PROFILE(discovery)->msg_url = g_strdup(description->Endpoint); +// } /* XXX: else, description->WsdlURLK, get endpoint automatically */ +// +// return 0; +//} + +/** + * lasso_discovery_init_query + * @discovery: a #LassoDiscovery + * + * Initializes a disco:Query message. + * + * Return value: 0 on success; or a negative value otherwise. + **/ +gint +lasso_idwsf2_discovery_init_query(LassoIdwsf2Discovery *discovery, const gchar *security_mech_id) +{ + LassoIdwsf2DiscoQuery *query; +// LassoIdwsf2DiscoResourceOffering *offering; +// LassoIdwsf2DiscoDescription *description; + + query = lasso_idwsf2_disco_query_new(); + lasso_wsf2_profile_init_soap_request(LASSO_WSF2_PROFILE(discovery), LASSO_NODE(query)); + + /* get discovery service resource id from principal assertion */ +// offering = lasso_discovery_get_resource_offering_auto(discovery, LASSO_DISCO_HREF); +// if (offering == NULL) +// return LASSO_PROFILE_ERROR_MISSING_RESOURCE_OFFERING; +// +// if (security_mech_id == NULL) { +// description = LASSO_DISCO_DESCRIPTION(offering->ServiceInstance->Description->data); +// } else { +// description = lasso_discovery_get_description_auto(offering, security_mech_id); +// } +// if (description == NULL) +// return LASSO_PROFILE_ERROR_MISSING_SERVICE_DESCRIPTION; +// +// lasso_wsf_profile_set_description(LASSO_WSF_PROFILE(discovery), description); +// +// /* XXX: EncryptedResourceID support */ +// query->ResourceID = g_object_ref(offering->ResourceID); +// lasso_node_destroy(LASSO_NODE(offering)); + + LASSO_WSF2_PROFILE(discovery)->request = LASSO_NODE(query); + +// if (description->Endpoint != NULL) { +// LASSO_WSF_PROFILE(discovery)->msg_url = g_strdup(description->Endpoint); +// } /* XXX: else, description->WsdlURLK, get endpoint automatically */ + + return 0; +} + + +/** + * lasso_discovery_process_modify_msg: + * @discovery: a #LassoDiscovery + * @message: the disco:Modify SOAP message + * + * Processes a disco:Modify SOAP message. Rebuilds a request object from the + * message and extracts ResourceID. + * + * Return value: 0 on success; or a negative value otherwise. + **/ +//gint +//lasso_discovery_process_modify_msg(LassoDiscovery *discovery, const gchar *message, +// const gchar *security_mech_id) +//{ +// LassoDiscoModify *request; +// int res = 0; +// +// g_return_val_if_fail(LASSO_IS_DISCOVERY(discovery), LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ); +// g_return_val_if_fail(message != NULL, LASSO_PARAM_ERROR_INVALID_VALUE); +// +// res = lasso_wsf_profile_process_soap_request_msg(LASSO_WSF_PROFILE(discovery), message, +// LASSO_DISCO_HREF, security_mech_id); +// if (res != 0) +// return res; +// +// request = LASSO_DISCO_MODIFY(LASSO_WSF_PROFILE(discovery)->request); +// +// if (request->ResourceID) +// discovery->resource_id = g_object_ref(request->ResourceID); +// if (request->EncryptedResourceID) +// discovery->encrypted_resource_id = g_object_ref(request->EncryptedResourceID); +// +// return 0; +//} +// +// +///** +// * lasso_discovery_build_modify_response_msg: +// * @discovery: a #LassoDiscovery +// * +// * Builds a disco:ModifyResponse message; answer to the disco:Modify passed +// * to lasso_discovery_process_modify_msg(). It inserts and removed +// * ResourceOfferings from identity; it must be saved afterwards. +// * +// * Sets @msg_body to the SOAP answer. +// * +// * Return value: 0 on success; or a negative value otherwise. +// **/ +//gint +//lasso_discovery_build_modify_response_msg(LassoDiscovery *discovery) +//{ +// LassoDiscoModify *request = LASSO_DISCO_MODIFY(LASSO_WSF_PROFILE(discovery)->request); +// LassoDiscoModifyResponse *response; +// LassoSoapEnvelope *envelope; +// LassoUtilityStatus *status; +// GList *iter; +// gboolean failure = FALSE; +// char *new_entry_ids = NULL, *t_new_entry_ids = NULL; +// +// if (lasso_wsf_profile_get_fault(LASSO_WSF_PROFILE(discovery))) { +// return lasso_wsf_profile_build_soap_response_msg(LASSO_WSF_PROFILE(discovery)); +// } +// +// if (LASSO_WSF_PROFILE(discovery)->identity == NULL) { +// return LASSO_PROFILE_ERROR_IDENTITY_NOT_FOUND; +// } +// +// /* build response */ +// status = lasso_utility_status_new(LASSO_DISCO_STATUS_CODE_FAILED); +// response = lasso_disco_modify_response_new(status); +// LASSO_WSF_PROFILE(discovery)->response = LASSO_NODE(response); +// envelope = LASSO_WSF_PROFILE(discovery)->soap_envelope_response; +// envelope->Body->any = g_list_append(envelope->Body->any, response); +// +// /* First verify remove entries are all ok */ +// iter = request->RemoveEntry; +// while (iter) { +// LassoDiscoRemoveEntry *entry = iter->data; +// iter = g_list_next(iter); +// +// if (lasso_identity_get_resource_offering( +// LASSO_WSF_PROFILE(discovery)->identity, +// entry->entryID) == NULL) { +// return LASSO_PROFILE_ERROR_MISSING_RESOURCE_OFFERING; +// } +// } +// +// if (request->InsertEntry) { +// new_entry_ids = g_malloc(10*g_list_length(request->InsertEntry)); +// t_new_entry_ids = new_entry_ids; +// } +// +// iter = request->InsertEntry; +// while (iter) { +// LassoDiscoInsertEntry *entry = iter->data; +// iter = g_list_next(iter); +// +// lasso_identity_add_resource_offering(LASSO_WSF_PROFILE(discovery)->identity, +// entry->ResourceOffering); +// +// t_new_entry_ids = g_stpcpy(t_new_entry_ids, entry->ResourceOffering->entryID); +// t_new_entry_ids = g_stpcpy(t_new_entry_ids, " "); +// } +// if (t_new_entry_ids) { +// t_new_entry_ids[-1] = 0; /* remove trailing white space */ +// } +// +// iter = request->RemoveEntry; +// while (iter) { +// LassoDiscoRemoveEntry *entry = iter->data; +// iter = g_list_next(iter); +// +// if (lasso_identity_remove_resource_offering( +// LASSO_WSF_PROFILE(discovery)->identity, +// entry->entryID) == FALSE) { +// failure = TRUE; +// } +// } +// +// if (new_entry_ids) { +// response->newEntryIDs = g_strdup(new_entry_ids); +// g_free(new_entry_ids); +// } +// +// g_free(status->code); +// status->code = g_strdup(LASSO_DISCO_STATUS_CODE_OK); +// +// return lasso_wsf_profile_build_soap_response_msg(LASSO_WSF_PROFILE(discovery)); +//} +// +///** +// * lasso_discovery_process_modify_response_msg: +// * @discovery: a #LassoDiscovery +// * @message: the disco:ModifyResponse SOAP message +// * +// * Processes a disco:ModifyResponse SOAP message. +// * +// * Return value: 0 on success; or a negative value otherwise. +// **/ +//gint +//lasso_discovery_process_modify_response_msg(LassoDiscovery *discovery, const gchar *message) +//{ +// int rc; +// LassoDiscoModifyResponse *response; +// +// rc = lasso_wsf_profile_process_soap_response_msg(LASSO_WSF_PROFILE(discovery), message); +// if (rc) { +// return rc; +// } +// +// response = LASSO_DISCO_MODIFY_RESPONSE(LASSO_WSF_PROFILE(discovery)->response); +// if (strcmp(response->Status->code, "OK") != 0) { +// return LASSO_PROFILE_ERROR_STATUS_NOT_SUCCESS; +// } +// +// return 0; +//} +// +///** +// * lasso_discovery_process_query_msg: +// * @discovery: a #LassoDiscovery +// * @message: the disco:Query SOAP message +// * +// * Processes a disco:Query SOAP message. Rebuilds a request object from the +// * message and extracts ResourceID. +// * +// * Return value: 0 on success; or a negative value otherwise. +// **/ +//gint +//lasso_discovery_process_query_msg(LassoDiscovery *discovery, const gchar *message, +// const char *security_mech_id) +//{ +// LassoDiscoQuery *request; +// LassoSoapEnvelope *envelope; +// +// g_return_val_if_fail(LASSO_IS_DISCOVERY(discovery), LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ); +// g_return_val_if_fail(message != NULL, LASSO_PARAM_ERROR_INVALID_VALUE); +// +// lasso_wsf_profile_process_soap_request_msg(LASSO_WSF_PROFILE(discovery), +// message, LASSO_DISCO_HREF, security_mech_id); +// +// envelope = LASSO_WSF_PROFILE(discovery)->soap_envelope_response; +// request = LASSO_DISCO_QUERY(LASSO_WSF_PROFILE(discovery)->request); +// +// if (request->ResourceID) { +// discovery->resource_id = g_object_ref(request->ResourceID); +// } else if (request->EncryptedResourceID) { +// discovery->encrypted_resource_id = g_object_ref(request->EncryptedResourceID); +// } else { +// return LASSO_ERROR_UNIMPLEMENTED; /* implied ? */ +// } +// +// return 0; +//} +// +// +///** +// * lasso_discovery_build_response_msg +// * @discovery: a #LassoDiscovery +// * +// * Builds a disco:QueryResponse message; answer to the disco:Query passed to +// * lasso_discovery_process_query_msg(). It looks up resource offerings in the +// * principal identity and extracts those of the requested service type. +// * +// * Sets @msg_body to the SOAP answer. +// * +// * Return value: 0 on success; or a negative value otherwise. +// **/ +//gint +//lasso_discovery_build_response_msg(LassoDiscovery *discovery) +//{ +// LassoDiscoQuery *request = LASSO_DISCO_QUERY(LASSO_WSF_PROFILE(discovery)->request); +// LassoDiscoQueryResponse *response; +// LassoSoapEnvelope *envelope; +// +// GList *offerings = NULL; +// GList *iter, *iter2, *iter3; +// int res = 0; +// +// gchar *credentialRef; +// +// if (lasso_wsf_profile_get_fault(LASSO_WSF_PROFILE(discovery))) { +// return lasso_wsf_profile_build_soap_response_msg(LASSO_WSF_PROFILE(discovery)); +// } +// +// if (LASSO_WSF_PROFILE(discovery)->identity == NULL) { +// return LASSO_PROFILE_ERROR_IDENTITY_NOT_FOUND; +// } +// +// iter = request->RequestedServiceType; +// while (iter) { +// LassoDiscoRequestedServiceType *service_type = iter->data; +// iter = g_list_next(iter); +// offerings = g_list_concat(offerings, lasso_identity_get_offerings( +// LASSO_WSF_PROFILE(discovery)->identity, +// service_type->ServiceType)); +// } +// +// /* build response */ +// response = lasso_disco_query_response_new( +// lasso_utility_status_new(LASSO_DST_STATUS_CODE_OK)); +// response->ResourceOffering = offerings; +// LASSO_WSF_PROFILE(discovery)->response = LASSO_NODE(response); +// envelope = LASSO_WSF_PROFILE(discovery)->soap_envelope_response; +// envelope->Body->any = g_list_append(envelope->Body->any, response); +// +// /* Add needed credentials for offerings */ +// iter = offerings; +// while (iter) { +// LassoDiscoResourceOffering *resource_offering = iter->data; +// iter = g_list_next(iter); +// iter2 = resource_offering->ServiceInstance->Description; +// while (iter2) { +// LassoDiscoDescription *description = LASSO_DISCO_DESCRIPTION(iter2->data); +// iter3 = description->SecurityMechID; +// while (iter3) { +// if (lasso_security_mech_id_is_saml_authentication( +// iter3->data) == TRUE) { +// credentialRef = lasso_discovery_build_credential( +// discovery, NULL); +// description->CredentialRef = g_list_append( +// description->CredentialRef, credentialRef); +// } +// iter3 = g_list_next(iter3); +// } +// iter2 = g_list_next(iter2); +// } +// } +// +// res = lasso_wsf_profile_build_soap_response_msg(LASSO_WSF_PROFILE(discovery)); +// +// return res; +//} +// +///** +// * lasso_discovery_process_query_response_msg: +// * @discovery: a #LassoDiscovery +// * @message: the disco:QueryResponse message +// * +// * Processes a disco:QueryResponse message. +// * +// * Return value: 0 on success; or a negative value otherwise. +// **/ +//gint +//lasso_discovery_process_query_response_msg(LassoDiscovery *discovery, const gchar *message) +//{ +// int rc; +// LassoDiscoQueryResponse *response; +// +// rc = lasso_wsf_profile_process_soap_response_msg(LASSO_WSF_PROFILE(discovery), message); +// if (rc) { +// return rc; +// } +// +// response = LASSO_DISCO_QUERY_RESPONSE(LASSO_WSF_PROFILE(discovery)->response); +// if (strcmp(response->Status->code, "OK") != 0) { +// return LASSO_PROFILE_ERROR_STATUS_NOT_SUCCESS; +// } +// +// /* XXX: anything else to do ? */ +// +// return 0; +//} +// +// +///** +// * lasso_discovery_get_service: +// * @discovery: a #LassoDiscovery +// * @service_type: the requested service type +// * +// * After a disco:query message, creates a #LassoDataService instance for the +// * requested @service_type. +// * +// * Return value: a newly created #LassoDataService object; or NULL if an +// * error occured. +// **/ +//LassoDataService* +//lasso_discovery_get_service(LassoDiscovery *discovery, const char *service_type) +//{ +// LassoDiscoQueryResponse *response; +// GList *iter; +// LassoDiscoResourceOffering *offering = NULL; +// LassoDataService *service; +// +// response = LASSO_DISCO_QUERY_RESPONSE(LASSO_WSF_PROFILE(discovery)->response); +// if (response == NULL) { +// /* no response; probably called at wrong time */ +// return NULL; +// } +// +// iter = response->ResourceOffering; +// if (iter == NULL) { +// return NULL; /* resource not found */ +// } +// if (service_type == NULL) { +// offering = iter->data; +// } else { +// while (iter) { +// LassoDiscoResourceOffering *t = iter->data; +// iter = g_list_next(iter); +// if (t->ServiceInstance == NULL) +// continue; +// if (strcmp(t->ServiceInstance->ServiceType, service_type) == 0) { +// offering = t; +// break; +// } +// } +// if (offering == NULL) { +// return NULL; /* resource not found */ +// } +// } +// +// if (strcmp(offering->ServiceInstance->ServiceType, LASSO_PP_HREF) == 0) { +// service = LASSO_DATA_SERVICE(lasso_personal_profile_service_new( +// LASSO_WSF_PROFILE(discovery)->server, offering)); +// } else { +// service = lasso_data_service_new_full(LASSO_WSF_PROFILE(discovery)->server, +// offering); +// } +// +// lasso_wsf_profile_move_credentials(LASSO_WSF_PROFILE(discovery), +// LASSO_WSF_PROFILE(service)); +// +// return service; +//} +// +// +///** +// * lasso_discovery_get_services: +// * @discovery: a #LassoDiscovery +// * +// * After a disco:query message, creates a GList object of #LassoDataService. +// * +// * Return value: a newly created GList object of #LassoDataService; +// * or NULL if an error occured. +// **/ +//GList* +//lasso_discovery_get_services(LassoDiscovery *discovery) +//{ +// LassoDiscoQueryResponse *response; +// GList *iter; +// LassoDiscoResourceOffering *offering; +// LassoDataService *service; +// GList *services; +// +// response = LASSO_DISCO_QUERY_RESPONSE(LASSO_WSF_PROFILE(discovery)->response); +// iter = response->ResourceOffering; +// if (iter == NULL) { +// return NULL; /* resource not found */ +// } +// +// services = NULL; +// while (iter) { +// offering = iter->data; +// iter = g_list_next(iter); +// if (offering->ServiceInstance == NULL) +// continue; +// if (strcmp(offering->ServiceInstance->ServiceType, LASSO_PP_HREF) == 0) { +// service = LASSO_DATA_SERVICE(lasso_personal_profile_service_new( +// LASSO_WSF_PROFILE(discovery)->server, offering)); +// service->provider_id = g_strdup(offering->ServiceInstance->ProviderID); +// service->abstract_description = g_strdup(offering->Abstract); +// } else { +// service = lasso_data_service_new_full(LASSO_WSF_PROFILE(discovery)->server, +// offering); +// service->provider_id = g_strdup(offering->ServiceInstance->ProviderID); +// service->abstract_description = g_strdup(offering->Abstract); +// } +// services = g_list_append(services, service); +// } +// +// return services; +//} + +/*****************************************************************************/ +/* private methods */ +/*****************************************************************************/ + +static LassoNodeClass *parent_class = NULL; + +static xmlNode* +get_xmlNode(LassoNode *node, gboolean lasso_dump) +{ + xmlNode *xmlnode; + + xmlnode = parent_class->get_xmlNode(node, lasso_dump); + xmlNodeSetName(xmlnode, (xmlChar*)"Discovery"); + xmlSetProp(xmlnode, (xmlChar*)"DiscoveryDumpVersion", (xmlChar*)"2"); + + return xmlnode; +} + +static int +init_from_xml(LassoNode *node, xmlNode *xmlnode) +{ + int rc; + + rc = parent_class->init_from_xml(node, xmlnode); + if (rc) return rc; + + return 0; +} + +/*****************************************************************************/ +/* overrided parent class methods */ +/*****************************************************************************/ + +static void +dispose(GObject *object) +{ + LassoIdwsf2Discovery *discovery = LASSO_IDWSF2_DISCOVERY(object); + + if (discovery->private_data->dispose_has_run == TRUE) + return; + discovery->private_data->dispose_has_run = TRUE; + + G_OBJECT_CLASS(parent_class)->dispose(object); +} + +static void +finalize(GObject *object) +{ + LassoIdwsf2Discovery *discovery = LASSO_IDWSF2_DISCOVERY(object); + g_free(discovery->private_data); + discovery->private_data = NULL; + G_OBJECT_CLASS(parent_class)->finalize(object); +} + +/*****************************************************************************/ +/* instance and class init functions */ +/*****************************************************************************/ + +static void +instance_init(LassoIdwsf2Discovery *discovery) +{ + discovery->private_data = g_new0(LassoIdwsf2DiscoveryPrivate, 1); + discovery->private_data->dispose_has_run = FALSE; +} + +static void +class_init(LassoIdwsf2DiscoveryClass *klass) +{ + parent_class = g_type_class_peek_parent(klass); + + LASSO_NODE_CLASS(klass)->get_xmlNode = get_xmlNode; + LASSO_NODE_CLASS(klass)->init_from_xml = init_from_xml; + + G_OBJECT_CLASS(klass)->dispose = dispose; + G_OBJECT_CLASS(klass)->finalize = finalize; +} + +GType +lasso_idwsf2_discovery_get_type() +{ + static GType this_type = 0; + + if (!this_type) { + static const GTypeInfo this_info = { + sizeof(LassoIdwsf2DiscoveryClass), + NULL, + NULL, + (GClassInitFunc) class_init, + NULL, + NULL, + sizeof(LassoIdwsf2Discovery), + 0, + (GInstanceInitFunc) instance_init, + }; + + this_type = g_type_register_static(LASSO_TYPE_WSF2_PROFILE, + "LassoIdwsf2Discovery", &this_info, 0); + } + return this_type; +} + +/** + * lasso_idwsf2_discovery_new: + * @server: the #LassoServer + * + * Creates a new #LassoIdwsf2Discovery. + * + * Return value: a newly created #LassoIdwsf2Discovery object; or NULL if an error + * occured. + **/ +LassoIdwsf2Discovery* +lasso_idwsf2_discovery_new(LassoServer *server) +{ + LassoIdwsf2Discovery *discovery = NULL; + + g_return_val_if_fail(LASSO_IS_SERVER(server), NULL); + + discovery = g_object_new(LASSO_TYPE_IDWSF2_DISCOVERY, NULL); + LASSO_WSF2_PROFILE(discovery)->server = g_object_ref(server); + + return discovery; +} diff --git a/lasso/id-wsf-2.0/discovery.h b/lasso/id-wsf-2.0/discovery.h new file mode 100644 index 00000000..80df67ae --- /dev/null +++ b/lasso/id-wsf-2.0/discovery.h @@ -0,0 +1,128 @@ +/* $Id: discovery.h,v 1.30 2006/02/21 09:51:49 fpeters Exp $ + * + * Lasso - A free implementation of the Liberty Alliance specifications. + * + * Copyright (C) 2004, 2005 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef __LASSO_IDWSF2_DISCOVERY_H__ +#define __LASSO_IDWSF2_DISCOVERY_H__ + +#ifdef __cplusplus +extern "C" { + +#endif /* __cplusplus */ + +//#include <lasso/xml/disco_insert_entry.h> +//#include <lasso/xml/disco_modify.h> +//#include <lasso/xml/disco_modify_response.h> +#include <lasso/xml/id-wsf-2.0/disco_query.h> +#include <lasso/xml/id-wsf-2.0/disco_query_response.h> +//#include <lasso/xml/disco_remove_entry.h> +//#include <lasso/xml/disco_requested_service_type.h> + +#include <lasso/id-wsf-2.0/wsf2_profile.h> +//#include <lasso/id-wsf/data_service.h> + +#define LASSO_TYPE_IDWSF2_DISCOVERY (lasso_idwsf2_discovery_get_type()) +#define LASSO_IDWSF2_DISCOVERY(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), LASSO_TYPE_IDWSF2_DISCOVERY, LassoIdwsf2Discovery)) +#define LASSO_IDWSF2_DISCOVERY_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), LASSO_TYPE_IDWSF2_DISCOVERY, LassoIdwsf2DiscoveryClass)) +#define LASSO_IS_IDWSF2_DISCOVERY(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), LASSO_TYPE_IDWSF2_DISCOVERY)) +#define LASSO_IS_IDWSF2_DISCOVERY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LASSO_TYPE_IDWSF2_DISCOVERY)) +#define LASSO_IDWSF2_DISCOVERY_GET_CLASS(o) \ + (G_TYPE_INSTANCE_GET_CLASS ((o), LASSO_TYPE_IDWSF2_DISCOVERY, LassoIdwsf2DiscoveryClass)) + +typedef struct _LassoIdwsf2Discovery LassoIdwsf2Discovery; +typedef struct _LassoIdwsf2DiscoveryClass LassoIdwsf2DiscoveryClass; +typedef struct _LassoIdwsf2DiscoveryPrivate LassoIdwsf2DiscoveryPrivate; + + +struct _LassoIdwsf2Discovery { + LassoWsf2Profile parent; + + /*< public >*/ +// LassoDiscoResourceID *resource_id; +// LassoDiscoEncryptedResourceID *encrypted_resource_id; + + /*< private >*/ + LassoIdwsf2DiscoveryPrivate *private_data; +}; + +struct _LassoIdwsf2DiscoveryClass { + LassoWsf2ProfileClass parent; +}; + +LASSO_EXPORT GType lasso_idwsf2_discovery_get_type(void); + +LASSO_EXPORT LassoIdwsf2Discovery* lasso_idwsf2_discovery_new(LassoServer *server); + +//LASSO_EXPORT LassoDiscoInsertEntry* lasso_idwsf2_discovery_add_insert_entry(LassoIdwsf2Discovery *discovery, +// LassoDiscoServiceInstance *serviceInstance, LassoDiscoResourceID *resourceId); +// +//LASSO_EXPORT gint lasso_idwsf2_discovery_add_remove_entry(LassoIdwsf2Discovery *discovery, +// const gchar *entryID); +// +//LASSO_EXPORT LassoDiscoRequestedServiceType* lasso_idwsf2_discovery_add_requested_service_type( +// LassoIdwsf2Discovery *discovery, const gchar *service_type, const gchar *option); + +LASSO_EXPORT void lasso_idwsf2_discovery_destroy(LassoIdwsf2Discovery *discovery); + +//LASSO_EXPORT gint lasso_idwsf2_discovery_init_insert(LassoIdwsf2Discovery *discovery, +// LassoDiscoResourceOffering *new_offering, const char *security_mech_id); +// +//LASSO_EXPORT gint lasso_idwsf2_discovery_init_remove(LassoIdwsf2Discovery *discovery, const char *entry_id); +// +//LASSO_EXPORT gint lasso_idwsf2_discovery_build_response_msg(LassoIdwsf2Discovery *discovery); +// +//LASSO_EXPORT gint lasso_idwsf2_discovery_build_modify_response_msg(LassoIdwsf2Discovery *discovery); +// +//LASSO_EXPORT gint lasso_idwsf2_discovery_init_modify(LassoIdwsf2Discovery *discovery, +// LassoDiscoResourceOffering *resourceOffering, LassoDiscoDescription *description); + +LASSO_EXPORT gint lasso_idwsf2_discovery_init_query(LassoIdwsf2Discovery *discovery, + const gchar *security_mech_id); + +//LASSO_EXPORT gint lasso_idwsf2_discovery_process_modify_msg(LassoIdwsf2Discovery *discovery, +// const gchar *message, const gchar *security_mech_id); +// +//LASSO_EXPORT gint lasso_idwsf2_discovery_process_modify_response_msg(LassoIdwsf2Discovery *discovery, +// const gchar *message); +// +//LASSO_EXPORT gint lasso_idwsf2_discovery_process_query_msg(LassoIdwsf2Discovery *discovery, +// const gchar *message, const char *security_mech_id); +// +//LASSO_EXPORT gint lasso_idwsf2_discovery_process_query_response_msg(LassoIdwsf2Discovery *discovery, +// const gchar *message); +// +//LASSO_EXPORT LassoDataService* lasso_idwsf2_discovery_get_service(LassoIdwsf2Discovery *discovery, +// const char *service_type); +// +//LASSO_EXPORT GList* lasso_idwsf2_discovery_get_services(LassoIdwsf2Discovery *discovery); +// +//LASSO_EXPORT LassoDiscoDescription* lasso_idwsf2_discovery_get_description_auto( +// LassoDiscoResourceOffering *offering, const gchar *security_mech); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __LASSO_IDWSF2_DISCOVERY_H__ */ diff --git a/lasso/id-wsf-2.0/wsf2_profile.c b/lasso/id-wsf-2.0/wsf2_profile.c new file mode 100644 index 00000000..0e7961fe --- /dev/null +++ b/lasso/id-wsf-2.0/wsf2_profile.c @@ -0,0 +1,1524 @@ +/* $Id: wsf_profile.c,v 1.45 2007/01/05 16:11:02 fpeters Exp $ + * + * Lasso - A free implementation of the Liberty Alliance specifications. + * + * Copyright (C) 2004, 2005 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include <libxml/xpath.h> +#include <libxml/xpathInternals.h> + +#include <xmlsec/xmltree.h> +#include <xmlsec/xmldsig.h> +#include <xmlsec/templates.h> +#include <xmlsec/crypto.h> + +#include <lasso/id-wsf-2.0/wsf2_profile.h> +//#include <lasso/xml/disco_modify.h> +#include <lasso/xml/soap_fault.h> +#include <lasso/xml/soap_binding_correlation.h> +#include <lasso/xml/soap_binding_provider.h> +#include <lasso/xml/soap_binding_processing_context.h> +//#include <lasso/xml/wsse_security.h> +//#include <lasso/xml/saml_assertion.h> +//#include <lasso/xml/saml_authentication_statement.h> +//#include <lasso/xml/saml_subject_statement_abstract.h> +//#include <lasso/xml/saml_subject.h> + +#include <lasso/id-ff/server.h> +#include <lasso/id-ff/providerprivate.h> + +#include <lasso/id-wsf-2.0/wsf2_profile_private.h> + +struct _LassoWsf2ProfilePrivate +{ + gboolean dispose_has_run; +// LassoDiscoDescription *description; + LassoSoapFault *fault; + gchar *public_key; + GList *credentials; +}; + +//gint lasso_wsf_profile_verify_x509_authentication(LassoWsfProfile *profile, +// xmlDoc *doc, xmlSecKey *public_key); +//static gboolean lasso_wsf_profile_has_saml_authentication(LassoWsfProfile *profile); +//static gboolean lasso_wsf_profile_has_x509_authentication(LassoWsfProfile *profile); +//static gint lasso_wsf_profile_verify_credential_signature( +// LassoWsfProfile *profile, xmlDoc *doc, xmlNode *credential); +//static gint lasso_wsf_profile_add_credential_signature(LassoWsfProfile *profile, +// xmlDoc *doc, xmlNode *credential, LassoSignatureMethod sign_method); +//static xmlSecKey* lasso_wsf_profile_get_public_key_from_credential( +// LassoWsfProfile *profile, xmlNode *credential); +//static gint lasso_wsf_profile_verify_saml_authentication(LassoWsfProfile *profile, xmlDoc *doc); +//static gint lasso_wsf_profile_add_soap_signature(LassoWsfProfile *profile, +// xmlDoc *doc, xmlNode *envelope_node, LassoSignatureMethod sign_method); +//static int lasso_wsf_profile_ensure_soap_credentials_signature( +// LassoWsfProfile *profile, xmlDoc *doc, xmlNode *soap_envelope); +//static LassoDiscoDescription* lasso_wsf_profile_get_description_auto( +// LassoDiscoServiceInstance *si, const gchar *security_mech_id); + +/*****************************************************************************/ +/* private methods */ +/*****************************************************************************/ + +//gint +//lasso_wsf_profile_move_credentials(LassoWsfProfile *src, LassoWsfProfile *dest) +//{ +// xmlNode *credential; +// GList *iter; +// +// iter = src->private_data->credentials; +// while (iter) { +// credential = (xmlNode *) iter->data; +// lasso_wsf_profile_add_credential(dest, credential); +// iter = iter->next; +// } +// +// g_list_free(src->private_data->credentials); +// +// return 0; +//} +// +//gint +//lasso_wsf_profile_add_credential(LassoWsfProfile *profile, xmlNode *credential) +//{ +// profile->private_data->credentials = g_list_append(profile->private_data->credentials, +// credential); +// return 0; +//} +// +//void +//lasso_wsf_profile_set_public_key(LassoWsfProfile *profile, const char *public_key) +//{ +// if (public_key) +// profile->private_data->public_key = g_strdup(public_key); +//} +// +//static LassoDiscoDescription* +//lasso_wsf_profile_get_description_auto(LassoDiscoServiceInstance *si, const gchar *security_mech_id) +//{ +// GList *iter, *iter2; +// LassoDiscoDescription *description; +// +// if (security_mech_id == NULL) +// return NULL; +// +// iter = si->Description; +// while (iter) { +// description = LASSO_DISCO_DESCRIPTION(iter->data); +// iter2 = description->SecurityMechID; +// while (iter2) { +// if (strcmp(security_mech_id, iter->data) == 0) +// return description; +// iter2 = iter2->next; +// } +// iter = iter->next; +// } +// +// return NULL; +//} +// +//LassoSoapFault* +//lasso_wsf_profile_get_fault(LassoWsfProfile *profile) +//{ +// return profile->private_data->fault; +//} +// +//static gboolean +//lasso_wsf_profile_has_saml_authentication(LassoWsfProfile *profile) +//{ +// GList *iter; +// gchar *security_mech_id; +// +// if (profile->private_data->description == NULL) +// return FALSE; +// +// iter = profile->private_data->description->SecurityMechID; +// while (iter) { +// security_mech_id = iter->data; +// if (strcmp(security_mech_id, LASSO_SECURITY_MECH_CLIENT_TLS_SAML) == 0 || +// strcmp(security_mech_id, LASSO_SECURITY_MECH_TLS_SAML) == 0 || +// strcmp(security_mech_id, LASSO_SECURITY_MECH_SAML) == 0) { +// return TRUE; +// } +// iter = g_list_next(iter); +// } +// +// return FALSE; +//} +// +//static gboolean +//lasso_wsf_profile_has_x509_authentication(LassoWsfProfile *profile) +//{ +// GList *iter; +// gchar *security_mech_id; +// +// if (profile->private_data->description == NULL) +// return FALSE; +// +// iter = profile->private_data->description->SecurityMechID; +// while (iter) { +// security_mech_id = iter->data; +// if (strcmp(security_mech_id, LASSO_SECURITY_MECH_CLIENT_TLS_X509) == 0 || +// strcmp(security_mech_id, LASSO_SECURITY_MECH_TLS_X509) == 0 || +// strcmp(security_mech_id, LASSO_SECURITY_MECH_X509) == 0) { +// return TRUE; +// } +// iter = g_list_next(iter); +// } +// +// return FALSE; +//} +// +//gboolean +//lasso_security_mech_id_is_saml_authentication(const gchar *security_mech_id) +//{ +// if (!security_mech_id) +// return FALSE; +// +// if (strcmp(security_mech_id, LASSO_SECURITY_MECH_SAML) == 0 || +// strcmp(security_mech_id, LASSO_SECURITY_MECH_TLS_SAML) == 0 || +// strcmp(security_mech_id, LASSO_SECURITY_MECH_CLIENT_TLS_SAML) == 0) +// return TRUE; +// +// return FALSE; +//} +// +//void +//lasso_wsf_profile_set_description(LassoWsfProfile *profile, LassoDiscoDescription *description) +//{ +// profile->private_data->description = g_object_ref(description); +//} +// +//static gint +//lasso_wsf_profile_verify_credential_signature( +// LassoWsfProfile *profile, xmlDoc *doc, xmlNode *credential) +//{ +// LassoProvider *lasso_provider; +// +// xmlSecKeysMngr *keys_mngr = NULL; +// xmlNode *x509data = NULL, *node; +// +// xmlChar *id; +// xmlAttr *id_attr; +// +// xmlSecDSigCtx *dsigCtx; +// +// xmlChar *issuer; +// +// /* Retrieve provider id of credential signer . Issuer could be the right place */ +// issuer = xmlGetProp(credential, (xmlChar*)"Issuer"); +// if (issuer == NULL) { +// return LASSO_PROFILE_ERROR_MISSING_ISSUER; +// } +// +// lasso_provider = lasso_server_get_provider(profile->server, (char*)issuer); +// if (lasso_provider == NULL) { +// return LASSO_SERVER_ERROR_PROVIDER_NOT_FOUND; +// } +// +// /* Set credential reference */ +// id_attr = xmlHasProp(credential, (xmlChar *)"AssertionID"); +// id = xmlGetProp(credential, (xmlChar *) "AssertionID"); +// xmlAddID(NULL, doc, id, id_attr); +// xmlFree(id); +// +// /* Case of X509 signature type */ +// x509data = xmlSecFindNode(xmlDocGetRootElement(doc), xmlSecNodeX509Data, xmlSecDSigNs); +// if (x509data != NULL && lasso_provider != NULL && lasso_provider->ca_cert_chain != NULL) { +// keys_mngr = lasso_load_certs_from_pem_certs_chain_file( +// lasso_provider->ca_cert_chain); +// if (keys_mngr == NULL) { +// return LASSO_DS_ERROR_CA_CERT_CHAIN_LOAD_FAILED; +// } +// } else if (x509data != NULL) { +// return LASSO_DS_ERROR_CA_CERT_CHAIN_LOAD_FAILED; +// } +// +// dsigCtx = xmlSecDSigCtxCreate(keys_mngr); +// +// /* Case of simple public key signature type */ +// if (keys_mngr == NULL) { +// if (lasso_provider != NULL) { +// dsigCtx->signKey = xmlSecKeyDuplicate( +// lasso_provider_get_public_key(lasso_provider)); +// } else if (profile->private_data->public_key) { +// /* TODO */ +// } +// if (dsigCtx->signKey == NULL) { +// xmlSecDSigCtxDestroy(dsigCtx); +// return LASSO_DS_ERROR_PUBLIC_KEY_LOAD_FAILED; +// } +// } +// +// node = xmlSecFindNode(credential, xmlSecNodeSignature, xmlSecDSigNs); +// if (xmlSecDSigCtxVerify(dsigCtx, node) < 0) { +// xmlSecDSigCtxDestroy(dsigCtx); +// if (keys_mngr) +// xmlSecKeysMngrDestroy(keys_mngr); +// return LASSO_DS_ERROR_SIGNATURE_VERIFICATION_FAILED; +// } +// +// if (keys_mngr) +// xmlSecKeysMngrDestroy(keys_mngr); +// +// if (dsigCtx->status != xmlSecDSigStatusSucceeded) { +// xmlSecDSigCtxDestroy(dsigCtx); +// return LASSO_DS_ERROR_INVALID_SIGNATURE; +// } +// +// /* Remove uneeded signature node */ +// xmlUnlinkNode(node); +// xmlFreeNode(node); +// +// return 0; +//} +// +//static gint +//lasso_wsf_profile_add_credential_signature(LassoWsfProfile *profile, +// xmlDoc *doc, xmlNode *credential, LassoSignatureMethod sign_method) +//{ +// xmlNode *signature = NULL, *sign_tmpl, *reference, *key_info; +// char *uri; +// +// xmlAttr *id_attr; +// +// xmlSecDSigCtx *dsigCtx; +// +// /* Add signature template */ +// if (sign_method == LASSO_SIGNATURE_METHOD_RSA_SHA1) { +// signature = xmlSecTmplSignatureCreate(NULL, +// xmlSecTransformExclC14NId, +// xmlSecTransformRsaSha1Id, NULL); +// } else { +// signature = xmlSecTmplSignatureCreate(NULL, +// xmlSecTransformExclC14NId, +// xmlSecTransformDsaSha1Id, NULL); +// } +// +// xmlAddChild(credential, signature); +// +// /* Credential reference */ +// uri = g_strdup_printf("#%s", xmlGetProp(credential, (xmlChar *) "AssertionID")); +// reference = xmlSecTmplSignatureAddReference(signature, xmlSecTransformSha1Id, +// NULL, (xmlChar*)uri, NULL); +// xmlSecTmplReferenceAddTransform(reference, xmlSecTransformEnvelopedId); +// xmlSecTmplReferenceAddTransform(reference, xmlSecTransformExclC14NId); +// id_attr = xmlHasProp(credential, (xmlChar *)"AssertionID"); +// xmlAddID(NULL, doc, xmlGetProp(credential, (xmlChar *) "AssertionID"), id_attr); +// +// /* FIXME: X509 authentication needs X509 signature type */ +// if (profile->server->certificate != NULL && profile->server->certificate[0] != 0) { +// key_info = xmlSecTmplSignatureEnsureKeyInfo(signature, NULL); +// xmlSecTmplKeyInfoAddX509Data(key_info); +// } +// +// /* Sign SOAP message */ +// sign_tmpl = xmlSecFindNode(credential, xmlSecNodeSignature, xmlSecDSigNs); +// if (sign_tmpl == NULL) +// return LASSO_DS_ERROR_SIGNATURE_TEMPLATE_NOT_FOUND; +// +// dsigCtx = xmlSecDSigCtxCreate(NULL); +// dsigCtx->signKey = xmlSecCryptoAppKeyLoad(profile->server->private_key, +// xmlSecKeyDataFormatPem, NULL, NULL, NULL); +// if (dsigCtx->signKey == NULL) { +// xmlSecDSigCtxDestroy(dsigCtx); +// return LASSO_DS_ERROR_PRIVATE_KEY_LOAD_FAILED; +// } +// if (profile->server->certificate != NULL && profile->server->certificate[0] != 0) { +// if (xmlSecCryptoAppKeyCertLoad(dsigCtx->signKey, profile->server->certificate, +// xmlSecKeyDataFormatPem) < 0) { +// xmlSecDSigCtxDestroy(dsigCtx); +// return LASSO_DS_ERROR_CERTIFICATE_LOAD_FAILED; +// } +// } +// +// if (xmlSecDSigCtxSign(dsigCtx, sign_tmpl) < 0) { +// xmlSecDSigCtxDestroy(dsigCtx); +// return LASSO_DS_ERROR_SIGNATURE_FAILED; +// } +// xmlSecDSigCtxDestroy(dsigCtx); +// +// return 0; +//} +// +//static xmlSecKey* +//lasso_wsf_profile_get_public_key_from_credential(LassoWsfProfile *profile, xmlNode *credential) +//{ +// xmlNode *authentication_statement, *subject, *subject_confirmation, *key_info; +// xmlSecKeyPtr public_key; +// xmlSecKeyInfoCtx *ctx; +// +// /* get AuthenticationStatement element */ +// authentication_statement = credential->children; +// while (authentication_statement) { +// if (authentication_statement->type == XML_ELEMENT_NODE && +// strcmp((char*)authentication_statement->name, +// "AuthenticationStatement") == 0) +// break; +// authentication_statement = authentication_statement->next; +// } +// if (authentication_statement == NULL) { +// return NULL; +// } +// +// /* get Subject element */ +// subject = authentication_statement->children; +// while (subject) { +// if (subject->type == XML_ELEMENT_NODE && +// strcmp((char*)subject->name, "Subject") == 0) +// break; +// subject = subject->next; +// } +// if (subject == NULL) { +// return NULL; +// } +// +// /* get SubjectConfirmation */ +// subject_confirmation = subject->children; +// while (subject_confirmation) { +// if (subject_confirmation->type == XML_ELEMENT_NODE && +// strcmp((char*)subject_confirmation->name, "SubjectConfirmation") == 0) +// break; +// subject_confirmation = subject_confirmation->next; +// } +// if (subject_confirmation == NULL) { +// return NULL; +// } +// +// /* get KeyInfo */ +// key_info = subject_confirmation->children; +// while (key_info) { +// if (key_info->type == XML_ELEMENT_NODE && +// strcmp((char*)key_info->name, "KeyInfo") == 0) +// break; +// key_info = key_info->next; +// } +// if (!key_info) +// return NULL; +// +// ctx = xmlSecKeyInfoCtxCreate(NULL); +// xmlSecKeyInfoCtxInitialize(ctx, NULL); +// +// ctx->mode = xmlSecKeyInfoModeRead; +// ctx->keyReq.keyType = xmlSecKeyDataTypePublic; +// +// public_key = xmlSecKeyCreate(); +// +// /* FIXME: get xml sec key from key_info instead of a rebuilt local node */ +// /* xmlSecKeyInfoNodeRead(key_info, public_key, ctx); */ +// +// { +// xmlDoc *doc; +// xmlChar *modulus_value, *exponent_value; +// xmlNode *rsa_key_value, *xmlnode, *modulus, *exponent; +// +// xmlnode = key_info->children; +// while (xmlnode) { +// if (strcmp((char*)xmlnode->name, "KeyValue") == 0) { +// break; +// } +// xmlnode = xmlnode->next; +// } +// rsa_key_value = xmlnode->children; +// while (rsa_key_value) { +// if (strcmp((char*)rsa_key_value->name, "RsaKeyValue") == 0) { +// break; +// } +// rsa_key_value = rsa_key_value->next; +// } +// xmlnode = rsa_key_value->children; +// while (xmlnode) { +// if (strcmp((char*)xmlnode->name, "Modulus") == 0) { +// modulus_value = xmlNodeGetContent(xmlnode); +// } else if (strcmp((char*)xmlnode->name, "Exponent") == 0) { +// exponent_value = xmlNodeGetContent(xmlnode); +// } +// xmlnode = xmlnode->next; +// } +// +// doc = xmlSecCreateTree((xmlChar*)"KeyInfo", +// (xmlChar*)"http://www.w3.org/2000/09/xmldsig#"); +// key_info = xmlDocGetRootElement(doc); +// +// xmlnode = xmlSecAddChild(key_info, (xmlChar*)"KeyValue", +// (xmlChar*)"http://www.w3.org/2000/09/xmldsig#"); +// xmlnode = xmlSecAddChild(xmlnode, (xmlChar*)"RSAKeyValue", +// (xmlChar*)"http://www.w3.org/2000/09/xmldsig#"); +// modulus = xmlSecAddChild(xmlnode, (xmlChar*)"Modulus", +// (xmlChar*)"http://www.w3.org/2000/09/xmldsig#"); +// xmlNodeSetContent(modulus, modulus_value); +// +// exponent = xmlSecAddChild(xmlnode, (xmlChar*)"Exponent", +// (xmlChar*)"http://www.w3.org/2000/09/xmldsig#"); +// xmlNodeSetContent(exponent, exponent_value); +// } +// +// xmlSecKeyInfoNodeRead(key_info, public_key, ctx); +// +// return public_key; +//} +// +//static gint +//lasso_wsf_profile_verify_saml_authentication(LassoWsfProfile *profile, xmlDoc *doc) +//{ +// xmlXPathContext *xpathCtx = NULL; +// xmlXPathObject *xpathObj; +// xmlNode *credential; +// xmlSecKey *public_key; +// int res; +// +// xpathCtx = xmlXPathNewContext(doc); +// +// xmlXPathRegisterNs(xpathCtx, (xmlChar*)"wsse", (xmlChar*)LASSO_WSSE_HREF); +// xmlXPathRegisterNs(xpathCtx, (xmlChar*)"saml", (xmlChar*)LASSO_SAML_ASSERTION_HREF); +// +// xpathObj = xmlXPathEvalExpression((xmlChar*)"//wsse:Security/saml:Assertion", xpathCtx); +// +// /* FIXME: Need to consider more every credentials. */ +// if (xpathObj->nodesetval == NULL || xpathObj->nodesetval->nodeNr == 0) { +// xmlXPathFreeContext(xpathCtx); +// xmlXPathFreeObject(xpathObj); +// return LASSO_PROFILE_ERROR_MISSING_ASSERTION; +// } +// +// +// credential = xpathObj->nodesetval->nodeTab[0]; +// +// res = lasso_wsf_profile_verify_credential_signature(profile, doc, credential); +// if (res < 0) { +// xmlXPathFreeContext(xpathCtx); +// xmlXPathFreeObject(xpathObj); +// return res; +// } +// +// public_key = lasso_wsf_profile_get_public_key_from_credential(profile, credential); +// xmlXPathFreeContext(xpathCtx); +// xmlXPathFreeObject(xpathObj); +// +// if (public_key == NULL) { +// return LASSO_DS_ERROR_PUBLIC_KEY_LOAD_FAILED; +// } +// +// res = lasso_wsf_profile_verify_x509_authentication(profile, doc, public_key); +// xmlSecKeyDestroy(public_key); +// if (res != 0) +// return res; +// +// return 0; +//} +// +//static gint +//lasso_wsf_profile_add_soap_signature(LassoWsfProfile *profile, +// xmlDoc *doc, xmlNode *envelope_node, LassoSignatureMethod sign_method) +//{ +// xmlNode *signature = NULL, *sign_tmpl, *reference, *key_info, *t; +// xmlNode *header = NULL, *provider = NULL, *correlation = NULL, *security = NULL; +// xmlNode *body = NULL; +// xmlSecDSigCtx *dsigCtx; +// xmlChar *id; +// char *uri; +// xmlAttr *id_attr; +// +// /* Get Correlation, Provider, Security, Body elements */ +// t = envelope_node->children; +// while (t) { +// if (strcmp((char *) t->name, "Header") == 0) { +// header = t; +// } else if (strcmp((char *) t->name, "Body") == 0) { +// body = t; +// } +// t = t->next; +// } +// if (header == NULL) +// return LASSO_SOAP_ERROR_MISSING_HEADER; +// +// if (body == NULL) +// return LASSO_SOAP_ERROR_MISSING_BODY; +// +// t = header->children; +// while (t) { +// if (strcmp((char *) t->name, "Correlation") == 0) { +// correlation = t; +// } else if (strcmp((char *) t->name, "Provider") == 0) { +// provider = t; +// } else if (strcmp((char *) t->name, "Security") == 0) { +// security = t; +// } +// t = t->next; +// } +// if (correlation == NULL) +// return LASSO_WSF_PROFILE_ERROR_MISSING_CORRELATION; +// if (security == NULL) +// return LASSO_WSF_PROFILE_ERROR_MISSING_SECURITY; +// +// /* Add signature template */ +// if (sign_method == LASSO_SIGNATURE_METHOD_RSA_SHA1) { +// signature = xmlSecTmplSignatureCreate(NULL, +// xmlSecTransformExclC14NId, +// xmlSecTransformRsaSha1Id, NULL); +// } else { +// signature = xmlSecTmplSignatureCreate(NULL, +// xmlSecTransformExclC14NId, +// xmlSecTransformDsaSha1Id, NULL); +// } +// +// xmlAddChild(security, signature); +// +// /* Correlation reference */ +// id = xmlGetProp(correlation, (xmlChar *) "id"); +// uri = g_strdup_printf("#%s", id); +// reference = xmlSecTmplSignatureAddReference(signature, xmlSecTransformSha1Id, +// NULL, (xmlChar *)uri, NULL); +// xmlFree(uri); +// xmlSecTmplReferenceAddTransform(reference, xmlSecTransformEnvelopedId); +// xmlSecTmplReferenceAddTransform(reference, xmlSecTransformExclC14NId); +// id_attr = xmlHasProp(correlation, (xmlChar *)"id"); +// xmlAddID(NULL, doc, (xmlChar *)id, id_attr); +// xmlFree(id); +// +// /* Body reference */ +// id = xmlGetProp(body, (xmlChar *) "id"); +// uri = g_strdup_printf("#%s", id); +// reference = xmlSecTmplSignatureAddReference(signature, xmlSecTransformSha1Id, +// NULL, (xmlChar *)uri, NULL); +// g_free(uri); +// xmlSecTmplReferenceAddTransform(reference, xmlSecTransformEnvelopedId); +// xmlSecTmplReferenceAddTransform(reference, xmlSecTransformExclC14NId); +// id_attr = xmlHasProp(body, (xmlChar *)"id"); +// xmlAddID(NULL, doc, (xmlChar *)id, id_attr); +// xmlFree(id); +// +// /* Provider reference */ +// if (provider) { +// uri = g_strdup_printf("#%s", xmlGetProp(provider, (xmlChar *) "id")); +// reference = xmlSecTmplSignatureAddReference(signature, xmlSecTransformSha1Id, +// NULL, (xmlChar*)uri, NULL); +// xmlSecTmplReferenceAddTransform(reference, xmlSecTransformEnvelopedId); +// xmlSecTmplReferenceAddTransform(reference, xmlSecTransformExclC14NId); +// id_attr = xmlHasProp(provider, (xmlChar *)"id"); +// xmlAddID(NULL, doc, xmlGetProp(provider, (xmlChar *) "id"), id_attr); +// } +// +// /* FIXME: X509 authentication needs X509 signature type */ +// if (profile->server->certificate != NULL && profile->server->certificate[0] != 0) { +// key_info = xmlSecTmplSignatureEnsureKeyInfo(signature, NULL); +// xmlSecTmplKeyInfoAddX509Data(key_info); +// } +// +// /* Sign SOAP message */ +// sign_tmpl = signature; +// +// dsigCtx = xmlSecDSigCtxCreate(NULL); +// dsigCtx->signKey = xmlSecCryptoAppKeyLoad(profile->server->private_key, +// xmlSecKeyDataFormatPem, NULL, NULL, NULL); +// if (dsigCtx->signKey == NULL) { +// xmlSecDSigCtxDestroy(dsigCtx); +// return LASSO_DS_ERROR_PRIVATE_KEY_LOAD_FAILED; +// } +// if (profile->server->certificate != NULL && profile->server->certificate[0] != 0) { +// if (xmlSecCryptoAppKeyCertLoad(dsigCtx->signKey, profile->server->certificate, +// xmlSecKeyDataFormatPem) < 0) { +// xmlSecDSigCtxDestroy(dsigCtx); +// return LASSO_DS_ERROR_CERTIFICATE_LOAD_FAILED; +// } +// } +// if (xmlSecDSigCtxSign(dsigCtx, sign_tmpl) < 0) { +// xmlSecDSigCtxDestroy(dsigCtx); +// return LASSO_DS_ERROR_SIGNATURE_FAILED; +// } +// xmlSecDSigCtxDestroy(dsigCtx); +// +// return 0; +//} +// +//gint +//lasso_wsf_profile_verify_x509_authentication(LassoWsfProfile *profile, +// xmlDoc *doc, xmlSecKey *public_key) +//{ +// LassoProvider *lasso_provider = NULL; +// +// xmlNode *provider = NULL, *correlation = NULL, *body = NULL; +// xmlNode *x509data = NULL, *node; +// xmlChar *id; +// xmlAttr *id_attr; +// +// xmlSecKeysMngr *keys_mngr = NULL; +// xmlSecDSigCtx *dsigCtx; +// +// xmlXPathContext *xpathCtx = NULL; +// xmlXPathObject *xpathObj; +// +// xpathCtx = xmlXPathNewContext(doc); +// +// /* Correlation */ +// xmlXPathRegisterNs(xpathCtx, (xmlChar*)"sb", (xmlChar*)LASSO_SOAP_BINDING_HREF); +// xpathObj = xmlXPathEvalExpression((xmlChar*)"//sb:Correlation", xpathCtx); +// if (xpathObj->nodesetval && xpathObj->nodesetval->nodeNr) { +// correlation = xpathObj->nodesetval->nodeTab[0]; +// } +// if (correlation == NULL) { +// xmlXPathFreeObject(xpathObj); +// xmlXPathFreeContext(xpathCtx); +// return LASSO_WSF_PROFILE_ERROR_MISSING_CORRELATION; +// } +// +// id_attr = xmlHasProp(correlation, (xmlChar *)"id"); +// id = xmlGetProp(correlation, (xmlChar *) "id"); +// xmlAddID(NULL, doc, id, id_attr); +// xmlFree(id); +// +// xmlXPathFreeObject(xpathObj); +// xpathObj = NULL; +// +// /* Body */ +// xmlXPathRegisterNs(xpathCtx, (xmlChar*)"s", (xmlChar*)LASSO_SOAP_ENV_HREF); +// xpathObj = xmlXPathEvalExpression((xmlChar*)"//s:Body", xpathCtx); +// if (xpathObj->nodesetval && xpathObj->nodesetval->nodeNr) { +// body = xpathObj->nodesetval->nodeTab[0]; +// } +// if (body == NULL) { +// xmlXPathFreeObject(xpathObj); +// xmlXPathFreeContext(xpathCtx); +// return LASSO_SOAP_ERROR_MISSING_BODY; +// } +// +// id_attr = xmlHasProp(body, (xmlChar *)"id"); +// id = xmlGetProp(body, (xmlChar *) "id"); +// xmlAddID(NULL, doc, id, id_attr); +// xmlFree(id); +// +// xmlXPathFreeObject(xpathObj); +// xpathObj = NULL; +// +// /* Provider */ +// xmlXPathRegisterNs(xpathCtx, (xmlChar*)"sb", (xmlChar*)LASSO_SOAP_BINDING_HREF); +// xpathObj = xmlXPathEvalExpression((xmlChar*)"//sb:Provider", xpathCtx); +// if (xpathObj->nodesetval && xpathObj->nodesetval->nodeNr) { +// provider = xpathObj->nodesetval->nodeTab[0]; +// } +// if (provider) { +// char *providerID; +// id_attr = xmlHasProp(provider, (xmlChar *)"id"); +// id = xmlGetProp(provider, (xmlChar *) "id"); +// xmlAddID(NULL, doc, id, id_attr); +// xmlFree(id); +// +// providerID = (char *) xmlGetProp(provider, (xmlChar *) "providerID"); +// lasso_provider = lasso_server_get_provider(profile->server, providerID); +// xmlFree(providerID); +// } +// +// xmlXPathFreeObject(xpathObj); +// xpathObj = NULL; +// +// /* Verify signature */ +// node = NULL; +// xmlXPathRegisterNs(xpathCtx, (xmlChar*)"ds", (xmlChar*)LASSO_DS_HREF); +// xpathObj = xmlXPathEvalExpression((xmlChar*)"//ds:Signature", xpathCtx); +// if (xpathObj->nodesetval && xpathObj->nodesetval->nodeNr) { +// node = xpathObj->nodesetval->nodeTab[0]; +// } +// if (node == NULL) { +// xmlXPathFreeContext(xpathCtx); +// xmlXPathFreeObject(xpathObj); +// return LASSO_DS_ERROR_SIGNATURE_NOT_FOUND; +// } +// +// /* Case of X509 signature type */ +// x509data = xmlSecFindNode(xmlDocGetRootElement(doc), xmlSecNodeX509Data, xmlSecDSigNs); +// if (x509data != NULL && lasso_provider != NULL && lasso_provider->ca_cert_chain != NULL) { +// keys_mngr = lasso_load_certs_from_pem_certs_chain_file( +// lasso_provider->ca_cert_chain); +// if (keys_mngr == NULL) { +// xmlXPathFreeObject(xpathObj); +// xmlXPathFreeContext(xpathCtx); +// return LASSO_DS_ERROR_CA_CERT_CHAIN_LOAD_FAILED; +// } +// } else if (x509data != NULL) { +// xmlXPathFreeObject(xpathObj); +// xmlXPathFreeContext(xpathCtx); +// return LASSO_DS_ERROR_CA_CERT_CHAIN_LOAD_FAILED; +// } +// +// dsigCtx = xmlSecDSigCtxCreate(keys_mngr); +// +// /* Case of simple public key signature type */ +// if (keys_mngr == NULL) { +// if (lasso_provider != NULL) { +// dsigCtx->signKey = xmlSecKeyDuplicate( +// lasso_provider_get_public_key(lasso_provider)); +// } else if (public_key) { +// dsigCtx->signKey = xmlSecKeyDuplicate(public_key); +// } +// if (dsigCtx->signKey == NULL) { +// xmlSecDSigCtxDestroy(dsigCtx); +// xmlXPathFreeObject(xpathObj); +// xmlXPathFreeContext(xpathCtx); +// return LASSO_DS_ERROR_PUBLIC_KEY_LOAD_FAILED; +// } +// } +// +// if (xmlSecDSigCtxVerify(dsigCtx, node) < 0) { +// xmlSecDSigCtxDestroy(dsigCtx); +// if (keys_mngr) +// xmlSecKeysMngrDestroy(keys_mngr); +// xmlXPathFreeObject(xpathObj); +// xmlXPathFreeContext(xpathCtx); +// return LASSO_DS_ERROR_SIGNATURE_VERIFICATION_FAILED; +// } +// +// xmlXPathFreeObject(xpathObj); +// xmlXPathFreeContext(xpathCtx); +// +// if (keys_mngr) +// xmlSecKeysMngrDestroy(keys_mngr); +// +// if (dsigCtx->status != xmlSecDSigStatusSucceeded) { +// xmlSecDSigCtxDestroy(dsigCtx); +// return LASSO_DS_ERROR_INVALID_SIGNATURE; +// } +// +// return 0; +//} + +LassoSoapEnvelope* +lasso_wsf2_profile_build_soap_envelope(const char *refToMessageId, const char *providerId) +{ + LassoSoapEnvelope *envelope; + LassoSoapHeader *header; + LassoSoapBody *body; + LassoSoapBindingCorrelation *correlation; + gchar *messageId, *timestamp; + + /* Body */ + body = lasso_soap_body_new(); + body->id = lasso_build_unique_id(32); + envelope = lasso_soap_envelope_new(body); + + /* Header */ + header = lasso_soap_header_new(); + envelope->Header = header; + + /* Correlation */ + messageId = lasso_build_unique_id(32); + timestamp = lasso_get_current_time(); + correlation = lasso_soap_binding_correlation_new(messageId, timestamp); + correlation->id = lasso_build_unique_id(32); + if (refToMessageId != NULL) + correlation->refToMessageID = g_strdup(refToMessageId); + header->Other = g_list_append(header->Other, correlation); + + /* Provider */ + if (providerId) { + LassoSoapBindingProvider *provider = lasso_soap_binding_provider_new(providerId); + provider->id = lasso_build_unique_id(32); + header->Other = g_list_append(header->Other, provider); + } + + return envelope; +} + +/*****************************************************************************/ +/* public methods */ +/*****************************************************************************/ + +/** + * lasso_wsf_profile_is_principal_online(): + * @profile: a #LassoWsfProfile + * + * Check if the principal is set to be online. + * + **/ +//gboolean +//lasso_wsf_profile_principal_is_online(LassoWsfProfile *profile) +//{ +// LassoSoapHeader *header; +// LassoSoapBindingProcessingContext *processing_context = NULL; +// GList *iter; +// +// header = profile->soap_envelope_request->Header; +// iter = header->Other; +// while (iter) { +// if (LASSO_IS_SOAP_BINDING_PROCESSING_CONTEXT(iter->data) == TRUE) { +// processing_context = iter->data; +// break; +// } +// iter = g_list_next(iter); +// } +// if (!processing_context) +// return FALSE; +// if (!processing_context->content) +// return FALSE; +// +// if (strcmp(processing_context->content, +// LASSO_SOAP_BINDING_PROCESS_CONTEXT_PRINCIPAL_ONLINE) == 0) +// return TRUE; +// +// return FALSE; +//} +// +///** +// * lasso_wsf_profile_set_principal_online(): +// * @profile: a #LassoWsfProfile +// * @status : a char* representing status of principal. +// * +// * Set the status of the principal. +// * +// **/ +//void +//lasso_wsf_profile_set_principal_status(LassoWsfProfile *profile, const char *status) +//{ +// LassoSoapHeader *header; +// LassoSoapBindingProcessingContext *processing_context = NULL; +// GList *iter; +// +// header = profile->soap_envelope_request->Header; +// iter = header->Other; +// while (iter) { +// if (LASSO_IS_SOAP_BINDING_PROCESSING_CONTEXT(iter->data) == TRUE) { +// processing_context = iter->data; +// break; +// } +// iter = g_list_next(iter); +// } +// if (!processing_context) { +// processing_context = LASSO_SOAP_BINDING_PROCESSING_CONTEXT( +// lasso_soap_binding_processing_context_new()); +// header->Other = g_list_append(header->Other, processing_context); +// } +// if (processing_context->content) +// g_free(processing_context->content); +// processing_context->content = g_strdup(status); +//} +// +///** +// * lasso_wsf_profile_set_principal_online(): +// * @profile: a #LassoWsfProfile +// * +// * Set the principal status as offline. +// * +// **/ +//void +//lasso_wsf_profile_set_principal_online(LassoWsfProfile *profile) +//{ +// lasso_wsf_profile_set_principal_status( +// profile, LASSO_SOAP_BINDING_PROCESS_CONTEXT_PRINCIPAL_ONLINE); +//} +// +///** +// * lasso_wsf_profile_set_principal_offline(): +// * @profile: a #LassoWsfProfile +// * +// * Set the principal status as offline. +// * +// **/ +//void +//lasso_wsf_profile_set_principal_offline(LassoWsfProfile *profile) +//{ +// lasso_wsf_profile_set_principal_status( +// profile, LASSO_SOAP_BINDING_PROCESS_CONTEXT_PRINCIPAL_OFFLINE); +//} +// +///** +// * lasso_wsf_profile_get_identity: +// * @profile: a #LassoWsfProfile +// * +// * Gets the identity bound to @profile. +// * +// * Return value: the identity or NULL if it none was found. The #LassoIdentity +// * object is internally allocated and must not be freed by the caller. +// **/ +//LassoIdentity* +//lasso_wsf_profile_get_identity(LassoWsfProfile *profile) +//{ +// if (profile->identity && g_hash_table_size(profile->identity->federations)) +// return profile->identity; +// return NULL; +//} +// +// +///** +// * lasso_wsf_profile_get_session: +// * @profile: a #LassoWsfProfile +// * +// * Gets the session bound to @profile. +// * +// * Return value: the session or NULL if it none was found. The #LassoSession +// * object is internally allocated and must not be freed by the caller. +// **/ +//LassoSession* +//lasso_wsf_profile_get_session(LassoWsfProfile *profile) +//{ +// if (profile->session == NULL) +// return NULL; +// +// if (lasso_session_is_empty(profile->session)) +// return NULL; +// +// return profile->session; +//} +// +// +///** +// * lasso_wsf_profile_is_identity_dirty: +// * @profile: a #LassoWsfProfile +// * +// * Checks whether identity has been modified (and should therefore be saved). +// * +// * Return value: %TRUE if identity has changed +// **/ +//gboolean +//lasso_wsf_profile_is_identity_dirty(LassoWsfProfile *profile) +//{ +// return (profile->identity && profile->identity->is_dirty); +//} +// +// +///** +// * lasso_wsf_profile_is_session_dirty: +// * @profile: a #LassoWsfProfile +// * +// * Checks whether session has been modified (and should therefore be saved). +// * +// * Return value: %TRUE if session has changed +// **/ +//gboolean +//lasso_wsf_profile_is_session_dirty(LassoWsfProfile *profile) +//{ +// return (profile->session && profile->session->is_dirty); +//} +// +// +///** +// * lasso_wsf_profile_set_identity_from_dump: +// * @profile: a #LassoWsfProfile +// * @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. +// **/ +//gint +//lasso_wsf_profile_set_identity_from_dump(LassoWsfProfile *profile, const gchar *dump) +//{ +// g_return_val_if_fail(dump != NULL, LASSO_PARAM_ERROR_INVALID_VALUE); +// +// profile->identity = lasso_identity_new_from_dump(dump); +// if (profile->identity == NULL) +// return critical_error(LASSO_PROFILE_ERROR_BAD_IDENTITY_DUMP); +// +// return 0; +//} +// +// +///** +// * lasso_wsf_profile_set_session_from_dump: +// * @profile: a #LassoWsfProfile +// * @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. +// **/ +//gint +//lasso_wsf_profile_set_session_from_dump(LassoWsfProfile *profile, const gchar *dump) +//{ +// g_return_val_if_fail(dump != NULL, LASSO_PARAM_ERROR_INVALID_VALUE); +// +// profile->session = lasso_session_new_from_dump(dump); +// if (profile->session == NULL) +// return critical_error(LASSO_PROFILE_ERROR_BAD_SESSION_DUMP); +// profile->session->is_dirty = FALSE; +// +// return 0; +//} + + + +gint +lasso_wsf2_profile_init_soap_request(LassoWsf2Profile *profile, LassoNode *request) +{ + LassoSoapEnvelope *envelope; + + envelope = lasso_wsf2_profile_build_soap_envelope(NULL, + LASSO_PROVIDER(profile->server)->ProviderID); + LASSO_WSF2_PROFILE(profile)->soap_envelope_request = envelope; + envelope->Body->any = g_list_append(envelope->Body->any, request); + + return 0; +} + +gint +lasso_wsf2_profile_build_soap_request_msg(LassoWsf2Profile *profile) +{ + LassoSoapEnvelope *envelope; + LassoSoapHeader *header; +// LassoWsseSecurity *security = NULL; + int ret; + GList *iter = NULL; + xmlNode *security_xmlNode, *credential; + xmlOutputBuffer *buf; + xmlCharEncodingHandler *handler; + xmlDoc *doc = NULL; + xmlNode *envelope_node = NULL; + xmlXPathContext *xpathCtx = NULL; + xmlXPathObject *xpathObj = NULL; + + + g_return_val_if_fail(LASSO_IS_WSF2_PROFILE(profile), + LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ); + + envelope = profile->soap_envelope_request; + + /* FIXME: find a better way to add needed security element */ +// if (lasso_wsf_profile_has_saml_authentication(profile) == TRUE || +// lasso_wsf_profile_has_x509_authentication(profile) == TRUE) { +// security = lasso_wsse_security_new(); +// header = envelope->Header; +// header->Other = g_list_append(header->Other, security); +// } + + /* Apply wsf authentication */ + doc = xmlNewDoc((xmlChar*)"1.0"); + envelope_node = lasso_node_get_xmlNode(LASSO_NODE(envelope), FALSE); + xmlDocSetRootElement(doc, envelope_node); + +// if (lasso_wsf_profile_has_saml_authentication(profile) == TRUE) { +// if (profile->private_data->credentials) { +// xpathCtx = xmlXPathNewContext(doc); +// +// xmlXPathRegisterNs(xpathCtx, (xmlChar*)"wsse", (xmlChar*)LASSO_WSSE_HREF); +// xpathObj = xmlXPathEvalExpression((xmlChar*)"//wsse:Security", xpathCtx); +// +// if (xpathObj->nodesetval && xpathObj->nodesetval->nodeNr) { +// security_xmlNode = xpathObj->nodesetval->nodeTab[0]; +// iter = profile->private_data->credentials; +// +// /* FIXME: not sure it's the proper way to avoid ns error */ +// xmlNewNs(envelope_node, +// (xmlChar*)LASSO_SAML_ASSERTION_HREF, +// (xmlChar*)LASSO_SAML_ASSERTION_PREFIX); +// xmlNewNs(envelope_node, +// (xmlChar*)LASSO_DS_HREF, +// (xmlChar*)LASSO_DS_PREFIX); +// +// while (iter) { +// credential = (xmlNode *) iter->data; +// credential = xmlAddChild(security_xmlNode, credential); +// iter = iter->next; +// } +// /* xml doc has xml node credentials, so remove profile +// credential list */ +// g_list_free(profile->private_data->credentials); +// } +// +// xmlXPathFreeContext(xpathCtx); +// xmlXPathFreeObject(xpathObj); +// xpathCtx = NULL; +// xpathObj = NULL; +// } + + /* FIXME: do we need to sign if SAML authentication or X509 authentication ? */ +// ret = lasso_wsf_profile_add_soap_signature(profile, doc, envelope_node, +// LASSO_SIGNATURE_METHOD_RSA_SHA1); +// if (ret != 0) { +// xmlFreeDoc(doc); +// return ret; +// } +// } + +// if (lasso_wsf_profile_has_x509_authentication(profile) == TRUE) { +// ret = lasso_wsf_profile_add_soap_signature(profile, doc, envelope_node, +// LASSO_SIGNATURE_METHOD_RSA_SHA1); +// if (ret != 0) { +// xmlFreeDoc(doc); +// return ret; +// } +// } + + /* Dump soap request */ + handler = xmlFindCharEncodingHandler("utf-8"); + buf = xmlAllocOutputBuffer(handler); + xmlNodeDumpOutput(buf, NULL, envelope_node, 0, 0, "utf-8"); + xmlOutputBufferFlush(buf); + profile->msg_body = g_strdup( + (char*)(buf->conv ? buf->conv->content : buf->buffer->content)); + xmlOutputBufferClose(buf); + xmlFreeDoc(doc); + + return 0; +} + +//static int +//lasso_wsf_profile_ensure_soap_credentials_signature(LassoWsfProfile *profile, +// xmlDoc *doc, xmlNode *soap_envelope) +//{ +// xmlXPathContext *xpathCtx = NULL; +// xmlXPathObject *xpathObj; +// int i; +// +// xpathCtx = xmlXPathNewContext(doc); +// +// xmlXPathRegisterNs(xpathCtx, (xmlChar*)"wsse", (xmlChar*)LASSO_WSSE_HREF); +// xmlXPathRegisterNs(xpathCtx, (xmlChar*)"saml", (xmlChar*)LASSO_SAML_ASSERTION_HREF); +// +// /* FIXME: should find credential from //wsse:Security/saml:Assertion instead.*/ +// xpathObj = xmlXPathEvalExpression((xmlChar*)"//saml:Assertion", xpathCtx); +// if (xpathObj->nodesetval && xpathObj->nodesetval->nodeNr) { +// for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) { +// lasso_wsf_profile_add_credential_signature(profile, doc, +// xpathObj->nodesetval->nodeTab[i], LASSO_SIGNATURE_METHOD_RSA_SHA1); +// } +// } +// +// xmlXPathFreeContext(xpathCtx); +// xmlXPathFreeObject(xpathObj); +// +// return 0; +//} +// +//int +//lasso_wsf_profile_build_soap_response_msg(LassoWsfProfile *profile) +//{ +// LassoSoapEnvelope *envelope; +// LassoSoapHeader *header; +// LassoWsseSecurity *security; +// +// xmlNode *soap_envelope; +// +// xmlDoc *doc; +// +// xmlOutputBuffer *buf; +// xmlCharEncodingHandler *handler; +// +// g_return_val_if_fail(LASSO_IS_WSF_PROFILE(profile), LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ); +// +// /* FIXME: find a better way to add needed security element */ +// envelope = profile->soap_envelope_response; +// if (lasso_wsf_profile_has_saml_authentication(profile) == TRUE || +// lasso_wsf_profile_has_x509_authentication(profile) == TRUE) { +// security = lasso_wsse_security_new(); +// header = envelope->Header; +// header->Other = g_list_append(header->Other, security); +// } +// +// /* Apply wsf authentication */ +// doc = xmlNewDoc((xmlChar*)"1.0"); +// soap_envelope = lasso_node_get_xmlNode(LASSO_NODE(envelope), TRUE); +// xmlDocSetRootElement(doc, soap_envelope); +// +// /* SAML authentication, if credentials in response, verify they are signed */ +// lasso_wsf_profile_ensure_soap_credentials_signature(profile, doc, soap_envelope); +// +// /* X509 authentication */ +// if (lasso_wsf_profile_has_x509_authentication(profile) == TRUE) { +// int res = lasso_wsf_profile_add_soap_signature(profile, doc, soap_envelope, +// LASSO_SIGNATURE_METHOD_RSA_SHA1); +// if (res != 0) { +// xmlFreeDoc(doc); +// return res; +// } +// } +// +// /* Dump soap response */ +// handler = xmlFindCharEncodingHandler("utf-8"); +// buf = xmlAllocOutputBuffer(handler); +// xmlNodeDumpOutput(buf, NULL, soap_envelope, 0, 0, "utf-8"); +// xmlOutputBufferFlush(buf); +// profile->msg_body = g_strdup( +// (char*)(buf->conv ? buf->conv->content : buf->buffer->content)); +// xmlOutputBufferClose(buf); +// xmlFreeDoc(doc); +// +// return 0; +//} +// +//gint +//lasso_wsf_profile_process_soap_request_msg(LassoWsfProfile *profile, const gchar *message, +// const gchar *service_type, const gchar *security_mech_id) +//{ +// LassoDiscoServiceInstance *si; +// LassoSoapBindingCorrelation *correlation; +// LassoSoapEnvelope *envelope = NULL; +// LassoSoapFault *fault = NULL; +// gchar *messageId; +// int res = 0; +// xmlDoc *doc; +// +// g_return_val_if_fail(LASSO_IS_WSF_PROFILE(profile), LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ); +// g_return_val_if_fail(message != NULL, LASSO_PARAM_ERROR_INVALID_VALUE); +// +// si = lasso_server_get_service(profile->server, (char *) service_type); +// +// if (security_mech_id == NULL) { +// if (si) { +// profile->private_data->description = LASSO_DISCO_DESCRIPTION( +// si->Description->data); +// } else { +// profile->private_data->description = NULL; +// } +// } else { +// if (si == NULL) { +// return LASSO_PROFILE_ERROR_MISSING_SERVICE_INSTANCE; +// } else { +// lasso_wsf_profile_get_description_auto(si, security_mech_id); +// } +// } +// +// doc = xmlParseMemory(message, strlen(message)); +// +// /* Verify authentication mecanisms */ +// if (lasso_wsf_profile_has_x509_authentication(profile) == TRUE) { +// res = lasso_wsf_profile_verify_x509_authentication(profile, doc, NULL); +// } else if (lasso_wsf_profile_has_saml_authentication(profile) == TRUE) { +// res = lasso_wsf_profile_verify_saml_authentication(profile, doc); +// } +// +// /* FIXME: Return a soap fault if authentication verification failed ? */ +// if (res > 0) { +// fault = lasso_soap_fault_new(); +// fault->faultstring = g_strdup("Invalid signature"); +// } else if (res < 0) { +// xmlFreeDoc(doc); +// return res; +// } +// +// /* FIXME: Remove Signature element if exists, it seg fault when a call to +// lasso_node_new_from_xmlNode() */ +// { +// xmlNode *xmlnode = xmlSecFindNode(xmlDocGetRootElement(doc), xmlSecNodeSignature, +// xmlSecDSigNs); +// if (xmlnode) { +// xmlUnlinkNode(xmlnode); +// xmlFreeNode(xmlnode); +// } +// } +// +// /* Get soap request and his message id */ +// envelope = LASSO_SOAP_ENVELOPE(lasso_node_new_from_xmlNode(xmlDocGetRootElement(doc))); +// profile->soap_envelope_request = envelope; +// profile->request = LASSO_NODE(envelope->Body->any->data); +// correlation = LASSO_SOAP_BINDING_CORRELATION(envelope->Header->Other->data); +// messageId = correlation->messageID; +// +// /* Set soap response */ +// envelope = lasso_wsf_profile_build_soap_envelope(messageId, +// LASSO_PROVIDER(profile->server)->ProviderID); +// LASSO_WSF_PROFILE(profile)->soap_envelope_response = envelope; +// +// /* If fault built at this level (X509 authentication error ?), +// then save it in soap response */ +// if (fault) { +// envelope->Body->any = g_list_append(envelope->Body->any, fault); +// /* FIXME: Need to store it in private data's profile ? */ +// profile->private_data->fault = fault; +// } +// +// xmlFreeDoc(doc); +// +// return res; +//} +// +//gint +//lasso_wsf_profile_process_soap_response_msg(LassoWsfProfile *profile, const gchar *message) +//{ +// LassoSoapEnvelope *envelope; +// xmlNode *credential; +// int res = 0; +// +// xmlXPathContext *xpathCtx = NULL; +// xmlXPathObject *xpathObj; +// +// xmlDoc *doc; +// +// g_return_val_if_fail(LASSO_IS_WSF_PROFILE(profile), LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ); +// g_return_val_if_fail(message != NULL, LASSO_PARAM_ERROR_INVALID_VALUE); +// +// doc = xmlParseMemory(message, strlen(message)); +// +// if (lasso_wsf_profile_has_x509_authentication(profile) == TRUE) { +// xmlNode *xmlnode; +// int res; +// +// res = lasso_wsf_profile_verify_x509_authentication(profile, doc, NULL); +// if (res != 0) { +// xmlFreeDoc(doc); +// return res; +// } +// +// /* FIXME: Remove Signature element if exists, it seg fault when a call to +// lasso_node_new_from_xmlNode() */ +// xmlnode = xmlSecFindNode(xmlDocGetRootElement(doc), xmlSecNodeSignature, +// xmlSecDSigNs); +// if (xmlnode) { +// xmlUnlinkNode(xmlnode); +// xmlFreeNode(xmlnode); +// } +// } +// +// if (res != 0) { +// xmlFreeDoc(doc); +// return res; +// } +// +// /* If credentials are found, save and remove them from message */ +// { +// int i; +// +// xpathCtx = xmlXPathNewContext(doc); +// xmlXPathRegisterNs(xpathCtx, (xmlChar*)"saml", (xmlChar*)LASSO_SAML_ASSERTION_HREF); +// xpathObj = xmlXPathEvalExpression((xmlChar*)"//saml:Assertion", xpathCtx); +// if (xpathObj->nodesetval && xpathObj->nodesetval->nodeNr) { +// for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) { +// credential = xpathObj->nodesetval->nodeTab[i]; +// xmlUnlinkNode(credential); +// lasso_wsf_profile_add_credential(profile, credential); +// } +// } +// xmlXPathFreeContext(xpathCtx); +// xmlXPathFreeObject(xpathObj); +// } +// +// envelope = LASSO_SOAP_ENVELOPE(lasso_node_new_from_xmlNode(xmlDocGetRootElement(doc))); +// xmlFreeDoc(doc); +// +// profile->soap_envelope_response = envelope; +// +// /* Soap Fault message */ +// if (LASSO_IS_SOAP_FAULT(envelope->Body->any->data) == FALSE) +// profile->response = LASSO_NODE(envelope->Body->any->data); +// +// return 0; +//} +// +//LassoSoapBindingProvider *lasso_wsf_profile_set_provider_soap_request(LassoWsfProfile *profile, +// const char *providerId) +//{ +// LassoSoapBindingProvider *provider; +// LassoSoapEnvelope *soap_request; +// LassoSoapHeader *header; +// +// g_return_val_if_fail(LASSO_IS_WSF_PROFILE(profile), NULL); +// g_return_val_if_fail(providerId != NULL, NULL); +// +// soap_request = profile->soap_envelope_request; +// g_return_val_if_fail(LASSO_IS_SOAP_ENVELOPE(soap_request) == TRUE, NULL); +// +// header = profile->soap_envelope_request->Header; +// provider = lasso_soap_binding_provider_new(providerId); +// header->Other = g_list_append(header->Other, provider); +// +// return provider; +//} + +/*****************************************************************************/ +/* overrided parent class methods */ +/*****************************************************************************/ + +static LassoNodeClass *parent_class = NULL; + +static void +dispose(GObject *object) +{ + LassoWsf2Profile *profile = LASSO_WSF2_PROFILE(object); + + if (profile->private_data->dispose_has_run == TRUE) + return; + profile->private_data->dispose_has_run = TRUE; + + G_OBJECT_CLASS(parent_class)->dispose(object); +} + +static void +finalize(GObject *object) +{ + LassoWsf2Profile *profile = LASSO_WSF2_PROFILE(object); + g_free(profile->private_data); + profile->private_data = NULL; + G_OBJECT_CLASS(parent_class)->finalize(object); +} + +/*****************************************************************************/ +/* instance and class init functions */ +/*****************************************************************************/ + +static void +instance_init(LassoWsf2Profile *profile) +{ + profile->server = NULL; + profile->request = NULL; + profile->response = NULL; + profile->soap_envelope_request = NULL; + profile->soap_envelope_response = NULL; + profile->msg_url = NULL; + profile->msg_body = NULL; + + profile->private_data = g_new0(LassoWsf2ProfilePrivate, 1); + profile->private_data->dispose_has_run = FALSE; +// profile->private_data->description = NULL; + profile->private_data->fault = NULL; + profile->private_data->credentials = NULL; +} + +static void +class_init(LassoWsf2ProfileClass *klass) +{ + parent_class = g_type_class_peek_parent(klass); + + G_OBJECT_CLASS(klass)->dispose = dispose; + G_OBJECT_CLASS(klass)->finalize = finalize; +} + +GType +lasso_wsf2_profile_get_type() +{ + static GType this_type = 0; + + if (!this_type) { + static const GTypeInfo this_info = { + sizeof(LassoWsf2ProfileClass), + NULL, + NULL, + (GClassInitFunc) class_init, + NULL, + NULL, + sizeof(LassoWsf2Profile), + 0, + (GInstanceInitFunc) instance_init, + }; + + this_type = g_type_register_static(LASSO_TYPE_NODE, + "LassoWsf2Profile", &this_info, 0); + } + return this_type; +} + +LassoWsf2Profile* +lasso_wsf2_profile_new(LassoServer *server) +{ + LassoWsf2Profile *profile = NULL; + + g_return_val_if_fail(server != NULL, NULL); + + profile = g_object_new(LASSO_TYPE_WSF2_PROFILE, NULL); + + return profile; +} diff --git a/lasso/id-wsf-2.0/wsf2_profile.h b/lasso/id-wsf-2.0/wsf2_profile.h new file mode 100644 index 00000000..eb398d2d --- /dev/null +++ b/lasso/id-wsf-2.0/wsf2_profile.h @@ -0,0 +1,133 @@ +/* $Id: wsf_profile.h,v 1.13 2006/11/14 17:07:30 fpeters Exp $ + * + * Lasso - A free implementation of the Liberty Alliance specifications. + * + * Copyright (C) 2004, 2005 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef __LASSO_WSF2_PROFILE_H__ +#define __LASSO_WSF2_PROFILE_H__ + +#ifdef __cplusplus +extern "C" { + +#endif /* __cplusplus */ + +#include <lasso/id-ff/server.h> +#include <lasso/id-ff/identity.h> +#include <lasso/id-ff/session.h> +#include <lasso/xml/soap_envelope.h> +#include <lasso/xml/soap_binding_provider.h> +//#include <lasso/xml/saml_assertion.h> + +#define LASSO_TYPE_WSF2_PROFILE (lasso_wsf2_profile_get_type()) +#define LASSO_WSF2_PROFILE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \ + LASSO_TYPE_WSF2_PROFILE, LassoWsf2Profile)) +#define LASSO_WSF2_PROFILE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), LASSO_TYPE_WSF2_PROFILE, LassoWsf2ProfileClass)) +#define LASSO_IS_WSF2_PROFILE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), LASSO_TYPE_WSF2_PROFILE)) +#define LASSO_IS_WSF2_PROFILE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), \ + LASSO_TYPE_WSF2_PROFILE)) +#define LASSO_WSF2_PROFILE_GET_CLASS(o) \ + (G_TYPE_INSTANCE_GET_CLASS ((o), LASSO_TYPE_WSF2_PROFILE, LassoWsf2ProfileClass)) + +typedef struct _LassoWsf2Profile LassoWsf2Profile; +typedef struct _LassoWsf2ProfileClass LassoWsf2ProfileClass; +typedef struct _LassoWsf2ProfilePrivate LassoWsf2ProfilePrivate; + +struct _LassoWsf2Profile { + LassoNode parent; + + LassoServer *server; + + LassoNode *request; + LassoNode *response; + + LassoSoapEnvelope *soap_envelope_request; + LassoSoapEnvelope *soap_envelope_response; + + gchar *msg_url; + gchar *msg_body; + + /*< private >*/ + LassoIdentity *identity; + LassoSession *session; + + LassoWsf2ProfilePrivate *private_data; +}; + +struct _LassoWsf2ProfileClass { + LassoNodeClass parent; +}; + +LASSO_EXPORT GType lasso_wsf2_profile_get_type(void); + +//LASSO_EXPORT gboolean lasso_security_mech_id_is_saml_authentication(const gchar *security_mech_id); +// +//LASSO_EXPORT gint lasso_wsf_profile_move_credentials(LassoWsfProfile *src, LassoWsfProfile *dest); +// +//LASSO_EXPORT LassoIdentity* lasso_wsf_profile_get_identity(LassoWsfProfile *profile); +//LASSO_EXPORT LassoSession* lasso_wsf_profile_get_session(LassoWsfProfile *profile); +//LASSO_EXPORT gboolean lasso_wsf_profile_is_identity_dirty(LassoWsfProfile *profile); +//LASSO_EXPORT gboolean lasso_wsf_profile_is_session_dirty(LassoWsfProfile *profile); +//LASSO_EXPORT gint lasso_wsf_profile_set_identity_from_dump(LassoWsfProfile *profile, +// const gchar *dump); +//LASSO_EXPORT gint lasso_wsf_profile_set_session_from_dump(LassoWsfProfile *profile, +// const gchar *dump); + +LASSO_EXPORT LassoSoapEnvelope* lasso_wsf2_profile_build_soap_envelope(const char *refToMessageId, + const char *providerId); + +LASSO_EXPORT gint lasso_wsf2_profile_build_soap_request_msg(LassoWsf2Profile *profile); + +//LASSO_EXPORT gint lasso_wsf_profile_build_soap_response_msg(LassoWsfProfile *profile); +// +//LASSO_EXPORT gint lasso_wsf_profile_init_soap_request(LassoWsfProfile *profile, +// LassoNode *request); +// +//LASSO_EXPORT gint lasso_wsf_profile_process_soap_request_msg(LassoWsfProfile *profile, +// const gchar *message, const gchar *service_type, const gchar *security_mech_id); +// +//LASSO_EXPORT gint lasso_wsf_profile_process_soap_response_msg(LassoWsfProfile *profile, +// const gchar *message); +// +//LASSO_EXPORT LassoSoapBindingProvider* lasso_wsf_profile_set_provider_soap_request( +// LassoWsfProfile *profile, const char *providerId); +// +//LASSO_EXPORT LassoWsfProfile* lasso_wsf_profile_new(LassoServer *server); +// +//LASSO_EXPORT gboolean lasso_wsf_profile_principal_is_online(LassoWsfProfile *profile); +// +//LASSO_EXPORT gint lasso_wsf_profile_add_credential(LassoWsfProfile *profile, xmlNode *credential); +// +//LASSO_EXPORT void lasso_wsf_profile_set_description(LassoWsfProfile *profile, +// LassoDiscoDescription *description); +//LASSO_EXPORT void lasso_wsf_profile_set_principal_status(LassoWsfProfile *profile, +// const char *status); +// +//LASSO_EXPORT void lasso_wsf_profile_set_principal_online(LassoWsfProfile *profile); +// +//LASSO_EXPORT void lasso_wsf_profile_set_principal_offline(LassoWsfProfile *profile); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __LASSO_WSF2_PROFILE_H__ */ diff --git a/lasso/id-wsf-2.0/wsf2_profile_private.h b/lasso/id-wsf-2.0/wsf2_profile_private.h new file mode 100644 index 00000000..518ce971 --- /dev/null +++ b/lasso/id-wsf-2.0/wsf2_profile_private.h @@ -0,0 +1,47 @@ +/* $Id: wsf_profile_private.h,v 1.4 2005/10/06 15:03:56 nclapies Exp $ + * + * Lasso - A free implementation of the Liberty Alliance specifications. + * + * Copyright (C) 2004, 2005 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef __LASSO_WSF2_PROFILE_PRIVATE_H__ +#define __LASSO_WSF2_PROFILE_PRIVATE_H__ + +#ifdef __cplusplus +extern "C" { + +#endif /* __cplusplus */ + +#include <lasso/xml/soap_fault.h> + +//void lasso_wsf_profile_set_description(LassoWsfProfile *profile, +// LassoDiscoDescription *description); +//void lasso_wsf_profile_set_security_mech_id(LassoWsfProfile *profile, +// const gchar *security_mech_id); +LassoSoapFault* lasso_wsf2_profile_get_fault(LassoWsf2Profile *profile); + +void lasso_wsf2_profile_set_public_key(LassoWsf2Profile *profile, const char *public_key); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __LASSO_WSF2_PROFILE_PRIVATE_H__ */ |