1
/* $Id: lecp.c,v 1.18 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: Nicolas Clapies <nclapies@entrouvert.com>
9
* Valery Febvre <vfebvre@easter-eggs.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/environs/lecp.h>
28
static GObjectClass *parent_class = NULL;
30
/*****************************************************************************/
32
/*****************************************************************************/
35
lasso_lecp_build_authn_request_envelope_msg(LassoLecp *lecp)
37
LassoProfile *profile;
38
gchar *assertionConsumerServiceURL;
40
g_return_val_if_fail(LASSO_IS_LECP(lecp), -1);
42
profile = LASSO_PROFILE(lecp);
44
assertionConsumerServiceURL = lasso_provider_get_assertionConsumerServiceURL(LASSO_PROVIDER(profile->server),
47
if (assertionConsumerServiceURL == NULL) {
48
message(G_LOG_LEVEL_CRITICAL, "AssertionConsumerServiceURL not found\n");
52
if (profile->request == NULL) {
53
message(G_LOG_LEVEL_CRITICAL, "AuthnRequest not found\n");
57
lecp->authnRequestEnvelope = lasso_authn_request_envelope_new(LASSO_AUTHN_REQUEST(profile->request),
58
profile->server->providerID,
59
assertionConsumerServiceURL);
60
if (lecp->authnRequestEnvelope == NULL) {
61
message(G_LOG_LEVEL_CRITICAL, "Error while building AuthnRequestEnvelope\n");
65
profile->msg_body = lasso_node_export(lecp->authnRequestEnvelope);
66
if (profile->msg_body == NULL) {
67
message(G_LOG_LEVEL_CRITICAL, "Error while exporting the AuthnRequestEnvelope to POST msg\n");
75
lasso_lecp_build_authn_request_msg(LassoLecp *lecp,
76
const gchar *remote_providerID)
78
LassoProfile *profile;
79
LassoProvider *remote_provider;
81
g_return_val_if_fail(LASSO_IS_LECP(lecp), -1);
83
profile = LASSO_PROFILE(lecp);
85
LASSO_PROFILE(lecp)->remote_providerID = g_strdup(remote_providerID);
86
remote_provider = lasso_server_get_provider_ref(LASSO_PROFILE(lecp)->server,
87
LASSO_PROFILE(lecp)->remote_providerID,
90
profile->msg_url = lasso_provider_get_singleSignOnServiceURL(remote_provider, NULL);
91
profile->msg_body = lasso_node_export_to_soap(profile->request);
92
if (profile->msg_body == NULL) {
93
message(G_LOG_LEVEL_CRITICAL, "Error while building the AuthnRequest SOAP message\n");
101
lasso_lecp_build_authn_response_msg(LassoLecp *lecp)
103
LassoProfile *profile;
105
g_return_val_if_fail(LASSO_IS_LECP(lecp), -1);
107
profile = LASSO_PROFILE(lecp);
108
profile->msg_url = g_strdup(lecp->assertionConsumerServiceURL);
109
if (profile->msg_url == NULL) {
110
message(G_LOG_LEVEL_CRITICAL, "AssertionConsumerServiceURL not found\n");
113
profile->msg_body = lasso_node_export_to_base64(profile->response);
114
if (profile->msg_body == NULL) {
115
message(G_LOG_LEVEL_CRITICAL, "AuthnResponse Base64 msg not found\n");
123
lasso_lecp_build_authn_response_envelope_msg(LassoLecp *lecp,
124
gint authentication_result,
125
const gchar *authenticationMethod,
126
const gchar *reauthenticateOnOrAfter)
128
LassoProfile *profile;
129
LassoProvider *provider;
130
gchar *assertionConsumerServiceURL;
132
g_return_val_if_fail(LASSO_IS_LECP(lecp), -1);
134
profile = LASSO_PROFILE(lecp);
136
if (LASSO_IS_AUTHN_RESPONSE(profile->response) == FALSE) {
137
message(G_LOG_LEVEL_CRITICAL, "AuthnResponse not found\n");
141
provider = lasso_server_get_provider_ref(profile->server,
142
profile->remote_providerID,
144
if (provider == NULL) {
145
message(G_LOG_LEVEL_CRITICAL, "Provider %s not found\n", profile->remote_providerID);
149
/* build lib:AuthnResponse */
150
lasso_login_build_authn_response_msg(LASSO_LOGIN(lecp),
151
authentication_result,
152
authenticationMethod,
153
reauthenticateOnOrAfter);
155
assertionConsumerServiceURL = lasso_provider_get_assertionConsumerServiceURL(provider,
158
if (assertionConsumerServiceURL == NULL) {
159
message(G_LOG_LEVEL_CRITICAL, "AssertionConsumerServiceURL not found\n");
163
xmlFree(LASSO_PROFILE(lecp)->msg_body);
164
LASSO_PROFILE(lecp)->msg_body = NULL;
165
xmlFree(LASSO_PROFILE(lecp)->msg_url);
166
LASSO_PROFILE(lecp)->msg_url = NULL;
167
lecp->authnResponseEnvelope = lasso_authn_response_envelope_new(LASSO_AUTHN_RESPONSE(profile->response),
168
assertionConsumerServiceURL);
169
LASSO_PROFILE(lecp)->msg_body = lasso_node_export_to_soap(lecp->authnResponseEnvelope);
171
if (LASSO_PROFILE(lecp)->msg_body == NULL) {
172
message(G_LOG_LEVEL_CRITICAL, "Error while exporting the AuthnResponseEnvelope to SOAP msg\n");
180
lasso_lecp_init_authn_request(LassoLecp *lecp)
184
g_return_val_if_fail(LASSO_IS_LECP(lecp), -1);
186
/* FIXME : BAD usage of http_method
187
using POST method so that the lib:AuthnRequest is initialize with
188
a signature template */
189
res = lasso_login_init_authn_request(LASSO_LOGIN(lecp), lassoHttpMethodPost);
195
lasso_lecp_init_from_authn_request_msg(LassoLecp *lecp,
196
gchar *authn_request_msg,
197
lassoHttpMethod authn_request_method)
201
g_return_val_if_fail(LASSO_IS_LECP(lecp), -1);
202
g_return_val_if_fail(authn_request_msg!=NULL, -1);
204
if (authn_request_method != lassoHttpMethodSoap) {
205
message(G_LOG_LEVEL_CRITICAL, "Invalid authentication request method\n");
208
res = lasso_login_init_from_authn_request_msg(LASSO_LOGIN(lecp), authn_request_msg, authn_request_method);
213
lasso_lecp_process_authn_request_envelope_msg(LassoLecp *lecp,
216
g_return_val_if_fail(LASSO_IS_LECP(lecp), -1);
217
g_return_val_if_fail(request_msg!=NULL, -1);
219
lecp->authnRequestEnvelope = lasso_authn_request_envelope_new_from_export(request_msg, lassoNodeExportTypeXml);
220
if (lecp->authnRequestEnvelope == NULL) {
221
message(G_LOG_LEVEL_CRITICAL, "Error while building the authentication request envelope\n");
225
LASSO_PROFILE(lecp)->request = lasso_authn_request_envelope_get_authnRequest(LASSO_AUTHN_REQUEST_ENVELOPE(lecp->authnRequestEnvelope));
226
if (LASSO_PROFILE(lecp)->request == NULL) {
227
message(G_LOG_LEVEL_CRITICAL, "AuthnRequest not found\n");
235
lasso_lecp_process_authn_response_envelope_msg(LassoLecp *lecp,
238
LassoProfile *profile;
240
g_return_val_if_fail(LASSO_IS_LECP(lecp), -1);
241
g_return_val_if_fail(response_msg!=NULL, -2);
243
profile = LASSO_PROFILE(lecp);
245
lecp->authnResponseEnvelope = lasso_authn_response_envelope_new_from_export(response_msg, lassoNodeExportTypeSoap);
246
if (lecp->authnResponseEnvelope == NULL) {
247
message(G_LOG_LEVEL_CRITICAL, "Error while building AuthnResponseEnvelope\n");
251
profile->response = lasso_authn_response_envelope_get_authnResponse(LASSO_AUTHN_RESPONSE_ENVELOPE(lecp->authnResponseEnvelope));
252
if (profile->response == NULL) {
253
message(G_LOG_LEVEL_CRITICAL, "AuthnResponse not found\n");
257
lecp->assertionConsumerServiceURL = lasso_authn_response_envelope_get_assertionConsumerServiceURL(
258
LASSO_AUTHN_RESPONSE_ENVELOPE(lecp->authnResponseEnvelope));
259
if (lecp->assertionConsumerServiceURL == NULL){
260
message(G_LOG_LEVEL_CRITICAL, "AssertionConsumerServiceURL not found\n");
268
lasso_lecp_destroy(LassoLecp *lecp)
270
g_object_unref(G_OBJECT(lecp));
274
/*****************************************************************************/
275
/* overrided parent class methods */
276
/*****************************************************************************/
279
lasso_lecp_finalize(LassoLecp *lecp)
281
debug("Lecp object 0x%x finalized ...\n", lecp);
283
parent_class->finalize(G_OBJECT(lecp));
286
/*****************************************************************************/
287
/* instance and class init functions */
288
/*****************************************************************************/
291
lasso_lecp_instance_init(LassoLecp *lecp)
293
lecp->authnRequestEnvelope = NULL;
294
lecp->authnResponseEnvelope = NULL;
295
lecp->assertionConsumerServiceURL = NULL;
299
lasso_lecp_class_init(LassoLecpClass *class)
301
GObjectClass *gobject_class = G_OBJECT_CLASS(class);
303
parent_class = g_type_class_peek_parent(class);
304
/* override parent class methods */
305
gobject_class->finalize = (void *)lasso_lecp_finalize;
308
GType lasso_lecp_get_type() {
309
static GType this_type = 0;
312
static const GTypeInfo this_info = {
313
sizeof (LassoLecpClass),
316
(GClassInitFunc) lasso_lecp_class_init,
321
(GInstanceInitFunc) lasso_lecp_instance_init,
324
this_type = g_type_register_static(LASSO_TYPE_LOGIN,
332
lasso_lecp_new(LassoServer *server)
336
lecp = g_object_new(LASSO_TYPE_LECP, NULL);
338
if (LASSO_IS_SERVER(server)) {
339
debug("Add server to lecp object\n");
340
LASSO_PROFILE(lecp)->server = lasso_server_copy(server);