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

« back to all changes in this revision

Viewing changes to lasso/xml/saml-2.0/samlp2_status_response.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2006-07-11 10:01:32 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060711100132-e50ymjc54bsizza6
Tags: 0.6.5-2ubuntu1
* Synchronize with Debian unstable.
* Convert to updated Python policy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: samlp2_status_response.c,v 1.2 2005/11/21 18:51:52 fpeters Exp $ 
 
2
 *
 
3
 * Lasso - A free implementation of the Liberty Alliance specifications.
 
4
 *
 
5
 * Copyright (C) 2004, 2005 Entr'ouvert
 
6
 * http://lasso.entrouvert.org
 
7
 * 
 
8
 * Authors: See AUTHORS file in top-level directory.
 
9
 *
 
10
 * This program is free software; you can redistribute it and/or modify
 
11
 * it under the terms of the GNU General Public License as published by
 
12
 * the Free Software Foundation; either version 2 of the License, or
 
13
 * (at your option) any later version.
 
14
 * 
 
15
 * This program is distributed in the hope that it will be useful,
 
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
 * GNU General Public License for more details.
 
19
 * 
 
20
 * You should have received a copy of the GNU General Public License
 
21
 * along with this program; if not, write to the Free Software
 
22
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
23
 */
 
24
 
 
25
 
 
26
#include <xmlsec/xmldsig.h>
 
27
#include <xmlsec/templates.h>
 
28
 
 
29
#include "samlp2_status_response.h"
 
30
 
 
31
/*
 
32
 * Schema fragment (saml-schema-protocol-2.0.xsd):
 
33
 *
 
34
 * <complexType name="StatusResponseType">
 
35
 *   <sequence>
 
36
 *     <element ref="saml:Issuer" minOccurs="0"/>
 
37
 *     <element ref="ds:Signature" minOccurs="0"/>
 
38
 *     <element ref="samlp:Extensions" minOccurs="0"/>
 
39
 *     <element ref="samlp:Status"/>
 
40
 *   </sequence>
 
41
 *   <attribute name="ID" type="ID" use="required"/>
 
42
 *   <attribute name="InResponseTo" type="NCName" use="optional"/>
 
43
 *   <attribute name="Version" type="string" use="required"/>
 
44
 *   <attribute name="IssueInstant" type="dateTime" use="required"/>
 
45
 *   <attribute name="Destination" type="anyURI" use="optional"/>
 
46
 *   <attribute name="Consent" type="anyURI" use="optional"/>
 
47
 * </complexType>
 
48
 */
 
49
 
 
50
/*****************************************************************************/
 
51
/* private methods                                                           */
 
52
/*****************************************************************************/
 
53
 
 
54
 
 
55
static struct XmlSnippet schema_snippets[] = {
 
56
        { "Issuer", SNIPPET_NODE,
 
57
                G_STRUCT_OFFSET(LassoSamlp2StatusResponse, Issuer),
 
58
                "LassoSaml2NameID" },
 
59
        { "Extensions", SNIPPET_NODE,
 
60
                G_STRUCT_OFFSET(LassoSamlp2StatusResponse, Extensions) },
 
61
        { "Status", SNIPPET_NODE,
 
62
                G_STRUCT_OFFSET(LassoSamlp2StatusResponse, Status) },
 
63
        { "ID", SNIPPET_ATTRIBUTE,
 
64
                G_STRUCT_OFFSET(LassoSamlp2StatusResponse, ID) },
 
65
        { "InResponseTo", SNIPPET_ATTRIBUTE,
 
66
                G_STRUCT_OFFSET(LassoSamlp2StatusResponse, InResponseTo) },
 
67
        { "Version", SNIPPET_ATTRIBUTE,
 
68
                G_STRUCT_OFFSET(LassoSamlp2StatusResponse, Version) },
 
69
        { "IssueInstant", SNIPPET_ATTRIBUTE,
 
70
                G_STRUCT_OFFSET(LassoSamlp2StatusResponse, IssueInstant) },
 
71
        { "Destination", SNIPPET_ATTRIBUTE,
 
72
                G_STRUCT_OFFSET(LassoSamlp2StatusResponse, Destination) },
 
73
        { "Consent", SNIPPET_ATTRIBUTE,
 
74
                G_STRUCT_OFFSET(LassoSamlp2StatusResponse, Consent) },
 
75
        { "Signature", SNIPPET_SIGNATURE,
 
76
                G_STRUCT_OFFSET(LassoSamlp2StatusResponse, ID) },
 
77
 
 
78
        /* hidden fields; used in lasso dumps */
 
79
        { "SignType", SNIPPET_ATTRIBUTE | SNIPPET_INTEGER | SNIPPET_LASSO_DUMP,
 
80
                G_STRUCT_OFFSET(LassoSamlp2StatusResponse, sign_type) },
 
81
        { "SignMethod", SNIPPET_ATTRIBUTE | SNIPPET_INTEGER | SNIPPET_LASSO_DUMP,
 
82
                G_STRUCT_OFFSET(LassoSamlp2StatusResponse, sign_method) },
 
83
        { "PrivateKeyFile", SNIPPET_CONTENT | SNIPPET_LASSO_DUMP,
 
84
                G_STRUCT_OFFSET(LassoSamlp2StatusResponse, private_key_file) },
 
85
        { "CertificateFile", SNIPPET_CONTENT | SNIPPET_LASSO_DUMP,
 
86
                G_STRUCT_OFFSET(LassoSamlp2StatusResponse, certificate_file) },
 
87
 
 
88
        {NULL, 0, 0}
 
89
};
 
90
 
 
91
static LassoNodeClass *parent_class = NULL;
 
92
 
 
93
 
 
94
static gchar*
 
95
build_query(LassoNode *node)
 
96
{
 
97
        char *ret, *deflated_message;
 
98
 
 
99
        deflated_message = lasso_node_build_deflated_query(node);
 
100
        ret = g_strdup_printf("SAMLResponse=%s", deflated_message);
 
101
        /* XXX: must support RelayState (which profiles?) */
 
102
        g_free(deflated_message);
 
103
        return ret;
 
104
}
 
105
 
 
106
 
 
107
static gboolean
 
108
init_from_query(LassoNode *node, char **query_fields)
 
109
{
 
110
        gboolean rc;
 
111
        char *relay_state = NULL;
 
112
        rc = lasso_node_init_from_saml2_query_fields(node, query_fields, &relay_state);
 
113
        if (rc && relay_state != NULL) {
 
114
                /* XXX: support RelayState? */
 
115
        }
 
116
        return rc;
 
117
}
 
118
 
 
119
 
 
120
 
 
121
static xmlNode*
 
122
get_xmlNode(LassoNode *node, gboolean lasso_dump)
 
123
{
 
124
        LassoSamlp2StatusResponse *request = LASSO_SAMLP2_STATUS_RESPONSE(node);
 
125
        xmlNode *xmlnode;
 
126
        int rc;
 
127
        
 
128
        xmlnode = parent_class->get_xmlNode(node, lasso_dump);
 
129
 
 
130
        if (lasso_dump == FALSE && request->sign_type) {
 
131
                rc = lasso_sign_node(xmlnode, "ID", request->ID,
 
132
                                request->private_key_file, request->certificate_file);
 
133
                /* signature may have failed; what to do ? */
 
134
        }
 
135
 
 
136
        return xmlnode;
 
137
}
 
138
 
 
139
 
 
140
/*****************************************************************************/
 
141
/* instance and class init functions                                         */
 
142
/*****************************************************************************/
 
143
 
 
144
static void
 
145
instance_init(LassoSamlp2StatusResponse *node)
 
146
{
 
147
        node->Issuer = NULL;
 
148
        node->Extensions = NULL;
 
149
        node->Status = NULL;
 
150
        node->ID = NULL;
 
151
        node->InResponseTo = NULL;
 
152
        node->Version = NULL;
 
153
        node->IssueInstant = NULL;
 
154
        node->Destination = NULL;
 
155
        node->Consent = NULL;
 
156
        node->sign_type = LASSO_SIGNATURE_TYPE_NONE;
 
157
}
 
158
 
 
159
static void
 
160
class_init(LassoSamlp2StatusResponseClass *klass)
 
161
{
 
162
        LassoNodeClass *nclass = LASSO_NODE_CLASS(klass);
 
163
 
 
164
        parent_class = g_type_class_peek_parent(klass);
 
165
        nclass->build_query = build_query;
 
166
        nclass->init_from_query = init_from_query;
 
167
        nclass->get_xmlNode = get_xmlNode;
 
168
        nclass->node_data = g_new0(LassoNodeClassData, 1);
 
169
        lasso_node_class_set_nodename(nclass, "StatusResponse"); 
 
170
        lasso_node_class_set_ns(nclass, LASSO_SAML2_PROTOCOL_HREF, LASSO_SAML2_PROTOCOL_PREFIX);
 
171
        lasso_node_class_add_snippets(nclass, schema_snippets);
 
172
 
 
173
        nclass->node_data->sign_type_offset = G_STRUCT_OFFSET(
 
174
                        LassoSamlp2StatusResponse, sign_type);
 
175
        nclass->node_data->sign_method_offset = G_STRUCT_OFFSET(
 
176
                        LassoSamlp2StatusResponse, sign_method);
 
177
}
 
178
 
 
179
GType
 
180
lasso_samlp2_status_response_get_type()
 
181
{
 
182
        static GType this_type = 0;
 
183
 
 
184
        if (!this_type) {
 
185
                static const GTypeInfo this_info = {
 
186
                        sizeof (LassoSamlp2StatusResponseClass),
 
187
                        NULL,
 
188
                        NULL,
 
189
                        (GClassInitFunc) class_init,
 
190
                        NULL,
 
191
                        NULL,
 
192
                        sizeof(LassoSamlp2StatusResponse),
 
193
                        0,
 
194
                        (GInstanceInitFunc) instance_init,
 
195
                };
 
196
 
 
197
                this_type = g_type_register_static(LASSO_TYPE_NODE,
 
198
                                "LassoSamlp2StatusResponse", &this_info, 0);
 
199
        }
 
200
        return this_type;
 
201
}
 
202
 
 
203
/**
 
204
 * lasso_samlp2_status_response_new:
 
205
 *
 
206
 * Creates a new #LassoSamlp2StatusResponse object.
 
207
 *
 
208
 * Return value: a newly created #LassoSamlp2StatusResponse object
 
209
 **/
 
210
LassoNode*
 
211
lasso_samlp2_status_response_new()
 
212
{
 
213
        return g_object_new(LASSO_TYPE_SAMLP2_STATUS_RESPONSE, NULL);
 
214
}