Example #1
0
 dispatch__(IceInternal.Incoming inc, Current current)
 {
     try
     {
         DispatchStatus status = dispatch(inc);
         if(status != DispatchStatus.DispatchAsync)
         {
             //
             // Make sure 'inc' owns the connection etc.
             //
             inc.killAsync();
         }
         return status;
     }
     catch(ResponseSentException)
     {
         return DispatchStatus.DispatchAsync;
     }
     catch(System.Exception)
     {
         try
         {
             inc.killAsync();
             throw;
         }
         catch(ResponseSentException)
         {
             return DispatchStatus.DispatchAsync;
         }
     }
 }
Example #2
0
 internal EndpointI(Instance instance, IceInternal.BasicStream s) :
     base(instance, s)
 {
     _instance = instance;
     _timeout = s.readInt();
     _compress = s.readBool();
 }
Example #3
0
        public int initialize(IceInternal.Buffer readBuffer, IceInternal.Buffer writeBuffer, ref bool hasMoreData)
        {
            int status = _stream.connect(readBuffer, writeBuffer, ref hasMoreData);
            if(status != IceInternal.SocketOperation.None)
            {
                return status;
            }

            _stream.setBlock(true); // SSL requires a blocking socket

            if(_sslStream == null)
            {
                NetworkStream ns = new NetworkStream(_stream.fd(), false);
                _sslStream = new SslStream(ns, false, new RemoteCertificateValidationCallback(validationCallback),
                                                      new LocalCertificateSelectionCallback(selectCertificate));
                return IceInternal.SocketOperation.Connect;
            }

            Debug.Assert(_sslStream.IsAuthenticated);
            _authenticated = true;
            _instance.verifyPeer((NativeConnectionInfo)getInfo(), _stream.fd(), _host);

            if(_instance.securityTraceLevel() >= 1)
            {
                _instance.traceStream(_sslStream, _stream.ToString());
            }
            return IceInternal.SocketOperation.None;
        }
Example #4
0
    public override int CompareTo(IceInternal.EndpointI obj)
    {
        EndpointI p = null;

        try
        {
            p = (EndpointI)obj;
        }
        catch(System.InvalidCastException)
        {
            try
            {
                return type() < obj.type() ? -1 : 1;
            }
            catch(System.InvalidCastException)
            {
                Debug.Assert(false);
            }
        }

        if(this == p)
        {
            return 0;
        }

        return _endpoint.CompareTo(p._endpoint);
    }
Example #5
0
        public bool startAccept(IceInternal.AsyncCallback callback, object state)
        {
            //
            // The plug-in may not be fully initialized.
            //
            if(!_instance.initialized())
            {
                Ice.PluginInitializationException ex = new Ice.PluginInitializationException();
                ex.reason = "IceSSL: plug-in is not initialized";
                throw ex;
            }

            try
            {
                _result = _fd.BeginAccept(delegate(IAsyncResult result)
                                          {
                                              if(!result.CompletedSynchronously)
                                              {
                                                  callback(result.AsyncState);
                                              }
                                          }, state);
                return _result.CompletedSynchronously;
            }
            catch(SocketException ex)
            {
                throw new Ice.SocketException(ex);
            }
        }
Example #6
0
 public override void streamWrite(IceInternal.BasicStream s)
 {
     s.startWriteEncaps();
     s.writeShort(_endpoint.type());
     _endpoint.streamWrite(s);
     s.endWriteEncaps();
 }
Example #7
0
    public void finishRead(IceInternal.Buffer buf)
    {
        _configuration.checkReadException();
        if(_buffered)
        {
            if(buf.b.hasRemaining())
            {
                _transceiver.finishRead(_readBuffer);

                int pos = _readBuffer.b.position();
                int requested = buf.b.remaining();
                int available = pos - _readBufferPos;
                if(available > 0)
                {
                    if(available >= requested)
                    {
                        available = requested;
                    }

                    byte[] arr = new byte[available];
                    _readBuffer.b.position(_readBufferPos);
                    _readBuffer.b.get(arr);
                    buf.b.put(arr);
                    _readBufferPos += available;
                    _readBuffer.b.position(pos);
                }
            }
        }
        else
        {
            _transceiver.finishRead(buf);
        }
    }
Example #8
0
 collocDispatch__(IceInternal.Direct request) 
 {
     //
     // Should only return DispatchOK or DispatchUserException
     //
     return dispatch(request);
 }
Example #9
0
 internal WSConnector(ProtocolInstance instance, IceInternal.Connector del, string host, string resource)
 {
     _instance = instance;
     _delegate = del;
     _host = host;
     _resource = resource;
 }
Example #10
0
 public bool startRead(IceInternal.Buffer buf, IceInternal.AsyncCallback callback, object state)
 {
     if(_configuration.readReady())
     {
         _configuration.checkReadException(); // Only raise if we're configured to read now.
     }
     return _transceiver.startRead(buf, callback, state);
 }
Example #11
0
    public IceInternal.EndpointI read(IceInternal.BasicStream s)
    {
        short type = s.readShort();
        Debug.Assert(type == _factory.type());

        s.startReadEncaps();
        IceInternal.EndpointI endpoint = new EndpointI(_factory.read(s));
        s.endReadEncaps();
        return endpoint;
    }
Example #12
0
    public int write(IceInternal.Buffer buf)
    {
        if(!_configuration.writeReady() && buf.b.hasRemaining())
        {
            return IceInternal.SocketOperation.Write;
        }

        _configuration.checkWriteException();
        return _transceiver.write(buf);
    }
Example #13
0
 //
 // Only for use by Connector, Acceptor
 //
 internal Transceiver(IceInternal.Transceiver transceiver)
 {
     _transceiver = transceiver;
     _configuration = Configuration.getInstance();
     _initialized = false;
     _readBuffer = new IceInternal.Buffer();
     _readBuffer.resize(1024 * 8, true); // 8KB buffer
     _readBuffer.b.position(0);
     _readBufferPos = 0;
     _buffered = _configuration.buffered();
 }
Example #14
0
 public bool startAccept(IceInternal.AsyncCallback callback, object state)
 {
     //
     // The plug-in may not be fully initialized.
     //
     if(!_instance.initialized())
     {
         Ice.PluginInitializationException ex = new Ice.PluginInitializationException();
         ex.reason = "IceSSL: plug-in is not initialized";
         throw ex;
     }
     return _delegate.startAccept(callback, state);
 }
Example #15
0
    public int read(IceInternal.Buffer buf, ref bool hasMoreData)
    {
        if(!_configuration.readReady() && buf.b.hasRemaining())
        {
            return IceInternal.SocketOperation.Read;
        }

        _configuration.checkReadException();

        if(_buffered)
        {
            while(buf.b.hasRemaining())
            {
                if(_readBufferPos == _readBuffer.b.position())
                {
                    _readBufferPos = 0;
                    _readBuffer.b.position(0);
                    _transceiver.read(_readBuffer, ref hasMoreData);
                    if(_readBufferPos == _readBuffer.b.position())
                    {
                        hasMoreData = false;
                        return IceInternal.SocketOperation.Read;
                    }
                }

                int pos = _readBuffer.b.position();
                Debug.Assert(pos > _readBufferPos);
                int requested = buf.b.remaining();
                int available = pos - _readBufferPos;
                Debug.Assert(available > 0);
                if(available >= requested)
                {
                    available = requested;
                }

                byte[] arr = new byte[available];
                _readBuffer.b.position(_readBufferPos);
                _readBuffer.b.get(arr);
                buf.b.put(arr);
                _readBufferPos += available;
                _readBuffer.b.position(pos);
            }
            hasMoreData = _readBufferPos < _readBuffer.b.position();
            return IceInternal.SocketOperation.None;
        }
        else
        {
            return _transceiver.read(buf, ref hasMoreData);
        }
    }
Example #16
0
 public int initialize(IceInternal.Buffer readBuffer, IceInternal.Buffer writeBuffer, ref bool hasMoreData)
 {
     _configuration.checkInitializeException();
     if(!_initialized)
     {
         int status = _transceiver.initialize(readBuffer, writeBuffer, ref hasMoreData);
         if(status != IceInternal.SocketOperation.None)
         {
             return status;
         }
         _initialized = true;
     }
     return IceInternal.SocketOperation.None;
 }
Example #17
0
 public static void write(IceInternal.BasicStream os__, MCS.GuiHub.PushData[] v__)
 {
     if(v__ == null)
     {
         os__.writeSize(0);
     }
     else
     {
         os__.writeSize(v__.Length);
         for(int ix__ = 0; ix__ < v__.Length; ++ix__)
         {
             os__.writeByte((byte)v__[ix__], 10);
         }
     }
 }
Example #18
0
    public bool read(IceInternal.Buffer buf)
    {
        if(!_initialized)
        {
            throw new Ice.SocketException();
        }

        if(!_configuration.readReady())
        {
            return false;
        }

        _configuration.checkReadException();
        return _transceiver.read(buf);
    }
Example #19
0
        //
        // Only for use by EndpointI.
        //
        internal ConnectorI(Instance instance, string host, EndPoint addr, IceInternal.NetworkProxy proxy, int timeout, 
                            string conId)
        {
            _instance = instance;
            _host = host;
            _logger = instance.communicator().getLogger();
            _addr = (IPEndPoint)addr;
            _proxy = proxy; 
            _timeout = timeout;
            _connectionId = conId;

            _hashCode = 5381;
            IceInternal.HashUtil.hashAdd(ref _hashCode, _addr);
            IceInternal.HashUtil.hashAdd(ref _hashCode, _timeout);
            IceInternal.HashUtil.hashAdd(ref _hashCode, _connectionId);
        }
Example #20
0
        internal AcceptorI(EndpointI endpoint, Instance instance, IceInternal.Acceptor del, string adapterName)
        {
            _endpoint = endpoint;
            _delegate = del;
            _instance = instance;
            _adapterName = adapterName;

            //
            // .NET requires that a certificate be supplied.
            //
            if(instance.certs().Count == 0)
            {
                Ice.SecurityException ex = new Ice.SecurityException();
                ex.reason = "IceSSL: certificate required for server endpoint";
                throw ex;
            }
        }
Example #21
0
        internal int isCompleteMessage(IceInternal.ByteBuffer buf, int begin, int end)
        {
            byte[] raw = buf.rawBytes();
            int p = begin;

            //
            // Skip any leading CR-LF characters.
            //
            while(p < end)
            {
                byte ch = raw[p];
                if(ch != (byte)'\r' && ch != (byte)'\n')
                {
                    break;
                }
                ++p;
            }

            //
            // Look for adjacent CR-LF/CR-LF or LF/LF.
            //
            bool seenFirst = false;
            while(p < end)
            {
                byte ch = raw[p++];
                if(ch == (byte)'\n')
                {
                    if(seenFirst)
                    {
                        return p;
                    }
                    else
                    {
                        seenFirst = true;
                    }
                }
                else if(ch != (byte)'\r')
                {
                    seenFirst = false;
                }
            }

            return -1;
        }
Example #22
0
 internal SSLEngine(IceInternal.ProtocolPluginFacade facade)
 {
     _communicator = facade.getCommunicator();
     _logger = _communicator.getLogger();
     _facade = facade;
     _securityTraceLevel = _communicator.getProperties().getPropertyAsIntWithDefault("IceSSL.Trace.Security", 0);
     _securityTraceCategory = "Security";
     _initialized = false;
     _trustManager = new TrustManager(_communicator);
     _tls12Support = false;
     try
     {
         Enum.Parse(typeof(System.Security.Authentication.SslProtocols), "Tls12");
         _tls12Support = true;
     }
     catch(Exception)
     {
     }
 }
Example #23
0
        //
        // Only for use by EndpointI.
        //
        internal ConnectorI(Instance instance, string host, EndPoint addr, IceInternal.NetworkProxy proxy,
                            EndPoint sourceAddr, int timeout, string conId)
        {
            _instance = instance;
            _host = host;
            _addr = (IPEndPoint)addr;
            _proxy = proxy;
            _sourceAddr = sourceAddr;
            _timeout = timeout;
            _connectionId = conId;

            _hashCode = 5381;
            IceInternal.HashUtil.hashAdd(ref _hashCode, _addr);
            if(_sourceAddr != null)
            {
                IceInternal.HashUtil.hashAdd(ref _hashCode, _sourceAddr);
            }
            IceInternal.HashUtil.hashAdd(ref _hashCode, _timeout);
            IceInternal.HashUtil.hashAdd(ref _hashCode, _connectionId);
        }
Example #24
0
        //
        // Only for use by ConnectorI, AcceptorI.
        //
        internal TransceiverI(Instance instance, IceInternal.StreamSocket stream, string hostOrAdapterName, bool incoming)
        {
            _instance = instance;
            _stream = stream;
            _incoming = incoming;
            if(_incoming)
            {
                _adapterName = hostOrAdapterName;
            }
            else
            {
                _host = hostOrAdapterName;
            }
            _sslStream = null;

            _verifyPeer = _instance.properties().getPropertyAsIntWithDefault("IceSSL.VerifyPeer", 2);

            _chain = new X509Chain(_instance.engine().useMachineContext());

            if(_instance.checkCRL() == 0)
            {
                _chain.ChainPolicy.RevocationMode = X509RevocationMode.NoCheck;
            }

            X509Certificate2Collection caCerts = _instance.engine().caCerts();
            if(caCerts != null)
            {
            #if !UNITY
                //
                // We need to set this flag to be able to use a certificate authority from the extra store.
                //
                _chain.ChainPolicy.VerificationFlags = X509VerificationFlags.AllowUnknownCertificateAuthority;
            #endif
                foreach(X509Certificate2 cert in caCerts)
                {
                    _chain.ChainPolicy.ExtraStore.Add(cert);
                }
            }
        }
Example #25
0
 protected override IceInternal.Connector createConnector(EndPoint addr, IceInternal.NetworkProxy proxy)
 {
     return new ConnectorI(_instance, host_, addr, proxy, sourceAddr_, _timeout, connectionId_);
 }
Example #26
0
 public IceInternal.EndpointFactory clone(IceInternal.ProtocolInstance instance)
 {
     return new EndpointFactoryI(new Instance(_instance.engine(), instance.type(), instance.protocol()));
 }
Example #27
0
        //
        // Compare endpoints for sorting purposes
        //
        public override int CompareTo(IceInternal.EndpointI obj)
        {
            if(!(obj is EndpointI))
            {
                return type() < obj.type() ? -1 : 1;
            }

            EndpointI p = (EndpointI)obj;
            if(this == p)
            {
                return 0;
            }

            if(_timeout < p._timeout)
            {
                return -1;
            }
            else if(p._timeout < _timeout)
            {
                return 1;
            }

            if(!_compress && p._compress)
            {
                return -1;
            }
            else if(!p._compress && _compress)
            {
                return 1;
            }

            return base.CompareTo(p);
        }
Example #28
0
        private bool beginAuthenticate(IceInternal.AsyncCallback callback, object state)
        {
            NetworkStream ns = new NetworkStream(_fd, true);
            _stream = new SslStream(ns, false, new RemoteCertificateValidationCallback(validationCallback), null);

            try
            {
                if(_adapterName == null)
                {
                    //
                    // Client authentication.
                    //
                    _writeResult = _stream.BeginAuthenticateAsClient(_host, _instance.certs(),
                                                                     _instance.protocols(),
                                                                     _instance.checkCRL() > 0,
                                                                     delegate(IAsyncResult result)
                                                                     {
                                                                         if(!result.CompletedSynchronously)
                                                                         {
                                                                             callback(result.AsyncState);
                                                                         }
                                                                     }, state);
                }
                else
                {
                    //
                    // Server authentication.
                    //
                    // Get the certificate collection and select the first one.
                    //
                    X509Certificate2Collection certs = _instance.certs();
                    X509Certificate2 cert = null;
                    if(certs.Count > 0)
                    {
                        cert = certs[0];
                    }

                    _writeResult = _stream.BeginAuthenticateAsServer(cert, _verifyPeer > 1, _instance.protocols(),
                                                                     _instance.checkCRL() > 0, 
                                                                     delegate(IAsyncResult result)
                                                                     {
                                                                         if(!result.CompletedSynchronously)
                                                                         {
                                                                             callback(result.AsyncState);
                                                                         }
                                                                     }, state);
                }
            }
            catch(IOException ex)
            {
                if(IceInternal.Network.connectionLost(ex))
                {
                    //
                    // This situation occurs when connectToSelf is called; the "remote" end
                    // closes the socket immediately.
                    //
                    throw new Ice.ConnectionLostException();
                }
                throw new Ice.SocketException(ex);
            }
            catch(AuthenticationException ex)
            {
                Ice.SecurityException e = new Ice.SecurityException(ex);
                e.reason = ex.Message;
                throw e;
            }
            catch(Exception ex)
            {
                throw new Ice.SyscallException(ex);
            }

            Debug.Assert(_writeResult != null);
            return _writeResult.CompletedSynchronously;
        }
Example #29
0
 public void checkSendSize(IceInternal.Buffer buf, int messageSizeMax)
 {
     if(buf.size() > messageSizeMax)
     {
         IceInternal.Ex.throwMemoryLimitException(buf.size(), messageSizeMax);
     }
 }
Example #30
0
        public void finishWrite(IceInternal.Buffer buf)
        {
            if(_fd == null) // Transceiver was closed
            {
                if(buf.size() - buf.b.position() < _maxSendPacketSize)
                {
                    buf.b.position(buf.size()); // Assume all the data was sent for at-most-once semantics.
                }
                _writeResult = null;
                return; 
            }
            
            if(_state < StateConnected)
            {
                return;
            }

            Debug.Assert(_fd != null && _writeResult != null);

            try
            {
                _stream.EndWrite(_writeResult);
                _writeResult = null;

                int packetSize = buf.b.remaining();
                if(_maxSendPacketSize > 0 && packetSize > _maxSendPacketSize)
                {
                    packetSize = _maxSendPacketSize;
                }

                if(_instance.networkTraceLevel() >= 3)
                {
                    string s = "sent " + packetSize + " of " + packetSize + " bytes via ssl\n" + ToString();
                    _logger.trace(_instance.networkTraceCategory(), s);
                }

                if(_stats != null)
                {
#pragma warning disable 618
                    _stats.bytesSent(type(), packetSize);
#pragma warning restore 618
                }

                buf.b.position(buf.b.position() + packetSize);
            }
            catch(IOException ex)
            {
                if(IceInternal.Network.connectionLost(ex))
                {
                    throw new Ice.ConnectionLostException(ex);
                }
                if(IceInternal.Network.timeout(ex))
                {
                    throw new Ice.TimeoutException();
                }
                throw new Ice.SocketException(ex);
            }
            catch(Ice.LocalException)
            {
                throw;
            }
            catch(ObjectDisposedException ex)
            {
                throw new Ice.ConnectionLostException(ex);
            }
            catch(Exception ex)
            {
                throw new Ice.SyscallException(ex);
            }
        }