Exemplo n.º 1
0
        public void TestExchange()
        {
            // dtm server exchange parameters X11RNS1R2
            DtmParameters srvDtmParams = DtmParamSets.FromName(DtmParamSets.DtmParamNames.X32RNR1R1);       // preset contains all the settings required for the exchange

            // dtm server id
            DtmClientStruct srvDmtId = new DtmClientStruct(
                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..");

            // forward secrecy framework
            _dtmServer.KeyRequested    += new DtmKex.KeyRequestedDelegate(OnKeyRequested);
            _dtmServer.KeySynchronized += new DtmKex.KeySynchronizedDelegate(OnKeySynchronized);

            // server starts listening
            _dtmServer.Listen(IPAddress.Any, Port);
            // wait for the key exchange to complete
            _initDone.WaitOne();

            // start the message stream
            StartMessageStream();
        }
Exemplo n.º 2
0
        private IdentityWithGMSS _myIdentity; // MZ@20190707

        public void TestExchange()
        {
            using (IdentityWithGMSS identity = new IdentityWithGMSS("DMTClientTEST001", @"C:\_Marek\_GMSSTEST"))
            {
                _myIdentity = identity;

                // dtm server exchange parameters X11RNS1R2
                DtmParameters cltDtmParams = DtmParamSets.FromName(DtmParamSets.DtmParamNames.X99SUPER1); //.X11RNS1R2); //.X32RNR1R1);       // preset contains all the settings required for the exchange

                // dtm client id
                DtmClientStruct cltDtmId = new DtmClientStruct(
                    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)
                    identity.GenerateTestIdentityPacket("DTMServerTEST001", 3600)); //  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);
                // wait for the connection
                _initDone.WaitOne();

                // forward secrecy framework
                _dtmClient.KeyRequested    += new DtmKex.KeyRequestedDelegate(OnKeyRequested);
                _dtmClient.KeySynchronized += new DtmKex.KeySynchronizedDelegate(OnKeySynchronized);

                // start the message stream
                StartMessageStream();
            }
        }