Derk2006/moonsso/src/spnego does not have a README file

    DerError

    pub suberror DerError {
    Truncated(Int)
    BadTag(Int, Int)
    BadLength(Int)
    MissingToken
    }

    Just enough DER to read and write the two SPNEGO structures that carry an NTLM token. Definite lengths only, which is what every implementation sends; BER's indefinite form is rejected rather than guessed at.

    NegState

    pub(all) enum NegState {
    AcceptCompleted
    AcceptIncomplete
    Rejected
    RequestMic
    }

    The four values negState can take (RFC 4178 section 4.2.2). A server sends accept-incomplete while it still expects a token, request-mic when it wants a mechListMIC before it will finish, and accept-completed on the last message.

    NegState::from_int

    fn NegState::from_int(value : Int) -> NegState?

    NegState::to_int

    fn NegState::to_int(self : NegState) -> Int

    NegTarg

    pub struct NegTarg {
    state : NegState?
    supported_mech : Bytes?
    response_token : Bytes?
    mech_list_mic : Bytes?
    }

    The fields of a NegTokenTarg that matter over HTTP.

    NegTarg::mech_list_mic

    fn NegTarg::mech_list_mic(self : NegTarg) -> Bytes?

    NegTarg::response_token

    fn NegTarg::response_token(self : NegTarg) -> Bytes?

    NegTarg::state

    fn NegTarg::state(self : NegTarg) -> NegState?

    NegTarg::supported_mech

    fn NegTarg::supported_mech(self : NegTarg) -> Bytes?

    The mechanism the acceptor selected, as the raw OID content. RFC 4178 puts it in the first NegTokenTarg an acceptor sends and forbids it afterwards.

    Tlv

    pub struct Tlv {
    tag : Int
    content : Int
    length : Int
    }

    Tlv::content

    fn Tlv::content(self : Tlv) -> Int

    Tlv::length

    fn Tlv::length(self : Tlv) -> Int

    Tlv::tag

    fn Tlv::tag(self : Tlv) -> Int

    context

    fn context(n : Int, content : Bytes) -> Bytes

    [n] in constructed form, which is what every SPNEGO field uses.

    describe

    fn describe(token : Bytes) -> String

    A one-line description of a token, for the CLI and for error messages.

    enumerated

    fn enumerated(value : Int) -> Bytes

    is_ntlmssp

    fn is_ntlmssp(token : Bytes) -> Bool

    is_spnego

    fn is_spnego(token : Bytes) -> Bool

    A SPNEGO token starts with either the GSS application tag (0x60) or one of the NegotiationToken choice tags.

    mech_list_der

    fn mech_list_der() -> Bytes

    The DER of the MechTypeList this library offers: a SEQUENCE holding the NTLMSSP OID. This is the byte string a mechListMIC is computed over, so wrap_init and the MIC both go through here rather than each building its own encoding — two encoders that agree today can disagree after an edit.

    octet_string

    fn octet_string(content : Bytes) -> Bytes

    offered_mech_list

    fn offered_mech_list(token : Bytes) -> Bytes raise DerError

    The MechTypeList an incoming NegTokenInit carried, as the exact DER bytes it arrived in.

    A mechListMIC covers what the initiator sent, not what this library would have encoded, so an acceptor has to check against these bytes rather than against mech_list_der(). A peer that offers two mechanisms would otherwise be rejected for a MIC it computed correctly.

    oid

    fn oid(raw : Bytes) -> Bytes

    parse_neg_targ

    fn parse_neg_targ(token : Bytes) -> NegTarg raise DerError

    Parse a NegTokenTarg, either with its [1] wrapper or as the bare SEQUENCE some stacks emit. Unknown context tags are skipped rather than rejected: a peer may add fields this code does not model.

    read_tlv

    fn read_tlv(data : Bytes, at : Int) -> Tlv raise DerError

    Read one element header at at. The content itself is not copied; callers slice it out when they need it.

    sequence

    fn sequence(content : Bytes) -> Bytes

    tlv

    fn tlv(tag : Int, content : Bytes) -> Bytes

    Tag, then length, then content.

    unwrap

    fn unwrap(token : Bytes) -> Bytes raise DerError

    Pull the NTLM message out of whatever the peer sent: a bare NTLMSSP message, a GSS-wrapped NegTokenInit, or a NegTokenTarg.

    wrap_challenge

    fn wrap_challenge(ntlm_token : Bytes, state : NegState) -> Bytes

    The acceptor's first NegTokenTarg: negState, the NTLMSSP mechanism, and the challenge. This is the shape RFC 4178 asks for; a bare NegTokenTarg without supportedMech is accepted by many clients but is not conformant.

    wrap_final

    fn wrap_final(state : NegState, mech_list_mic : Bytes) -> Bytes

    The acceptor's last NegTokenTarg: negState and its own mechListMIC, with no responseToken — the negotiation has no further NTLM message to carry, and an empty [2] would be a field where RFC 4178 allows none.

    wrap_init

    fn wrap_init(ntlm_token : Bytes) -> Bytes

    The client's opening message: GSS-API wrapper around a NegTokenInit whose only offered mechanism is NTLMSSP.

    wrap_response

    fn wrap_response(ntlm_token : Bytes) -> Bytes

    A NegTokenTarg with no negState, which is what a client sends last.

    wrap_response_state

    fn wrap_response_state(ntlm_token : Bytes, state : Int) -> Bytes

    A NegTokenTarg carrying negState — a server uses 1 (accept-incomplete) with its challenge.

    wrap_targ

    fn wrap_targ(ntlm_token : Bytes, state : NegState?, mech_list_mic : Bytes?) -> Bytes

    A NegTokenTarg with only the fields HTTP needs: state, response token and an optional mechListMIC.

    wrap_targ_with_mech

    fn wrap_targ_with_mech(ntlm_token : Bytes, state : NegState?, supported_mech : Bytes?, mech_list_mic : Bytes?) -> Bytes

    A NegTokenTarg with a state, the selected mechanism and, when the server asked for one, a mechListMIC.

    RFC 4178 requires supportedMech in the first NegTokenTarg the acceptor sends and forbids it in later ones; callers that are not the acceptor pass None.

    The MIC value is computed by src/ntlm — mech_list_mic over mech_list_der() for the initiator, acceptor_mech_list_mic for the acceptor — because RFC 4178 hands the value to the GSS mechanism, and the mechanism here is NTLM. Passing a MIC this layer invented would be worse than passing none.

    Source Files