예제 #1
0
        public void TestExchange()
        {
            // dtm server exchange parameters X11RNS1R2
            DtmParameters srvDtmParams = DtmParamSets.FromName(DtmParamSets.DtmParamNames.X41RNT1R1);       // preset contains all the settings required for the exchange

            // dtm server id
            DtmClient srvDmtId = new DtmClient(
                new byte[] { 3, 3, 3, 3 },      // the clients public id, (should be at least 32 bytes, can be used as a contact lookup and initial auth)
                new byte[] { 4, 4, 4, 4 });     // the clients secret id, (secret id can be anything.. a serialized structure, signed data, hash, etc)

            // create the server
            _dtmServer = new DtmKex(srvDtmParams, srvDmtId);
            _dtmServer.IdentityReceived += new DtmKex.IdentityReceivedDelegate(OnIdentityReceived);         // returns the client public and secret id fields, used to authenticate a host
            _dtmServer.PacketReceived += new DtmKex.PacketReceivedDelegate(OnPacketReceived);               // notify that a packet has been received (optional)
            _dtmServer.SessionEstablished += new DtmKex.SessionEstablishedDelegate(OnSessionEstablished);   // notify when the vpn state is up
            _dtmServer.PacketSent += new DtmKex.PacketReceivedDelegate(OnPacketSent);                       // notify when a packet has been sent to the remote host (optional)
            _dtmServer.DataReceived += new DtmKex.DataTransferredDelegate(OnDataReceived);                  // returns the decrypted message data
            _dtmServer.FileReceived += new DtmKex.FileTransferredDelegate(OnFileReceived);                  // notify that a file transfer has completed
            _dtmServer.FileRequest += new DtmKex.FileRequestDelegate(OnFileRequest);                        // notify that the remote host wants to send a file, can cancel or provide a path for the new file
            _dtmServer.SessionError += new DtmKex.SessionErrorDelegate(OnSessionError);                     // notify of any error conditions; includes the exception, and a severity code contained in the option flag

            Console.WriteLine(CON_TITLE + "Waiting for a connection..");

            // server starts listening
            _dtmServer.Listen(IPAddress.Any, Port);
            // wait for the key exchange to complete
            _initDone.WaitOne();
            // start the message stream
            StartMessageStream();
        }
예제 #2
0
        public void TestExchange()
        {
            // dtm server exchange parameters X11RNS1R2
            DtmParameters cltDtmParams = DtmParamSets.FromName(DtmParamSets.DtmParamNames.X42RNS1R1);       // preset contains all the settings required for the exchange

            // dtm client id
            DtmClient cltDtmId = new DtmClient(
                new byte[] { 1, 1, 1, 1 },      // the clients public id, (should be at least 32 bytes, can be used as a contact lookup and initial auth)
                new byte[] { 2, 2, 2, 2 });     // the clients secret id, (secret id can be anything.. a serialized structure, signed data, hash, etc)

            // create client
            _dtmClient = new DtmKex(cltDtmParams, cltDtmId);

            _dtmClient.IdentityReceived += new DtmKex.IdentityReceivedDelegate(OnIdentityReceived);         // returns the client public and secret id fields, used to authenticate a host
            _dtmClient.PacketReceived += new DtmKex.PacketReceivedDelegate(OnPacketReceived);               // notify that a packet has been received (optional)
            _dtmClient.SessionEstablished += new DtmKex.SessionEstablishedDelegate(OnSessionEstablished);   // notify when the vpn state is up
            _dtmClient.PacketSent += new DtmKex.PacketReceivedDelegate(OnPacketSent);                       // notify when a packet has been sent to the remote host (optional)
            _dtmClient.DataReceived += new DtmKex.DataTransferredDelegate(OnDataReceived);                  // returns the decrypted message data
            _dtmClient.FileReceived += new DtmKex.FileTransferredDelegate(OnFileReceived);                  // notify that a file transfer has completed
            _dtmClient.FileRequest += new DtmKex.FileRequestDelegate(OnFileRequest);                        // notify that the remote host wants to send a file, can cancel or provide a path for the new file
            _dtmClient.SessionError += new DtmKex.SessionErrorDelegate(OnSessionError);                     // notify of any error conditions; includes the exception, and a severity code contained in the option flag

            // client connects and starts the exchange
            _dtmClient.Connect(IPAddress.Loopback, 1024);//IPAddress.Parse("192.168.1.102")
            // wait for the connection
            _initDone.WaitOne();
            // start the message stream
            StartMessageStream();
        }