Generic Security Services API Library Functions
gss_init_sec_context(3GSS)
NAME
gss_init_sec_context - initiate a GSS-API security context
with a peer applicationSYNOPSIS
cc [ flag... ] file... -lgss [ library... ]
#include
OM_uint32 gss_init_sec_context(OM_uint32 *minor_status,
const gss_cred_id_t initiator_cred_handle,
gss_ctx_id_t *context_handle, const gss_name_t *target_name,
const gss_OID mech_type, OM_uint32 req_flags,
OM_uint32 time_req, const gss_channel_bindings_t input_chan_bindings,
const gss_buffer_t input_token, gss_OID *actual_mech_type,
gss_buffer_t output_token, OM_uint32 *ret_flags,
OM_uint32 *time_rec);
PARAMETERS
The parameter descriptions for gss_init_sec_context() fol-
low:minor_status
A mechanism specific status code.initiator_cred_handle
The handle for the credentials claimed. SupplyGSS_C_NO_CREDENTIAL to act as a default initiator prin-
cipal. If no default initiator is defined, the functionreturns GSS_S_NO_CRED.
context_handle
The context handle for a new context. Supply the valueGSS_C_NO_CONTEXT for the first call, and use the value
returned in any continuation calls. The resources asso-
ciated with context_handle must be released by the
application after use by a call togss_delete_sec_context(3GSS).
target_name
The name of the context acceptor.SunOS 5.11 Last change: 6 Nov 2009 1
Generic Security Services API Library Functionsgss_init_sec_context(3GSS)
mech_type
The object ID of the desired mechanism. To obtain aspecific default, supply the value GSS_C_NO_OID.
req_flags
Contains independent flags, each of which will request that the context support a specific service option. Asymbolic name is provided for each flag. Logically-OR
the symbolic name to the corresponding required flag toform the bit-mask value. req_flags may contain one of
the following values:GSS_C_DELEG_FLAG
If true, delegate credentials to a remote peer. Do not delegate the credentials if the value is false.GSS_C_MUTUAL_FLAG
If true, request that the peer authenticate itself. If false, authenticate to the remote peer only.GSS_C_REPLAY_FLAG
If true, enable replay detection for messages pro-
tected with gss_wrap(3GSS) or gss_get_mic(3GSS). Do
not attempt to detect replayed messages if false.GSS_C_SEQUENCE_FLAG
If true, enable detection of out-of-sequence pro-
tected messages. Do not attempt to detect out-of-
sequence messages if false.GSS_C_CONF_FLAG
If true, request that confidential service be madeavailable by means of gss_wrap(3GSS). If false, no
per-message confidential service is required.
GSS_C_INTEG_FLAG
If true, request that integrity service be madeSunOS 5.11 Last change: 6 Nov 2009 2
Generic Security Services API Library Functionsgss_init_sec_context(3GSS)
available by means of gss_wrap(3GSS) or
gss_get_mic(3GSS). If false, no per-message
integrity service is required.GSS_C_ANON_FLAG
If true, do not reveal the initiator's identify to the acceptor. If false, authenticate normally.time_req
The number of seconds for which the context will remainvalid. Supply a zero value to time_req to request a
default validity period.input_chan_bindings
Optional application-specified bindings. Allows applica-
tion to securely bind channel identification information to the security context. Set toGSS_C_NO_CHANNEL_BINDINGS if you do not want to use
channel bindings.input_token
Token received from the peer application. On the initialcall, supply GSS_C_NO_BUFFER or a pointer to a buffer
containing the value GSS_C_EMPTY_BUFFER.
actual_mech_type
The actual mechanism used. The OID returned by means of this parameter will be pointer to static storage thatshould be treated as read-only. The application should
not attempt to free it. To obtain a specific default,supply the value GSS_C_NO_OID. Specify NULL if the
parameter is not required.output_token
The token to send to the peer application. If the length field of the returned buffer is zero, no token need besent to the peer application. After use storage associ-
ated with this buffer must be freed by the applicationSunOS 5.11 Last change: 6 Nov 2009 3
Generic Security Services API Library Functionsgss_init_sec_context(3GSS)
by a call to gss_release_buffer(3GSS).
ret_flags
Contains various independent flags, each of which indi-
cates that the context supports a specific service option. If not needed, specify NULL. Test the returnedbit-mask ret_flags value against its symbolic name to
determine if the given option is supported by the con-
text. ret_flags may contain one of the following values:
GSS_C_DELEG_FLAG
If true, credentials were delegated to the remote peer. If false, no credentials were delegated.GSS_C_MUTUAL_FLAG
If true, the remote peer authenticated itself. If false, the remote peer did not authenticate itself.GSS_C_REPLAY_FLAG
If true, replay of protected messages will be detected. If false, replayed messages will not be detected.GSS_C_SEQUENCE_FLAG
If true, out of sequence protected messages will be detected. If false, they will not be detected.GSS_C_CONF_FLAG
If true, confidential service may be invoked by cal-
ling the gss_wrap() routine. If false, no confiden-
tiality service is available by means ofgss_wrap(3GSS). gss_wrap() will provide message
encapsulation, data-origin authentication and
integrity services only.GSS_C_INTEG_FLAG
If true, integrity service may be invoked by callingeither the gss_wrap(3GSS) or gss_get_mic(3GSS)
SunOS 5.11 Last change: 6 Nov 2009 4
Generic Security Services API Library Functionsgss_init_sec_context(3GSS)
routine. If false, per-message integrity service is
not available.GSS_C_ANON_FLAG
If true, the initiator's identity has not been revealed; it will not be revealed if any emittedtoken is passed to the acceptor. If false, the ini-
tiator has been or will be authenticated normally.GSS_C_PROT_READY_FLAG
If true, the protection services specified by thestates of GSS_C_CONF_FLAG and GSS_C_INTEG_FLAG are
available if the accompanying major status returnvalue is either GSS_S_COMPLETE or
GSS_S_CONTINUE_NEEDED. If false, the protection ser-
vices are available only if the accompanying majorstatus return value is GSS_S_COMPLETE.
GSS_C_TRANS_FLAG
If true, the resultant security context may be transferred to other processes by means of a call togss_export_sec_context(3GSS). If false, the security
context cannot be transferred.time_rec
The number of seconds for which the context will remain valid. Specify NULL if the parameter is not required.DESCRIPTION
The gss_init_sec_context() function initiates the establish-
ment of a security context between the application and aremote 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 with a length field that contains a
zero value. The routine may return a output_token, which
should be transferred to the peer application, which willpresent it to gss_accept_sec_context(3GSS). If no token need
be sent, gss_init_sec_context() will indicate this by set-
ting the length field of the output_token argument to zero.
To complete context establishment, one or more reply tokens may be required from the peer application; if so,SunOS 5.11 Last change: 6 Nov 2009 5
Generic Security Services API Library Functionsgss_init_sec_context(3GSS)
gss_init_sec_context() will return a status code that con-
tains the supplementary information bitGSS_S_CONTINUE_NEEDED. In this case, make another call to
gss_init_sec_context() when the reply token is received from
the peer application and pass the reply token togss_init_sec_context() by means of the input_token parame-
ter. Construct portable applications to use the token length and return status to determine whether to send or wait for a token. Whenever the routine returns a major status that includesthe value GSS_S_CONTINUE_NEEDED, the context is not fully
established, and the following restrictions apply to the output parameters:o The value returned by means of the time_rec parame-
ter is undefined. Unless the accompanying ret_flags
parameter contains the bit GSS_C_PROT_READY_FLAG,
which indicates that per-message services may be
applied in advance of a successful completion status, the value returned by means of theactual_mech_type parameter is undefined until the
routine returns a major status value ofGSS_S_COMPLETE.
o 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
by the ret_flags parameter contain values that will
be valid if context establishment succeeds. For example, if the application requests a service such as delegation or anonymous authentication by meansof the req_flags argument, and the service is una-
vailable from the underlying mechanism,gss_init_sec_context() generates a token that will
not provide the service, and it indicate by meansof the ret_flags argument that the service will not
be supported. The application may choose to abort context establishment by callinggss_delete_sec_context(3GSS) if it cannot continue
without the service, or if the service was merely desired but not mandatory, it may transmit the token and continue context establishment.o The values of the GSS_C_PROT_READY_FLAG and
GSS_C_TRANS_FLAG bits within ret_flags indicate the
SunOS 5.11 Last change: 6 Nov 2009 6
Generic Security Services API Library Functionsgss_init_sec_context(3GSS)
actual state at the time gss_init_sec_context()
returns, whether or not the context is fully esta-
blished.o The GSS-API sets the GSS_C_PROT_READY_FLAG in the
final ret_flags returned to a caller, for example,
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 1of the GSS-API. Instead, applications should
determine what per-message services are available
after a successful context establishment accordingto the GSS_C_INTEG_FLAG and GSS_C_CONF_FLAG values.
o All other bits within the ret_flags argument are
set to zero.If the initial call of gss_init_sec_context() fails, the
GSS-API does not create a context object; it leaves the
value of the context_handle parameter set to
GSS_C_NO_CONTEXT to indicate this. In the event of failure
on a subsequent call, the GSS-API leaves the security con-
text untouched for the application to delete usinggss_delete_sec_context(3GSS).
During context establishment, the informational status bitsGSS_S_OLD_TOKEN and GSS_S_DUPLICATE_TOKEN indicate fatal
errors, and GSS-API mechanisms should always return them in
association with a status code of GSS_S_FAILURE. This pair-
ing requirement was not part of Version 1 of the GSS-API
specification, so applications that wish to run on Version 1implementations must special-case these codes.
ERRORS
gss_init_sec_context() may return the following status
codes:GSS_S_COMPLETE
Successful completion.GSS_S_CONTINUE_NEEDED
A token from the peer application is required to com-
plete the context, and gss_init_sec_context() must be
called again with that token.SunOS 5.11 Last change: 6 Nov 2009 7
Generic Security Services API Library Functionsgss_init_sec_context(3GSS)
GSS_S_DEFECTIVE_TOKEN
Consistency checks performed on the input_token failed.
GSS_S_DEFECTIVE_CREDENTIAL
Consistency checks performed on the credential failed.GSS_S_NO_CRED
The supplied credentials are not valid for context acceptance, or the credential handle does not reference any credentials.GSS_S_CREDENTIALS_EXPIRED
The referenced credentials have expired.GSS_S_BAD_BINDINGS
The input_token contains different channel bindings than
those specified by means of the input_chan_bindings
parameter.GSS_S_BAD_SIG
The input_token contains an invalid MIC or a MIC that
cannot be verified.GSS_S_OLD_TOKEN
The input_token is too old. This is a fatal error while
establishing context.GSS_S_DUPLICATE_TOKEN
The input_token is valid, but it is a duplicate of a
token already processed. This is a fatal error while establishing context.GSS_S_NO_CONTEXT
The supplied context handle does not refer to a validSunOS 5.11 Last change: 6 Nov 2009 8
Generic Security Services API Library Functionsgss_init_sec_context(3GSS)
context.GSS_S_BAD_NAMETYPE
The provided target_name parameter contains an invalid
or unsupported name type.GSS_S_BAD_NAME
The supplied target_name parameter is ill-formed.
GSS_S_BAD_MECH
The token received specifies a mechanism that is notsupported by the implementation or the provided creden-
tial.GSS_S_FAILURE
The underlying mechanism detected an error for which nospecific GSS status code is defined. The mechanism-
specific status code reported by means of theminor_status parameter details the error condition.
EXAMPLES
Example 1 Invoking gss_init_sec_context() Within a Loop
A typical portable caller should always invokegss_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,
SunOS 5.11 Last change: 6 Nov 2009 9
Generic Security Services API Library Functionsgss_init_sec_context(3GSS)
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;
}; };ATTRIBUTES
See attributes(5) for descriptions of the following attri-
butes:____________________________________________________________
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
|_____________________________|_____________________________|
| MT-Level | Safe |
|_____________________________|_____________________________|
SEE ALSO
gss_delete_sec_context(3GSS), gss_export_sec_context(3GSS),
gss_get_mic(3GSS), gss_wrap(3GSS), attributes(5)
Oracle Solaris Security for Developers GuideSunOS 5.11 Last change: 6 Nov 2009 10
Generic Security Services API Library Functionsgss_init_sec_context(3GSS)
SunOS 5.11 Last change: 6 Nov 2009 11