WriteUInt8() 공개 메소드

public WriteUInt8 ( Byte value ) : void
value Byte
리턴 void
예제 #1
0
        protected override byte[] EncodeDataBytes(ProtocolVersion ver)
        {
            MemoryStream    memStream = new MemoryStream();
            HandshakeStream stream    = new HandshakeStream(memStream);

            stream.WriteUInt8(ServerVersion.Major);
            stream.WriteUInt8(ServerVersion.Minor);

            stream.WriteBytes(Random.GetBytes());

            stream.WriteUInt8((Byte)SessionID.Length);
            stream.WriteBytes(SessionID);

            stream.WriteUInt16(CipherSuite);
            stream.WriteUInt8(CompressionMethod);

            if (Extensions.Count > 0)
            {
                int length = 0;
                foreach (HelloExtension ext in Extensions)
                {
                    if (!ext.SupportsProtocolVersion(ServerVersion))
                    {
                        continue;
                    }
                    length += 4 + ext.Data.Length;
                }
                stream.WriteUInt16((UInt16)length);
                foreach (HelloExtension ext in Extensions)
                {
                    if (!ext.SupportsProtocolVersion(ServerVersion))
                    {
                        continue;
                    }

                    UInt16 type = ext.Type;
                    byte[] data = ext.Data;

                    stream.WriteUInt16(type);
                    stream.WriteUInt16((UInt16)data.Length);
                    stream.WriteBytes(data);
                }
            }

            return(memStream.ToArray());
        }
예제 #2
0
        public byte[] Encode()
        {
            MemoryStream    memStream = new MemoryStream();
            HandshakeStream stream    = new HandshakeStream(memStream);

            byte[] dataBytes;
            try {
                dataBytes = EncodeDataBytes(_version);
            } catch (AlertException ae) {
                throw ae;
            } catch (Exception e) {
                throw new AlertException(AlertDescription.InternalError, e.Message);
            }

            stream.WriteUInt8((byte)Type);
            stream.WriteUInt24((UInt32)dataBytes.Length);
            stream.WriteBytes(dataBytes);

            return(memStream.ToArray());
        }
예제 #3
0
        public byte[] Encode()
        {
            MemoryStream memStream = new MemoryStream();
            HandshakeStream stream = new HandshakeStream(memStream);

            byte[] dataBytes;
            try {
                dataBytes = EncodeDataBytes(_version);
            } catch (AlertException ae) {
                throw ae;
            } catch (Exception e) {
                throw new AlertException(AlertDescription.InternalError, e.Message);
            }

            stream.WriteUInt8((byte) Type);
            stream.WriteUInt24((UInt32) dataBytes.Length);
            stream.WriteBytes(dataBytes);

            return memStream.ToArray();
        }
예제 #4
0
        protected override byte[] EncodeDataBytes(ProtocolVersion version)
        {
            int typesLength = 0;

            if (CertificateTypes.Count > 255)
            {
                throw new Exception("Number of certificate types too large: " + CertificateTypes.Count);
            }
            else
            {
                typesLength = CertificateTypes.Count;
            }

            int sighashLength = 0;

            if (version.HasSelectableSighash)
            {
                if (SignatureAndHashAlgorithms.Count > 65535)
                {
                    throw new Exception("Number of sighash values too large: " + SignatureAndHashAlgorithms.Count);
                }
                else
                {
                    sighashLength = 2 * SignatureAndHashAlgorithms.Count;
                }
            }

            int authsLength = 0;

            foreach (string name in CertificateAuthorities)
            {
                // TODO: Should support punycode as well?
                authsLength += 2;
                authsLength += Encoding.ASCII.GetBytes(name).Length;
                if (authsLength > 65535)
                {
                    throw new Exception("Certificate authorities length too large");
                }
            }

            MemoryStream    memStream = new MemoryStream();
            HandshakeStream stream    = new HandshakeStream(memStream);

            stream.WriteUInt8((byte)typesLength);
            foreach (byte type in CertificateTypes)
            {
                stream.WriteUInt8(type);
            }

            if (version.HasSelectableSighash)
            {
                stream.WriteUInt16((UInt16)sighashLength);
                foreach (UInt16 sighash in SignatureAndHashAlgorithms)
                {
                    stream.WriteUInt16(sighash);
                }
            }

            stream.WriteUInt16((UInt16)authsLength);
            foreach (string name in CertificateAuthorities)
            {
                // TODO: Should support punycode as well?
                int nameLen = Encoding.ASCII.GetBytes(name).Length;
                stream.WriteUInt16((UInt16)nameLen);
                stream.WriteBytes(Encoding.ASCII.GetBytes(name));
            }

            return(memStream.ToArray());
        }
예제 #5
0
        protected override byte[] EncodeDataBytes(ProtocolVersion ver)
        {
            if (CipherSuites.Count == 0 || CompressionMethods.Count == 0) {
                throw new Exception("No cipher suites or compression methods defined");
            }

            MemoryStream memStream = new MemoryStream();
            HandshakeStream stream = new HandshakeStream(memStream);

            stream.WriteUInt8(ClientVersion.Major);
            stream.WriteUInt8(ClientVersion.Minor);
            stream.WriteBytes(Random.GetBytes());
            stream.WriteUInt8((Byte) SessionID.Length);
            stream.WriteBytes(SessionID);
            if (ClientVersion.IsUsingDatagrams) {
                stream.WriteUInt8((Byte) Cookie.Length);
                stream.WriteBytes(Cookie);
            }

            stream.WriteUInt16((UInt16) (2*CipherSuites.Count));
            foreach (UInt16 cipher in CipherSuites) {
                stream.WriteUInt16(cipher);
            }

            stream.WriteUInt8((Byte) CompressionMethods.Count);
            foreach (Byte compression in CompressionMethods) {
                stream.WriteUInt8(compression);
            }

            if (Extensions.Count > 0) {
                int length = 0;
                foreach (HelloExtension ext in Extensions) {
                    if (!ext.SupportsProtocolVersion(ClientVersion))
                        continue;
                    length += 4 + ext.Data.Length;
                }
                stream.WriteUInt16((UInt16) length);
                foreach (HelloExtension ext in Extensions) {
                    if (!ext.SupportsProtocolVersion(ClientVersion))
                        continue;

                    UInt16 type = ext.Type;
                    byte[] data = ext.Data;

                    stream.WriteUInt16(type);
                    stream.WriteUInt16((UInt16) data.Length);
                    stream.WriteBytes(data);
                }
            }

            return memStream.ToArray();
        }
        protected override byte[] EncodeDataBytes(ProtocolVersion version)
        {
            int typesLength = 0;
            if (CertificateTypes.Count > 255) {
                throw new Exception("Number of certificate types too large: " + CertificateTypes.Count);
            } else {
                typesLength = CertificateTypes.Count;
            }

            int sighashLength = 0;
            if (version.HasSelectableSighash) {
                if (SignatureAndHashAlgorithms.Count > 65535) {
                    throw new Exception("Number of sighash values too large: " + SignatureAndHashAlgorithms.Count);
                } else {
                    sighashLength = 2*SignatureAndHashAlgorithms.Count;
                }
            }

            int authsLength = 0;
            foreach (string name in CertificateAuthorities) {
                // TODO: Should support punycode as well?
                authsLength += 2;
                authsLength += Encoding.ASCII.GetBytes(name).Length;
                if (authsLength > 65535) {
                    throw new Exception("Certificate authorities length too large");
                }
            }

            MemoryStream memStream = new MemoryStream();
            HandshakeStream stream = new HandshakeStream(memStream);

            stream.WriteUInt8((byte) typesLength);
            foreach (byte type in CertificateTypes) {
                stream.WriteUInt8(type);
            }

            if (version.HasSelectableSighash) {
                stream.WriteUInt16((UInt16) sighashLength);
                foreach (UInt16 sighash in SignatureAndHashAlgorithms) {
                    stream.WriteUInt16(sighash);
                }
            }

            stream.WriteUInt16((UInt16) authsLength);
            foreach (string name in CertificateAuthorities) {
                // TODO: Should support punycode as well?
                int nameLen = Encoding.ASCII.GetBytes(name).Length;
                stream.WriteUInt16((UInt16) nameLen);
                stream.WriteBytes(Encoding.ASCII.GetBytes(name));
            }

            return memStream.ToArray();
        }
예제 #7
0
        protected override byte[] EncodeDataBytes(ProtocolVersion ver)
        {
            if (CipherSuites.Count == 0 || CompressionMethods.Count == 0)
            {
                throw new Exception("No cipher suites or compression methods defined");
            }

            MemoryStream    memStream = new MemoryStream();
            HandshakeStream stream    = new HandshakeStream(memStream);

            stream.WriteUInt8(ClientVersion.Major);
            stream.WriteUInt8(ClientVersion.Minor);
            stream.WriteBytes(Random.GetBytes());
            stream.WriteUInt8((Byte)SessionID.Length);
            stream.WriteBytes(SessionID);
            if (ClientVersion.IsUsingDatagrams)
            {
                stream.WriteUInt8((Byte)Cookie.Length);
                stream.WriteBytes(Cookie);
            }

            stream.WriteUInt16((UInt16)(2 * CipherSuites.Count));
            foreach (UInt16 cipher in CipherSuites)
            {
                stream.WriteUInt16(cipher);
            }

            stream.WriteUInt8((Byte)CompressionMethods.Count);
            foreach (Byte compression in CompressionMethods)
            {
                stream.WriteUInt8(compression);
            }

            if (Extensions.Count > 0)
            {
                int length = 0;
                foreach (HelloExtension ext in Extensions)
                {
                    if (!ext.SupportsProtocolVersion(ClientVersion))
                    {
                        continue;
                    }
                    length += 4 + ext.Data.Length;
                }
                stream.WriteUInt16((UInt16)length);
                foreach (HelloExtension ext in Extensions)
                {
                    if (!ext.SupportsProtocolVersion(ClientVersion))
                    {
                        continue;
                    }

                    UInt16 type = ext.Type;
                    byte[] data = ext.Data;

                    stream.WriteUInt16(type);
                    stream.WriteUInt16((UInt16)data.Length);
                    stream.WriteBytes(data);
                }
            }

            return(memStream.ToArray());
        }