public bool StartRead(ref ArraySegment <byte> buffer, ref int offset, IceInternal.AsyncCallback callback, object state) { if (!_isConnected) { return(_delegate.StartRead(ref buffer, ref offset, callback, state)); } Debug.Assert(_sslStream != null && _sslStream.IsAuthenticated); int packetSize = GetRecvPacketSize(buffer.Count - offset); try { _readCallback = callback; _readResult = _sslStream.BeginRead(buffer.Array, buffer.Offset + offset, packetSize, ReadCompleted, state); return(_readResult.CompletedSynchronously); } catch (IOException ex) { if (IceInternal.Network.ConnectionLost(ex)) { throw new ConnectionLostException(ex); } if (IceInternal.Network.Timeout(ex)) { throw new Ice.ConnectionTimeoutException(); } throw new Ice.TransportException(ex); } catch (ObjectDisposedException ex) { throw new ConnectionLostException(ex); } }
private bool StartAuthenticate(IceInternal.AsyncCallback callback, object state) { Debug.Assert(_sslStream != null); try { _writeCallback = callback; if (!_incoming) { // // Client authentication. // _writeResult = _sslStream.BeginAuthenticateAsClient(_host, _instance.Certs(), _instance.Protocols(), _instance.CheckCRL() > 0, WriteCompleted, state); } else { // // Server authentication. // // Get the certificate collection and select the first one. // X509Certificate2Collection?certs = _instance.Certs(); X509Certificate2? cert = null; if (certs != null && certs.Count > 0) { cert = certs[0]; } _writeResult = _sslStream.BeginAuthenticateAsServer(cert, _verifyPeer > 0, _instance.Protocols(), _instance.CheckCRL() > 0, WriteCompleted, 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.TransportException(ex); } catch (AuthenticationException ex) { throw new Ice.SecurityException(ex); } Debug.Assert(_writeResult != null); return(_writeResult.CompletedSynchronously); }
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); } }
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)); }
public bool startRead(IceInternal.Buffer buf, IceInternal.AsyncCallback callback, object state) { Debug.Assert(_fd != null); if (_state == StateProxyConnectRequestPending) { _proxy.beginReadConnectRequestResponse(buf); } int packetSize = buf.b.remaining(); if (_maxReceivePacketSize > 0 && packetSize > _maxReceivePacketSize) { packetSize = _maxReceivePacketSize; } try { _readCallback = callback; if (_stream != null) { _readResult = _stream.BeginRead(buf.b.rawBytes(), buf.b.position(), packetSize, readCompleted, state); } else { _readResult = _fd.BeginReceive(buf.b.rawBytes(), buf.b.position(), packetSize, SocketFlags.None, readCompleted, state); } return(_readResult.CompletedSynchronously); } 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); } }
public bool StartAccept(IceInternal.AsyncCallback callback, object state) { // // The plug-in may not be fully initialized. // if (!_instance.Initialized()) { throw new Ice.InitializationException("IceSSL: plug-in is not initialized"); } return(_delegate.StartAccept(callback, state)); }
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)); }
StartWrite(IList <ArraySegment <byte> > buffer, int offset, IceInternal.AsyncCallback cb, object state, out bool completed) { if (!_isConnected) { return(_delegate.StartWrite(buffer, offset, cb, state, out completed)); } else if (_sslStream == null) { throw new ConnectionLostException(); } Debug.Assert(_sslStream != null); if (!_authenticated) { completed = false; return(StartAuthenticate(cb, state)); } // // We limit the packet size for beingWrite to ensure connection timeouts are based // on a fixed packet size. // int remaining = buffer.GetByteCount() - offset; int packetSize = GetSendPacketSize(remaining); try { _writeCallback = cb; ArraySegment <byte> data = buffer.GetSegment(offset, packetSize); _writeResult = _sslStream.BeginWrite(data.Array, 0, data.Count, WriteCompleted, state); completed = packetSize == remaining; return(_writeResult.CompletedSynchronously); } catch (IOException ex) { if (IceInternal.Network.ConnectionLost(ex)) { throw new ConnectionLostException(ex); } if (IceInternal.Network.Timeout(ex)) { throw new Ice.ConnectionTimeoutException(); } throw new Ice.TransportException(ex); } catch (ObjectDisposedException ex) { throw new Ice.ConnectionLostException(ex); } }
public bool startWrite(IceInternal.Buffer buf, IceInternal.AsyncCallback callback, object state, out bool completed) { if (!_stream.isConnected()) { return(_stream.startWrite(buf, callback, state, out completed)); } Debug.Assert(_sslStream != null); if (!_authenticated) { completed = false; return(startAuthenticate(callback, state)); } // // We limit the packet size for beingWrite to ensure connection timeouts are based // on a fixed packet size. // int packetSize = _stream.getSendPacketSize(buf.b.remaining()); try { _writeCallback = callback; _writeResult = _sslStream.BeginWrite(buf.b.rawBytes(), buf.b.position(), packetSize, writeCompleted, state); completed = packetSize == buf.b.remaining(); return(_writeResult.CompletedSynchronously); } 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 (ObjectDisposedException ex) { throw new Ice.ConnectionLostException(ex); } catch (Exception ex) { throw new Ice.SyscallException(ex); } }
public bool startWrite(IceInternal.Buffer buf, IceInternal.AsyncCallback cb, object state, out bool completed) { if (!_isConnected) { return(_delegate.startWrite(buf, cb, state, out completed)); } Debug.Assert(_sslStream != null); if (!_authenticated) { completed = false; return(startAuthenticate(cb, state)); } // // We limit the packet size for beingWrite to ensure connection timeouts are based // on a fixed packet size. // int packetSize = getSendPacketSize(buf.b.remaining()); try { _writeResult = _sslStream.WriteAsync(buf.b.rawBytes(), buf.b.position(), packetSize); _writeResult.ContinueWith(task => cb(state), TaskScheduler.Default); completed = packetSize == buf.b.remaining(); return(false); } 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 (ObjectDisposedException ex) { throw new Ice.ConnectionLostException(ex); } catch (Exception ex) { throw new Ice.SyscallException(ex); } }
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. } if (_buffered) { int pos = _readBuffer.b.position(); int available = pos - _readBufferPos; if (available > 0) { int requested = buf.b.remaining(); 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); } if (_readBufferPos == _readBuffer.b.position() && buf.b.hasRemaining()) { _readBufferPos = 0; _readBuffer.b.position(0); return(_transceiver.startRead(_readBuffer, callback, state)); } else { Debug.Assert(!buf.b.hasRemaining()); return(true); // Completed synchronously } } else { return(_transceiver.startRead(buf, callback, state)); } }
public bool StartRead(ref ArraySegment <byte> buffer, ref int offset, IceInternal.AsyncCallback callback, object state) { if (_configuration.readReady()) { _configuration.checkReadException(); // Only raise if we're configured to read now. } if (_buffered) { int available = _readBufferOffset - _readBufferPos; if (available > 0) { int requested = buffer.Count - offset; if (available >= requested) { available = requested; } _readBuffer.Slice(_readBufferPos, available).CopyTo(buffer.Slice(offset)); offset += available; _readBufferPos += available; } if (_readBufferPos == _readBufferOffset && offset < buffer.Count) { _readBufferPos = 0; _readBufferOffset = 0; return(_transceiver.StartRead(ref _readBuffer, ref _readBufferOffset, callback, state)); } else { Debug.Assert(offset == buffer.Count); return(true); // Completed synchronously } } else { return(_transceiver.StartRead(ref buffer, ref offset, callback, state)); } }
public bool startRead(IceInternal.Buffer buf, IceInternal.AsyncCallback callback, object state) { if (!_isConnected) { return(_delegate.startRead(buf, callback, state)); } Debug.Assert(_sslStream != null && _sslStream.IsAuthenticated); int packetSz = getRecvPacketSize(buf.b.remaining()); try { _readCallback = callback; _readResult = _sslStream.BeginRead(buf.b.rawBytes(), buf.b.position(), packetSz, readCompleted, state); return(_readResult.CompletedSynchronously); } 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 (ObjectDisposedException ex) { throw new Ice.ConnectionLostException(ex); } catch (Exception ex) { throw new Ice.SyscallException(ex); } }
public bool startRead(IceInternal.Buffer buf, IceInternal.AsyncCallback callback, object state) { if (!_isConnected) { return(_delegate.startRead(buf, callback, state)); } Debug.Assert(_sslStream != null && _sslStream.IsAuthenticated); int packetSz = getRecvPacketSize(buf.b.remaining()); try { _readResult = _sslStream.ReadAsync(buf.b.rawBytes(), buf.b.position(), packetSz); _readResult.ContinueWith(task => callback(state), TaskScheduler.Default); return(false); } 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 (ObjectDisposedException ex) { throw new Ice.ConnectionLostException(ex); } catch (Exception ex) { throw new Ice.SyscallException(ex); } }
private bool startAuthenticate(IceInternal.AsyncCallback callback, object state) { try { _writeCallback = callback; if (!_incoming) { // // Client authentication. // _writeResult = _sslStream.BeginAuthenticateAsClient(_host, _instance.certs(), _instance.protocols(), _instance.checkCRL() > 0, writeCompleted, state); } else { #if UNITY throw new Ice.FeatureNotSupportedException("ssl server socket"); #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 = _sslStream.BeginAuthenticateAsServer(cert, _verifyPeer > 0, _instance.protocols(), _instance.checkCRL() > 0, writeCompleted, state); #endif } } 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); } #if !UNITY catch (AuthenticationException ex) { Ice.SecurityException e = new Ice.SecurityException(ex); e.reason = ex.Message; throw e; } #endif catch (Exception ex) { throw new Ice.SyscallException(ex); } Debug.Assert(_writeResult != null); return(_writeResult.CompletedSynchronously); }
public bool startAccept(IceInternal.AsyncCallback callback, object state) { return(_acceptor.startAccept(callback, state)); }
public bool StartWrite(IList <ArraySegment <byte> > buf, int offset, IceInternal.AsyncCallback callback, object state, out bool completed) { _configuration.checkWriteException(); return(_transceiver.StartWrite(buf, offset, callback, state, out completed)); }
public bool startWrite(IceInternal.Buffer buf, IceInternal.AsyncCallback callback, object state, out bool completed) { _configuration.checkWriteException(); return(_transceiver.startWrite(buf, callback, state, out completed)); }
private bool startAuthenticate(IceInternal.AsyncCallback callback, object state) { try { _writeCallback = callback; if(!_incoming) { // // Client authentication. // _writeResult = _sslStream.BeginAuthenticateAsClient(_host, _instance.certs(), _instance.protocols(), _instance.checkCRL() > 0, writeCompleted, state); } else { #if UNITY throw new Ice.FeatureNotSupportedException("ssl server socket"); #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 = _sslStream.BeginAuthenticateAsServer(cert, _verifyPeer > 0, _instance.protocols(), _instance.checkCRL() > 0, writeCompleted, state); #endif } } 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); } #if !UNITY catch(AuthenticationException ex) { Ice.SecurityException e = new Ice.SecurityException(ex); e.reason = ex.Message; throw e; } #endif catch(Exception ex) { throw new Ice.SyscallException(ex); } Debug.Assert(_writeResult != null); return _writeResult.CompletedSynchronously; }
public bool startWrite(IceInternal.Buffer buf, IceInternal.AsyncCallback callback, object state, out bool completed) { if(!_stream.isConnected()) { return _stream.startWrite(buf, callback, state, out completed); } Debug.Assert(_sslStream != null); if(!_authenticated) { completed = false; return startAuthenticate(callback, state); } // // We limit the packet size for beingWrite to ensure connection timeouts are based // on a fixed packet size. // int packetSize = _stream.getSendPacketSize(buf.b.remaining()); try { _writeCallback = callback; _writeResult = _sslStream.BeginWrite(buf.b.rawBytes(), buf.b.position(), packetSize, writeCompleted, state); completed = packetSize == buf.b.remaining(); return _writeResult.CompletedSynchronously; } 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(ObjectDisposedException ex) { throw new Ice.ConnectionLostException(ex); } catch(Exception ex) { throw new Ice.SyscallException(ex); } }
public bool startRead(IceInternal.Buffer buf, IceInternal.AsyncCallback callback, object state) { if(!_stream.isConnected()) { return _stream.startRead(buf, callback, state); } Debug.Assert(_sslStream != null && _sslStream.IsAuthenticated); int packetSz = _stream.getRecvPacketSize(buf.b.remaining()); try { _readCallback = callback; _readResult = _sslStream.BeginRead(buf.b.rawBytes(), buf.b.position(), packetSz, readCompleted, state); return _readResult.CompletedSynchronously; } 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(ObjectDisposedException ex) { throw new Ice.ConnectionLostException(ex); } catch(Exception ex) { throw new Ice.SyscallException(ex); } }
public bool startWrite(IceInternal.Buffer buf, IceInternal.AsyncCallback callback, object state, out bool completed) { Debug.Assert(_fd != null); if (_state < StateConnected) { completed = false; if (_state == StateConnectPending) { try { EndPoint addr = _proxy != null?_proxy.getAddress() : _addr; _writeResult = IceInternal.Network.doConnectAsync(_fd, addr, callback, state); return(_writeResult.CompletedSynchronously); } catch (Exception ex) { throw new Ice.SocketException(ex); } } else if (_state == StateProxyConnectRequest) { _proxy.beginWriteConnectRequest(_addr, buf); } else if (_state == StateAuthenticatePending) { return(beginAuthenticate(callback, state)); } } // // We limit the packet size for beingWrite to ensure connection timeouts are based // on a fixed packet size. // int packetSize = buf.b.remaining(); if (_maxSendPacketSize > 0 && packetSize > _maxSendPacketSize) { packetSize = _maxSendPacketSize; } try { _writeCallback = callback; if (_stream != null) { _writeResult = _stream.BeginWrite(buf.b.rawBytes(), buf.b.position(), packetSize, writeCompleted, state); } else { _writeResult = _fd.BeginSend(buf.b.rawBytes(), buf.b.position(), packetSize, SocketFlags.None, writeCompleted, state); } completed = packetSize == buf.b.remaining(); return(_writeResult.CompletedSynchronously); } 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); } }
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); }
private bool startAuthenticate(IceInternal.AsyncCallback callback, object state) { try { if (!_incoming) { // // Client authentication. // _writeResult = _sslStream.AuthenticateAsClientAsync(_host, _instance.certs(), _instance.protocols(), _instance.checkCRL() > 0); _writeResult.ContinueWith(task => callback(state), TaskScheduler.Default); } 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 = _sslStream.AuthenticateAsServerAsync(cert, _verifyPeer > 0, _instance.protocols(), _instance.checkCRL() > 0); _writeResult.ContinueWith(task => callback(state), TaskScheduler.Default); } } 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(false); }