|
HP Open Source Security for OpenVMS Volume 3: Kerberos > Chapter 5 GSSAPI (Generic Security Services Application
Programming Interface)
gss_init_sec_context — Establish a security context
C Prototype | |
OM_uint32 gss_init_sec_context( OM_uint32 * minor_status, gss_cred_id_t claimant_cred_handle, gss_ctx_id_t * context_handle, gss_name_t target_name, gss_OID mech_type, OM_uint32 req_flags, OM_uint32 time_req, gss_channel_bindings_t input_chan_bindings, gss_buffer_t input_token, gss_OID * actual_mech_type, gss_buffer_t output_token, OM_uint32 * ret_flags, OM_uint32 * time_rec );
|
Arguments | |
minor_status
(output) | | An implementation-specific
status code. | claimant_cred_handle (input) | | A handle for credentials
claimed. Supply GSS_C_NO_CREDENTIAL to act as a default initiator
principal. If no default initiator is defined, the routine will
return GSS_S_NO_CRED. | context_handle (input/output) | | The context handle for the
new context. Supply GSS_C_NO_CONTEXT for the first call; use the
value returned by the first call in continuation calls. Resources
associated with this context handle must be released by the application
after use with a call to gss_delete_sec_context. | target_name (input) | | The name of the target. | mech_type (input) | | The object ID of the desired
mechanism. Supply GSS_C_NOOID to obtain A mechanism-specific default. | req_flags (input) | | Contains various independent
flags, each of which requests that the context support a specific
service option. Symbolic names are provided for each flag, and
the symbolic names corresponding to the required flags should be
logically ORed together to form the bit-mask value. Valid values are: GSS_C_DELEG_FLAG TRUE — Delegate credentials to the remote peer. FALSE — Do not delegate. GSS_C_MUTUAL_FLAG TRUE — Request that the remote peer authenticate
itself.FALSE — Authenticate self to the remote peer only. GSS_C_REPLAY_FLAG TRUE — Enable replay detection for messages protected
with gss_wrap or gss_get_mic.FALSE — Do
not attempt to detect replayed messages. GSS_C_SEQUENCE_FLAG TRUE — Enable detection of out-of-sequence protected
messages.FALSE — Do not attempt to detect out-of-sequence
messages. GSS_C_CONF_FLAG TRUE — Request that confidentiality service be made
available (by calling gss_wrap).FALSE — No
per-message confidentiality service is required. GSS_C_INTEG_FLAG TRUE — Request that integrity service be made available
(by calling either gss_get_mic or gss_wrap).FALSE — No
per-message integrity service is required. GSS_C_ANON_FLAG TRUE — Do not reveal the initiator's identity to
the acceptor.FALSE — Authenticate normally. | time_req (input) | | The desired number of seconds
for which the context should remain valid. Supply zero to request
a default validity period. | input_chan_bindings (input) | | Application-specified bindings.
Allows the application to securely bind channel identification
information to the security context. Specify GSS_C_NO_CHANNEL_BINDINGS
if channel bindings are not used. | input_token (input) | | The token received from the
peer application. Supply GSS_C_NO_BUFFER, or a pointer to a buffer
containing the value GSS_C_EMPTY_BUFFER on the initial call. | actual_mech_type (output) | | The actual mechanism used.
The OID returned via this argument will be a pointer to static
storage that should be treated as read only; in particular the application
should not attempt to free it. Specify NULL if not required. | output_token (output) | | The token to be sent to the
peer application. If the length field of the returned buffer is
zero, no token need be sent to the peer application. Storage associated
with this buffer must be freed by the application after use with
a call to gss_release_buffer. | ret_flags (output) | | Contains various independent
flags, each of which indicates that the context supports a specific
service option. Specify NULL if not required. Symbolic names are
provided for each flag, and the symbolic names corresponding to
the required flags should be logically ANDed with the ret_flags value
to test whether a given option is supported by the context. The
flags are: GSS_C_DELEG_FLAG TRUE — Credentials were delegated to the remote peer.FALSE — No
credentials were delegated. GSS_C_MUTUAL_FLAG TRUE — The remote peer has authenticated itself.FALSE — The
remote peer has not authenticated itself. GSS_C_REPLAY_FLAG TRUE — Replay of protected messages will be detected.FALSE — Replayed
messages will not be detected. GSS_C_SEQUENCE_FLAG TRUE — Out-of-sequence protected messages will be
detected.FALSE — Out-of-sequence messages will not be detected. GSS_C_CONF_FLAG TRUE — Confidentiality service may be invoked by
calling the gss_wrap routine.FALSE — No
confidentiality service (via gss_wrap)
is available. The gss_wrap routine will
provide message encapsulation, data-origin authentication, and integrity
services only. GSS_C_INTEG_FLAG TRUE — Integrity service may be invoked by calling
either gss_get_mic or gss_wrap routines.FALSE — Per-message
integrity service is unavailable. GSS_C_ANON_FLAG TRUE — The initiator's identity has not been revealed,
and will not be revealed if any emitted token is passed to the acceptor.FALSE — The
initiator's identity has been or will be authenticated normally. GSS_C_PROT_READY_FLAG TRUE — Protection services (as specified by the states
of the GSS_C_CONF_FLAG and GSS_C_INTEG_FLAG) are available for use
if the accompanying status return value is either GSS_S_COMPLETE
or GSS_S_CONTINUE_NEEDED.FALSE — Protection services (as
specified by the states of the GSS_C_CONF_FLAG and GSS_C_INTEG_FLAG)
are available only if the accompanying major status return value
is GSS_S_COMPLETE. GSS_S_TRANS_FLAG TRUE — The resultant security context may be transferred
to other processes via a call to gss_export_sec_context.FALSE — The
security context is not transferable. All other bits should be set to zero. | time_rec (output) | | The number of seconds for
which the context will remain valid. If the implementation does
not support credential expiration, the value GSS_C_INDEFINITE will
be returned. Specify NULL if not required. |
Description | |
This routine indicates the establishment of a security context
between the application and a remote peer. Initially, the input_token argument
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 an output_token that
should be transferred to the peer application, where the peer application
will present it to gss_accept_sec_context.
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 token to gss_init_sec_context via the input_token arguments. 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 status that indicates the value
GSS_S_CONTINUE_NEEDED, the context is not fully established and
the following restrictions apply to the output arguments: The value returned via the
time_rec argument is undefined unless the accompanying ret_flags argument
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 argument
is undefined until the routine returns a 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_GLAG,
GSS_C_INTEG_FLAG and GSS_C_ANON_FLAG bits returned via the ret_flags argument
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 generates a token
that will not provide the service, and indicates 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 (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 indicate
the actual state at the time gss_init_sec_context returns,
whether or not the context is fully established. GSSAPI 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
(that is, 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 GSSAPI. 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.
If the initial call of gss_init_sec_context fails,
a context object is not created, and the value of the context_handle argument
is set to GSS_C_NO_CONTEXT to indicate this. During context establishment, the informational status bits
GSS_OLD_TOKEN and GSS_S_DUPLICATE_TOKEN indicate fatal errors, and
GSSAPI mechanisms return them in association with a routine error
of GSS_S_FAILURE. This requirement for pairing did not exist in
Version 1 of the GSSAPI specification, so applications that wish
to run over Version 1 implementations must special-case these codes. Return
Values | |
This routine returns one of the following GSS status codes: GSS_S_COMPLETE | Successful completion. | GSS_S_CONTINUE_NEEDED | Indicates that a token from the peer application
is required to complete the context and that gss_init_sec_context must
be called again with that token. | GSS_S_DEFECTIVE_TOKEN | Indicates that consistency checks performed
on the input_token failed. | GSS_S_DEFECTIVE_CREDENTIAL | Indicates that consistency checks performed
on the credential failed. | GSS_S_NO_CRED | The supplied credentials were not valid
for context initiation, or the credential handle did not reference any
credentials. | GSS_S_CREDENTIALS_EXPIRED | The referenced credentials have expired. | GSS_S_BAD_BINDINGS | The input_token contains
different channel bindings to those specified via the input_chan_bindings argument. | GSS_S_BAD_SIG | The input_token contains
an invalid MIC, or a MIC that could not be verified. | GSS_S_OLD_TOKEN | The input_token was
too old. This is a fatal error during context establishment. | GSS_S_DUPLICATE_TOKEN | The input_token is
valid, but is a duplicate of a token already processed. This is
a fatal error during context establishment. | GSS_S_NO_CONTEXT | Indicates that the supplied context handle
did not refer to a valid context. | GSS_S_BAD_NAMETYPE | The provided target_name argument
contained an invalid or unsupported type of name. | GSS_S_BAD_NAME | The provided target_name argument
was ill formed. | GSS_S_BAD_MECH | The specified mechanism is not supported
by the provided credential, or is unrecognized by the implementation. |
|
|