コード例 #1
0
ファイル: DtlsServer.cs プロジェクト: olivermertens/MeRTC
 public DtlsServer(DatagramTransport datagramTransport, CertificateInfo certificateInfo, DtlsServerProtocol dtlsServerProtocol = null)
 {
     DatagramTransport       = datagramTransport;
     this.dtlsServerProtocol = dtlsServerProtocol ?? new DtlsServerProtocol(new Org.BouncyCastle.Security.SecureRandom());
     tlsServer = new TlsServerImpl(certificateInfo);
     tlsServer.ClientCertificateReceived += TlsServer_ClientCertificateReceived;
 }
コード例 #2
0
        public ThreadedAssociation(DatagramTransport transport, AssociationListener al, bool isClient, int srcPort,
                                   int destPort)
            : base(transport, al, isClient, srcPort, destPort)
        {
            try
            {
                _transpMTU = Math.Min(transport.GetReceiveLimit(), transport.GetSendLimit());
                logger.LogDebug("Transport MTU is now " + _transpMTU);
            }
            catch (IOException x)
            {
                logger.LogWarning("Failed to get suitable transport mtu ");
                logger.LogWarning(x.ToString());
            }

            _freeBlocks = new Queue <DataChunk>(/*MAXBLOCKS*/);
            _inFlight   = new Dictionary <long, DataChunk>(MAXBLOCKS);

            for (int i = 0; i < MAXBLOCKS; i++)
            {
                DataChunk dc = new DataChunk();
                lock (_freeBlocks)
                {
                    _freeBlocks.Enqueue(dc);
                }
            }

            resetCwnd();
        }
コード例 #3
0
ファイル: DtlsClient.cs プロジェクト: olivermertens/MeRTC
 public DtlsClient(DatagramTransport datagramTransport, CertificateInfo certificateInfo, DtlsClientProtocol dtlsClientProtocol = null)
 {
     this.datagramTransport  = datagramTransport;
     this.dtlsClientProtocol = dtlsClientProtocol ?? new DtlsClientProtocol(new SecureRandom());
     tlsClient = new TlsClientImpl(certificateInfo);
     tlsClient.ServerCertificateInfoAvailable += TlsClient_ServerCertificateInfoAvailable;
 }
コード例 #4
0
 internal Server(DtlsTestCase outer, DtlsServerProtocol serverProtocol, DatagramTransport serverTransport, TlsTestServerImpl serverImpl)
 {
     this.mOuter           = outer;
     this.mServerProtocol  = serverProtocol;
     this.mServerTransport = serverTransport;
     this.mServerImpl      = serverImpl;
 }
コード例 #5
0
        public Association(DatagramTransport transport, AssociationListener al, bool client)
        {
            //Log.setLevel(Log.ALL);
            Logger.Debug("Created an Associaction of type: " + this.GetType().Name);
            _al         = al;
            _random     = new SecureRandom();
            _myVerTag   = _random.NextInt();
            _transp     = transport;
            _streams    = new Dictionary <int, SCTPStream>();
            _outbound   = new Dictionary <long, DataChunk>();
            _holdingPen = new Dictionary <uint, DataChunk>();
            var IInt = new FastBit.Int(_random.NextInt());

            _nearTSN = new FastBit.Uint(IInt.b0, IInt.b1, IInt.b2, IInt.b3).Auint;
            _state   = State.CLOSED;
            if (_transp != null)
            {
                startRcv();
            }
            else
            {
                Logger.Error("Created an Associaction with a null transport somehow...");
            }
            __assocNo++;

            /*
             * the method used to determine which
             * side uses odd or even is based on the underlying DTLS connection
             * role: the side acting as the DTLS client MUST use Streams with even
             * Stream Identifiers, the side acting as the DTLS server MUST use
             * Streams with odd Stream Identifiers. */
            _even = client;
        }
コード例 #6
0
        public UnicastMediaSubsession(bool reuseFirstSource, short initialPortNum = 6970, bool multiplexRTCPWithRTP = false)
        {
            // Make sure RTP ports are even-numbered:

            fInitialPortNum       = (short)((initialPortNum + 1) & (~1));
            fMultiplexRTCPWithRTP = multiplexRTCPWithRTP;

            int serverPortNum;

            for (serverPortNum = fInitialPortNum; ; ++serverPortNum)
            {
                // Normal case: We're streaming RTP (over UDP or TCP).  Create a pair of
                //	 groupsocks(RTP and RTCP), with adjacent port numbers(RTP port number even).
                //	 (If we're multiplexing RTCP and RTP over the same port number, it can be odd or even.)
                //	NoReuse dummy(envir()); // ensures that we skip over ports that are already in use

                ServerRTPPort = serverPortNum;

                try
                {
                    _rtpGroupsock = new DatagramTransport(ServerRTPPort, 255);
                }
                catch (Exception)
                {
                    _rtpGroupsock = null;
                }
                if (_rtpGroupsock == null)
                {
                    continue;
                }

                if (fMultiplexRTCPWithRTP)
                {
                    //Use the RTP 'groupsock' object for RTCP as well:

                    ServerRTCPPort = ServerRTPPort;
                    _rtcpGroupsock = _rtpGroupsock;
                }
                else
                {
                    // Create a separate 'groupsock' object(with the next(odd) port number) for RTCP:
                    ServerRTCPPort = ++serverPortNum;
                    try
                    {
                        _rtcpGroupsock = new DatagramTransport(ServerRTCPPort, 255);
                    }
                    catch (Exception)
                    {
                        _rtcpGroupsock = null;
                    }
                    if (_rtcpGroupsock == null)
                    {
                        continue;                         // try again
                    }
                }

                break;                 // success
            }
        }
コード例 #7
0
        public virtual DtlsTransport Connect(TlsClient client, DatagramTransport transport)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }
            if (transport == null)
            {
                throw new ArgumentNullException("transport");
            }

            SecurityParameters securityParameters = new SecurityParameters();

            securityParameters.entity = ConnectionEnd.client;

            ClientHandshakeState state = new ClientHandshakeState();

            state.client        = client;
            state.clientContext = new TlsClientContextImpl(mSecureRandom, securityParameters);

            securityParameters.clientRandom = TlsProtocol.CreateRandomBlock(client.ShouldUseGmtUnixTime(),
                                                                            state.clientContext.NonceRandomGenerator);

            client.Init(state.clientContext);

            DtlsRecordLayer recordLayer = new DtlsRecordLayer(transport, state.clientContext, client, ContentType.handshake);

            TlsSession sessionToResume = state.client.GetSessionToResume();

            if (sessionToResume != null)
            {
                SessionParameters sessionParameters = sessionToResume.ExportSessionParameters();
                if (sessionParameters != null)
                {
                    state.tlsSession        = sessionToResume;
                    state.sessionParameters = sessionParameters;
                }
            }

            try
            {
                return(ClientHandshake(state, recordLayer));
            }
            catch (TlsFatalAlert fatalAlert)
            {
                recordLayer.Fail(fatalAlert.AlertDescription);
                throw fatalAlert;
            }
            catch (IOException e)
            {
                recordLayer.Fail(AlertDescription.internal_error);
                throw e;
            }
            catch (Exception e)
            {
                recordLayer.Fail(AlertDescription.internal_error);
                throw new TlsFatalAlert(AlertDescription.internal_error, e);
            }
        }
コード例 #8
0
ファイル: DtlsClientProtocol.cs プロジェクト: bcgit/bc-csharp
        public virtual DtlsTransport Connect(TlsClient client, DatagramTransport transport)
        {
            if (client == null)
                throw new ArgumentNullException("client");
            if (transport == null)
                throw new ArgumentNullException("transport");

            SecurityParameters securityParameters = new SecurityParameters();
            securityParameters.entity = ConnectionEnd.client;

            ClientHandshakeState state = new ClientHandshakeState();
            state.client = client;
            state.clientContext = new TlsClientContextImpl(mSecureRandom, securityParameters);

            securityParameters.clientRandom = TlsProtocol.CreateRandomBlock(client.ShouldUseGmtUnixTime(),
                state.clientContext.NonceRandomGenerator);

            client.Init(state.clientContext);

            DtlsRecordLayer recordLayer = new DtlsRecordLayer(transport, state.clientContext, client, ContentType.handshake);

            TlsSession sessionToResume = state.client.GetSessionToResume();
            if (sessionToResume != null && sessionToResume.IsResumable)
            {
                SessionParameters sessionParameters = sessionToResume.ExportSessionParameters();
                if (sessionParameters != null)
                {
                    state.tlsSession = sessionToResume;
                    state.sessionParameters = sessionParameters;
                }
            }

            try
            {
                return ClientHandshake(state, recordLayer);
            }
            catch (TlsFatalAlert fatalAlert)
            {
                AbortClientHandshake(state, recordLayer, fatalAlert.AlertDescription);
                throw fatalAlert;
            }
            catch (IOException e)
            {
                AbortClientHandshake(state, recordLayer, AlertDescription.internal_error);
                throw e;
            }
            catch (Exception e)
            {
                AbortClientHandshake(state, recordLayer, AlertDescription.internal_error);
                throw new TlsFatalAlert(AlertDescription.internal_error, e);
            }
            finally
            {
                securityParameters.Clear();
            }
        }
コード例 #9
0
 public RTPMulticastStream(string name, string subSession, DatagramTransport rtpTransport, DatagramTransport rtcpTransport, string multicastIP, int rtpPort, int rtcpPort) :
     base(name, subSession, rtpTransport, rtcpTransport)
 {
     _rtpPort  = rtpPort;
     _rtcpPort = rtcpPort;
     _address  = IPAddress.Parse(multicastIP);
     _endPoint = new IPEndPoint(_address, rtpPort);
     _rtcpTasks.Add(RTCPSender());
     _rtcpTasks.Add(RTCPReader());
 }
コード例 #10
0
        public virtual DtlsTransport Connect(TlsClient client, DatagramTransport transport)
        {
            //IL_0008: Unknown result type (might be due to invalid IL or missing references)
            //IL_0016: Unknown result type (might be due to invalid IL or missing references)
            //IL_00d2: Expected O, but got Unknown
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }
            if (transport == null)
            {
                throw new ArgumentNullException("transport");
            }
            SecurityParameters securityParameters = new SecurityParameters();

            securityParameters.entity = 1;
            ClientHandshakeState clientHandshakeState = new ClientHandshakeState();

            clientHandshakeState.client        = client;
            clientHandshakeState.clientContext = new TlsClientContextImpl(mSecureRandom, securityParameters);
            securityParameters.clientRandom    = TlsProtocol.CreateRandomBlock(client.ShouldUseGmtUnixTime(), clientHandshakeState.clientContext.NonceRandomGenerator);
            client.Init(clientHandshakeState.clientContext);
            DtlsRecordLayer dtlsRecordLayer = new DtlsRecordLayer(transport, clientHandshakeState.clientContext, client, 22);
            TlsSession      sessionToResume = clientHandshakeState.client.GetSessionToResume();

            if (sessionToResume != null && sessionToResume.IsResumable)
            {
                SessionParameters sessionParameters = sessionToResume.ExportSessionParameters();
                if (sessionParameters != null)
                {
                    clientHandshakeState.tlsSession        = sessionToResume;
                    clientHandshakeState.sessionParameters = sessionParameters;
                }
            }
            try
            {
                return(ClientHandshake(clientHandshakeState, dtlsRecordLayer));
            }
            catch (TlsFatalAlert tlsFatalAlert)
            {
                dtlsRecordLayer.Fail(tlsFatalAlert.AlertDescription);
                throw tlsFatalAlert;
            }
            catch (IOException val)
            {
                IOException val2 = val;
                dtlsRecordLayer.Fail(80);
                throw val2;
            }
            catch (global::System.Exception alertCause)
            {
                dtlsRecordLayer.Fail(80);
                throw new TlsFatalAlert(80, alertCause);
            }
        }
コード例 #11
0
        public virtual DtlsTransport Accept(TlsServer server, DatagramTransport transport)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }
            if (transport == null)
            {
                throw new ArgumentNullException("transport");
            }

            SecurityParameters securityParameters = new SecurityParameters();

            securityParameters.entity = ConnectionEnd.server;

            ServerHandshakeState state = new ServerHandshakeState();

            state.server        = server;
            state.serverContext = new TlsServerContextImpl(mSecureRandom, securityParameters);

            securityParameters.serverRandom = TlsProtocol.CreateRandomBlock(server.ShouldUseGmtUnixTime(),
                                                                            state.serverContext.NonceRandomGenerator);

            server.Init(state.serverContext);

            DtlsRecordLayer recordLayer = new DtlsRecordLayer(transport, state.serverContext, server, ContentType.handshake);

            server.NotifyCloseHandle(recordLayer);

            // TODO Need to handle sending of HelloVerifyRequest without entering a full connection

            try
            {
                return(ServerHandshake(state, recordLayer));
            }
            catch (TlsFatalAlert fatalAlert)
            {
                AbortServerHandshake(state, recordLayer, fatalAlert.AlertDescription);
                throw fatalAlert;
            }
            catch (IOException e)
            {
                AbortServerHandshake(state, recordLayer, AlertDescription.internal_error);
                throw e;
            }
            catch (Exception e)
            {
                AbortServerHandshake(state, recordLayer, AlertDescription.internal_error);
                throw new TlsFatalAlert(AlertDescription.internal_error, e);
            }
            finally
            {
                securityParameters.Clear();
            }
        }
コード例 #12
0
ファイル: ThreadedAssociationTest.cs プロジェクト: sgf/SCTP
        private DatagramTransport[] mkMockTransports()
        {
            BlockingQueue <byte[]> left  = new BlockingQueue <byte[]>();
            BlockingQueue <byte[]> right = new BlockingQueue <byte[]>();

            DatagramTransport[] ret = new DatagramTransport[2];
            ret[0] = new MockTransport(left, right);
            ret[1] = new MockTransport(right, left);
            __transList.Add(ret[0]);
            __transList.Add(ret[1]);
            return(ret);
        }
コード例 #13
0
 internal DtlsRecordLayer(DatagramTransport transport, TlsContext context, TlsPeer peer, byte contentType)
 {
     mTransport    = transport;
     mContext      = context;
     mPeer         = peer;
     mInHandshake  = true;
     mCurrentEpoch = new DtlsEpoch(0, new TlsNullCipher(context));
     mPendingEpoch = null;
     mReadEpoch    = mCurrentEpoch;
     mWriteEpoch   = mCurrentEpoch;
     SetPlaintextLimit(16384);
 }
コード例 #14
0
        public virtual DtlsTransport Connect(TlsClient client, DatagramTransport transport)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }
            if (transport == null)
            {
                throw new ArgumentNullException("transport");
            }
            SecurityParameters securityParameters = new SecurityParameters();

            securityParameters.entity = 1;
            DtlsClientProtocol.ClientHandshakeState clientHandshakeState = new DtlsClientProtocol.ClientHandshakeState();
            clientHandshakeState.client        = client;
            clientHandshakeState.clientContext = new TlsClientContextImpl(this.mSecureRandom, securityParameters);
            securityParameters.clientRandom    = TlsProtocol.CreateRandomBlock(client.ShouldUseGmtUnixTime(), clientHandshakeState.clientContext.NonceRandomGenerator);
            client.Init(clientHandshakeState.clientContext);
            DtlsRecordLayer dtlsRecordLayer = new DtlsRecordLayer(transport, clientHandshakeState.clientContext, client, 22);
            TlsSession      sessionToResume = clientHandshakeState.client.GetSessionToResume();

            if (sessionToResume != null && sessionToResume.IsResumable)
            {
                SessionParameters sessionParameters = sessionToResume.ExportSessionParameters();
                if (sessionParameters != null)
                {
                    clientHandshakeState.tlsSession        = sessionToResume;
                    clientHandshakeState.sessionParameters = sessionParameters;
                }
            }
            DtlsTransport result;

            try
            {
                result = this.ClientHandshake(clientHandshakeState, dtlsRecordLayer);
            }
            catch (TlsFatalAlert tlsFatalAlert)
            {
                dtlsRecordLayer.Fail(tlsFatalAlert.AlertDescription);
                throw tlsFatalAlert;
            }
            catch (IOException ex)
            {
                dtlsRecordLayer.Fail(80);
                throw ex;
            }
            catch (Exception alertCause)
            {
                dtlsRecordLayer.Fail(80);
                throw new TlsFatalAlert(80, alertCause);
            }
            return(result);
        }
コード例 #15
0
        public UnreliableDatagramTransport(DatagramTransport transport, Random random,
            int percentPacketLossReceiving, int percentPacketLossSending)
        {
            if (percentPacketLossReceiving < 0 || percentPacketLossReceiving > 100)
                throw new ArgumentException("out of range", "percentPacketLossReceiving");
            if (percentPacketLossSending < 0 || percentPacketLossSending > 100)
                throw new ArgumentException("out of range", "percentPacketLossSending");

            this.transport = transport;
            this.random = random;
            this.percentPacketLossReceiving = percentPacketLossReceiving;
            this.percentPacketLossSending = percentPacketLossSending;
        }
コード例 #16
0
ファイル: DtlsRecordLayer.cs プロジェクト: niuk/bc-csharp
        private static void SendDatagram(DatagramTransport sender, byte[] buf, int off, int len)
        {
            //try
            //{
            //    sender.Send(buf, off, len);
            //}
            //catch (InterruptedIOException e)
            //{
            //    e.bytesTransferred = 0;
            //    throw e;
            //}

            sender.Send(buf, off, len);
        }
コード例 #17
0
        internal DtlsRecordLayer(DatagramTransport transport, TlsContext context, TlsPeer peer, byte contentType)
        {
            this.mTransport = transport;
            this.mContext   = context;
            this.mPeer      = peer;

            this.mInHandshake = true;

            this.mCurrentEpoch = new DtlsEpoch(0, new TlsNullCipher(context));
            this.mPendingEpoch = null;
            this.mReadEpoch    = mCurrentEpoch;
            this.mWriteEpoch   = mCurrentEpoch;

            SetPlaintextLimit(MAX_FRAGMENT_LENGTH);
        }
コード例 #18
0
ファイル: DtlsRecordLayer.cs プロジェクト: bcgit/bc-csharp
        internal DtlsRecordLayer(DatagramTransport transport, TlsContext context, TlsPeer peer, byte contentType)
        {
            this.mTransport = transport;
            this.mContext = context;
            this.mPeer = peer;

            this.mInHandshake = true;

            this.mCurrentEpoch = new DtlsEpoch(0, new TlsNullCipher(context));
            this.mPendingEpoch = null;
            this.mReadEpoch = mCurrentEpoch;
            this.mWriteEpoch = mCurrentEpoch;

            SetPlaintextLimit(MAX_FRAGMENT_LENGTH);
        }
コード例 #19
0
        /// <summary>
        /// Starts the SCTP transport receive thread.
        /// </summary>
        public void Start(DatagramTransport dtlsTransport, bool isDtlsClient)
        {
            if (!_isStarted)
            {
                _isStarted = true;

                transport    = dtlsTransport;
                IsDtlsClient = isDtlsClient;

                _receiveThread              = new Thread(DoReceive);
                _receiveThread.Name         = $"{THREAD_NAME_PREFIX}{RTCSctpAssociation.ID}";
                _receiveThread.IsBackground = true;
                _receiveThread.Start();
            }
        }
コード例 #20
0
ファイル: DtlsServerProtocol.cs プロジェクト: bcgit/bc-csharp
        public virtual DtlsTransport Accept(TlsServer server, DatagramTransport transport)
        {
            if (server == null)
                throw new ArgumentNullException("server");
            if (transport == null)
                throw new ArgumentNullException("transport");

            SecurityParameters securityParameters = new SecurityParameters();
            securityParameters.entity = ConnectionEnd.server;

            ServerHandshakeState state = new ServerHandshakeState();
            state.server = server;
            state.serverContext = new TlsServerContextImpl(mSecureRandom, securityParameters);

            securityParameters.serverRandom = TlsProtocol.CreateRandomBlock(server.ShouldUseGmtUnixTime(),
                state.serverContext.NonceRandomGenerator);

            server.Init(state.serverContext);

            DtlsRecordLayer recordLayer = new DtlsRecordLayer(transport, state.serverContext, server, ContentType.handshake);

            // TODO Need to handle sending of HelloVerifyRequest without entering a full connection

            try
            {
                return ServerHandshake(state, recordLayer);
            }
            catch (TlsFatalAlert fatalAlert)
            {
                AbortServerHandshake(state, recordLayer, fatalAlert.AlertDescription);
                throw fatalAlert;
            }
            catch (IOException e)
            {
                AbortServerHandshake(state, recordLayer, AlertDescription.internal_error);
                throw e;
            }
            catch (Exception e)
            {
                AbortServerHandshake(state, recordLayer, AlertDescription.internal_error);
                throw new TlsFatalAlert(AlertDescription.internal_error, e);
            }
            finally
            {
                securityParameters.Clear();
            }
        }
コード例 #21
0
        public UnreliableDatagramTransport(DatagramTransport transport, Random random,
                                           int percentPacketLossReceiving, int percentPacketLossSending)
        {
            if (percentPacketLossReceiving < 0 || percentPacketLossReceiving > 100)
            {
                throw new ArgumentException("out of range", "percentPacketLossReceiving");
            }
            if (percentPacketLossSending < 0 || percentPacketLossSending > 100)
            {
                throw new ArgumentException("out of range", "percentPacketLossSending");
            }

            this.transport = transport;
            this.random    = random;
            this.percentPacketLossReceiving = percentPacketLossReceiving;
            this.percentPacketLossSending   = percentPacketLossSending;
        }
コード例 #22
0
        public virtual DtlsTransport Accept(TlsServer server, DatagramTransport transport)
        {
            //IL_0008: Unknown result type (might be due to invalid IL or missing references)
            //IL_0016: Unknown result type (might be due to invalid IL or missing references)
            //IL_009d: Expected O, but got Unknown
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }
            if (transport == null)
            {
                throw new ArgumentNullException("transport");
            }
            SecurityParameters securityParameters = new SecurityParameters();

            securityParameters.entity = 0;
            ServerHandshakeState serverHandshakeState = new ServerHandshakeState();

            serverHandshakeState.server        = server;
            serverHandshakeState.serverContext = new TlsServerContextImpl(mSecureRandom, securityParameters);
            securityParameters.serverRandom    = TlsProtocol.CreateRandomBlock(server.ShouldUseGmtUnixTime(), serverHandshakeState.serverContext.NonceRandomGenerator);
            server.Init(serverHandshakeState.serverContext);
            DtlsRecordLayer dtlsRecordLayer = new DtlsRecordLayer(transport, serverHandshakeState.serverContext, server, 22);

            try
            {
                return(ServerHandshake(serverHandshakeState, dtlsRecordLayer));
            }
            catch (TlsFatalAlert tlsFatalAlert)
            {
                dtlsRecordLayer.Fail(tlsFatalAlert.AlertDescription);
                throw tlsFatalAlert;
            }
            catch (IOException val)
            {
                IOException val2 = val;
                dtlsRecordLayer.Fail(80);
                throw val2;
            }
            catch (global::System.Exception alertCause)
            {
                dtlsRecordLayer.Fail(80);
                throw new TlsFatalAlert(80, alertCause);
            }
        }
コード例 #23
0
        public static async Task <int> ReceiveAsync(this DatagramTransport transport, byte[] buf, int off, int len)
        {
            SpinWait spinWait = new SpinWait();

            while (true)
            {
                int count = transport.Receive(buf, off, len, 0);
                if (count == -1)
                {
                    spinWait.SpinOnce();
                    await Task.Yield();
                }
                else
                {
                    Console.WriteLine(count);
                    return(count);
                }
            }
        }
コード例 #24
0
        public virtual DtlsTransport Accept(TlsServer server, DatagramTransport transport)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }
            if (transport == null)
            {
                throw new ArgumentNullException("transport");
            }
            SecurityParameters securityParameters = new SecurityParameters();

            securityParameters.entity = 0;
            DtlsServerProtocol.ServerHandshakeState serverHandshakeState = new DtlsServerProtocol.ServerHandshakeState();
            serverHandshakeState.server        = server;
            serverHandshakeState.serverContext = new TlsServerContextImpl(this.mSecureRandom, securityParameters);
            securityParameters.serverRandom    = TlsProtocol.CreateRandomBlock(server.ShouldUseGmtUnixTime(), serverHandshakeState.serverContext.NonceRandomGenerator);
            server.Init(serverHandshakeState.serverContext);
            DtlsRecordLayer dtlsRecordLayer = new DtlsRecordLayer(transport, serverHandshakeState.serverContext, server, 22);
            DtlsTransport   result;

            try
            {
                result = this.ServerHandshake(serverHandshakeState, dtlsRecordLayer);
            }
            catch (TlsFatalAlert tlsFatalAlert)
            {
                dtlsRecordLayer.Fail(tlsFatalAlert.AlertDescription);
                throw tlsFatalAlert;
            }
            catch (IOException ex)
            {
                dtlsRecordLayer.Fail(80);
                throw ex;
            }
            catch (Exception alertCause)
            {
                dtlsRecordLayer.Fail(80);
                throw new TlsFatalAlert(80, alertCause);
            }
            return(result);
        }
コード例 #25
0
        public void TestClientServer()
        {
            SecureRandom secureRandom = new SecureRandom();

            DtlsClientProtocol clientProtocol = new DtlsClientProtocol(secureRandom);
            DtlsServerProtocol serverProtocol = new DtlsServerProtocol(secureRandom);

            MockDatagramAssociation network = new MockDatagramAssociation(1500);

            Server server = new Server(serverProtocol, network.Server);

            Thread serverThread = new Thread(new ThreadStart(server.Run));

            serverThread.Start();

            DatagramTransport clientTransport = network.Client;

            clientTransport = new UnreliableDatagramTransport(clientTransport, secureRandom, 0, 0);

            clientTransport = new LoggingDatagramTransport(clientTransport, Console.Out);

            MockDtlsClient client = new MockDtlsClient(null);

            DtlsTransport dtlsClient = clientProtocol.Connect(client, clientTransport);

            for (int i = 1; i <= 10; ++i)
            {
                byte[] data = new byte[i];
                Arrays.Fill(data, (byte)i);
                dtlsClient.Send(data, 0, data.Length);
            }

            byte[] buf = new byte[dtlsClient.GetReceiveLimit()];
            while (dtlsClient.Receive(buf, 0, buf.Length, 100) >= 0)
            {
            }

            dtlsClient.Close();

            server.Shutdown(serverThread);
        }
コード例 #26
0
 public AssociationImpl(DatagramTransport transport, AssociationListener al) : base(transport, al)
 {
 }
コード例 #27
0
 /// <summary>
 /// Creates a new SCTP association with the remote peer.
 /// </summary>
 /// <param name="dtlsTransport">The DTLS transport to create the association on top of.</param>
 /// <param name="isClient">True if this peer will be the client within the association. This
 /// dictates whether streams created use odd or even ID's.</param>
 /// <param name="srcPort">The source port to use when forming the association.</param>
 /// <param name="dstPort">The destination port to use when forming the association.</param>
 public RTCPeerSctpAssociation(DatagramTransport dtlsTransport, bool isClient, int srcPort, int dstPort)
 {
     logger.LogDebug($"SCTP creating association is client {isClient} {srcPort}:{dstPort}.");
     _isClient        = isClient;
     _sctpAssociation = new ThreadedAssociation(dtlsTransport, this, isClient, srcPort, dstPort);
 }
コード例 #28
0
ファイル: MockAssociation.cs プロジェクト: sgf/SCTP
 public MockAssociation(DatagramTransport transport, AssociationListener al) : base(transport, al)
 {
 }
コード例 #29
0
 internal Server(DtlsTestCase outer, DtlsServerProtocol serverProtocol, DatagramTransport serverTransport, TlsTestServerImpl serverImpl)
 {
     this.mOuter = outer;
     this.mServerProtocol = serverProtocol;
     this.mServerTransport = serverTransport;
     this.mServerImpl = serverImpl;
 }
コード例 #30
0
 public static Task SendAsync(this DatagramTransport transport, byte[] buf, int off, int len)
 {
     return(Task.Run(() => transport.Send(buf, off, len)));
 }
コード例 #31
0
        public void RunTest(TlsTestConfig config)
        {
            CheckDtlsVersion(config.clientMinimumVersion);
            CheckDtlsVersion(config.clientOfferVersion);
            CheckDtlsVersion(config.serverMaximumVersion);
            CheckDtlsVersion(config.serverMinimumVersion);

            SecureRandom secureRandom = new SecureRandom();

            DtlsClientProtocol clientProtocol = new DtlsClientProtocol(secureRandom);
            DtlsServerProtocol serverProtocol = new DtlsServerProtocol(secureRandom);

            MockDatagramAssociation network = new MockDatagramAssociation(1500);

            TlsTestClientImpl clientImpl = new TlsTestClientImpl(config);
            TlsTestServerImpl serverImpl = new TlsTestServerImpl(config);

            Server server = new Server(this, serverProtocol, network.Server, serverImpl);

            Thread serverThread = new Thread(new ThreadStart(server.Run));

            serverThread.Start();

            Exception caught = null;

            try
            {
                DatagramTransport clientTransport = network.Client;

                if (TlsTestConfig.DEBUG)
                {
                    clientTransport = new LoggingDatagramTransport(clientTransport, Console.Out);
                }

                DtlsTransport dtlsClient = clientProtocol.Connect(clientImpl, clientTransport);

                for (int i = 1; i <= 10; ++i)
                {
                    byte[] data = new byte[i];
                    Arrays.Fill(data, (byte)i);
                    dtlsClient.Send(data, 0, data.Length);
                }

                byte[] buf = new byte[dtlsClient.GetReceiveLimit()];
                while (dtlsClient.Receive(buf, 0, buf.Length, 100) >= 0)
                {
                }

                dtlsClient.Close();
            }
            catch (Exception e)
            {
                caught = e;
                LogException(caught);
            }

            server.Shutdown(serverThread);

            // TODO Add checks that the various streams were closed

            Assert.AreEqual(config.expectFatalAlertConnectionEnd, clientImpl.FirstFatalAlertConnectionEnd, "Client fatal alert connection end");
            Assert.AreEqual(config.expectFatalAlertConnectionEnd, serverImpl.FirstFatalAlertConnectionEnd, "Server fatal alert connection end");

            Assert.AreEqual(config.expectFatalAlertDescription, clientImpl.FirstFatalAlertDescription, "Client fatal alert description");
            Assert.AreEqual(config.expectFatalAlertDescription, serverImpl.FirstFatalAlertDescription, "Server fatal alert description");

            if (config.expectFatalAlertConnectionEnd == -1)
            {
                Assert.IsNull(caught, "Unexpected client exception");
                Assert.IsNull(server.mCaught, "Unexpected server exception");
            }
        }
コード例 #32
0
ファイル: Association.cs プロジェクト: xljiulang/sipsorcery
 // default is server
 public Association(DatagramTransport transport, AssociationListener al, int srcPort, int dstPort) : this(transport, al, false, srcPort, dstPort)
 {
 }
コード例 #33
0
 internal Server(DtlsServerProtocol serverProtocol, DatagramTransport serverTransport)
 {
     this.mServerProtocol = serverProtocol;
     this.mServerTransport = serverTransport;
 }
コード例 #34
0
 public LoggingDatagramTransport(DatagramTransport transport, TextWriter output)
 {
     this.transport = transport;
     this.output = output;
     this.launchTimestamp = DateTimeUtilities.CurrentUnixMs();
 }
コード例 #35
0
 public AssociationImpl(DatagramTransport transport, AssociationListener al, bool client) : base(transport, al, client)
 {
 }
コード例 #36
0
 internal Server(DtlsServerProtocol serverProtocol, DatagramTransport serverTransport)
 {
     this.mServerProtocol  = serverProtocol;
     this.mServerTransport = serverTransport;
 }
コード例 #37
0
 public LoggingDatagramTransport(DatagramTransport transport, TextWriter output)
 {
     this.transport       = transport;
     this.output          = output;
     this.launchTimestamp = DateTimeUtilities.CurrentUnixMs();
 }