Ejemplo n.º 1
0
        protected void SendChallenge(long her_flags, long our_flags, int challenge)
        {
            OtpOutputStream obuf = new OtpOutputStream();
            string          str  = Local.Node;

            if ((her_flags & AbstractNode.dFlagHandshake23) == 0)
            {
                obuf.Write2BE(1 + 2 + 4 + 4 + str.Length);
                obuf.Write1('n');
                obuf.Write2BE(5);
                obuf.Write4BE(our_flags & 0xffffffff);
                obuf.Write4BE(challenge);
                obuf.Write(Encoding.GetEncoding("ISO-8859-1").GetBytes(str));
            }
            else
            {
                obuf.Write2BE(1 + 8 + 4 + 4 + 2 + str.Length);
                obuf.Write1('N');
                obuf.Write8BE(our_flags);
                obuf.Write4BE(challenge);
                obuf.Write4BE(Local.Creation);
                obuf.Write2BE(str.Length);
                obuf.Write(Encoding.GetEncoding("ISO-8859-1").GetBytes(str));
            }

            obuf.WriteTo(socket.OutputStream);

            if (TraceLevel >= TraceHandshake)
            {
                Logger.Debug($"-> HANDSHAKE sendChallenge flags={our_flags} challenge={challenge} local={Local}");
            }
        }
Ejemplo n.º 2
0
        protected int SendName(int dist, long aflags, int creation)
        {
            OtpOutputStream obuf    = new OtpOutputStream();
            string          str     = Local.Node;
            int             nameTag = (dist == 5 ? 'n' : 'N');

            if (dist == 5)
            {
                obuf.Write2BE(1 + 2 + 4 + str.Length);
                obuf.Write1(nameTag);
                obuf.Write2BE(dist);
                obuf.Write4BE(aflags);
                obuf.Write(Encoding.GetEncoding("ISO-8859-1").GetBytes(str));
            }
            else
            {
                obuf.Write2BE(1 + 8 + 4 + 2 + str.Length);
                obuf.Write1(nameTag);
                obuf.Write8BE(aflags);
                obuf.Write4BE(creation);
                obuf.Write2BE(str.Length);
                obuf.Write(Encoding.GetEncoding("ISO-8859-1").GetBytes(str));
            }

            obuf.WriteTo(socket.OutputStream);

            if (TraceLevel >= TraceHandshake)
            {
                Logger.Debug($"-> HANDSHAKE sendName flags={aflags} dist={dist} local={Local}");
            }

            return(nameTag);
        }
Ejemplo n.º 3
0
        protected void SendStatus(string status)
        {
            OtpOutputStream obuf = new OtpOutputStream();

            obuf.Write2BE(status.Length + 1);
            obuf.Write1(ChallengeStatus);
            obuf.Write(Encoding.GetEncoding("ISO-8859-1").GetBytes(status));

            obuf.WriteTo(socket.OutputStream);

            if (TraceLevel >= TraceHandshake)
            {
                Logger.Debug($"-> HANDSHAKE sendStatus status={status} local={Local}");
            }
        }
Ejemplo n.º 4
0
        protected void SendChallengeAck(byte[] digest)
        {
            OtpOutputStream obuf = new OtpOutputStream();

            obuf.Write2BE(17);
            obuf.Write1(ChallengeAck);
            obuf.Write(digest);

            obuf.WriteTo(socket.OutputStream);

            if (TraceLevel >= TraceHandshake)
            {
                Logger.Debug($"-> HANDSHAKE sendChallengeAck digest={Hex(digest)} local={Local}");
            }
        }
Ejemplo n.º 5
0
        protected void SendChallengeReply(int challenge, byte[] digest)
        {
            OtpOutputStream obuf = new OtpOutputStream();

            obuf.Write2BE(21);
            obuf.Write1(ChallengeReply);
            obuf.Write4BE(challenge);
            obuf.Write(digest);

            obuf.WriteTo(socket.OutputStream);

            if (TraceLevel >= TraceHandshake)
            {
                Logger.Debug($"-> HANDSHAKE sendChallengeReply challenge={challenge} digest={Hex(digest)} local={Local}");
            }
        }