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

    HttpError

    pub suberror HttpError {
    Malformed(String)
    EmptyToken
    }

    The header layer: Authorization and WWW-Authenticate as HTTP writes them, which is the part NTLM libraries usually leave to the caller.

    A server may offer several schemes in one WWW-Authenticate header, and a client picks one. Parameters are comma separated, except inside a quoted string, so Basic realm="a,b" must not be split in the middle.

    Challenge

    pub struct Challenge {
    scheme : String
    token : Bytes
    }

    Challenge::scheme

    fn Challenge::scheme(self : Challenge) -> String

    Challenge::token

    fn Challenge::token(self : Challenge) -> Bytes

    Client

    pub struct Client {
    user : String
    domain : String
    password : String
    workstation : String
    spnego : Bool
    client_challenge : Bytes
    timestamp : UInt64
    flags : UInt
    last_session_key : Bytes
    last_flags : UInt
    last_mech_list_mic : Bytes
    }

    Client::answer

    fn Client::answer(self : Client, www_authenticate : String) -> String raise

    The second Authorization value, built from the server's WWW-Authenticate header. The answer uses the scheme the server offered, so a server that skips SPNEGO still gets a bare NTLM message back.

    Three things can end up in the answer: the NTLMv2 response, the message MIC when the challenge carries MsvAvFlags bit 1 or a timestamp, and the mechListMIC when the acceptor asked for it. The two MICs are different values over different bytes and are computed separately.

    Client::bare

    fn Client::bare(self : Client) -> Client

    Client::mech_list_mic

    fn Client::mech_list_mic(self : Client) -> Bytes

    The mechListMIC the last answer carried, empty when it carried none.

    Client::new

    fn Client::new(user : String, domain : String, password : String) -> Client

    Client::start

    fn Client::start(self : Client) -> String

    The first Authorization value, to be sent after a bare 401.

    Client::type1_token

    fn Client::type1_token(self : Client) -> Bytes

    The raw NTLM negotiate message this client sends. Exposed because a MIC is computed over exactly these bytes, so a caller that builds the exchange by hand must use the same message rather than one with its own flags.

    Client::verify_acceptor_mic

    fn Client::verify_acceptor_mic(self : Client, www_authenticate : String) -> Bool raise

    Check the acceptor's mechListMIC, which arrives in the WWW-Authenticate of the reply that ends the negotiation. A server that asked for a MIC and does not send its own is not rejected here — RFC 4178 makes the acceptor's MIC conditional — but one that sends a wrong value is.

    Client::with_fixed_challenge

    fn Client::with_fixed_challenge(user : String, domain : String, password : String, client_challenge : Bytes, timestamp : UInt64) -> Client

    A client with a fixed client challenge and timestamp, which is what tests and reproducible runs need. Deterministic challenges are not for production.

    Server

    pub struct Server {
    user : String
    domain : String
    password : String
    challenge : Bytes
    target_domain : String
    computer : String
    mic_required : Bool
    mech_list_mic_required : Bool
    last_type1 : Bytes
    last_type2 : Bytes
    last_mech_list : Bytes
    last_session_key : Bytes
    last_flags : UInt
    }

    Server::accept

    fn Server::accept(self : Server, authorization : String) -> Bool raise

    Check a client's answer against the password this server knows: the NTLMv2 proof, the message MIC when one was demanded, and the mechListMIC when the challenge asked for it.

    Server::challenge_for

    fn Server::challenge_for(self : Server, authorization : String) -> String raise

    The type 2 message this server would send, wrapped if the client spoke SPNEGO. authorization is what arrived, so the reply mirrors its scheme.

    Server::finish_token

    fn Server::finish_token(self : Server) -> String raise

    The acceptor's closing NegTokenTarg: accept-completed plus its own mechListMIC. Over HTTP this travels in the WWW-Authenticate of the reply that ends the negotiation, and the client's next request carries an empty Negotiate token to collect the 200.

    Server::new

    fn Server::new(user : String, domain : String, password : String, challenge : Bytes) -> Server

    challenge must be fresh per connection in real use; it is a parameter so that tests and demos can pin it.

    Server::require_mech_list_mic

    fn Server::require_mech_list_mic(self : Server) -> Server

    Ask the client for a mechListMIC as well (RFC 4178 section 5). The challenge goes out with negState = request-mic, accept refuses an answer that does not carry the value, and finish_token produces the acceptor's own MIC so the client can check the other direction.

    Server::require_mic

    fn Server::require_mic(self : Server) -> Server

    Ask the client for a MIC. The challenge then carries MsvAvFlags = 0x2 and a timestamp, and accept checks the field instead of ignoring it.

    authorization_header

    fn authorization_header(scheme : String, token : Bytes) -> String

    challenge_header

    fn challenge_header(scheme : String) -> String

    challenge_header_with_token

    fn challenge_header_with_token(scheme : String, token : Bytes) -> String

    parse_authorization

    fn parse_authorization(header : String) -> Challenge raise

    parse_challenges

    fn parse_challenges(header : String) -> Array[Challenge]

    Every challenge in a WWW-Authenticate header, in the order offered.

    preferred

    fn preferred(challenges : Array[Challenge]) -> Challenge?

    The scheme a client should prefer: SPNEGO first, then raw NTLM.

    trim

    fn trim(text : String) -> String