~ubuntu-branches/ubuntu/hardy/lasso/hardy

« back to all changes in this revision

Viewing changes to lasso/id-wsf/discovery.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Bienia
  • Date: 2007-07-31 21:35:26 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070731213526-oc6jw5mprcd5tjyy
Tags: 2.0.0-1ubuntu1
* Merge from debian unstable. Remaining changes:
  + debian/control:
    - Modify Maintainer value to match DebianMaintainerField spec.
* debian/rules:
  + Add CC=gcc-4.2 to the configure call else configure won't find jni.h
    from libgcj8-dev.
* configure{,.ac}:
  + Add missing quotes around the value for PHP[45]_LIBS.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: discovery.c,v 1.62 2006/02/21 09:51:49 fpeters Exp $
 
1
/* $Id: discovery.c,v 1.75 2007/01/03 23:35:17 fpeters Exp $
2
2
 *
3
3
 * Lasso - A free implementation of the Liberty Alliance specifications.
4
4
 *
22
22
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
23
 */
24
24
 
 
25
#include <libxml/xpath.h>
 
26
#include <libxml/xpathInternals.h>
 
27
 
 
28
#include <xmlsec/xmltree.h>
 
29
 
25
30
#include <lasso/xml/soap_binding_correlation.h>
26
31
#include <lasso/xml/saml_assertion.h>
27
32
#include <lasso/xml/saml_attribute_value.h>
52
57
/* static methods/functions */
53
58
/*****************************************************************************/
54
59
 
55
 
gchar*
 
60
static gchar* lasso_discovery_build_credential(LassoDiscovery *discovery, const gchar *providerId);
 
61
 
 
62
static gchar*
56
63
lasso_discovery_build_credential(LassoDiscovery *discovery, const gchar *providerId)
57
64
{
58
65
        LassoSoapHeader *header;
102
109
        if (provider) {
103
110
                identifier->Format = g_strdup(LASSO_LIB_NAME_IDENTIFIER_FORMAT_ENTITYID);
104
111
                identifier->content = g_strdup(provider->providerID);
105
 
        }
106
 
        else {
 
112
        } else {
107
113
                identifier->Format = g_strdup(LASSO_LIB_NAME_IDENTIFIER_FORMAT_FEDERATED);
108
114
        }
109
115
        subject->NameIdentifier = identifier;
141
147
                ctx->mode = xmlSecKeyInfoModeWrite;
142
148
                ctx->keyReq.keyType = xmlSecKeyDataTypePublic;
143
149
 
144
 
                doc = xmlSecCreateTree("KeyInfo", "http://www.w3.org/2000/09/xmldsig#");
 
150
                doc = xmlSecCreateTree((xmlChar*)"KeyInfo",
 
151
                                (xmlChar*)"http://www.w3.org/2000/09/xmldsig#");
145
152
                key_info_node = xmlDocGetRootElement(doc);
146
 
                xmlSecAddChild(key_info_node,
147
 
                               "KeyValue", "http://www.w3.org/2000/09/xmldsig#");
 
153
                xmlSecAddChild(key_info_node, (xmlChar*)"KeyValue",
 
154
                                (xmlChar*)"http://www.w3.org/2000/09/xmldsig#");
148
155
 
149
156
                xmlSecKeyInfoNodeWrite(key_info_node, public_key, ctx);
150
157
 
151
158
                xpathCtx = xmlXPathNewContext(doc);
152
 
                xmlXPathRegisterNs(xpathCtx, (xmlChar*)"ds", "http://www.w3.org/2000/09/xmldsig#");
 
159
                xmlXPathRegisterNs(xpathCtx, (xmlChar*)"ds",
 
160
                                (xmlChar*)"http://www.w3.org/2000/09/xmldsig#");
153
161
 
154
162
                rsa_key_value = lasso_ds_rsa_key_value_new();
155
163
                xpathObj = xmlXPathEvalExpression((xmlChar*)"//ds:Modulus", xpathCtx);
157
165
                        xmlnode = xpathObj->nodesetval->nodeTab[0];
158
166
                        rsa_key_value->Modulus = (gchar *) xmlNodeGetContent(xmlnode);
159
167
                }
 
168
                xmlXPathFreeObject(xpathObj);
160
169
 
161
170
                xpathObj = xmlXPathEvalExpression((xmlChar*)"//ds:Exponent", xpathCtx);
162
171
                if (xpathObj->nodesetval && xpathObj->nodesetval->nodeNr) {
163
172
                        xmlnode = xpathObj->nodesetval->nodeTab[0];
164
173
                        rsa_key_value->Exponent = (gchar *) xmlNodeGetContent(xmlnode);
165
174
                }
 
175
                xmlXPathFreeObject(xpathObj);
166
176
 
167
177
                key_value = lasso_ds_key_value_new();
168
178
                key_value->RSAKeyValue = rsa_key_value;
169
179
                key_info = lasso_ds_key_info_new();
170
180
                key_info->KeyValue = key_value;
171
181
                subject_confirmation->KeyInfo = key_info;
 
182
 
 
183
                xmlXPathFreeContext(xpathCtx);
 
184
                xmlFreeDoc(doc);
172
185
        }
173
186
 
174
187
        subject->SubjectConfirmation = subject_confirmation;
213
226
                if (LASSO_IS_DISCO_MODIFY(profile->request)) {
214
227
                        LASSO_DISCO_MODIFY(profile->request)->ResourceID = \
215
228
                                resourceOffering->ResourceID;
216
 
                }
217
 
                else if (LASSO_IS_DISCO_QUERY(profile->request)) {
 
229
                } else if (LASSO_IS_DISCO_QUERY(profile->request)) {
218
230
                        LASSO_DISCO_QUERY(profile->request)->ResourceID = \
219
231
                                resourceOffering->ResourceID;
220
232
                }
221
 
        }
222
 
        else if (resourceOffering->EncryptedResourceID != NULL) {
 
233
        } else if (resourceOffering->EncryptedResourceID != NULL) {
223
234
                g_object_ref(resourceOffering->EncryptedResourceID);
224
235
                if (LASSO_IS_DISCO_MODIFY(profile->request)) {
225
236
                        LASSO_DISCO_MODIFY(profile->request)->EncryptedResourceID = \
226
237
                                resourceOffering->EncryptedResourceID;
227
 
                }
228
 
                else if (LASSO_IS_DISCO_QUERY(profile->request)) {
 
238
                } else if (LASSO_IS_DISCO_QUERY(profile->request)) {
229
239
                        LASSO_DISCO_QUERY(profile->request)->EncryptedResourceID = \
230
240
                                resourceOffering->EncryptedResourceID;
231
241
                }
233
243
 
234
244
        if (description->Endpoint != NULL) {
235
245
                profile->msg_url = g_strdup(description->Endpoint);
236
 
        }
237
 
        else if (description->WsdlURI != NULL) {
 
246
        } else if (description->WsdlURI != NULL) {
238
247
                /* TODO: get Endpoint at WsdlURI */
239
248
        }
240
249
 
314
323
        /* option is optional */
315
324
 
316
325
        query = LASSO_DISCO_QUERY(LASSO_WSF_PROFILE(discovery)->request);
 
326
        if (query == NULL) {
 
327
                /* missing request */
 
328
                return NULL;
 
329
        }
317
330
 
318
331
        rst = lasso_disco_requested_service_type_new(service_type);
319
332
 
416
429
 
417
430
end:
418
431
 
419
 
        /* XXX lasso_node_destroy(assertions) */
 
432
        g_list_free(assertions);
 
433
 
420
434
        if (resource_offering) {
421
435
                return g_object_ref(resource_offering);
422
436
        }
478
492
        /* get discovery service resource id from principal assertion */
479
493
        offering = lasso_discovery_get_resource_offering_auto(discovery, LASSO_DISCO_HREF);
480
494
        if (offering == NULL) {
481
 
                return -1;
 
495
                return LASSO_PROFILE_ERROR_MISSING_RESOURCE_OFFERING;
482
496
        }
483
 
        if (security_mech_id)
 
497
        if (security_mech_id) {
484
498
                description = lasso_discovery_get_description_auto(offering, security_mech_id);
485
 
        else
 
499
        } else {
486
500
                description = LASSO_DISCO_DESCRIPTION(offering->ServiceInstance->Description->data);
487
 
        if (!description)
488
 
               return -1;
 
501
        }
 
502
        if (!description) {
 
503
                return LASSO_PROFILE_ERROR_MISSING_SERVICE_DESCRIPTION;
 
504
        }
489
505
        lasso_wsf_profile_set_description(LASSO_WSF_PROFILE(discovery), description);
490
 
        
 
506
 
491
507
        /* XXX: EncryptedResourceID support */
492
508
        modify->ResourceID = g_object_ref(offering->ResourceID);
493
509
        lasso_node_destroy(LASSO_NODE(offering));
526
542
        /* get discovery service resource id from principal assertion */
527
543
        offering = lasso_discovery_get_resource_offering_auto(discovery, LASSO_DISCO_HREF);
528
544
        if (offering == NULL) {
529
 
                return -1;
 
545
                return LASSO_PROFILE_ERROR_MISSING_RESOURCE_OFFERING;
530
546
        }
531
547
        description = lasso_discovery_get_description_auto(offering,
532
548
                LASSO_SECURITY_MECH_NULL);
567
583
        /* get discovery service resource id from principal assertion */
568
584
        offering = lasso_discovery_get_resource_offering_auto(discovery, LASSO_DISCO_HREF);
569
585
        if (offering == NULL)
570
 
                return -1;
 
586
                return LASSO_PROFILE_ERROR_MISSING_RESOURCE_OFFERING;
571
587
 
572
 
        if (!security_mech_id)
 
588
        if (security_mech_id == NULL) {
573
589
                description = LASSO_DISCO_DESCRIPTION(offering->ServiceInstance->Description->data);
574
 
        else {
 
590
        } else {
575
591
                description = lasso_discovery_get_description_auto(offering, security_mech_id);
576
592
        }
577
 
        if (!description)
578
 
                return -1;
 
593
        if (description == NULL)
 
594
                return LASSO_PROFILE_ERROR_MISSING_SERVICE_DESCRIPTION;
579
595
 
580
596
        lasso_wsf_profile_set_description(LASSO_WSF_PROFILE(discovery), description);
581
597
 
655
671
        if (lasso_wsf_profile_get_fault(LASSO_WSF_PROFILE(discovery))) {
656
672
                return lasso_wsf_profile_build_soap_response_msg(LASSO_WSF_PROFILE(discovery));
657
673
        }
 
674
        
 
675
        if (LASSO_WSF_PROFILE(discovery)->identity == NULL) {
 
676
                return LASSO_PROFILE_ERROR_IDENTITY_NOT_FOUND;
 
677
        }
658
678
 
659
679
        /* build response */
660
680
        status = lasso_utility_status_new(LASSO_DISCO_STATUS_CODE_FAILED);
672
692
                if (lasso_identity_get_resource_offering(
673
693
                                        LASSO_WSF_PROFILE(discovery)->identity,
674
694
                                        entry->entryID) == NULL) {
675
 
                        /* FIXME: Return a better code error. */
676
 
                        return -1;
 
695
                        return LASSO_PROFILE_ERROR_MISSING_RESOURCE_OFFERING;
677
696
                }
678
697
        }
679
698
 
736
755
        LassoDiscoModifyResponse *response;
737
756
        
738
757
        rc = lasso_wsf_profile_process_soap_response_msg(LASSO_WSF_PROFILE(discovery), message);
739
 
        if (rc) return rc;
 
758
        if (rc) {
 
759
                return rc;
 
760
        }
740
761
 
741
762
        response = LASSO_DISCO_MODIFY_RESPONSE(LASSO_WSF_PROFILE(discovery)->response);
742
 
        if (strcmp(response->Status->code, "OK") != 0)
743
 
                return LASSO_ERROR_UNDEFINED;
 
763
        if (strcmp(response->Status->code, "OK") != 0) {
 
764
                return LASSO_PROFILE_ERROR_STATUS_NOT_SUCCESS;
 
765
        }
744
766
 
745
767
        return 0;
746
768
}
771
793
        envelope = LASSO_WSF_PROFILE(discovery)->soap_envelope_response;
772
794
        request = LASSO_DISCO_QUERY(LASSO_WSF_PROFILE(discovery)->request);
773
795
        
774
 
        if (request->ResourceID)
 
796
        if (request->ResourceID) {
775
797
                discovery->resource_id = g_object_ref(request->ResourceID);
776
 
        else if (request->EncryptedResourceID)
 
798
        } else if (request->EncryptedResourceID) {
777
799
                discovery->encrypted_resource_id = g_object_ref(request->EncryptedResourceID);
778
 
        else {
 
800
        } else {
779
801
                return LASSO_ERROR_UNIMPLEMENTED; /* implied ? */
780
802
        }
781
803
 
802
824
        LassoDiscoQueryResponse *response;
803
825
        LassoSoapEnvelope *envelope;
804
826
 
805
 
        LassoSoapBindingProvider *provider = NULL;
806
 
 
807
827
        GList *offerings = NULL;
808
 
        GList *iter, *iter2, *iter3, *iter4;
 
828
        GList *iter, *iter2, *iter3;
809
829
        int res = 0;
810
830
        
811
831
        gchar *credentialRef;
814
834
                return lasso_wsf_profile_build_soap_response_msg(LASSO_WSF_PROFILE(discovery));
815
835
        }
816
836
 
 
837
        if (LASSO_WSF_PROFILE(discovery)->identity == NULL) {
 
838
                return LASSO_PROFILE_ERROR_IDENTITY_NOT_FOUND;
 
839
        }
 
840
 
817
841
        iter = request->RequestedServiceType;
818
842
        while (iter) {
819
843
                LassoDiscoRequestedServiceType *service_type = iter->data;
843
867
                        while (iter3) {
844
868
                                if (lasso_security_mech_id_is_saml_authentication(
845
869
                                            iter3->data) == TRUE) {
846
 
                                        printf("At disco, add credential\n");
847
870
                                        credentialRef = lasso_discovery_build_credential(
848
871
                                                discovery, NULL);
849
872
                                        description->CredentialRef = g_list_append(
876
899
        LassoDiscoQueryResponse *response;
877
900
 
878
901
        rc = lasso_wsf_profile_process_soap_response_msg(LASSO_WSF_PROFILE(discovery), message);
879
 
        if (rc) return rc;
 
902
        if (rc) {
 
903
                return rc;
 
904
        }
880
905
 
881
906
        response = LASSO_DISCO_QUERY_RESPONSE(LASSO_WSF_PROFILE(discovery)->response);
882
 
        if (strcmp(response->Status->code, "OK") != 0)
883
 
                return LASSO_ERROR_UNDEFINED;
 
907
        if (strcmp(response->Status->code, "OK") != 0) {
 
908
                return LASSO_PROFILE_ERROR_STATUS_NOT_SUCCESS;
 
909
        }
884
910
 
885
911
        /* XXX: anything else to do ? */
886
912
 
908
934
        LassoDataService *service;
909
935
 
910
936
        response = LASSO_DISCO_QUERY_RESPONSE(LASSO_WSF_PROFILE(discovery)->response);
 
937
        if (response == NULL) {
 
938
                /* no response; probably called at wrong time */
 
939
                return NULL;
 
940
        }
 
941
 
911
942
        iter = response->ResourceOffering;
912
943
        if (iter == NULL) {
913
944
                return NULL; /* resource not found */