1
/* $Id: samlp2_status_response.c,v 1.2 2005/11/21 18:51:52 fpeters Exp $
3
* Lasso - A free implementation of the Liberty Alliance specifications.
5
* Copyright (C) 2004, 2005 Entr'ouvert
6
* http://lasso.entrouvert.org
8
* Authors: See AUTHORS file in top-level directory.
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.
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.
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
26
#include <xmlsec/xmldsig.h>
27
#include <xmlsec/templates.h>
29
#include "samlp2_status_response.h"
32
* Schema fragment (saml-schema-protocol-2.0.xsd):
34
* <complexType name="StatusResponseType">
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"/>
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"/>
50
/*****************************************************************************/
52
/*****************************************************************************/
55
static struct XmlSnippet schema_snippets[] = {
56
{ "Issuer", SNIPPET_NODE,
57
G_STRUCT_OFFSET(LassoSamlp2StatusResponse, Issuer),
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) },
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) },
91
static LassoNodeClass *parent_class = NULL;
95
build_query(LassoNode *node)
97
char *ret, *deflated_message;
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);
108
init_from_query(LassoNode *node, char **query_fields)
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? */
122
get_xmlNode(LassoNode *node, gboolean lasso_dump)
124
LassoSamlp2StatusResponse *request = LASSO_SAMLP2_STATUS_RESPONSE(node);
128
xmlnode = parent_class->get_xmlNode(node, lasso_dump);
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 ? */
140
/*****************************************************************************/
141
/* instance and class init functions */
142
/*****************************************************************************/
145
instance_init(LassoSamlp2StatusResponse *node)
148
node->Extensions = 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;
160
class_init(LassoSamlp2StatusResponseClass *klass)
162
LassoNodeClass *nclass = LASSO_NODE_CLASS(klass);
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);
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);
180
lasso_samlp2_status_response_get_type()
182
static GType this_type = 0;
185
static const GTypeInfo this_info = {
186
sizeof (LassoSamlp2StatusResponseClass),
189
(GClassInitFunc) class_init,
192
sizeof(LassoSamlp2StatusResponse),
194
(GInstanceInitFunc) instance_init,
197
this_type = g_type_register_static(LASSO_TYPE_NODE,
198
"LassoSamlp2StatusResponse", &this_info, 0);
204
* lasso_samlp2_status_response_new:
206
* Creates a new #LassoSamlp2StatusResponse object.
208
* Return value: a newly created #LassoSamlp2StatusResponse object
211
lasso_samlp2_status_response_new()
213
return g_object_new(LASSO_TYPE_SAMLP2_STATUS_RESPONSE, NULL);