Ejemplo n.º 1
0
        public override int Write(byte[] buffer, int offset, int size, out bool wantMore)
        {
            Debug("Write: {0} {1} {2}", buffer.Length, offset, size);

            var data = Marshal.AllocHGlobal(size);

            if (data == IntPtr.Zero)
            {
                throw new OutOfMemoryException();
            }

            try {
                MonoBtlsError.ClearError();
                Marshal.Copy(buffer, offset, data, size);
                var status = ssl.Write(data, ref size);
                Debug("Write done: {0} {1}", status, size);

                if (status == MonoBtlsSslError.WantWrite)
                {
                    wantMore = true;
                    return(0);
                }
                else if (status != MonoBtlsSslError.None)
                {
                    throw GetException(status);
                }

                wantMore = false;
                return(size);
            } finally {
                Marshal.FreeHGlobal(data);
            }
        }
Ejemplo n.º 2
0
        public override (int ret, bool wantMore) Read(byte[] buffer, int offset, int size)
        {
            Debug("Read: {0} {1} {2}", buffer.Length, offset, size);

            var data = Marshal.AllocHGlobal(size);

            if (data == IntPtr.Zero)
            {
                throw new OutOfMemoryException();
            }

            try {
                MonoBtlsError.ClearError();
                var status = ssl.Read(data, ref size);
                Debug("Read done: {0} {1}", status, size);

                if (status == MonoBtlsSslError.WantRead)
                {
                    return(0, true);
                }
                if (status == MonoBtlsSslError.ZeroReturn)
                {
                    return(size, false);
                }
                if (status != MonoBtlsSslError.None)
                {
                    throw GetException(status);
                }

                if (size > 0)
                {
                    Marshal.Copy(data, buffer, offset, size);
                }

                return(size, false);
            } finally {
                Marshal.FreeHGlobal(data);
            }
        }
Ejemplo n.º 3
0
        public override bool ProcessHandshake()
        {
            var done = false;

            while (!done)
            {
                Debug("ProcessHandshake");
                MonoBtlsError.ClearError();
                var status = DoProcessHandshake();
                Debug("ProcessHandshake #1: {0}", status);

                switch (status)
                {
                case MonoBtlsSslError.None:
                    if (connected)
                    {
                        done = true;
                    }
                    else
                    {
                        connected = true;
                    }
                    break;

                case MonoBtlsSslError.WantRead:
                case MonoBtlsSslError.WantWrite:
                    return(false);

                default:
                    ctx.CheckLastError();
                    throw GetException(status);
                }
            }

            ssl.PrintErrors();

            return(true);
        }