コード例 #1
0
        private void HandleClosePipeRequest(IHasSerializationTag rpc)
        {
            var c = (ClosePipeRPC)rpc;

            mTunnel.ClosePipe(c.ID);
            SendOk(c.RequestID);
        }
コード例 #2
0
        private void HandleNextTID(IHasSerializationTag rpc)
        {
            NextTID nextTid = (NextTID)rpc;

            this.mTunnel.NextTID(nextTid.TID);
            this.SendOk(rpc.RequestID);
        }
コード例 #3
0
        private void HandlePrepareRekey(IHasSerializationTag rpc)
        {
            var p = (PrepareRekey)rpc;

            this.mTunnel.SetNextRecipentPublicKey(p.NextPublicKey);
            RekeyResponse   response = new RekeyResponse((PrepareRekey)this.mTunnel.PrepareRekey());
            EncryptedPacket packet   = new EncryptedPacket(this.mTunnel.ID, this.ID);

            packet.RPCs.Add(response);
            this.mTunnel.EncryptAndSendPacket(packet);
            rekeyReady = true;
        }
コード例 #4
0
 private void HandleReKeyNow(IHasSerializationTag rpc)
 {
     if (rekeyReady)
     {
         this.mTunnel.RekeyNow();
         this.SendOk(rpc.RequestID);
         this.rekeyReady = false;
     }
     else
     {
         this.SendRefuse(rpc.RequestID);
     }
 }
コード例 #5
0
        private void HandleOpenAnonymousPipeRequest(IHasSerializationTag rpc)
        {
            var c = (CreateAnonymousPipe)rpc;
            //handle the pipe type....
            PipeType ctype;

            if (Enum.TryParse(c.PipeType, out ctype))
            {
                //todo: how do we want to handle anonymous pipes? should we make a policy mechanisim?
                if (mTunnel.PipeIDExists(c.ID))
                {
                    RefusePipe(c.ID, Packet.RefusePipe.RefusalReason.ID_ALREADY_EXISTS);
                }
                else if (c.ID == 0)
                {
                    RefusePipe(c.ID, Packet.RefusePipe.RefusalReason.CANNOT_OPEN_ANOTHER_CONTROL);
                }
                else
                {
                    //create the pipe
                    PipeBase createdPipe = null;
                    switch (ctype)
                    {
                    case PipeType.Control:
                        RefusePipe(c.ID, Packet.RefusePipe.RefusalReason.UNSUPPORTED_PIPE_TYPE);
                        break;

                    case PipeType.Duplex:
                        createdPipe = new DuplexPipe(mTunnel, c.ID);
                        mTunnel.OpenPipe(createdPipe);
                        OnPipeCreated(createdPipe);
                        break;

                    default:
                        RefusePipe(c.ID, Packet.RefusePipe.RefusalReason.UNSUPPORTED_PIPE_TYPE);
                        Debug.Fail("Unknown Pipe Type");
                        break;
                    }
                    if (createdPipe != null)
                    {
                        var packet = new EncryptedPacket(mTunnel.ID, ID);
                        packet.RPCs.Add(new AckPipe(createdPipe.ID));
                        mTunnel.EncryptAndSendPacket(packet);
                    }
                }
            }
            else
            {
                RefusePipe(c.ID, Tunneler.Packet.RefusePipe.RefusalReason.UNKNOWN);
            }
        }
コード例 #6
0
        private void HandleAckPipeRequest(IHasSerializationTag rpc)
        {
            //pipe request has been accepted by the otherside
            var      ack = (AckPipe)rpc;
            UInt32   id  = ack.ID;
            PipeBase pipe;

            if (this.requestedPipes.Remove(id, out pipe))
            {
                //register the pipe to the tunnel and
                //change the pipe state to connected
                this.mTunnel.OpenPipe(pipe);
                this.OnPipeCreated(pipe);
                //send an ok?
            }
            else
            {
                //todo: handle error
            }
        }
コード例 #7
0
        public bool DecryptPacket(byte[] sk, byte[] pk)
        {
            byte[] decrypt;
            try
            {
                decrypt = Sodium.PublicKeyBox.Open(this.CipherText, this.Nonce, sk, pk);
            }
            catch (CryptographicException ex)
            {
                Debug.Fail(ex.StackTrace);
                return(false);
            }
            catch (Exception ex)
            {
                Debug.Fail(ex.StackTrace);
                return(false);
            }
            MemoryStream ms = new MemoryStream(decrypt);

            UInt32 seq = 0;
            UInt32 ack = 0;
            UInt32 cid = 0;

            PackingHelpers.UnpackUint32(ref seq, ms);
            PackingHelpers.UnpackUint32(ref ack, ms);
            PackingHelpers.UnpackUint32(ref cid, ms);
            this.Seq = seq;
            this.Ack = ack;
            this.CID = cid;
            int flag = ms.ReadByte();

            Debug.Assert((flag == (int)RPCType.RPCStart || flag == (int)START_PAYLOAD_FLAG));
            if (flag == (int)RPCType.RPCStart)
            {
                //deserialize the RPC
                this.RPCs = new ArrayList <IHasSerializationTag>();
                byte serializationTag;
                while ((serializationTag = (byte)ms.ReadByte()) != (byte)RPCType.RPCEnd)
                {
                    IHasSerializationTag rpc = null;
                    switch ((RPCType)serializationTag)
                    {
                    case RPCType.AnonymousPipe:
                        rpc = RPCBase <CreateAnonymousPipe> .Unpack(ms);

                        break;

                    case RPCType.AuthenticatedPipe:
                        rpc = RPCBase <CreateAuthenticatedPipe> .Unpack(ms);

                        break;

                    case RPCType.ClosePipe:
                        rpc = RPCBase <ClosePipeRPC> .Unpack(ms);

                        break;

                    case RPCType.AckPipe:
                        rpc = RPCBase <AckPipe> .Unpack(ms);

                        break;

                    case RPCType.RefusePipe:
                        rpc = RPCBase <RefusePipe> .Unpack(ms);

                        break;

                    case RPCType.RequestCertificate:
                        rpc = RPCBase <RequestCertificate> .Unpack(ms);

                        break;

                    case RPCType.GiveCertificate:
                        rpc = RPCBase <GiveCertificate> .Unpack(ms);

                        break;

                    case RPCType.Ok:
                        rpc = RPCBase <OkRPC> .Unpack(ms);

                        break;

                    case RPCType.NextTID:
                        rpc = RPCBase <NextTID> .Unpack(ms);

                        break;

                    case RPCType.RekeyNow:
                        rpc = RPCBase <RekeyNow> .Unpack(ms);

                        break;

                    case RPCType.PosePuzzle:
                        rpc = RPCBase <PosePuzzle> .Unpack(ms);

                        break;

                    case RPCType.PuzzleSolution:
                        //RPCBase<>.Unpack(ms);
                        //major todo
                        break;

                    case RPCType.WindowResize:
                        rpc = RPCBase <ResizeWindow> .Unpack(ms);

                        break;

                    default:
                        //todo we should error out but simply drop packets
                        throw new ArgumentOutOfRangeException();
                    }
                    this.RPCs.Add(rpc);
                }
                flag = ms.ReadByte();
            }

            if (flag == START_PAYLOAD_FLAG)
            {
                int    index   = (int)ms.Position;
                byte[] payload = new byte[decrypt.Length - index];
                Array.Copy(decrypt, index, payload, 0, payload.Length);
                this.Payload = payload;
            }
            else
            {
                this.Payload = new byte[0];
            }
            return(true);
        }
コード例 #8
0
 public RPCEventArgs(IHasSerializationTag rpc, TunnelBase tunnel)
 {
     this.RPC    = rpc;
     this.Tunnel = tunnel;
 }
コード例 #9
0
 private void HandleWindowResize(IHasSerializationTag rpc)
 {
     //used for flow control...major todo
 }
コード例 #10
0
 private void HandleSolvePuzzle(IHasSerializationTag rpc)
 {
 }
コード例 #11
0
 private void HandleOk(IHasSerializationTag rpc)
 {
     //todo -- this has to be related to the RPC requests
 }
コード例 #12
0
 private void HandleRecieveCertificate(IHasSerializationTag rpc)
 {
     //todo
 }
コード例 #13
0
 private void HandleRequestCertificateRequest(IHasSerializationTag rpc)
 {
     throw new NotImplementedException("We need to figure out how to setup a certificate");
 }
コード例 #14
0
        private void HandleRefusePipeRequest(IHasSerializationTag rpc)
        {
            var c = (RefusePipe)rpc;

            OnPipeRefused(c);
        }
コード例 #15
0
 private void HandleOpenAuthenticatedPipeRequest(IHasSerializationTag rpc)
 {
     //todo: figure out how to "authenticate" a pipe
 }
コード例 #16
0
 private void HandleRefuse(IHasSerializationTag rpc)
 {
     Refuse refuse = (Refuse)rpc;
     //todo
 }