Пример #1
0
        /// <summary>
        /// Attempt to decode a stream of bytes into a <see cref="KdcProxyMessage"/>
        /// </summary>
        /// <param name="encoded">The message to decode</param>
        /// <param name="decoded">The decoded message</param>
        /// <returns>Returns true if it was successfully decoded, otherwise returns false</returns>
        public static bool TryDecode(ReadOnlyMemory <byte> encoded, out KdcProxyMessage decoded)
        {
            decoded = null;

            var reader = new AsnReader(encoded, AsnEncodingRules.DER);

            var tag = reader.PeekTag();

            if (tag != Asn1Tag.Sequence)
            {
                return(false);
            }

            try
            {
                Decode(reader, Asn1Tag.Sequence, out decoded);
                reader.ThrowIfNotEmpty();
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Пример #2
0
        /// <summary>
        /// Wraps a standard KDC message into a proxy message
        /// </summary>
        /// <param name="message">The message to wrap</param>
        /// <param name="domain">The optional domain hint for downstream processing</param>
        /// <param name="hint">A DC location hint for downstream processing</param>
        /// <param name="mode">The encoding mode which indicates whether the message should include the length prefix or not</param>
        /// <returns>Returns a formed KDC Message</returns>
        public static KdcProxyMessage WrapMessage(
            ReadOnlyMemory <byte> message,
            string domain            = null,
            DcLocatorHint?hint       = null,
            KdcProxyMessageMode mode = KdcProxyMessageMode.IncludeLengthPrefix
            )
        {
            var proxyMessage = new KdcProxyMessage()
            {
                TargetDomain  = domain,
                DcLocatorHint = hint
            };

            if (mode == KdcProxyMessageMode.NoPrefix)
            {
                proxyMessage.KerbMessage = message;
            }
            else
            {
                proxyMessage.KerbMessage = Tcp.FormatKerberosMessageStream(message);
            }

            return(proxyMessage);
        }