def ssh_init_sec_context(<EOL>self, target, desired_mech=None, username=None, recv_token=None<EOL>):
from pyasn1.codec.der import decoder<EOL>self._username = username<EOL>self._gss_host = target<EOL>targ_name = gssapi.Name(<EOL>"<STR_LIT>" + self._gss_host, gssapi.C_NT_HOSTBASED_SERVICE<EOL>)<EOL>ctx = gssapi.Context()<EOL>ctx.flags = self._gss_flags<EOL>if desired_mech is None:<EOL><INDENT>krb5_mech = gssapi.OID.mech_from_string(self._krb5_mech)<EOL><DEDENT>else:<EOL><INDENT>mech, __ = decoder.decode(desired_mech)<EOL>if mech.__str__() != self._krb5_mech:<EOL><INDENT>raise SSHException("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>krb5_mech = gssapi.OID.mech_from_string(self._krb5_mech)<EOL><DEDENT><DEDENT>token = None<EOL>try:<EOL><INDENT>if recv_token is None:<EOL><INDENT>self._gss_ctxt = gssapi.InitContext(<EOL>peer_name=targ_name,<EOL>mech_type=krb5_mech,<EOL>req_flags=ctx.flags,<EOL>)<EOL>token = self._gss_ctxt.step(token)<EOL><DEDENT>else:<EOL><INDENT>token = self._gss_ctxt.step(recv_token)<EOL><DEDENT><DEDENT>except gssapi.GSSException:<EOL><INDENT>message = "<STR_LIT>".format(sys.exc_info()[<NUM_LIT:1>], self._gss_host)<EOL>raise gssapi.GSSException(message)<EOL><DEDENT>self._gss_ctxt_status = self._gss_ctxt.established<EOL>return token<EOL>
Initialize a GSS-API context.

:param str username: The name of the user who attempts to login
:param str target: The hostname of the target to connect to
:param str desired_mech: The negotiated GSS-API mechanism
                         ("pseudo negotiated" mechanism, because we
                         support just the krb5 mechanism :-))
:param str recv_token: The GSS-API token received from the Server
:raises:
    `.SSHException` -- Is raised if the desired mechanism of the client
    is not supported
:return: A ``String`` if the GSS-API has returned a token or
    ``None`` if no token was returned