Ejemplo n.º 1
0
        protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer)
        {
            // read the type
            byte type = reader.ReadByte();

            regionLength = reader.ReadSInt16();
            long fileLength = regionLength;

            if (type == 0x01)
            {
                // this is just the signature
            }
            else
            {
                long start = reader.BaseStream.Position;

                base.ProcessInternal(reader, writer);

                long amountProcessed = reader.BaseStream.Position - start;
                fileLength -= amountProcessed;
            }

            if (fileLength > 0)
            {
                // deal with a remaining fileLength that is greater than int
                while (fileLength > int.MaxValue)
                {
                    reader.ReadBytes(int.MaxValue);
                    fileLength -= int.MaxValue;
                }
                reader.ReadBytes((int)fileLength);
            }
        }
Ejemplo n.º 2
0
        protected override void ProcessInternal(CustomBinaryReader reader)
        {
            // read the type
            byte type = reader.ReadByte();

            regionLength = reader.ReadSInt16();
            long fileLength = regionLength;

            if (type == 0x01)
            {
                // this is just the signature
                this.signature = reader.ReadBytes((int)fileLength);
                fileLength     = 0;

                long currentOffset = reader.BaseStream.Position;

                reader.BaseStream.Position = SignatureRegion.signedDataOffsetBegin;
                Validator.ValidateDelayedGen1(reader.ReadBytes(SignatureRegion.GetSignedDataLength()), this.signature);

                reader.BaseStream.Position = currentOffset;
            }
            else
            {
                long start = reader.BaseStream.Position;

                base.ProcessInternal(reader);

                long amountProcessed = reader.BaseStream.Position - start;
                fileLength -= amountProcessed;

                if (this.Name == "CardCertificate")
                {
                    Validator.SetCertificate(this);
                }
                else if (this.Name == "CACertificate")
                {
                    Validator.SetCACertificate(this);
                }
                ;
            }

            if (fileLength > 0)
            {
                // deal with a remaining fileLength that is greater than int
                while (fileLength > int.MaxValue)
                {
                    reader.ReadBytes(int.MaxValue);
                    fileLength -= int.MaxValue;
                }
                reader.ReadBytes((int)fileLength);
            }
        }
Ejemplo n.º 3
0
            public CertificateGen1(byte[] certificateData)
            {
                using (var reader = new CustomBinaryReader(new MemoryStream(certificateData)))
                {
                    this.profileIdentifier = Convert.ToInt32(reader.ReadByte());
                    this.certificationAuthorityReference = new CertificationAuthorityReference(reader);
                    this.holderAuthorisation             = reader.ReadBytes(7);

                    var timestamp = reader.ReadSInt32();
                    if (timestamp != 0xFFFFFFFF)
                    {
                        this.endOfValidity = DateTimeOffset.FromUnixTimeSeconds(timestamp);
                    }
                    else
                    {
                        this.endOfValidity = null;
                    };
                    this.holderReference = reader.ReadBytes(8);
                    this.publicKey       = new RSAPublicKey(reader);
                };
            }
Ejemplo n.º 4
0
        protected override void ProcessInternal(CustomBinaryReader reader)
        {
            SignatureRegion.signedDataOffsetEnd = reader.BaseStream.Position;

            base.ProcessInternal(reader);

            long currentOffset = reader.BaseStream.Position;

            reader.BaseStream.Position = SignatureRegion.signedDataOffsetBegin;
            Validator.ValidateGen1(reader.ReadBytes(SignatureRegion.GetSignedDataLength()), this.ToBytes(), SignatureRegion.newestDateTime);

            reader.BaseStream.Position = currentOffset;
        }
Ejemplo n.º 5
0
        protected override void ProcessInternal(CustomBinaryReader reader)
        {
            // read the type
            byte type = reader.ReadByte();

            regionLength = reader.ReadSInt16();
            long fileLength = regionLength;

            long start = reader.BaseStream.Position;

            if (DataFile.StrictProcessing && start + regionLength > reader.BaseStream.Length)
            {
                throw new InvalidOperationException(string.Format("{0}: Would try to read more than length of stream! Position 0x{1:X4} + RegionLength 0x{2:X4} > Length 0x{3:X4}", Name, start, regionLength, reader.BaseStream.Length));
            }

            if (type == 0x01)
            {
                // this is just the signature
                this.signature = reader.ReadBytes((int)fileLength);
                fileLength     = 0;

                long currentOffset = reader.BaseStream.Position;

                reader.BaseStream.Position = SignatureRegion.signedDataOffsetBegin;
                Validator.ValidateDelayedGen1(reader.ReadBytes(SignatureRegion.GetSignedDataLength()), this.signature, () => { return(SignatureRegion.newestDateTime); });

                reader.BaseStream.Position = currentOffset;
            }
            else
            {
                base.ProcessInternal(reader);

                long amountProcessed = reader.BaseStream.Position - start;
                fileLength -= amountProcessed;

                if (this.Name == "CardCertificate")
                {
                    Validator.SetCertificate(this);
                }
                else if (this.Name == "CACertificate")
                {
                    Validator.SetCACertificate(this);
                }
                ;
            }

            if (DataFile.StrictProcessing && fileLength != 0)
            {
                throw new InvalidOperationException(string.Format("{0}: Read wrong number of bytes! Position 0x{1:X4} and end of region 0x{2:X4} but bytes left 0x{3:X4}", Name, reader.BaseStream.Position, start + regionLength, fileLength));
            }

            if (DataFile.StrictProcessing && reader.BaseStream.Position > start + regionLength)
            {
                throw new InvalidOperationException(string.Format("{0}: Read past end of region! Position 0x{1:X4} > end of region 0x{2:X4}", Name, reader.BaseStream.Position, start + regionLength));
            }

            if (fileLength > 0)
            {
                // deal with a remaining fileLength that is greater than int
                while (fileLength > int.MaxValue)
                {
                    reader.ReadBytes(int.MaxValue);
                    fileLength -= int.MaxValue;
                }
                reader.ReadBytes((int)fileLength);
            }
        }
Ejemplo n.º 6
0
        protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer)
        {
            // read the type
            byte type=reader.ReadByte();

            regionLength=reader.ReadSInt16();
            long fileLength=regionLength;

            if ( type == 0x01 )
            {
                // this is just the signature
            }
            else
            {
                long start=reader.BaseStream.Position;

                base.ProcessInternal(reader, writer);

                long amountProcessed=reader.BaseStream.Position-start;
                fileLength -= amountProcessed;
            }

            if ( fileLength > 0 )
            {
                // deal with a remaining fileLength that is greater than int
                while ( fileLength > int.MaxValue )
                {
                    reader.ReadBytes(int.MaxValue);
                    fileLength-=int.MaxValue;
                }
                reader.ReadBytes((int) fileLength);
            }
        }