Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifdef HAVE_CONFIG_H
00024 # include "config.h"
00025 #endif
00026
00027
00028 #include "saml20.h"
00029
00030
00031 #include <string.h>
00032
00033
00034 #include <stdlib.h>
00035
00036
00037 #include <stdbool.h>
00038
00039
00040 #include "mechtools.h"
00041
00042 struct saml20_client_state
00043 {
00044 int step;
00045 };
00046
00047 int
00048 _gsasl_saml20_client_start (Gsasl_session * sctx, void **mech_data)
00049 {
00050 struct saml20_client_state *state;
00051
00052 state = (struct saml20_client_state *) calloc (sizeof (*state), 1);
00053 if (state == NULL)
00054 return GSASL_MALLOC_ERROR;
00055
00056 *mech_data = state;
00057
00058 return GSASL_OK;
00059 }
00060
00061 int
00062 _gsasl_saml20_client_step (Gsasl_session * sctx,
00063 void *mech_data,
00064 const char *input, size_t input_len,
00065 char **output, size_t * output_len)
00066 {
00067 struct saml20_client_state *state = mech_data;
00068 int res = GSASL_MECHANISM_CALLED_TOO_MANY_TIMES;
00069
00070 switch (state->step)
00071 {
00072 case 0:
00073 {
00074 const char *authzid = gsasl_property_get (sctx, GSASL_AUTHZID);
00075 const char *p;
00076 int len;
00077
00078 p = gsasl_property_get (sctx, GSASL_SAML20_IDP_IDENTIFIER);
00079 if (!p || !*p)
00080 return GSASL_NO_SAML20_IDP_IDENTIFIER;
00081
00082 res = _gsasl_gs2_generate_header (false, 'n', NULL, authzid,
00083 strlen (p), p,
00084 output, output_len);
00085 if (res == GSASL_OK)
00086 return res;
00087
00088 res = GSASL_NEEDS_MORE;
00089 state->step++;
00090 break;
00091 }
00092
00093 case 1:
00094 {
00095 gsasl_property_set_raw (sctx, GSASL_SAML20_REDIRECT_URL,
00096 input, input_len);
00097
00098 res = gsasl_callback (NULL, sctx,
00099 GSASL_SAML20_AUTHENTICATE_IN_BROWSER);
00100 if (res == GSASL_OK)
00101 {
00102 *output_len = 0;
00103 *output = NULL;
00104 }
00105
00106 state->step++;
00107 }
00108 break;
00109
00110 default:
00111 break;
00112 }
00113
00114 return res;
00115 }
00116
00117 void
00118 _gsasl_saml20_client_finish (Gsasl_session * sctx, void *mech_data)
00119 {
00120 struct saml20_client_state *state = mech_data;
00121
00122 if (!state)
00123 return;
00124
00125 free (state);
00126 }