示例#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();
        }
示例#3
0
文件: DtmKex.cs 项目: modulexcite/CEX
 /// <summary>
 /// Initialize this class with a random generator
 /// </summary>
 /// 
 /// <param name="Parameters">A populated <see cref="DtmParameters"/> class containing the session parameters</param>
 /// <param name="Host">A populated <see cref="DtmClient"/> class containing the servers identity data</param>
 /// <param name="Generator">The initialized <see cref="IRandom"/> Prng instance</param>
 /// <param name="BufferCount">The number of send/receive buffers, default is 1024</param>
 /// <param name="DisposeEngines">if set to true (default), the primary symmetric ciphers are disposed when this class is disposed</param>
 public DtmKex(DtmParameters Parameters, DtmClient Host, IRandom Generator, int BufferCount = 1024, bool DisposeEngines = true)
 {
     _disposeEngines = DisposeEngines;
     _dtmParameters = Parameters;
     _dtmHost = Host;
     _srvIdentity = new DtmIdentity(Host.PublicId, Parameters.AuthPkeId, Parameters.AuthSession, 0);
     _exchangeState = DtmExchangeFlags.Connect;
     _rcvBuffer = new PacketBuffer(BufferCount);
     _sndBuffer = new PacketBuffer(BufferCount);
     _rndGenerator = Generator;
     _bufferCount = BufferCount;
 }
示例#4
0
 /// <summary>
 /// Serialize an DtmClient structure
 /// </summary>
 /// 
 /// <param name="Client">A DtmClient structure</param>
 /// 
 /// <returns>A stream containing the DtmClient data</returns>
 public static Stream Serialize(DtmClient Client)
 {
     return Client.ToStream();
 }