Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            // Changes from corefx source:
            //
            // AsnReader.AdvanceReader to skip over the tag after reading
            // Patch CheckExceptedTag to not care about the Universal tag.
            // Why?
            // Because of TryGetPrimitiveOctetStringBytes.
            //
            // The strings here are encoded as UniversalString,
            // which blows up in AsnCharacterStringEncoding.GetEncoding
            // Now, Kerberos strings are actually IA5String:
            // KerberosString  ::= GeneralString (IA5String)
            //
            // But if I do
            // reader.GetCharacterString(new Asn1Tag(UniversalTagNumber.GeneralString), KerberosTags.KerberosStringTag)
            // then CheckExceptedTag blows up.


            var bytes = new byte[] { 0x7e, 0x6a, 0x30, 0x68, 0xa0, 0x03, 0x02, 0x01, 0x05, 0xa1, 0x03, 0x02, 0x01, 0x1e, 0xa4, 0x11, 0x18, 0x0f, 0x32, 0x30, 0x31, 0x38, 0x30, 0x38, 0x30, 0x36, 0x32, 0x30, 0x33, 0x33, 0x30, 0x35, 0x5a, 0xa5, 0x05, 0x02, 0x03, 0x0d, 0xa5, 0x5f, 0xa6, 0x03, 0x02, 0x01, 0x34, 0xa9, 0x14, 0x1b, 0x12, 0x49, 0x4e, 0x54, 0x2e, 0x44, 0x45, 0x56, 0x44, 0x4f, 0x4d, 0x41, 0x49, 0x4e, 0x53, 0x2e, 0x4f, 0x52, 0x47, 0xaa, 0x27, 0x30, 0x25, 0xa0, 0x03, 0x02, 0x01, 0x02, 0xa1, 0x1e, 0x30, 0x1c, 0x1b, 0x06, 0x6b, 0x72, 0x62, 0x74, 0x67, 0x74, 0x1b, 0x12, 0x49, 0x4e, 0x54, 0x2e, 0x44, 0x45, 0x56, 0x44, 0x4f, 0x4d, 0x41, 0x49, 0x4e, 0x53, 0x2e, 0x4f, 0x52, 0x47 };

            var reader = new AsnReader(bytes, AsnEncodingRules.BER);
            var tag    = reader.ReadTagAndLength(out var contentLength, out var bytesRead);

            reader = reader.AdvanceReader(bytesRead);

            if (tag == KerberosError.Id)
            {
                var krbError = new KerberosError(ref reader);
            }
        }
Ejemplo n.º 2
0
        public PrincipalName(ref AsnReader reader)
        {
            var tag = reader.ReadTagAndLength(out var contentLength, out var bytesRead);

            reader = reader.AdvanceReader(bytesRead);

            if (tag.TagClass != TagClass.Universal || tag.TagValue != (int)UniversalTagNumber.Sequence)
            {
                throw new InvalidOperationException("Not a sequence but " + tag);
            }

            while (reader.HasData)
            {
                tag    = reader.ReadTagAndLength(out contentLength, out bytesRead);
                reader = reader.AdvanceReader(bytesRead);

                if (tag.TagClass == TagClass.ContextSpecific)
                {
                    switch (tag.TagValue)
                    {
                    case 0:
                        Type = (NameType)(int)reader.GetInteger();
                        break;

                    case 1:
                        reader = reader.ReadSequence();
                        var names = new List <string>();
                        while (reader.HasData)
                        {
                            names.Add(reader.GetCharacterString(new Asn1Tag(UniversalTagNumber.GeneralString), KerberosTags.KerberosStringTag));
                        }
                        Name = names.ToArray();
                        break;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public KerberosError(ref AsnReader reader)
        {
            var tag = reader.ReadTagAndLength(out var contentLength, out var bytesRead);

            reader = reader.AdvanceReader(bytesRead);

            if (tag.TagClass != TagClass.Universal || tag.TagValue != (int)UniversalTagNumber.Sequence)
            {
                throw new InvalidOperationException("Not a sequence but " + tag);
            }

            while (reader.HasData)
            {
                tag    = reader.ReadTagAndLength(out contentLength, out bytesRead);
                reader = reader.AdvanceReader(bytesRead);

                if (tag.TagClass == TagClass.ContextSpecific)
                {
                    switch (tag.TagValue)
                    {
                    case 0:
                        //         pvno            [0] INTEGER (5),
                        ProtocolVersionNumber = (int)reader.GetInteger();
                        break;

                    case 1:
                        //         msg-type        [1] INTEGER (30),
                        MessageType = (MessageType)(int)reader.GetInteger();
                        break;

                    case 2:
                        //         ctime           [2] KerberosTime OPTIONAL,
                        CTime = reader.GetGeneralizedTime(disallowFractions: true);
                        break;

                    case 3:
                        //         cusec           [3] Microseconds OPTIONAL,
                        var cusec = reader.GetInteger();
                        CUsec = new Microseconds((int)cusec);
                        break;

                    case 4:
                        //         stime           [4] KerberosTime,
                        STime = reader.GetGeneralizedTime(disallowFractions: true);
                        break;

                    case 5:
                        //         susec           [5] Microseconds,
                        var susec = reader.GetInteger();
                        SUsec = new Microseconds((int)susec);
                        break;

                    case 6:
                        //         error-code      [6] Int32,
                        ErrorCode = (KrbErrorCode)(int)reader.GetInteger();
                        break;

                    case 7:
                        //         crealm          [7] Realm OPTIONAL,
                        CRealm = reader.GetCharacterString(new Asn1Tag(UniversalTagNumber.GeneralString), KerberosTags.RealmTag);
                        break;

                    case 8:
                        //         cname           [8] PrincipalName OPTIONAL,
                        CName = new PrincipalName(ref reader);
                        break;

                    case 9:
                        //         realm           [9] Realm -- service realm --,
                        ServiceRealm = reader.GetCharacterString(new Asn1Tag(UniversalTagNumber.GeneralString), KerberosTags.RealmTag);
                        break;

                    case 10:
                        //         sname           [10] PrincipalName -- service name --,
                        SName = new PrincipalName(ref reader);
                        break;

                    case 11:
                        //         e-text          [11] KerberosString OPTIONAL,
                        EText = reader.GetCharacterString(new Asn1Tag(UniversalTagNumber.GeneralString), KerberosTags.KerberosStringTag);
                        break;

                    case 12:
                        //         e-data          [12] OCTET STRING OPTIONAL
                        EData = new byte[contentLength.Value];
                        reader.TryCopyOctetStringBytes(EData, out _);
                        break;
                    }
                }
            }
        }