Initiates the establishment of a security context between the
application and a remote peer.
Initially, the input_token parameter should be specified either as
GSS_C_NO_BUFFER, or as a pointer to a
gss_buffer_desc object whose length field contains the value zero.
The routine may return a output_token which should be transferred to
the peer application, where the peer application will present it to
gss_accept_sec_context(3). If no token need be sent,
gss_init_sec_context()
will indicate this by setting the
length field
of the output_token argument to zero. To complete the context
establishment, one or more reply tokens may be required from the peer
application; if so,
gss_init_sec_context()
will return a status
containing the supplementary information bit
GSS_S_CONTINUE_NEEDED.
In this case,
gss_init_sec_context()
should be called again when the reply token is received from the peer
application, passing the reply token to
gss_init_sec_context()
via the input_token parameters.
Portable applications should be constructed to use the token length
and return status to determine whether a token needs to be sent or
waited for. Thus a typical portable caller should always invoke
gss_init_sec_context()
within a loop:
int context_established = 0;
gss_ctx_id_t context_hdl = GSS_C_NO_CONTEXT;
...
input_token->length = 0;
while (!context_established) {
maj_stat = gss_init_sec_context(&min_stat,
cred_hdl,
&context_hdl,
target_name,
desired_mech,
desired_services,
desired_time,
input_bindings,
input_token,
&actual_mech,
output_token,
&actual_services,
&actual_time);
if (GSS_ERROR(maj_stat)) {
report_error(maj_stat, min_stat);
};
if (output_token->length != 0) {
send_token_to_peer(output_token);
gss_release_buffer(&min_stat, output_token)
};
if (GSS_ERROR(maj_stat)) {
if (context_hdl != GSS_C_NO_CONTEXT)
gss_delete_sec_context(&min_stat,
&context_hdl,
GSS_C_NO_BUFFER);
break;
};
if (maj_stat & GSS_S_CONTINUE_NEEDED) {
receive_token_from_peer(input_token);
} else {
context_established = 1;
};
};
Whenever the routine returns a major status that includes the value
GSS_S_CONTINUE_NEEDED, the context is not fully established and the
following restrictions apply to the output parameters:
- The value returned via the
time_rec
parameter is undefined Unless
the accompanying
ret_flags
parameter contains the bit
GSS_C_PROT_READY_FLAG, indicating that per-message services may be
applied in advance of a successful completion status, the value
returned via the
actual_mech_type
parameter is undefined until the
routine returns a major status value of
GSS_S_COMPLETE.
- The values of the
GSS_C_DELEG_FLAG,
GSS_C_MUTUAL_FLAG,
GSS_C_REPLAY_FLAG,
GSS_C_SEQUENCE_FLAG,
GSS_C_CONF_FLAG,
GSS_C_INTEG_FLAG and
GSS_C_ANON_FLAG bits returned via the
ret_flags
parameter should contain the values that the
implementation expects would be valid if context establishment
were to succeed. In particular, if the application has requested
a service such as delegation or anonymous authentication via the
req_flags
argument, and such a service is unavailable from the
underlying mechanism,
gss_init_sec_context()
should generate a token
that will not provide the service, and indicate via the
ret_flags
argument that the service will not be supported. The application
may choose to abort the context establishment by calling
gss_delete_sec_context(3)
(if it cannot continue in the absence of
the service), or it may choose to transmit the token and continue
context establishment (if the service was merely desired but not
mandatory).
- The values of the
GSS_C_PROT_READY_FLAG and
GSS_C_TRANS_FLAG bits
within
ret_flags
should indicate the actual state at the time
gss_init_sec_context()
returns, whether or not the context is fully established.
- GSS-API implementations that support per-message protection are
encouraged to set the
GSS_C_PROT_READY_FLAG in the final
ret_flags
returned to a caller (i.e. when accompanied by a
GSS_S_COMPLETE
status code). However, applications should not rely on this
behavior as the flag was not defined in Version 1 of the GSS-API.
Instead, applications should determine what per-message services
are available after a successful context establishment according
to the
GSS_C_INTEG_FLAG and
GSS_C_CONF_FLAG values.
- All other bits within the
ret_flags
argument should be set to
zero.
If the initial call of
gss_init_sec_context()
fails, the
implementation should not create a context object, and should leave
the value of the
context_handle
parameter set to
GSS_C_NO_CONTEXT to
indicate this. In the event of a failure on a subsequent call, the
implementation is permitted to delete the "half-built" security
context (in which case it should set the
context_handle
parameter to
GSS_C_NO_CONTEXT ), but the preferred behavior is to leave the
security context untouched for the application to delete (using
gss_delete_sec_context(3) ).
During context establishment, the informational status bits
GSS_S_OLD_TOKEN and
GSS_S_DUPLICATE_TOKEN indicate fatal errors, and
GSS-API mechanisms should always return them in association with a
routine error of
GSS_S_FAILURE.
This requirement for pairing did not
exist in version 1 of the GSS-API specification, so applications that
wish to run over version 1 implementations must special-case these
codes.