1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
/* client.c --- SAML20 mechanism, client side.
* Copyright (C) 2010-2025 Simon Josefsson
*
* This file is part of GNU SASL Library.
*
* GNU SASL Library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* GNU SASL Library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with GNU SASL Library; if not, see
* <https://www.gnu.org/licenses/>.
*
*/
#include <config.h>
/* Get specification. */
#include "saml20.h"
/* Get strdup, strlen. */
#include <string.h>
/* Get free. */
#include <stdlib.h>
/* Get bool. */
#include <stdbool.h>
/* Get _gsasl_gs2_generate_header. */
#include "mechtools.h"
struct saml20_client_state
{
int step;
};
int
_gsasl_saml20_client_start (Gsasl_session *sctx _GL_UNUSED, void **mech_data)
{
struct saml20_client_state *state;
state = (struct saml20_client_state *) calloc (1, sizeof (*state));
if (state == NULL)
return GSASL_MALLOC_ERROR;
*mech_data = state;
return GSASL_OK;
}
int
_gsasl_saml20_client_step (Gsasl_session *sctx,
void *mech_data,
const char *input, size_t input_len,
char **output, size_t *output_len)
{
struct saml20_client_state *state = mech_data;
int res = GSASL_MECHANISM_CALLED_TOO_MANY_TIMES;
switch (state->step)
{
case 0:
{
const char *authzid = gsasl_property_get (sctx, GSASL_AUTHZID);
const char *idp =
gsasl_property_get (sctx, GSASL_SAML20_IDP_IDENTIFIER);
if (!idp || !*idp)
return GSASL_NO_SAML20_IDP_IDENTIFIER;
res = _gsasl_gs2_generate_header (false, 'n', NULL, authzid,
strlen (idp), idp,
output, output_len);
if (res != GSASL_OK)
return res;
res = GSASL_NEEDS_MORE;
state->step++;
}
break;
case 1:
{
res = gsasl_property_set_raw (sctx, GSASL_SAML20_REDIRECT_URL,
input, input_len);
if (res != GSASL_OK)
return res;
res = gsasl_callback (NULL, sctx,
GSASL_SAML20_AUTHENTICATE_IN_BROWSER);
if (res != GSASL_OK)
return res;
*output_len = 1;
*output = strdup ("=");
if (!*output)
return GSASL_MALLOC_ERROR;
res = GSASL_OK;
state->step++;
}
break;
default:
break;
}
return res;
}
void
_gsasl_saml20_client_finish (Gsasl_session *sctx _GL_UNUSED, void *mech_data)
{
struct saml20_client_state *state = mech_data;
if (!state)
return;
free (state);
}
|