Fail() private method

private Fail ( byte alertDescription ) : void
alertDescription byte
return void
Esempio n. 1
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);
            }
        }
        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);
            }
        }
Esempio n. 3
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);
        }
        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)
            {
                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);
            }
        }
        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)
            {
                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);
            }
        }
Esempio n. 6
0
        public virtual int Receive(byte[] buf, int off, int len, int waitMillis)
        {
            if (null == buf)
            {
                throw new ArgumentNullException("buf");
            }
            if (off < 0 || off >= buf.Length)
            {
                throw new ArgumentException("invalid offset: " + off, "off");
            }
            if (len < 0 || len > buf.Length - off)
            {
                throw new ArgumentException("invalid length: " + len, "len");
            }
            if (waitMillis < 0)
            {
                throw new ArgumentException("cannot be negative", "waitMillis");
            }

            try
            {
                return(mRecordLayer.Receive(buf, off, len, waitMillis));
            }
            catch (TlsFatalAlert fatalAlert)
            {
                mRecordLayer.Fail(fatalAlert.AlertDescription);
                throw fatalAlert;
            }
            catch (TlsTimeoutException e)
            {
                throw e;
            }
#if !PORTABLE || DOTNET
            catch (SocketException e)
            {
                if (TlsUtilities.IsTimeout(e))
                {
                    throw e;
                }

                mRecordLayer.Fail(AlertDescription.internal_error);
                throw new TlsFatalAlert(AlertDescription.internal_error, e);
            }
#endif
            //catch (InterruptedIOException e)
            //{
            //    throw e;
            //}
            catch (IOException e)
            {
                mRecordLayer.Fail(AlertDescription.internal_error);
                throw e;
            }
            catch (Exception e)
            {
                mRecordLayer.Fail(AlertDescription.internal_error);
                throw new TlsFatalAlert(AlertDescription.internal_error, e);
            }
        }
        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);
            }
        }
        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)
            {
                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);
            }
        }
Esempio n. 9
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);
        }
Esempio n. 10
0
 public virtual int Receive(byte[] buf, int off, int len, int waitMillis)
 {
     try
     {
         return(mRecordLayer.Receive(buf, off, len, waitMillis));
     }
     catch (TlsFatalAlert fatalAlert)
     {
         mRecordLayer.Fail(fatalAlert.AlertDescription);
         throw fatalAlert;
     }
     catch (IOException e)
     {
         mRecordLayer.Fail(AlertDescription.internal_error);
         throw e;
     }
     catch (Exception e)
     {
         mRecordLayer.Fail(AlertDescription.internal_error);
         throw new TlsFatalAlert(AlertDescription.internal_error, e);
     }
 }
Esempio n. 11
0
 public virtual int Receive(byte[] buf, int off, int len, int waitMillis)
 {
     //IL_0028: Expected O, but got Unknown
     try
     {
         return(mRecordLayer.Receive(buf, off, len, waitMillis));
     }
     catch (TlsFatalAlert tlsFatalAlert)
     {
         mRecordLayer.Fail(tlsFatalAlert.AlertDescription);
         throw tlsFatalAlert;
     }
     catch (IOException val)
     {
         IOException val2 = val;
         mRecordLayer.Fail(80);
         throw val2;
     }
     catch (global::System.Exception alertCause)
     {
         mRecordLayer.Fail(80);
         throw new TlsFatalAlert(80, alertCause);
     }
 }
Esempio n. 12
0
 internal virtual void AbortServerHandshake(ServerHandshakeState state, DtlsRecordLayer recordLayer, byte alertDescription)
 {
     recordLayer.Fail(alertDescription);
     InvalidateSession(state);
 }
Esempio n. 13
0
 internal virtual void AbortServerHandshake(ServerHandshakeState state, DtlsRecordLayer recordLayer, byte alertDescription)
 {
     recordLayer.Fail(alertDescription);
     InvalidateSession(state);
 }