Ejemplo n.º 1
0
        /// <summary>
        /// Process the clients identity structure <see cref="DtmIdentity"/>.
        /// </summary>
        /// 
        /// <param name="PacketStream">A Stream containing the raw packet data</param>
        private void ProcessSync(MemoryStream PacketStream)
        {
            // get the header
            DtmPacket pktHdr = new DtmPacket(PacketStream);
            // read the data
            byte[] data = new byte[pktHdr.PayloadLength];
            PacketStream.Read(data, 0, data.Length);
            // use clients symmetric key to decrypt data
            byte[] dec = SymmetricTransform(_cltSymProcessor, data);
            // remove random padding
            dec = UnwrapMessage(dec);
            // get the identity
            _cltIdentity = new DtmIdentity(dec);

            // pass id to the client, include oid
            long resp = 0;
            if (IdentityReceived != null)
            {
                DtmIdentityEventArgs args = new DtmIdentityEventArgs(DtmExchangeFlags.Init, _cltIdentity.OptionFlag, _cltIdentity);
                IdentityReceived(this, args);
                resp = args.Flag;
                if (args.Cancel)
                {
                    // back out of session
                    TearDown();
                }
            }

            // get the params oid
            _cltAsmParams = GetAsymmetricParams(_cltIdentity.PkeId);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Processes the clients public identity and clients Auth-Stage PKE parameter set Id; <see cref="IAsymmetricParameters"/>.
        /// <para>Process the clients Auth-Stage public identity structure; <see cref="DtmIdentity"/></para>
        /// </summary>
        /// 
        /// <param name="PacketStream">A Stream containing the raw packet data</param>
        /// 
        /// <remarks>Fires the <see cref="IdentityReceived"/> event; returning the <see cref="DtmIdentityEventArgs"/> object containing the clients public id structure.
        /// <para>The session can be aborted by setting the DtmIdentityEventArgs Cancel flag to true.</para>
        /// </remarks>
        private void ProcessInit(MemoryStream PacketStream)
        {
            // seek past header
            PacketStream.Seek(DtmPacket.GetHeaderSize(), SeekOrigin.Begin);
            // get the clients id structure
            _cltIdentity = new DtmIdentity(PacketStream);
            // get client asymmetric params
            _cltAsmParams = GetAsymmetricParams(_cltIdentity.PkeId);
            // store the auth session
            _cltAuthSession = _cltIdentity.Session;

            // pass it to the client again, so it can be refused on basis of params
            long resp = 0;
            if (IdentityReceived != null)
            {
                DtmIdentityEventArgs args = new DtmIdentityEventArgs(DtmExchangeFlags.Init, 0, _cltIdentity);
                IdentityReceived(this, args);
                resp = args.Flag;
                if (args.Cancel)
                {
                    // back out of session
                    TearDown();
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Process the clients private identity.
        /// <para>Decrypts and stores the clients private identity using the clients Auth-Stage Symmetric Key.</para>
        /// </summary>
        /// 
        /// <param name="PacketStream">A Stream containing the raw packet data</param>
        private void ProcessAuth(MemoryStream PacketStream)
        {
            // get the header
            DtmPacket pktHdr = new DtmPacket(PacketStream);
            byte[] data = new byte[pktHdr.PayloadLength];
            PacketStream.Read(data, 0, data.Length);
            // create the clients auth-stage symmetric cipher
            _cltSymProcessor = SymmetricInit(_cltIdentity.Session, _cltKeyParams);
            // decrypt the payload
            byte[] dec = SymmetricTransform(_cltSymProcessor, data);
            // remove random padding
            dec = UnwrapMessage(dec);
            // get the clients private id
            _cltIdentity = new DtmIdentity(new MemoryStream(dec));

            // notify user
            long resp = 0;
            if (IdentityReceived != null)
            {
                DtmIdentityEventArgs args = new DtmIdentityEventArgs(DtmExchangeFlags.Auth, resp, _cltIdentity);
                IdentityReceived(this, args);
                resp = args.Flag;
                if (args.Cancel)
                {
                    // back out of session
                    TearDown();
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Processes the clients public identity field for preliminary authentication.
        /// <para>Process the clients partial Auth-Stage public identity structure; <see cref="DtmIdentity"/></para>
        /// </summary>
        /// 
        /// <param name="PacketStream">A Stream containing the raw packet data</param>
        /// 
        /// <remarks>
        /// The client auto-negotiates to the security level of the server (the host accepting the connection request).
        /// Fires the <see cref="IdentityReceived"/> event; returning the <see cref="DtmIdentityEventArgs"/> object containing the clients public id structure.
        /// <para>The session can be aborted by setting the DtmIdentityEventArgs Cancel flag to true.</para>
        /// </remarks>
        private void ProcessConnect(MemoryStream PacketStream)
        {
            // seek past header
            PacketStream.Seek(DtmPacket.GetHeaderSize(), SeekOrigin.Begin);
            // get the clients id structure
            _cltIdentity = new DtmIdentity(PacketStream);

            // pass it to the client, evaluate the id
            if (IdentityReceived != null)
            {
                DtmIdentityEventArgs args = new DtmIdentityEventArgs(DtmExchangeFlags.Init, 0, _cltIdentity);
                IdentityReceived(this, args);

                if (args.Cancel)
                {
                    // back out of session
                    TearDown();
                }
            }

            // synchronize security level with the server
            if (!_isServer)
            {
                // get the servers security context and compare it to ours
                DtmParamSets.SecurityContexts srvSec = (DtmParamSets.SecurityContexts)_cltIdentity.OptionFlag;
                DtmParamSets.SecurityContexts cltSec = DtmParamSets.GetContext(_dtmParameters.OId);

                if (cltSec != srvSec)
                {
                    // match servers security parameters
                    if (!NegotiateSecurity(srvSec))
                    {
                        // the negotiation failed
                        Disconnect();
                    }
                }
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Fires when a packet containing an identity is received, the args contain the id
 /// </summary>
 private void OnIdentityReceived(object owner, DtmIdentityEventArgs args)
 {
     Console.WriteLine(CON_TITLE + String.Format("Server received an identity packet: {0}", IdToString(args.DtmID.Identity)));
 }