/// <summary> /// Try and parse data into an Negotiate authentication token. /// </summary> /// <param name="data">The data to parse.</param> /// <param name="token">The Negotiate authentication token.</param> /// <param name="client">True if this is a token from a client.</param> /// <param name="token_count">The token count number.</param> /// <returns>True if parsed successfully.</returns> internal static bool TryParse(byte[] data, int token_count, bool client, out NegotiateAuthenticationToken token) { token = null; try { token = new NegotiateAuthenticationToken(data); return(true); } catch (EndOfStreamException) { return(false); } }
/// <summary> /// Try and parse data into an Negotiate authentication token. /// </summary> /// <param name="data">The data to parse.</param> /// <param name="token">The Negotiate authentication token.</param> /// <param name="client">True if this is a token from a client.</param> /// <param name="token_count">The token count number.</param> /// <returns>True if parsed successfully.</returns> internal static bool TryParse(byte[] data, int token_count, bool client, out NegotiateAuthenticationToken token) { token = null; try { byte[] token_data; if (GSSAPIUtils.TryParse(data, out token_data, out string oid)) { if (oid != OIDValues.SPNEGO) { return(false); } } else { token_data = data; } DERValue[] values = DERParser.ParseData(token_data, 0); if (values.Length != 1 || values[0].Type != DERTagType.ContextSpecific) { return(false); } if (values[0].CheckContext(0)) { return(ParseInit(data, values[0].Children, token_count, client, out token)); } else if (values[0].CheckContext(1)) { return(ParseResp(data, values[0].Children, token_count, client, out token)); } else { return(false); } } catch (EndOfStreamException) { } catch (InvalidDataException) { } return(false); }
/// <summary> /// Try and parse data into an Negotiate authentication token. /// </summary> /// <param name="data">The data to parse.</param> /// <param name="token">The Negotiate authentication token.</param> /// <param name="client">True if this is a token from a client.</param> /// <param name="token_count">The token count number.</param> /// <returns>True if parsed successfully.</returns> internal static bool TryParse(byte[] data, int token_count, bool client, out NegotiateAuthenticationToken token) { token = null; try { if (GSSAPIUtils.TryParse(data, out byte[] token_data, out string oid))
private static bool ParseResp(byte[] data, DERValue[] values, int token_count, bool client, out NegotiateAuthenticationToken token) { token = null; if (!values.CheckValueSequence()) { return(false); } string mech = null; NegotiateAuthenticationState state = NegotiateAuthenticationState.Reject; AuthenticationToken auth_token = null; byte[] mic = null; foreach (var next in values[0].Children) { if (next.Type != DERTagType.ContextSpecific) { return(false); } switch (next.Tag) { case 0: state = (NegotiateAuthenticationState)next.ReadChildEnumerated(); break; case 1: mech = next.ReadChildObjID(); break; case 2: auth_token = ParseToken(next.ReadChildOctetString(), token_count, client); break; case 3: mic = next.ReadChildOctetString(); break; default: return(false); } } token = new NegotiateResponseAuthenticationToken(data, mech, state, auth_token, mic); return(true); }
private static bool ParseInit(byte[] data, DERValue[] values, int token_count, bool client, out NegotiateAuthenticationToken token) { token = null; if (!values.CheckValueSequence()) { return(false); } IEnumerable <string> mech_list = null; NegotiateContextFlags flags = NegotiateContextFlags.None; AuthenticationToken auth_token = null; byte[] mic = null; foreach (var next in values[0].Children) { if (next.Type != DERTagType.ContextSpecific) { return(false); } switch (next.Tag) { case 0: mech_list = ParseMechList(next.Children); break; case 1: flags = ConvertContextFlags(next.ReadChildBitString()); break; case 2: auth_token = ParseToken(next.ReadChildOctetString(), token_count, client); break; case 3: // If NegTokenInit2 then just ignore neg hints. if (next.HasChildren() && next.Children[0].CheckSequence()) { break; } mic = next.ReadChildOctetString(); break; case 4: // Used if NegTokenInit2. mic = next.ReadChildOctetString(); break; default: return(false); } } token = new NegotiateInitAuthenticationToken(data, mech_list, flags, auth_token, mic); return(true); }