public void TryGettingSspiTicketTest() { using (var contextSender = new SspiContext($"host/{Environment.MachineName}", "negotiate")) using (var contextReceiver = new SspiContext($"host/{Environment.MachineName}", "negotiate")) { byte[] token = null; byte[] serverResponse = null; do { token = contextSender.RequestToken(serverResponse); Assert.IsNotNull(token); if (token != null && token.Length > 0) { contextReceiver.AcceptToken(token, out serverResponse); Assert.IsNotNull(serverResponse); } }while (token != null && token.Length > 0); var serverContext = NegotiationToken.Decode(serverResponse); Assert.IsNotNull(serverContext); Assert.IsNotNull(serverContext.ResponseToken); Assert.IsNull(serverContext.InitialToken); Assert.IsNotNull(contextSender.SessionKey); Assert.IsTrue(KerberosCryptoTransformer.AreEqualSlow(contextSender.SessionKey, contextReceiver.SessionKey)); } }
internal void ProcessMessage(byte[] message, string source = null) { if (messageParsed) { return; } ResetLayout(); object parsedMessage = null; try { parsedMessage = MessageParser.Parse(message); } catch { } if (parsedMessage == null) { try { var nego = NegotiationToken.Decode(message); if (nego.ResponseToken != null) { parsedMessage = MessageParser.Parse(nego.ResponseToken.ResponseToken.Value); } } catch { } } if (parsedMessage is NtlmContextToken ntlm) { ProcessNtlm(ntlm, source); } else if (parsedMessage is NegotiateContextToken nego) { ProcessNegotiate(nego.Token, source); } else if (parsedMessage is KerberosContextToken kerb) { ProcessKerberos(kerb, source); } try { if (KdcProxyMessage.TryDecode(message, out KdcProxyMessage proxyMessage)) { ProcessKdcProxy(proxyMessage, source); } } catch { } }
public void SPNegoInitTokenRoundtrip() { NegotiationToken negToken = new NegotiationToken { InitialToken = new NegTokenInit { MechTypes = new Oid[] { new Oid(MechType.NTLM) }, MechToken = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 } } }; var encoded = negToken.Encode(); var decoded = NegotiationToken.Decode(encoded); Assert.IsNotNull(decoded); Assert.IsNotNull(decoded.InitialToken); Assert.IsNull(decoded.ResponseToken); }
public void SPNegoResponseTokenRoundtrip() { NegotiationToken negToken = new NegotiationToken { ResponseToken = new NegTokenResp { State = NegotiateState.Rejected, SupportedMech = new Oid(MechType.NTLM), ResponseToken = new byte[] { 7, 6, 5, 4, 3, 2, 1, 0 } } }; var encoded = negToken.Encode(); var decoded = NegotiationToken.Decode(encoded); Assert.IsNotNull(decoded); Assert.IsNull(decoded.InitialToken); Assert.IsNotNull(decoded.ResponseToken); }
public void TryGettingSspiTicketTest() { using (var contextSender = new SspiContext($"host/{Environment.MachineName}", "Negotiate")) using (var contextReceiver = new SspiContext($"host/{Environment.MachineName}", "Negotiate")) { var token = contextSender.RequestToken(); Assert.IsNotNull(token); var contextToken = MessageParser.Parse <NegotiateContextToken>(token); Assert.IsNotNull(contextToken); contextReceiver.AcceptToken(token, out byte[] serverResponse); Assert.IsNotNull(serverResponse); var serverContext = NegotiationToken.Decode(serverResponse); Assert.IsNotNull(serverContext); Assert.IsNotNull(serverContext.ResponseToken); Assert.IsNull(serverContext.InitialToken); } }