Org.Mentalis.Security.Ssl.SecureSocket.ChangeSecurityProtocol C# (CSharp) Method

ChangeSecurityProtocol() public method

Changes the security protocol. This method can only be used to 'upgrade' a connection from no-security to either SSL or TLS.
Programs should only call this method if there is no active Connect, Accept, Send or Receive!
An error occurs while changing the security protocol.
public ChangeSecurityProtocol ( Org.Mentalis.Security.Ssl.SecurityOptions options ) : void
options Org.Mentalis.Security.Ssl.SecurityOptions The new parameters.
return void
		public void ChangeSecurityProtocol(SecurityOptions options) {
			if (options == null)
				throw new ArgumentNullException();
			if (m_Options != null && m_Options.Protocol != SecureProtocol.None)
				throw new ArgumentException("Only changing from a normal connection to a secure connection is supported.");
			if (base.ProtocolType != ProtocolType.Tcp && options.Protocol != SecureProtocol.None)
				throw new SecurityException("Security protocols require underlying TCP connections!");
			// check SecurityOptions structure
			if (options.Protocol != SecureProtocol.None) {
				if (options.Entity == ConnectionEnd.Server && options.Certificate == null)
					throw new ArgumentException("The certificate cannot be set to a null reference when creating a server socket.");
				if (options.Certificate != null && !options.Certificate.HasPrivateKey())
					throw new ArgumentException("If a certificate is specified, it must have a private key.");
				if (((int)options.AllowedAlgorithms & (int)SslAlgorithms.NULL_COMPRESSION) == 0)
					throw new ArgumentException("The allowed algorithms field must contain at least one compression algorithm.");
				if (((int)options.AllowedAlgorithms ^ (int)SslAlgorithms.NULL_COMPRESSION) == 0)
					throw new ArgumentException("The allowed algorithms field must contain at least one cipher suite.");
				if (options.VerificationType == CredentialVerification.Manual && options.Verifier == null)
					throw new ArgumentException("A CertVerifyEventHandler is required when using manual certificate verification.");
			}
			m_Options = (SecurityOptions)options.Clone();
			if (options.Protocol != SecureProtocol.None) {
				if (this.Connected)
					m_Controller = new SocketController(this, base.InternalSocket, options);
			}
		}
		/// <summary>

Usage Example

 /// <summary>
 /// Changes the security protocol. This method can only be used to 'upgrade' a connection from no-security to either SSL or TLS.
 /// </summary>
 /// <param name="options">The new <see cref="SecurityOptions"/> parameters.</param>
 /// <exception cref="SecurityException">An error occurs while changing the security protocol.</exception>
 /// <remarks>
 /// Programs should only call this method if there is no active <see cref="Read"/> or <see cref="Write"/>!
 /// </remarks>
 public void ChangeSecurityProtocol(SecurityOptions options)
 {
     Socket.ChangeSecurityProtocol(options);
 }
All Usage Examples Of Org.Mentalis.Security.Ssl.SecureSocket::ChangeSecurityProtocol