1
/* $Id: artifact.c,v 1.16 2004/09/01 09:59:53 fpeters Exp $
3
* Lasso - A free implementation of the Liberty Alliance specifications.
5
* Copyright (C) 2004 Entr'ouvert
6
* http://lasso.entrouvert.org
8
* Authors: Valery Febvre <vfebvre@easter-eggs.com>
9
* Nicolas Clapies <nclapies@entrouvert.com>
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.
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.
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
26
#include <lasso/xml/errors.h>
27
#include <lasso/protocols/artifact.h>
28
#include <xmlsec/base64.h>
30
/*****************************************************************************/
32
/*****************************************************************************/
35
lasso_artifact_split_samlArt(gchar *b64_samlArt,
37
gchar *identityProviderSuccinctID,
38
gchar *assertionHandle)
40
xmlSecByte samlArt[42+1];
41
gint i, j, byte_code = 0;
44
i = xmlSecBase64Decode((const xmlChar *)b64_samlArt, samlArt, 42+1);
45
if (i < 0 || i > 42) {
48
/* extract ByteCode, IdentityProviderSuccinctID and AssertionHandle */
51
byte_code += (guint)samlArt[j];
53
else if (j >= 2 && j < 22) {
54
identityProviderSuccinctID[j-2] = samlArt[j];
57
assertionHandle[j-22] = samlArt[j];
60
sprintf(byteCode, "%d", byte_code);
65
/*****************************************************************************/
67
/*****************************************************************************/
70
lasso_artifact_get_assertionHandle(LassoArtifact *artifact,
73
xmlChar *assertionHandle;
74
GError *tmp_err = NULL;
76
if (err != NULL && *err != NULL) {
77
g_set_error(err, g_quark_from_string("Lasso"),
78
LASSO_PARAM_ERROR_CHECK_FAILED,
79
lasso_strerror(LASSO_PARAM_ERROR_CHECK_FAILED));
80
g_return_val_if_fail (err == NULL || *err == NULL, NULL);
82
if (LASSO_IS_ARTIFACT(artifact) == FALSE) {
83
g_set_error(err, g_quark_from_string("Lasso"),
84
LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ,
85
lasso_strerror(LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ));
86
g_return_val_if_fail(LASSO_IS_ARTIFACT(artifact), NULL);
89
assertionHandle = lasso_node_get_child_content(LASSO_NODE(artifact),
92
if (assertionHandle == NULL) {
93
g_propagate_error (err, tmp_err);
96
return assertionHandle;
100
* lasso_artifact_get_byteCode:
101
* @artifact: an LassoArtifact
102
* @err: return location for an allocated GError, or NULL to ignore errors
104
* Gets the ByteCode of the artifact
106
* Return value: the ByteCode or a negative integer if an error occurs.
109
lasso_artifact_get_byteCode(LassoArtifact *artifact,
114
GError *tmp_err = NULL;
116
if (err != NULL && *err != NULL) {
117
g_set_error(err, g_quark_from_string("Lasso"),
118
LASSO_PARAM_ERROR_CHECK_FAILED,
119
lasso_strerror(LASSO_PARAM_ERROR_CHECK_FAILED));
120
g_return_val_if_fail (err == NULL || *err == NULL,
121
LASSO_PARAM_ERROR_CHECK_FAILED);
123
if (LASSO_IS_ARTIFACT(artifact) == FALSE) {
124
g_set_error(err, g_quark_from_string("Lasso"),
125
LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ,
126
lasso_strerror(LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ));
127
g_return_val_if_fail(LASSO_IS_ARTIFACT(artifact),
128
LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ);
131
byteCode = lasso_node_get_child_content(LASSO_NODE(artifact),
132
"ByteCode", NULL, &tmp_err);
133
if (byteCode == NULL) {
134
g_propagate_error (err, tmp_err);
138
ret = (gint)g_strtod(byteCode, NULL);
145
lasso_artifact_get_b64IdentityProviderSuccinctID(LassoArtifact *artifact,
148
xmlChar *b64_identityProviderSuccinctID;
149
GError *tmp_err = NULL;
151
if (err != NULL && *err != NULL) {
152
g_set_error(err, g_quark_from_string("Lasso"),
153
LASSO_PARAM_ERROR_CHECK_FAILED,
154
lasso_strerror(LASSO_PARAM_ERROR_CHECK_FAILED));
155
g_return_val_if_fail (err == NULL || *err == NULL, NULL);
157
if (LASSO_IS_ARTIFACT(artifact) == FALSE) {
158
g_set_error(err, g_quark_from_string("Lasso"),
159
LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ,
160
lasso_strerror(LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ));
161
g_return_val_if_fail(LASSO_IS_ARTIFACT(artifact), NULL);
164
b64_identityProviderSuccinctID = lasso_node_get_child_content(LASSO_NODE(artifact),
165
"B64IdentityProviderSuccinctID",
167
if (b64_identityProviderSuccinctID == NULL) {
168
g_propagate_error (err, tmp_err);
171
return b64_identityProviderSuccinctID;
175
lasso_artifact_get_relayState(LassoArtifact *artifact,
179
GError *tmp_err = NULL;
181
if (err != NULL && *err != NULL) {
182
g_set_error(err, g_quark_from_string("Lasso"),
183
LASSO_PARAM_ERROR_CHECK_FAILED,
184
lasso_strerror(LASSO_PARAM_ERROR_CHECK_FAILED));
185
g_return_val_if_fail (err == NULL || *err == NULL, NULL);
187
if (LASSO_IS_ARTIFACT(artifact) == FALSE) {
188
g_set_error(err, g_quark_from_string("Lasso"),
189
LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ,
190
lasso_strerror(LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ));
191
g_return_val_if_fail(LASSO_IS_ARTIFACT(artifact), NULL);
194
relayState = lasso_node_get_child_content(LASSO_NODE(artifact),
195
"RelayState", NULL, &tmp_err);
196
if (relayState == NULL) {
197
g_propagate_error (err, tmp_err);
204
lasso_artifact_get_samlArt(LassoArtifact *artifact,
208
GError *tmp_err = NULL;
210
if (err != NULL && *err != NULL) {
211
g_set_error(err, g_quark_from_string("Lasso"),
212
LASSO_PARAM_ERROR_CHECK_FAILED,
213
lasso_strerror(LASSO_PARAM_ERROR_CHECK_FAILED));
214
g_return_val_if_fail (err == NULL || *err == NULL, NULL);
216
if (LASSO_IS_ARTIFACT(artifact) == FALSE) {
217
g_set_error(err, g_quark_from_string("Lasso"),
218
LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ,
219
lasso_strerror(LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ));
220
g_return_val_if_fail(LASSO_IS_ARTIFACT(artifact), NULL);
223
samlArt = lasso_node_get_child_content(LASSO_NODE(artifact),
224
"SAMLart", NULL, &tmp_err);
225
if (samlArt == NULL) {
226
g_propagate_error (err, tmp_err);
232
/*****************************************************************************/
233
/* instance and class init functions */
234
/*****************************************************************************/
237
lasso_artifact_instance_init(LassoArtifact *artifact)
239
LassoNodeClass *class = LASSO_NODE_GET_CLASS(LASSO_NODE(artifact));
241
class->set_name(LASSO_NODE(artifact), "Artifact");
245
lasso_artifact_class_init(LassoArtifactClass *class)
249
GType lasso_artifact_get_type() {
250
static GType this_type = 0;
253
static const GTypeInfo this_info = {
254
sizeof (LassoArtifactClass),
257
(GClassInitFunc) lasso_artifact_class_init,
260
sizeof(LassoArtifact),
262
(GInstanceInitFunc) lasso_artifact_instance_init,
265
this_type = g_type_register_static(LASSO_TYPE_NODE,
273
lasso_artifact_new(gchar *samlArt,
275
gchar *identityProviderSuccinctID,
276
gchar *assertionHandle,
280
LassoNodeClass *class;
281
xmlChar *b64_identityProviderSuccinctID;
283
g_return_val_if_fail(byteCode != NULL, NULL);
284
g_return_val_if_fail(identityProviderSuccinctID != NULL, NULL);
285
g_return_val_if_fail(assertionHandle != NULL, NULL);
287
artifact = LASSO_NODE(g_object_new(LASSO_TYPE_ARTIFACT, NULL));
289
class = LASSO_NODE_GET_CLASS(artifact);
290
class->new_child(artifact, "SAMLart", samlArt, FALSE);
291
class->new_child(artifact, "ByteCode", byteCode, FALSE);
292
b64_identityProviderSuccinctID = xmlSecBase64Encode((const xmlSecByte *)identityProviderSuccinctID,
294
class->new_child(artifact, "B64IdentityProviderSuccinctID",
295
b64_identityProviderSuccinctID, FALSE);
296
xmlFree(b64_identityProviderSuccinctID);
297
class->new_child(artifact, "AssertionHandle", assertionHandle, FALSE);
298
if (relayState != NULL) {
299
class->new_child(artifact, "RelayState", relayState, FALSE);
306
lasso_artifact_new_from_query(const xmlChar *query)
308
LassoNode *artifact = NULL;
310
gchar *b64_samlArt, *relayState;
311
gchar *byteCode, *identityProviderSuccinctID, *assertionHandle;
314
g_return_val_if_fail(query != NULL, NULL);
317
gd = lasso_query_to_dict(query);
318
b64_samlArt = g_strdup(lasso_g_ptr_array_index((GPtrArray *)g_datalist_get_data(&gd, "SAMLart"), 0));
319
relayState = g_strdup(lasso_g_ptr_array_index((GPtrArray *)g_datalist_get_data(&gd, "RelayState"), 0));
320
g_datalist_clear(&gd);
322
byteCode = (gchar *) g_new0(gchar, 5+1);
323
identityProviderSuccinctID = (gchar *) g_new0(gchar, 21);
324
assertionHandle = (gchar *) g_new0(gchar, 20+1);
325
ret = lasso_artifact_split_samlArt((gchar*)b64_samlArt, byteCode,
326
identityProviderSuccinctID,
329
/* printf("b64_samlArt = %s\n", b64_samlArt); */
330
/* printf("relayState = %s\n", relayState); */
331
/* printf("byteCode = %s\n", byteCode); */
332
/* printf("identityProviderSuccinctID = %s\n", identityProviderSuccinctID); */
333
/* printf("assertionHandle = %s\n", assertionHandle); */
336
artifact = lasso_artifact_new(b64_samlArt,
337
byteCode, identityProviderSuccinctID,
342
g_free(identityProviderSuccinctID);
343
g_free(assertionHandle);
351
lasso_artifact_new_from_lares(const xmlChar *lares,
352
const xmlChar *relayState)
354
LassoNode *artifact = NULL;
355
gchar *byteCode, *identityProviderSuccinctID, *assertionHandle;
358
g_return_val_if_fail(lares != NULL, NULL);
360
byteCode = (gchar *) g_new0(gchar, 5+1);
361
identityProviderSuccinctID = (gchar *) g_new0(gchar, 20);
362
assertionHandle = (gchar *) g_new0(gchar, 20+1);
363
ret = lasso_artifact_split_samlArt((gchar*)lares, byteCode,
364
identityProviderSuccinctID,
367
artifact = lasso_artifact_new((gchar*)lares,
368
byteCode, identityProviderSuccinctID,
373
g_free(identityProviderSuccinctID);
374
g_free(assertionHandle);