125 lines
3.4 KiB
C
125 lines
3.4 KiB
C
/*
|
|
* idpc - IDP as a C CGI program
|
|
* Copyright (C) 2004 Entr'ouvert
|
|
*
|
|
* Author: Frederic Peters <fpeters@entrouvert.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*/
|
|
|
|
#include "idpc.h"
|
|
|
|
#define DATADIR "/home/fred/src/idpc/idpc/data/"
|
|
/* FIXME; should be defined from ./configure */
|
|
|
|
|
|
int single_sign_on()
|
|
{
|
|
LassoServer *server_context;
|
|
LassoLogin *login_context;
|
|
lassoHttpMethods response_method;
|
|
char *http_verb;
|
|
char *authn_request_msg;
|
|
int rc;
|
|
char *name_identifier, *assertion_artifact, *response_dump;
|
|
FILE *f;
|
|
|
|
|
|
http_verb = getenv("REQUEST_METHOD");
|
|
|
|
|
|
server_context = lasso_server_new(
|
|
DATADIR "idp-metadata.xml",
|
|
DATADIR "idp-public-key.pem",
|
|
DATADIR "idp-private-key.pem",
|
|
DATADIR "idp-crt.pem",
|
|
lassoSignatureMethodRsaSha1);
|
|
lasso_server_add_provider(server_context,
|
|
DATADIR "sp-metadata.xml",
|
|
DATADIR "sp-public-key.pem",
|
|
DATADIR "ca-cert.pem");
|
|
|
|
|
|
login_context = lasso_login_new(server_context);
|
|
|
|
if (strcmp(http_verb, "GET") == 0) {
|
|
char *t;
|
|
t = getenv("QUERY_STRING");
|
|
if (t) {
|
|
authn_request_msg = strdup(t);
|
|
} else {
|
|
authn_request_msg = strdup("");
|
|
}
|
|
response_method = lassoHttpMethodRedirect;
|
|
} else {
|
|
/* FIXME: handle POST */
|
|
}
|
|
|
|
rc = lasso_login_init_from_authn_request_msg(login_context,
|
|
authn_request_msg, response_method);
|
|
if (rc != 0) {
|
|
char msg[100];
|
|
sprintf(msg, "Lasso login error, %d", rc);
|
|
return error_page(msg);
|
|
}
|
|
|
|
rc = lasso_login_must_authenticate(login_context);
|
|
|
|
if (login_context->protocolProfile == lassoLoginProtocolProfileBrwsArt) {
|
|
rc = lasso_login_build_artifact_msg(login_context,
|
|
1, /* user authenticated */
|
|
lassoSamlAuthenticationMethodPassword,
|
|
"", /* reauthenticateOnOrAfter */
|
|
lassoHttpMethodRedirect);
|
|
/* TODO: error checking */
|
|
|
|
name_identifier = strdup(
|
|
LASSO_PROFILE_CONTEXT(login_context)->nameIdentifier);
|
|
f = fopen("/tmp/name_identifier", "w");
|
|
fputs(name_identifier, f);
|
|
fclose(f);
|
|
free(name_identifier);
|
|
|
|
assertion_artifact = strdup(login_context->assertionArtifact);
|
|
f = fopen("/tmp/assertion_artifact", "w");
|
|
fputs(assertion_artifact, f);
|
|
fclose(f);
|
|
free(assertion_artifact);
|
|
|
|
response_dump = strdup(login_context->response_dump);
|
|
/*printf("Content-type: text/plain\n\n");
|
|
printf("Response dump: %s", login_context->response_dump);*/
|
|
f = fopen("/tmp/response_dump", "w");
|
|
fputs(response_dump, f);
|
|
fclose(f);
|
|
free(response_dump);
|
|
|
|
printf("Location: %s\n\nRedirected",
|
|
LASSO_PROFILE_CONTEXT(login_context)->msg_url);
|
|
|
|
}
|
|
if (login_context->protocolProfile == lassoLoginProtocolProfileBrwsPost) {
|
|
;
|
|
}
|
|
|
|
|
|
printf("Content-type: text/plain\n\nsingle sign on; to be continued...");
|
|
|
|
/*auth_method = lassoSamlAuthenticationMethodPassword; */
|
|
|
|
return 0;
|
|
}
|
|
|