~ubuntu-branches/ubuntu/gutsy/lasso/gutsy

« back to all changes in this revision

Viewing changes to lasso/protocols/authn_request.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephan Hermann
  • Date: 2005-09-16 02:16:49 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050916021649-lr5tuka6pfmmks44
Tags: 0.6.2-3ubuntu1
* debian/control: removed hardcoded php dependency, added php:Depends
  substvar
* debian/rules: added phpapiver, added substitution of php:Depends

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: authn_request.c,v 1.28 2004/09/01 09:59:53 fpeters Exp $ 
2
 
 *
3
 
 * Lasso - A free implementation of the Liberty Alliance specifications.
4
 
 *
5
 
 * Copyright (C) 2004 Entr'ouvert
6
 
 * http://lasso.entrouvert.org
7
 
 * 
8
 
 * Authors: Valery Febvre   <vfebvre@easter-eggs.com>
9
 
 *          Nicolas Clapies <nclapies@entrouvert.com>
10
 
 *
11
 
 * This program is free software; you can redistribute it and/or modify
12
 
 * it under the terms of the GNU General Public License as published by
13
 
 * the Free Software Foundation; either version 2 of the License, or
14
 
 * (at your option) any later version.
15
 
 * 
16
 
 * This program is distributed in the hope that it will be useful,
17
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 
 * GNU General Public License for more details.
20
 
 * 
21
 
 * You should have received a copy of the GNU General Public License
22
 
 * along with this program; if not, write to the Free Software
23
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24
 
 */
25
 
 
26
 
#include <string.h>
27
 
#include <xmlsec/base64.h>
28
 
#include <lasso/protocols/authn_request.h>
29
 
 
30
 
/*****************************************************************************/
31
 
/* functions                                                                 */
32
 
/*****************************************************************************/
33
 
 
34
 
gchar *
35
 
lasso_authn_request_get_protocolProfile(gchar *query)
36
 
{
37
 
  gchar *protocolProfile;
38
 
 
39
 
  protocolProfile = lasso_g_ptr_array_index(lasso_query_get_value(query, "ProtocolProfile"), 0);
40
 
  if (protocolProfile == NULL)
41
 
    protocolProfile = (gchar *)lassoLibProtocolProfileBrwsArt;
42
 
 
43
 
  return protocolProfile;
44
 
}
45
 
 
46
 
/*****************************************************************************/
47
 
/* public methods                                                            */
48
 
/*****************************************************************************/
49
 
 
50
 
void
51
 
lasso_authn_request_set_requestAuthnContext(LassoAuthnRequest *request,
52
 
                                            GPtrArray         *authnContextClassRefs,
53
 
                                            GPtrArray         *authnContextStatementRefs,
54
 
                                            const xmlChar     *authnContextComparison)
55
 
{
56
 
  LassoNode *request_authn_context;
57
 
  gint i;
58
 
 
59
 
  g_return_if_fail (LASSO_IS_AUTHN_REQUEST(request));
60
 
 
61
 
  /*
62
 
    all arguments are optional
63
 
    however, we need at least one to create the RequestAuthnContext element
64
 
  */
65
 
  if (authnContextClassRefs || authnContextStatementRefs || authnContextComparison) {
66
 
    /* ok, we create a new RequestAuthnContext instance */
67
 
    request_authn_context = lasso_lib_request_authn_context_new();
68
 
    /* AuthnContextClassRefs */
69
 
    if (authnContextClassRefs != NULL) {
70
 
      if (authnContextClassRefs->len > 0) {
71
 
        for(i=0; i<authnContextClassRefs->len; i++) {
72
 
          lasso_lib_request_authn_context_add_authnContextClassRef(LASSO_LIB_REQUEST_AUTHN_CONTEXT(request_authn_context),
73
 
                                                                   lasso_g_ptr_array_index(authnContextClassRefs, i));
74
 
        }
75
 
      }
76
 
    }
77
 
    /* AuthnContextStatementRefs */
78
 
    if (authnContextStatementRefs != NULL) {
79
 
      if (authnContextStatementRefs->len > 0) {
80
 
        for(i=0; i<authnContextStatementRefs->len; i++) {
81
 
          lasso_lib_request_authn_context_add_authnContextStatementRef(LASSO_LIB_REQUEST_AUTHN_CONTEXT(request_authn_context),
82
 
                                                                       lasso_g_ptr_array_index(authnContextStatementRefs, i));
83
 
        }
84
 
      }
85
 
    }
86
 
    /* AuthnContextComparison */
87
 
    if (authnContextComparison != NULL) {
88
 
      lasso_lib_request_authn_context_set_authnContextComparison(LASSO_LIB_REQUEST_AUTHN_CONTEXT(request_authn_context),
89
 
                                                                 authnContextComparison);
90
 
    }
91
 
    /* Add RequestAuthnContext in AuthnRequest */
92
 
    lasso_lib_authn_request_set_requestAuthnContext(LASSO_LIB_AUTHN_REQUEST(request),
93
 
                                                    LASSO_LIB_REQUEST_AUTHN_CONTEXT(request_authn_context));
94
 
    lasso_node_destroy(request_authn_context);
95
 
  }
96
 
}
97
 
 
98
 
void
99
 
lasso_authn_request_set_scoping(LassoAuthnRequest *request,
100
 
                                gint               proxyCount)
101
 
{
102
 
  LassoNode *scoping;
103
 
 
104
 
  g_return_if_fail (LASSO_IS_AUTHN_REQUEST(request));
105
 
 
106
 
  /* create a new Scoping instance */
107
 
  scoping = lasso_lib_scoping_new();
108
 
  /* ProxyCount */
109
 
  lasso_lib_scoping_set_proxyCount(LASSO_LIB_SCOPING(scoping), proxyCount);
110
 
  /* FIXME : set IDPList here */
111
 
  lasso_lib_authn_request_set_scoping(LASSO_LIB_AUTHN_REQUEST(request),
112
 
                                      LASSO_LIB_SCOPING(scoping));
113
 
  lasso_node_destroy(scoping);
114
 
}
115
 
 
116
 
/*****************************************************************************/
117
 
/* instance and class init functions                                         */
118
 
/*****************************************************************************/
119
 
 
120
 
static void
121
 
lasso_authn_request_instance_init(LassoAuthnRequest *request)
122
 
{
123
 
}
124
 
 
125
 
static void
126
 
lasso_authn_request_class_init(LassoAuthnRequestClass *class)
127
 
{
128
 
}
129
 
 
130
 
GType lasso_authn_request_get_type() {
131
 
  static GType this_type = 0;
132
 
 
133
 
  if (!this_type) {
134
 
    static const GTypeInfo this_info = {
135
 
      sizeof (LassoAuthnRequestClass),
136
 
      NULL,
137
 
      NULL,
138
 
      (GClassInitFunc) lasso_authn_request_class_init,
139
 
      NULL,
140
 
      NULL,
141
 
      sizeof(LassoAuthnRequest),
142
 
      0,
143
 
      (GInstanceInitFunc) lasso_authn_request_instance_init,
144
 
    };
145
 
    
146
 
    this_type = g_type_register_static(LASSO_TYPE_LIB_AUTHN_REQUEST,
147
 
                                       "LassoAuthnRequest",
148
 
                                       &this_info, 0);
149
 
  }
150
 
  return this_type;
151
 
}
152
 
 
153
 
LassoNode*
154
 
lasso_authn_request_new(const xmlChar        *providerID,
155
 
                        lassoSignatureType    sign_type,
156
 
                        lassoSignatureMethod  sign_method)
157
 
{
158
 
  LassoNode *request;
159
 
  xmlChar   *id, *time;
160
 
 
161
 
  request = LASSO_NODE(g_object_new(LASSO_TYPE_AUTHN_REQUEST, NULL));
162
 
  
163
 
  /* Set ONLY required elements/attributes */
164
 
  /* RequestID */
165
 
  id = lasso_build_unique_id(32);
166
 
  lasso_samlp_request_abstract_set_requestID(LASSO_SAMLP_REQUEST_ABSTRACT(request),
167
 
                                             (const xmlChar *)id);
168
 
  xmlFree(id);
169
 
  /* MajorVersion */
170
 
  lasso_samlp_request_abstract_set_majorVersion(LASSO_SAMLP_REQUEST_ABSTRACT(request),
171
 
                                                lassoLibMajorVersion);
172
 
  /* MinorVersion */
173
 
  lasso_samlp_request_abstract_set_minorVersion(LASSO_SAMLP_REQUEST_ABSTRACT(request), 
174
 
                                                lassoLibMinorVersion);
175
 
  /* IssueInstant */
176
 
  time = lasso_get_current_time();
177
 
  lasso_samlp_request_abstract_set_issueInstant(LASSO_SAMLP_REQUEST_ABSTRACT(request),
178
 
                                                (const xmlChar *)time);
179
 
  xmlFree(time);
180
 
  /* Signature template */
181
 
  if (sign_type != lassoSignatureTypeNone) {
182
 
    lasso_samlp_request_abstract_set_signature_tmpl(LASSO_SAMLP_REQUEST_ABSTRACT(request),
183
 
                                                    sign_type,
184
 
                                                    sign_method,
185
 
                                                    NULL);
186
 
  }
187
 
  /* ProviderID */
188
 
  lasso_lib_authn_request_set_providerID(LASSO_LIB_AUTHN_REQUEST(request),
189
 
                                         providerID);
190
 
 
191
 
  return request;
192
 
}
193
 
 
194
 
LassoNode*
195
 
lasso_authn_request_new_from_export(gchar               *buffer,
196
 
                                    lassoNodeExportType  export_type)
197
 
{
198
 
  LassoNode *request = NULL, *authn_context = NULL, *scoping;
199
 
  LassoNode *request_node, *soap_node;
200
 
  GData     *gd;
201
 
  xmlChar   *str, *buffer_decoded;
202
 
  gchar     *export;
203
 
  GPtrArray *array;
204
 
  gint       i;
205
 
 
206
 
  g_return_val_if_fail(buffer != NULL, NULL);
207
 
 
208
 
  request = LASSO_NODE(g_object_new(LASSO_TYPE_AUTHN_REQUEST, NULL));
209
 
 
210
 
  switch (export_type) {
211
 
  case lassoNodeExportTypeXml:
212
 
    lasso_node_import(request, buffer);
213
 
    break;
214
 
  case lassoNodeExportTypeQuery:
215
 
    gd = lasso_query_to_dict(buffer);
216
 
    if (gd == NULL) {
217
 
      g_object_unref(request);
218
 
      return NULL;
219
 
    }
220
 
 
221
 
    /* RequestID */
222
 
    str = lasso_g_ptr_array_index((GPtrArray *)g_datalist_get_data(&gd, "RequestID"), 0);
223
 
    if (str != NULL)
224
 
      lasso_samlp_request_abstract_set_requestID(LASSO_SAMLP_REQUEST_ABSTRACT(request),
225
 
                                                 str);
226
 
    else {
227
 
      g_datalist_clear(&gd);
228
 
      g_object_unref(request);
229
 
      return NULL;
230
 
    }
231
 
 
232
 
    /* MajorVersion */
233
 
    str = lasso_g_ptr_array_index((GPtrArray *)g_datalist_get_data(&gd, "MajorVersion"), 0);
234
 
    if (str != NULL)
235
 
      lasso_samlp_request_abstract_set_majorVersion(LASSO_SAMLP_REQUEST_ABSTRACT(request),
236
 
                                                    str);
237
 
    else
238
 
      lasso_samlp_request_abstract_set_majorVersion(LASSO_SAMLP_REQUEST_ABSTRACT(request),
239
 
                                                    lassoLibMajorVersion);
240
 
    
241
 
    /* MinorVersion */
242
 
    str = lasso_g_ptr_array_index((GPtrArray *)g_datalist_get_data(&gd, "MinorVersion"), 0);
243
 
    if (str != NULL)
244
 
      lasso_samlp_request_abstract_set_minorVersion(LASSO_SAMLP_REQUEST_ABSTRACT(request), 
245
 
                                                    str);
246
 
    else
247
 
      lasso_samlp_request_abstract_set_minorVersion(LASSO_SAMLP_REQUEST_ABSTRACT(request), 
248
 
                                                    lassoLibMinorVersion);
249
 
    
250
 
    /* IssueInstant */
251
 
    str = lasso_g_ptr_array_index((GPtrArray *)g_datalist_get_data(&gd, "IssueInstant"), 0);
252
 
    if (str != NULL) {
253
 
      lasso_samlp_request_abstract_set_issueInstant(LASSO_SAMLP_REQUEST_ABSTRACT(request),
254
 
                                                    str);
255
 
    }
256
 
    else {
257
 
      g_datalist_clear(&gd);
258
 
      g_object_unref(request);
259
 
      return NULL;
260
 
    }
261
 
    
262
 
    /* ProviderID */
263
 
    str = lasso_g_ptr_array_index((GPtrArray *)g_datalist_get_data(&gd, "ProviderID"), 0);
264
 
    if (str != NULL)
265
 
      lasso_lib_authn_request_set_providerID(LASSO_LIB_AUTHN_REQUEST(request), str);
266
 
    else {
267
 
      g_datalist_clear(&gd);
268
 
      g_object_unref(request);
269
 
      return NULL;
270
 
    }
271
 
    
272
 
    /* NameIDPolicy */
273
 
    str = lasso_g_ptr_array_index((GPtrArray *)g_datalist_get_data(&gd, "NameIDPolicy"), 0);
274
 
    if (str != NULL)
275
 
      lasso_lib_authn_request_set_nameIDPolicy(LASSO_LIB_AUTHN_REQUEST(request), str);
276
 
    
277
 
    /* ForceAuthn */
278
 
    str = lasso_g_ptr_array_index((GPtrArray *)g_datalist_get_data(&gd, "ForceAuthn"), 0);
279
 
    if (str != NULL){
280
 
      if(!strcmp(str, "true"))
281
 
        lasso_lib_authn_request_set_forceAuthn(LASSO_LIB_AUTHN_REQUEST(request), TRUE);
282
 
      else if(!strcmp(str, "false"))
283
 
        lasso_lib_authn_request_set_forceAuthn(LASSO_LIB_AUTHN_REQUEST(request), FALSE);
284
 
    }
285
 
    
286
 
    /* IsPassive */
287
 
    str = lasso_g_ptr_array_index((GPtrArray *)g_datalist_get_data(&gd, "IsPassive"), 0);
288
 
    if (str != NULL){
289
 
      if(!strcmp(str, "true"))
290
 
        lasso_lib_authn_request_set_isPassive(LASSO_LIB_AUTHN_REQUEST(request), TRUE);
291
 
      else
292
 
        lasso_lib_authn_request_set_isPassive(LASSO_LIB_AUTHN_REQUEST(request), FALSE);
293
 
    }
294
 
    
295
 
    /* ProtocolProfile */
296
 
    str = lasso_g_ptr_array_index((GPtrArray *)g_datalist_get_data(&gd, "ProtocolProfile"), 0);
297
 
    if (str != NULL)
298
 
      lasso_lib_authn_request_set_protocolProfile(LASSO_LIB_AUTHN_REQUEST(request), str);
299
 
    
300
 
    /* AssertionConsumerServiceID */
301
 
    str = lasso_g_ptr_array_index((GPtrArray *)g_datalist_get_data(&gd, "AssertionConsumerServiceID"), 0);
302
 
    if (str != NULL)
303
 
      lasso_lib_authn_request_set_assertionConsumerServiceID(LASSO_LIB_AUTHN_REQUEST(request), str);
304
 
    
305
 
    /* AuthnContext */
306
 
    array = (GPtrArray *)g_datalist_get_data(&gd, "AuthnContextClassRef");
307
 
    if (array != NULL) {
308
 
      if (authn_context == NULL)
309
 
        authn_context = lasso_lib_request_authn_context_new();
310
 
      for(i=0; i<array->len; i++)
311
 
        lasso_lib_request_authn_context_add_authnContextClassRef(LASSO_LIB_REQUEST_AUTHN_CONTEXT(authn_context),
312
 
                                                                 lasso_g_ptr_array_index(array, i));
313
 
    }
314
 
    array = (GPtrArray *)g_datalist_get_data(&gd, "AuthnContextStatementRef");
315
 
    if (array != NULL) {
316
 
      if (authn_context == NULL)
317
 
        authn_context = lasso_lib_request_authn_context_new();
318
 
      for(i=0; i<array->len; i++)
319
 
        lasso_lib_request_authn_context_add_authnContextStatementRef(LASSO_LIB_REQUEST_AUTHN_CONTEXT(authn_context),
320
 
                                                                     lasso_g_ptr_array_index(array, i));
321
 
    }
322
 
    str = lasso_g_ptr_array_index((GPtrArray *)g_datalist_get_data(&gd, "AuthnContextComparison"), 0);
323
 
    if (str != NULL) {
324
 
      if (authn_context == NULL)
325
 
        authn_context = lasso_lib_request_authn_context_new();
326
 
      lasso_lib_request_authn_context_set_authnContextComparison(LASSO_LIB_REQUEST_AUTHN_CONTEXT(authn_context),
327
 
                                                                 str);
328
 
    }
329
 
    if (authn_context != NULL) {
330
 
      lasso_lib_authn_request_set_requestAuthnContext(LASSO_LIB_AUTHN_REQUEST(request),
331
 
                                                      LASSO_LIB_REQUEST_AUTHN_CONTEXT(authn_context));
332
 
      lasso_node_destroy(authn_context);
333
 
    }
334
 
    
335
 
    /* RelayState */
336
 
    str = lasso_g_ptr_array_index((GPtrArray *)g_datalist_get_data(&gd, "RelayState"), 0);
337
 
    if (str != NULL) {
338
 
      lasso_lib_authn_request_set_relayState(LASSO_LIB_AUTHN_REQUEST(request), str);
339
 
    }
340
 
    
341
 
    /* Scoping
342
 
       FIXME -> IDPList */
343
 
    str = lasso_g_ptr_array_index((GPtrArray *)g_datalist_get_data(&gd, "ProxyCount"), 0);
344
 
    if (str != NULL) {
345
 
      /* create a new Scoping instance */
346
 
      scoping = lasso_lib_scoping_new();
347
 
      /* ProxyCount */
348
 
      lasso_lib_scoping_set_proxyCount(LASSO_LIB_SCOPING(scoping), atoi(str));
349
 
      lasso_lib_authn_request_set_scoping(LASSO_LIB_AUTHN_REQUEST(request),
350
 
                                          LASSO_LIB_SCOPING(scoping));
351
 
      lasso_node_destroy(scoping);
352
 
    }
353
 
    
354
 
    /* consent */
355
 
    str = lasso_g_ptr_array_index((GPtrArray *)g_datalist_get_data(&gd, "consent"), 0);
356
 
    if (str != NULL) {
357
 
      lasso_lib_authn_request_set_consent(LASSO_LIB_AUTHN_REQUEST(request), str);
358
 
    }
359
 
    
360
 
    g_datalist_clear(&gd);
361
 
    break;
362
 
  case lassoNodeExportTypeBase64:
363
 
    buffer_decoded = xmlMalloc(strlen(buffer));
364
 
    xmlSecBase64Decode(buffer, buffer_decoded, strlen(buffer));
365
 
    lasso_node_import(request, buffer_decoded);
366
 
    xmlFree(buffer_decoded);
367
 
    break;
368
 
  case lassoNodeExportTypeSoap:
369
 
    soap_node = lasso_node_new_from_dump(buffer);
370
 
    request_node = lasso_node_get_child(soap_node, "AuthnRequest",
371
 
                                        lassoLibHRef, NULL);
372
 
    export = lasso_node_export(request_node);
373
 
    lasso_node_import(request, export);
374
 
    g_free(export);
375
 
    lasso_node_destroy(request_node);
376
 
    lasso_node_destroy(soap_node);
377
 
    break;
378
 
  }
379
 
 
380
 
  return request;
381
 
}