gsasl  2.2.1
saml20/client.c
Go to the documentation of this file.
1 /* client.c --- SAML20 mechanism, client side.
2  * Copyright (C) 2010-2024 Simon Josefsson
3  *
4  * This file is part of GNU SASL Library.
5  *
6  * GNU SASL Library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation; either version 2.1 of
9  * the License, or (at your option) any later version.
10  *
11  * GNU SASL Library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with GNU SASL Library; if not, write to the Free
18  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include <config.h>
24 
25 /* Get specification. */
26 #include "saml20.h"
27 
28 /* Get strdup, strlen. */
29 #include <string.h>
30 
31 /* Get free. */
32 #include <stdlib.h>
33 
34 /* Get bool. */
35 #include <stdbool.h>
36 
37 /* Get _gsasl_gs2_generate_header. */
38 #include "mechtools.h"
39 
41 {
42  int step;
43 };
44 
45 int
46 _gsasl_saml20_client_start (Gsasl_session *sctx _GL_UNUSED, void **mech_data)
47 {
48  struct saml20_client_state *state;
49 
50  state = (struct saml20_client_state *) calloc (sizeof (*state), 1);
51  if (state == NULL)
52  return GSASL_MALLOC_ERROR;
53 
54  *mech_data = state;
55 
56  return GSASL_OK;
57 }
58 
59 int
61  void *mech_data,
62  const char *input, size_t input_len,
63  char **output, size_t *output_len)
64 {
65  struct saml20_client_state *state = mech_data;
67 
68  switch (state->step)
69  {
70  case 0:
71  {
72  const char *authzid = gsasl_property_get (sctx, GSASL_AUTHZID);
73  const char *idp =
75 
76  if (!idp || !*idp)
78 
79  res = _gsasl_gs2_generate_header (false, 'n', NULL, authzid,
80  strlen (idp), idp,
81  output, output_len);
82  if (res != GSASL_OK)
83  return res;
84 
85  res = GSASL_NEEDS_MORE;
86  state->step++;
87  }
88  break;
89 
90  case 1:
91  {
93  input, input_len);
94  if (res != GSASL_OK)
95  return res;
96 
97  res = gsasl_callback (NULL, sctx,
99  if (res != GSASL_OK)
100  return res;
101 
102  *output_len = 1;
103  *output = strdup ("=");
104  if (!*output)
105  return GSASL_MALLOC_ERROR;
106 
107  res = GSASL_OK;
108  state->step++;
109  }
110  break;
111 
112  default:
113  break;
114  }
115 
116  return res;
117 }
118 
119 void
120 _gsasl_saml20_client_finish (Gsasl_session *sctx _GL_UNUSED, void *mech_data)
121 {
122  struct saml20_client_state *state = mech_data;
123 
124  if (!state)
125  return;
126 
127  free (state);
128 }
int gsasl_callback(Gsasl *ctx, Gsasl_session *sctx, Gsasl_property prop)
Definition: callback.c:71
@ GSASL_OK
Definition: gsasl.h:129
@ GSASL_NEEDS_MORE
Definition: gsasl.h:130
@ GSASL_MALLOC_ERROR
Definition: gsasl.h:133
@ GSASL_NO_SAML20_IDP_IDENTIFIER
Definition: gsasl.h:152
@ GSASL_MECHANISM_CALLED_TOO_MANY_TIMES
Definition: gsasl.h:132
_GSASL_API int gsasl_property_set_raw(Gsasl_session *sctx, Gsasl_property prop, const char *data, size_t len)
Definition: property.c:218
_GSASL_API const char * gsasl_property_get(Gsasl_session *sctx, Gsasl_property prop)
Definition: property.c:292
@ GSASL_SAML20_AUTHENTICATE_IN_BROWSER
Definition: gsasl.h:250
@ GSASL_AUTHZID
Definition: gsasl.h:225
@ GSASL_SAML20_IDP_IDENTIFIER
Definition: gsasl.h:244
@ GSASL_SAML20_REDIRECT_URL
Definition: gsasl.h:245
int _gsasl_gs2_generate_header(bool nonstd, char cbflag, const char *cbname, const char *authzid, size_t extralen, const char *extra, char **gs2h, size_t *gs2hlen)
Definition: mechtools.c:166
int _gsasl_saml20_client_start(Gsasl_session *sctx _GL_UNUSED, void **mech_data)
Definition: saml20/client.c:46
int _gsasl_saml20_client_step(Gsasl_session *sctx, void *mech_data, const char *input, size_t input_len, char **output, size_t *output_len)
Definition: saml20/client.c:60
void _gsasl_saml20_client_finish(Gsasl_session *sctx _GL_UNUSED, void *mech_data)