首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SSLStream从Socks5到IMAP。无法写入流

SSLStream从Socks5到IMAP。无法写入流
EN

Stack Overflow用户
提问于 2017-06-09 09:56:36
回答 1查看 217关注 0票数 0

我试图连接到一个Socks5服务器,告诉他连接到一个IMAP服务器并获得一个套接字。我想使用套接字登录到IMAP。我的问题是,在使用SSL流连接到IMAP之后,我只能从流中读取。发送登录数据后,我将不会收到来自IMAP服务器的响应。

这是我的准则:

代码语言:javascript
复制
public static void Main(string[] args)
    {               
        Console.WriteLine("Working *");

        var socksClient = new TcpClient();
        socksClient.Connect("127.0.0.1", 1080);

        var bw = new BinaryWriter(socksClient.GetStream(), Encoding.Default, true);
        var br = new BinaryReader(socksClient.GetStream(), Encoding.Default, true);

        //Tell the Socks5 to Connect to the IMAP:

        //Get the IP of the IMAP
        var ip = Dns.GetHostAddresses("mx.freenet.de")[0];

        //Me: Hello

        bw.Write(new byte[] {0x05, 0x01, 0x00});

        //Server: Hello

        br.ReadBytes(2);

        //Me: Connect to the IMAP on port 993

        byte[] data =  {0x05, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, getPortBytes(993)[0], getPortBytes(993)[1]};

        //Fill the IP in the DATA

        for (int i = 0; i < 4; i++)
        {
            data[i + 4] = ip.GetAddressBytes()[i];
        }

        bw.Write(data);

        //Server: Connection rdy

        br.ReadBytes(10);

        //Close our old Binary Writer/Reader

        br.Close();
        br.Dispose();
        bw.Close();
        bw.Dispose();

        //Handle SSL Stream

        var ssl = new SslStream(socksClient.GetStream(), false);

        //Auth as client
        ssl.AuthenticateAsClient("mx.freenet.de", null, SslProtocols.Tls, false);

        //Create new Binary Reader/Writer for the SSLStream
        var sslBr = new BinaryReader(ssl, Encoding.Default, true);
        var sslBw = new BinaryWriter(ssl, Encoding.Default, true);

        //Print the IMAP`s Hello
        string line = "";
        while (true)
        {
            char c = sslBr.ReadChar();
            line += c;
            if (c == '\n')
            {
                Console.WriteLine(line);
                break;
            }
        }

        //Send login to IMAP

        sslBw.Write((". login fipso@freenet.de HIDDEN"));

        //Read response as bytes
        while (true)
        {
            Console.WriteLine(sslBr.ReadByte());
        }

        /*
            Server gives no response.
            Why ?
        */

    }

编辑:运行代码时:

代码语言:javascript
复制
Working *
* OK IMAP ready.
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-06-09 12:50:33

所有IMAP命令必须以"\r\n“结尾。

看起来您并没有用任何新行来结束您的命令。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44454758

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档