public override byte[] GetBytes()
        {
            int sequenceLength              = GetTokenFieldsLength();
            int sequenceLengthFieldSize     = DerEncodingHelper.GetLengthFieldSize(sequenceLength);
            int constructionLength          = 1 + sequenceLengthFieldSize + sequenceLength;
            int constructionLengthFieldSize = DerEncodingHelper.GetLengthFieldSize(constructionLength);
            int bufferSize = 1 + constructionLengthFieldSize + 1 + sequenceLengthFieldSize + sequenceLength;

            byte[] buffer = new byte[bufferSize];
            int    offset = 0;

            ByteWriter.WriteByte(buffer, ref offset, NegTokenRespTag);
            DerEncodingHelper.WriteLength(buffer, ref offset, constructionLength);
            ByteWriter.WriteByte(buffer, ref offset, (byte)DerEncodingTag.Sequence);
            DerEncodingHelper.WriteLength(buffer, ref offset, sequenceLength);
            if (NegState.HasValue)
            {
                WriteNegState(buffer, ref offset, NegState.Value);
            }
            if (SupportedMechanism != null)
            {
                WriteSupportedMechanism(buffer, ref offset, SupportedMechanism);
            }
            if (ResponseToken != null)
            {
                WriteResponseToken(buffer, ref offset, ResponseToken);
            }
            if (MechanismListMIC != null)
            {
                WriteMechanismListMIC(buffer, ref offset, MechanismListMIC);
            }
            return(buffer);
        }
Esempio n. 2
0
        public override byte[] GetBytes()
        {
            int sequenceLength              = GetTokenFieldsLength();
            int sequenceLengthFieldSize     = DerEncodingHelper.GetLengthFieldSize(sequenceLength);
            int constructionLength          = 1 + sequenceLengthFieldSize + sequenceLength;
            int constructionLengthFieldSize = DerEncodingHelper.GetLengthFieldSize(constructionLength);
            int bufferSize = 1 + constructionLengthFieldSize + 1 + sequenceLengthFieldSize + sequenceLength;

            byte[] buffer = new byte[bufferSize];
            int    offset = 0;

            ByteWriter.WriteByte(buffer, ref offset, NegTokenInitTag);
            DerEncodingHelper.WriteLength(buffer, ref offset, constructionLength);
            ByteWriter.WriteByte(buffer, ref offset, (byte)DerEncodingTag.Sequence);
            DerEncodingHelper.WriteLength(buffer, ref offset, sequenceLength);
            if (MechanismTypeList != null)
            {
                WriteMechanismTypeList(buffer, ref offset, MechanismTypeList);
            }
            if (MechanismToken != null)
            {
                WriteMechanismToken(buffer, ref offset, MechanismToken);
            }
            if (MechanismListMIC != null)
            {
                WriteMechanismListMIC(buffer, ref offset, MechanismListMIC);
            }
            return(buffer);
        }
 private static void WriteNegState(byte[] buffer, ref int offset, NegState negState)
 {
     ByteWriter.WriteByte(buffer, ref offset, NegStateTag);
     DerEncodingHelper.WriteLength(buffer, ref offset, 3);
     ByteWriter.WriteByte(buffer, ref offset, (byte)DerEncodingTag.Enum);
     DerEncodingHelper.WriteLength(buffer, ref offset, 1);
     ByteWriter.WriteByte(buffer, ref offset, (byte)negState);
 }
Esempio n. 4
0
        private static void WriteMechanismListMIC(byte[] buffer, ref int offset, byte[] mechanismListMIC)
        {
            int mechanismListMICLengthFieldSize = DerEncodingHelper.GetLengthFieldSize(mechanismListMIC.Length);

            ByteWriter.WriteByte(buffer, ref offset, MechanismListMICTag);
            DerEncodingHelper.WriteLength(buffer, ref offset, 1 + mechanismListMICLengthFieldSize + mechanismListMIC.Length);
            ByteWriter.WriteByte(buffer, ref offset, (byte)DerEncodingTag.ByteArray);
            DerEncodingHelper.WriteLength(buffer, ref offset, mechanismListMIC.Length);
            ByteWriter.WriteBytes(buffer, ref offset, mechanismListMIC);
        }
Esempio n. 5
0
        private static void WriteMechanismToken(byte[] buffer, ref int offset, byte[] mechanismToken)
        {
            int constructionLength = 1 + DerEncodingHelper.GetLengthFieldSize(mechanismToken.Length) + mechanismToken.Length;

            ByteWriter.WriteByte(buffer, ref offset, MechanismTokenTag);
            DerEncodingHelper.WriteLength(buffer, ref offset, constructionLength);
            ByteWriter.WriteByte(buffer, ref offset, (byte)DerEncodingTag.ByteArray);
            DerEncodingHelper.WriteLength(buffer, ref offset, mechanismToken.Length);
            ByteWriter.WriteBytes(buffer, ref offset, mechanismToken);
        }
        private static void WriteResponseToken(byte[] buffer, ref int offset, byte[] responseToken)
        {
            int responseTokenLengthFieldSize = DerEncodingHelper.GetLengthFieldSize(responseToken.Length);

            ByteWriter.WriteByte(buffer, ref offset, ResponseTokenTag);
            DerEncodingHelper.WriteLength(buffer, ref offset, 1 + responseTokenLengthFieldSize + responseToken.Length);
            ByteWriter.WriteByte(buffer, ref offset, (byte)DerEncodingTag.ByteArray);
            DerEncodingHelper.WriteLength(buffer, ref offset, responseToken.Length);
            ByteWriter.WriteBytes(buffer, ref offset, responseToken);
        }
        private static void WriteSupportedMechanism(byte[] buffer, ref int offset, byte[] supportedMechanism)
        {
            int supportedMechanismLengthFieldSize = DerEncodingHelper.GetLengthFieldSize(supportedMechanism.Length);

            ByteWriter.WriteByte(buffer, ref offset, SupportedMechanismTag);
            DerEncodingHelper.WriteLength(buffer, ref offset, 1 + supportedMechanismLengthFieldSize + supportedMechanism.Length);
            ByteWriter.WriteByte(buffer, ref offset, (byte)DerEncodingTag.ObjectIdentifier);
            DerEncodingHelper.WriteLength(buffer, ref offset, supportedMechanism.Length);
            ByteWriter.WriteBytes(buffer, ref offset, supportedMechanism);
        }
Esempio n. 8
0
        private static void WriteHintAddress(byte[] buffer, ref int offset, byte[] hintAddress)
        {
            int constructionLength = 1 + DerEncodingHelper.GetLengthFieldSize(hintAddress.Length) + hintAddress.Length;

            ByteWriter.WriteByte(buffer, ref offset, HintAddressTag);
            DerEncodingHelper.WriteLength(buffer, ref offset, constructionLength);
            ByteWriter.WriteByte(buffer, ref offset, (byte)DerEncodingTag.ByteArray);
            DerEncodingHelper.WriteLength(buffer, ref offset, hintAddress.Length);
            ByteWriter.WriteBytes(buffer, ref offset, hintAddress);
        }
Esempio n. 9
0
        private static void WriteHintName(byte[] buffer, ref int offset, string hintName)
        {
            byte[] hintNameBytes      = DerEncodingHelper.EncodeGeneralString(hintName);
            int    constructionLength = 1 + DerEncodingHelper.GetLengthFieldSize(hintNameBytes.Length) + hintNameBytes.Length;

            ByteWriter.WriteByte(buffer, ref offset, HintNameTag);
            DerEncodingHelper.WriteLength(buffer, ref offset, constructionLength);
            ByteWriter.WriteByte(buffer, ref offset, (byte)DerEncodingTag.GeneralString);
            DerEncodingHelper.WriteLength(buffer, ref offset, hintNameBytes.Length);
            ByteWriter.WriteBytes(buffer, ref offset, hintNameBytes);
        }
Esempio n. 10
0
        private static void WriteMechanismTypeList(byte[] buffer, ref int offset, List <byte[]> mechanismTypeList)
        {
            int sequenceLength          = GetSequenceLength(mechanismTypeList);
            int sequenceLengthFieldSize = DerEncodingHelper.GetLengthFieldSize(sequenceLength);
            int constructionLength      = 1 + sequenceLengthFieldSize + sequenceLength;

            ByteWriter.WriteByte(buffer, ref offset, MechanismTypeListTag);
            DerEncodingHelper.WriteLength(buffer, ref offset, constructionLength);
            ByteWriter.WriteByte(buffer, ref offset, (byte)DerEncodingTag.Sequence);
            DerEncodingHelper.WriteLength(buffer, ref offset, sequenceLength);
            foreach (byte[] mechanismType in mechanismTypeList)
            {
                ByteWriter.WriteByte(buffer, ref offset, (byte)DerEncodingTag.ObjectIdentifier);
                DerEncodingHelper.WriteLength(buffer, ref offset, mechanismType.Length);
                ByteWriter.WriteBytes(buffer, ref offset, mechanismType);
            }
        }
Esempio n. 11
0
        private static void WriteHints(byte[] buffer, ref int offset, string hintName, byte[] hintAddress)
        {
            int sequenceLength          = GetHintsSequenceLength(hintName, hintAddress);
            int sequenceLengthFieldSize = DerEncodingHelper.GetLengthFieldSize(sequenceLength);
            int constructionLength      = 1 + sequenceLengthFieldSize + sequenceLength;

            ByteWriter.WriteByte(buffer, ref offset, NegHintsTag);
            DerEncodingHelper.WriteLength(buffer, ref offset, constructionLength);
            ByteWriter.WriteByte(buffer, ref offset, (byte)DerEncodingTag.Sequence);
            DerEncodingHelper.WriteLength(buffer, ref offset, sequenceLength);
            if (hintName != null)
            {
                WriteHintName(buffer, ref offset, hintName);
            }
            if (hintAddress != null)
            {
                WriteHintAddress(buffer, ref offset, hintAddress);
            }
        }
 /// <param name="includeHeader">Prepend the generic GSSAPI header. Required for negTokenInit, optional for negTokenResp.</param>
 public byte[] GetBytes(bool includeHeader)
 {
     byte[] tokenBytes = this.GetBytes();
     if (includeHeader)
     {
         int    objectIdentifierFieldSize = DerEncodingHelper.GetLengthFieldSize(SPNEGOIdentifier.Length);
         int    tokenLength          = 1 + objectIdentifierFieldSize + SPNEGOIdentifier.Length + tokenBytes.Length;
         int    tokenLengthFieldSize = DerEncodingHelper.GetLengthFieldSize(tokenLength);
         int    headerLength         = 1 + tokenLengthFieldSize + 1 + objectIdentifierFieldSize + SPNEGOIdentifier.Length;
         byte[] buffer = new byte[headerLength + tokenBytes.Length];
         int    offset = 0;
         ByteWriter.WriteByte(buffer, ref offset, ApplicationTag);
         DerEncodingHelper.WriteLength(buffer, ref offset, tokenLength);
         ByteWriter.WriteByte(buffer, ref offset, (byte)DerEncodingTag.ObjectIdentifier);
         DerEncodingHelper.WriteLength(buffer, ref offset, SPNEGOIdentifier.Length);
         ByteWriter.WriteBytes(buffer, ref offset, SPNEGOIdentifier);
         ByteWriter.WriteBytes(buffer, ref offset, tokenBytes);
         return(buffer);
     }
     else
     {
         return(tokenBytes);
     }
 }
 /// <summary>
 /// Will append the generic GSSAPI header.
 /// </summary>
 public static byte[] GetTokenBytes(SimpleProtectedNegotiationToken token)
 {
     if (token is SimpleProtectedNegotiationTokenInit)
     {
         byte[] tokenBytes = token.GetBytes();
         int    objectIdentifierFieldSize = DerEncodingHelper.GetLengthFieldSize(SPNEGOIdentifier.Length);
         int    tokenLength          = 1 + objectIdentifierFieldSize + SPNEGOIdentifier.Length + tokenBytes.Length;
         int    tokenLengthFieldSize = DerEncodingHelper.GetLengthFieldSize(tokenLength);
         int    headerLength         = 1 + tokenLengthFieldSize + 1 + objectIdentifierFieldSize + SPNEGOIdentifier.Length;
         byte[] buffer = new byte[headerLength + tokenBytes.Length];
         int    offset = 0;
         ByteWriter.WriteByte(buffer, ref offset, ApplicationTag);
         DerEncodingHelper.WriteLength(buffer, ref offset, tokenLength);
         ByteWriter.WriteByte(buffer, ref offset, (byte)DerEncodingTag.ObjectIdentifier);
         DerEncodingHelper.WriteLength(buffer, ref offset, SPNEGOIdentifier.Length);
         ByteWriter.WriteBytes(buffer, ref offset, SPNEGOIdentifier);
         ByteWriter.WriteBytes(buffer, ref offset, tokenBytes);
         return(buffer);
     }
     else
     {
         return(token.GetBytes());
     }
 }