/* * Mentalis.org Security Library * * Copyright © 2002-2005, The KPD-Team * All rights reserved. * http://www.mentalis.org/ * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * - Neither the name of the KPD-Team, nor the names of its contributors * may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ using System; using System.Net; using System.Net.Sockets; using System.Collections; using System.Runtime.InteropServices; using Org.Mentalis.Security.Certificates; namespace Org.Mentalis.Security.Ssl { /// /// Represents the security options that should be used when connecting to a secure server, or when accepting secure connections. /// public class SecurityOptions : ICloneable { /// /// Initializes a new instance of the SecurityOptions class. /// /// One of the values. /// A instance. /// One of the values. /// One of the values. /// The delegate. /// The common name of the remote computer. This is usually a domain name. /// A bitwise combination of the values. /// A bitwise combination of the values. /// The delegate. public SecurityOptions(SecureProtocol protocol, Certificate cert, ConnectionEnd entity, CredentialVerification verifyType, CertVerifyEventHandler verifier, string commonName, SecurityFlags flags, SslAlgorithms allowed, CertRequestEventHandler requestHandler) { this.Protocol = protocol; this.Certificate = cert; this.Entity = entity; this.VerificationType = verifyType; this.Verifier = verifier; this.CommonName = commonName; this.Flags = flags; this.AllowedAlgorithms = allowed; this.RequestHandler = requestHandler; } /// /// Initializes a new instance of the SecurityOptions class. /// /// One of the values. /// A instance. /// One of the values. /// /// All other members of the structure will be instantiated with default values. /// public SecurityOptions(SecureProtocol protocol, Certificate cert, ConnectionEnd entity) : this(protocol, cert, entity, CredentialVerification.Auto, null, null, SecurityFlags.Default, SslAlgorithms.ALL, null) {} /// /// Initializes a new instance of the SecurityOptions structure. /// /// One of the values. /// /// All other members of the structure will be instantiated with default values. /// public SecurityOptions(SecureProtocol protocol) : this(protocol, null, ConnectionEnd.Client, CredentialVerification.Auto, null, null, SecurityFlags.Default, SslAlgorithms.ALL, null) {} /// /// Gets or sets the secure protocol that the should use. /// /// A bitwise combination of the values. public SecureProtocol Protocol { get { return m_Protocol; } set { m_Protocol = value; } } /// /// Gets or sets the that the should use. /// /// An instance of the Certificate class. public Certificate Certificate { get { return m_Certificate; } set { m_Certificate = value; } } /// /// Gets or sets a value that indicates whether the is a server or a client socket. /// /// One of the values. public ConnectionEnd Entity { get { return m_Entity; } set { m_Entity = value; } } /// /// Gets or sets a value that indicates how the will try to verify the peer . /// /// One of the values. public CredentialVerification VerificationType { get { return m_VerificationType; } set { m_VerificationType = value; } } /// /// Gets or sets a delegate that will be called when the receives the peer certificate. /// /// A delegate. /// This member will only be used if the is set to Manual. public CertVerifyEventHandler Verifier { get { return m_Verifier; } set { m_Verifier = value; } } /// /// Gets or sets a delegate that will be called when the receives a request for a client certificate. /// /// A delegate. /// This member will only be used if no is specified in the Certificate property of this class. public CertRequestEventHandler RequestHandler { get { return m_RequestHandler; } set { m_RequestHandler = value; } } /// /// Gets or sets the common name of the peer. /// /// A that holds the common name of the peer. This is usually a domain name. /// Servers that do not use client authentication should set this member to a null reference (Nothing in Visual Basic). public string CommonName { get { return m_CommonName; } set { m_CommonName = value; } } /// /// Gets or sets the security flags associated with the . /// /// A bitwise combination of the values. public SecurityFlags Flags { get { return m_Flags; } set { m_Flags = value; } } /// /// Gets or sets the list of algorithms that can be used to encrypt and compress data. /// /// A bitwise combination of the values. /// /// This member should always contain at least one encryption algorithm and one compression algorithm. /// Currently, the only defined compression algorithm is SslAlgorithms.NULL_COMPRESSION. /// The default setting for this member is SslAlgorithms.ALL. /// public SslAlgorithms AllowedAlgorithms { get { return m_AllowedAlgorithms; } set { m_AllowedAlgorithms = value; } } /// /// Creates a shallow copy of this object. /// /// A shallow copy of this object. public object Clone() { return new SecurityOptions(this.Protocol, this.Certificate, this.Entity, this.VerificationType, this.Verifier, this.CommonName, this.Flags, this.AllowedAlgorithms, this.RequestHandler); } /// One of the values. private SecureProtocol m_Protocol; /// A instance. private Certificate m_Certificate; /// One of the values. private ConnectionEnd m_Entity; /// One of the values. private CredentialVerification m_VerificationType; /// The delegate. private CertVerifyEventHandler m_Verifier; /// The delegate. private CertRequestEventHandler m_RequestHandler; /// The common name of the remote computer. This is usually a domain name. private string m_CommonName; /// A bitwise combination of the values. private SecurityFlags m_Flags; /// A bitwise combination of the values. private SslAlgorithms m_AllowedAlgorithms; } }