Пример #1
0
        public static void GetDiminutiveBigInteger(PublicEncodingRules ruleSet)
        {
            // GetBigInteger with the last byte removed.
            // Since it is no longer an ArrayPool alignment size the fill code gets tested on netstandard.
            byte[] inputData = (
                "0282010000A46861FA9D5DB763633BF5A64EF6E7C2C2367F48D2D46643A22DFC" +
                "FCCB24E58A14D0F06BDC956437F2A56BA4BEF70BA361BF12964A0D665AFD84B0" +
                "F7494C8FA4ABC5FCA2E017C06178AEF2CDAD1B5F18E997A14B965C074E8F5649" +
                "70607276B00583932240FE6E2DD013026F9AE13D7C91CC07C4E1E8E87737DC06" +
                "EF2B575B89D62EFE46859F8255A123692A706C68122D4DAFE11CB205A7B3DE06" +
                "E553F7B95F978EF8601A8DF819BF32040BDF92A0DE0DF269B4514282E17AC699" +
                "34E8440A48AB9D1F5DF89A502CEF6DFDBE790045BD45E0C94E5CA8ADD76A013E" +
                "9C978440FC8A9E2A9A4940B2460819C3E302AA9C9F355AD754C86D3ED77DDAA3" +
                "DA13810B").HexToByteArray();

            BigInteger expected = BigInteger.Parse(
                "2075455505718444046766086325128514549301113944667492053189486607" +
                "5638152321436011512404808361119326026027238444019992518081753153" +
                "5965931647037093368608713442955529617501657176146245891571745113" +
                "4028700771890451167051818999837042261788828826028681595867897235" +
                "7967091503500375497498573022675671178275171110498592645868107163" +
                "8525996766798322809764200941677343791419428587801897366593842552" +
                "7272226864578661449281241619675217353931828233756506947863330597" +
                "8338073826285687331647183058971791153730741973483420110408271570" +
                "1367336140572971505716740825623220507359429297584634909330541150" +
                "79473593821332264673455059897928082590541") >> 8;

            AsnReader reader = new AsnReader(inputData, (AsnEncodingRules)ruleSet);

            Assert.Equal(expected, reader.GetInteger());
        }
Пример #2
0
        public static void GetNegativeBigInteger(PublicEncodingRules ruleSet)
        {
            // This uses a length that doesn't line up with the array pool size so
            // the fill code gets tested on netstandard.
            // It's the same data as above, minus the padding and lead byte (and the
            // next byte changed from 0x68 to 0x88)
            byte[] inputData = (
                "0281FF8861FA9D5DB763633BF5A64EF6E7C2C2367F48D2D46643A22DFC" +
                "FCCB24E58A14D0F06BDC956437F2A56BA4BEF70BA361BF12964A0D665AFD84B0" +
                "F7494C8FA4ABC5FCA2E017C06178AEF2CDAD1B5F18E997A14B965C074E8F5649" +
                "70607276B00583932240FE6E2DD013026F9AE13D7C91CC07C4E1E8E87737DC06" +
                "EF2B575B89D62EFE46859F8255A123692A706C68122D4DAFE11CB205A7B3DE06" +
                "E553F7B95F978EF8601A8DF819BF32040BDF92A0DE0DF269B4514282E17AC699" +
                "34E8440A48AB9D1F5DF89A502CEF6DFDBE790045BD45E0C94E5CA8ADD76A013E" +
                "9C978440FC8A9E2A9A4940B2460819C3E302AA9C9F355AD754C86D3ED77DDAA3" +
                "DA13810B4D").HexToByteArray();

            BigInteger expected = BigInteger.Parse(
                "-" +
                "5898547409447487884446992857601985651316300515844052200158198046" +
                "7814538020408452501006415149581619776188797413593169277984980446" +
                "1302361382932378450492052337986628823880000831383555853860116718" +
                "5361729331647715885538858385106930514758305144777880150203212976" +
                "6715081632226412951106013360243549075631850526067219857352295397" +
                "2308328327377769665309386917336850273904442596855844458638806936" +
                "6169824439111394938336579524651037239551388910737675470211780509" +
                "8035477769907389338548451561341965157059382875181284370047601682" +
                "6924486017215979427815833587119797658480104671279234402026468966" +
                "86109928634475300812601680679147599027");

            AsnReader reader = new AsnReader(inputData, (AsnEncodingRules)ruleSet);

            Assert.Equal(expected, reader.GetInteger());
        }
Пример #3
0
        protected object Deserializer(AsnReader reader)
        {
            var bigint = reader.GetInteger();

            if (bigint < MinInclusive || bigint > MaxInclusive)
            {
                throw new AsnSerializationConstraintException($"Value must range from {MinInclusive} to {MaxInclusive}, but was " + bigint);
            }
            return(ConvertDeserializedValue(bigint));
        }
Пример #4
0
        internal static void Decode(AsnReader reader, Asn1Tag expectedTag, out CertificationRequestInfoAsn decoded)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            decoded = default;
            AsnReader sequenceReader = reader.ReadSequence(expectedTag);
            AsnReader collectionReader;

            decoded.Version = sequenceReader.GetInteger();
            if (!sequenceReader.PeekTag().HasSameClassAndValue(new Asn1Tag((UniversalTagNumber)16)))
            {
                throw new CryptographicException();
            }

            decoded.Subject = sequenceReader.GetEncodedValue();
            System.Security.Cryptography.Asn1.SubjectPublicKeyInfoAsn.Decode(sequenceReader, out decoded.SubjectPublicKeyInfo);

            // Decode SEQUENCE OF for Attributes
            {
                collectionReader = sequenceReader.ReadSetOf(new Asn1Tag(TagClass.ContextSpecific, 0));
                var tmpList = new List <System.Security.Cryptography.Asn1.AttributeAsn>();
                System.Security.Cryptography.Asn1.AttributeAsn tmpItem;

                while (collectionReader.HasData)
                {
                    System.Security.Cryptography.Asn1.AttributeAsn.Decode(collectionReader, out tmpItem);
                    tmpList.Add(tmpItem);
                }

                decoded.Attributes = tmpList.ToArray();
            }


            sequenceReader.ThrowIfNotEmpty();
        }
Пример #5
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;
                    }
                }
            }
        }
Пример #6
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;
                    }
                }
            }
        }