using System; using System.IO; using System.Security.Authentication; using System.Security.Cryptography.X509Certificates; using Mono.Security.Protocol.Tls; namespace System.Net.Security { /// Provides a stream used for client-server communication that uses the Secure Socket Layer (SSL) security protocol to authenticate the server and optionally the client. // Token: 0x020001D7 RID: 471 [global::System.MonoTODO("Non-X509Certificate2 certificate is not supported")] public class SslStream : AuthenticatedStream { /// Initializes a new instance of the class using the specified . /// A object used by the for sending and receiving data. /// /// is not readable.-or- is not writable. /// /// is null.-or- is equal to . // Token: 0x06000F1D RID: 3869 RVA: 0x00029A14 File Offset: 0x00027C14 public SslStream(Stream innerStream) : this(innerStream, false) { } /// Initializes a new instance of the class using the specified and stream closure behavior. /// Initializes a new instance of the class using the specified and stream closure behavior. /// Initializes a new instance of the class using the specified and stream closure behavior. /// /// is not readable.-or- is not writable. /// /// is null.-or- is equal to . // Token: 0x06000F1E RID: 3870 RVA: 0x00029A20 File Offset: 0x00027C20 public SslStream(Stream innerStream, bool leaveStreamOpen) : base(innerStream, leaveStreamOpen) { } /// Initializes a new instance of the class using the specified , stream closure behavior and certificate validation delegate. /// Initializes a new instance of the class using the specified and stream closure behavior. /// Initializes a new instance of the class using the specified and stream closure behavior. /// A delegate responsible for validating the certificate supplied by the remote party. /// /// is not readable.-or- is not writable. /// /// is null.-or- is equal to . // Token: 0x06000F1F RID: 3871 RVA: 0x00029A2C File Offset: 0x00027C2C [global::System.MonoTODO("certValidationCallback is not passed X509Chain and SslPolicyErrors correctly")] public SslStream(Stream innerStream, bool leaveStreamOpen, RemoteCertificateValidationCallback certValidationCallback) : this(innerStream, leaveStreamOpen, certValidationCallback, null) { } /// Initializes a new instance of the class using the specified , stream closure behavior, certificate validation delegate and certificate selection delegate. /// Initializes a new instance of the class using the specified and stream closure behavior. /// Initializes a new instance of the class using the specified and stream closure behavior. /// A delegate responsible for validating the certificate supplied by the remote party. /// A delegate responsible for selecting the certificate used for authentication. /// /// is not readable.-or- is not writable. /// /// is null.-or- is equal to . // Token: 0x06000F20 RID: 3872 RVA: 0x00029A38 File Offset: 0x00027C38 [global::System.MonoTODO("certValidationCallback is not passed X509Chain and SslPolicyErrors correctly")] public SslStream(Stream innerStream, bool leaveStreamOpen, RemoteCertificateValidationCallback certValidationCallback, LocalCertificateSelectionCallback certSelectionCallback) : base(innerStream, leaveStreamOpen) { this.validation_callback = certValidationCallback; this.selection_callback = certSelectionCallback; } /// Gets a value that indicates whether the underlying stream is readable. /// true if authentication has occurred and the underlying stream is readable; otherwise false. // Token: 0x17000527 RID: 1319 // (get) Token: 0x06000F21 RID: 3873 RVA: 0x00029A54 File Offset: 0x00027C54 public override bool CanRead { get { return base.InnerStream.CanRead; } } /// Gets a value that indicates whether the underlying stream is seekable. /// This property always returns false. // Token: 0x17000528 RID: 1320 // (get) Token: 0x06000F22 RID: 3874 RVA: 0x00029A64 File Offset: 0x00027C64 public override bool CanSeek { get { return base.InnerStream.CanSeek; } } /// Gets a value that indicates whether the underlying stream supports time-outs. /// true if the underlying stream supports time-outs; otherwise, false. // Token: 0x17000529 RID: 1321 // (get) Token: 0x06000F23 RID: 3875 RVA: 0x00029A74 File Offset: 0x00027C74 public override bool CanTimeout { get { return base.InnerStream.CanTimeout; } } /// Gets a value that indicates whether the underlying stream is writable. /// true if authentication has occurred and the underlying stream is writable; otherwise false. // Token: 0x1700052A RID: 1322 // (get) Token: 0x06000F24 RID: 3876 RVA: 0x00029A84 File Offset: 0x00027C84 public override bool CanWrite { get { return base.InnerStream.CanWrite; } } /// Gets the length of the underlying stream. /// A . /// Getting the value of this property is not supported when the underlying stream is a . // Token: 0x1700052B RID: 1323 // (get) Token: 0x06000F25 RID: 3877 RVA: 0x00029A94 File Offset: 0x00027C94 public override long Length { get { return base.InnerStream.Length; } } /// Gets or sets the current position in the underlying stream. /// A . /// Setting this property is not supported.-or-Getting the value of this property is not supported when the underlying stream is a . // Token: 0x1700052C RID: 1324 // (get) Token: 0x06000F26 RID: 3878 RVA: 0x00029AA4 File Offset: 0x00027CA4 // (set) Token: 0x06000F27 RID: 3879 RVA: 0x00029AB4 File Offset: 0x00027CB4 public override long Position { get { return base.InnerStream.Position; } set { throw new NotSupportedException("This stream does not support seek operations"); } } /// Gets a value that indicates whether authentication was successful. /// true if successful authentication occurred; otherwise, false. // Token: 0x1700052D RID: 1325 // (get) Token: 0x06000F28 RID: 3880 RVA: 0x00029AC0 File Offset: 0x00027CC0 public override bool IsAuthenticated { get { return this.ssl_stream != null; } } /// Gets a value that indicates whether this uses data encryption. /// true if data is encrypted before being transmitted over the network and decrypted when it reaches the remote endpoint; otherwise false. // Token: 0x1700052E RID: 1326 // (get) Token: 0x06000F29 RID: 3881 RVA: 0x00029AD0 File Offset: 0x00027CD0 public override bool IsEncrypted { get { return this.IsAuthenticated; } } /// Gets a value that indicates whether both server and client have been authenticated. /// true if the server has been authenticated; otherwise false. // Token: 0x1700052F RID: 1327 // (get) Token: 0x06000F2A RID: 3882 RVA: 0x00029AD8 File Offset: 0x00027CD8 public override bool IsMutuallyAuthenticated { get { return this.IsAuthenticated && ((!this.IsServer) ? (this.LocalCertificate != null) : (this.RemoteCertificate != null)); } } /// Gets a value that indicates whether the local side of the connection used by this was authenticated as the server. /// true if the local endpoint was successfully authenticated as the server side of the authenticated connection; otherwise false. // Token: 0x17000530 RID: 1328 // (get) Token: 0x06000F2B RID: 3883 RVA: 0x00029B1C File Offset: 0x00027D1C public override bool IsServer { get { return this.ssl_stream is SslServerStream; } } /// Gets a value that indicates whether the data sent using this stream is signed. /// true if the data is signed before being transmitted; otherwise false. // Token: 0x17000531 RID: 1329 // (get) Token: 0x06000F2C RID: 3884 RVA: 0x00029B2C File Offset: 0x00027D2C public override bool IsSigned { get { return this.IsAuthenticated; } } /// Gets or sets the amount of time a read operation blocks waiting for data. /// A that specifies the amount of time that elapses before a synchronous read operation fails. // Token: 0x17000532 RID: 1330 // (get) Token: 0x06000F2D RID: 3885 RVA: 0x00029B34 File Offset: 0x00027D34 // (set) Token: 0x06000F2E RID: 3886 RVA: 0x00029B44 File Offset: 0x00027D44 public override int ReadTimeout { get { return base.InnerStream.ReadTimeout; } set { base.InnerStream.ReadTimeout = value; } } /// Gets or sets the amount of time a write operation blocks waiting for data. /// A that specifies the amount of time that elapses before a synchronous write operation fails. // Token: 0x17000533 RID: 1331 // (get) Token: 0x06000F2F RID: 3887 RVA: 0x00029B54 File Offset: 0x00027D54 // (set) Token: 0x06000F30 RID: 3888 RVA: 0x00029B64 File Offset: 0x00027D64 public override int WriteTimeout { get { return base.InnerStream.WriteTimeout; } set { base.InnerStream.WriteTimeout = value; } } /// Gets a value that indicates whether the certificate revocation list is checked during the certificate validation process. /// true if the certificate revocation list is checked; otherwise, false. // Token: 0x17000534 RID: 1332 // (get) Token: 0x06000F31 RID: 3889 RVA: 0x00029B74 File Offset: 0x00027D74 public virtual bool CheckCertRevocationStatus { get { return this.IsAuthenticated && this.ssl_stream.CheckCertRevocationStatus; } } /// Gets a value that identifies the bulk encryption algorithm used by this . /// A value. /// The property was accessed before the completion of the authentication process or the authentication process failed. // Token: 0x17000535 RID: 1333 // (get) Token: 0x06000F32 RID: 3890 RVA: 0x00029B90 File Offset: 0x00027D90 public virtual global::System.Security.Authentication.CipherAlgorithmType CipherAlgorithm { get { this.CheckConnectionAuthenticated(); switch (this.ssl_stream.CipherAlgorithm) { case Mono.Security.Protocol.Tls.CipherAlgorithmType.Des: return global::System.Security.Authentication.CipherAlgorithmType.Des; case Mono.Security.Protocol.Tls.CipherAlgorithmType.None: return global::System.Security.Authentication.CipherAlgorithmType.None; case Mono.Security.Protocol.Tls.CipherAlgorithmType.Rc2: return global::System.Security.Authentication.CipherAlgorithmType.Rc2; case Mono.Security.Protocol.Tls.CipherAlgorithmType.Rc4: return global::System.Security.Authentication.CipherAlgorithmType.Rc4; case Mono.Security.Protocol.Tls.CipherAlgorithmType.Rijndael: { int cipherStrength = this.ssl_stream.CipherStrength; if (cipherStrength == 128) { return global::System.Security.Authentication.CipherAlgorithmType.Aes128; } if (cipherStrength == 192) { return global::System.Security.Authentication.CipherAlgorithmType.Aes192; } if (cipherStrength == 256) { return global::System.Security.Authentication.CipherAlgorithmType.Aes256; } break; } case Mono.Security.Protocol.Tls.CipherAlgorithmType.TripleDes: return global::System.Security.Authentication.CipherAlgorithmType.TripleDes; } throw new InvalidOperationException("Not supported cipher algorithm is in use. It is likely a bug in SslStream."); } } /// Gets a value that identifies the strength of the cipher algorithm used by this . /// An value that specifies the strength of the algorithm, in bits. // Token: 0x17000536 RID: 1334 // (get) Token: 0x06000F33 RID: 3891 RVA: 0x00029C48 File Offset: 0x00027E48 public virtual int CipherStrength { get { this.CheckConnectionAuthenticated(); return this.ssl_stream.CipherStrength; } } /// Gets the algorithm used for generating message authentication codes (MACs). /// A value. /// The property was accessed before the completion of the authentication process or the authentication process failed. // Token: 0x17000537 RID: 1335 // (get) Token: 0x06000F34 RID: 3892 RVA: 0x00029C5C File Offset: 0x00027E5C public virtual global::System.Security.Authentication.HashAlgorithmType HashAlgorithm { get { this.CheckConnectionAuthenticated(); switch (this.ssl_stream.HashAlgorithm) { case Mono.Security.Protocol.Tls.HashAlgorithmType.Md5: return global::System.Security.Authentication.HashAlgorithmType.Md5; case Mono.Security.Protocol.Tls.HashAlgorithmType.None: return global::System.Security.Authentication.HashAlgorithmType.None; case Mono.Security.Protocol.Tls.HashAlgorithmType.Sha1: return global::System.Security.Authentication.HashAlgorithmType.Sha1; default: throw new InvalidOperationException("Not supported hash algorithm is in use. It is likely a bug in SslStream."); } } } /// Gets a value that identifies the strength of the hash algorithm used by this instance. /// An value that specifies the strength of the algorithm, in bits. Valid values are 128 or 160. // Token: 0x17000538 RID: 1336 // (get) Token: 0x06000F35 RID: 3893 RVA: 0x00029CAC File Offset: 0x00027EAC public virtual int HashStrength { get { this.CheckConnectionAuthenticated(); return this.ssl_stream.HashStrength; } } /// Gets the key exchange algorithm used by this . /// An value. // Token: 0x17000539 RID: 1337 // (get) Token: 0x06000F36 RID: 3894 RVA: 0x00029CC0 File Offset: 0x00027EC0 public virtual global::System.Security.Authentication.ExchangeAlgorithmType KeyExchangeAlgorithm { get { this.CheckConnectionAuthenticated(); switch (this.ssl_stream.KeyExchangeAlgorithm) { case Mono.Security.Protocol.Tls.ExchangeAlgorithmType.DiffieHellman: return global::System.Security.Authentication.ExchangeAlgorithmType.DiffieHellman; case Mono.Security.Protocol.Tls.ExchangeAlgorithmType.None: return global::System.Security.Authentication.ExchangeAlgorithmType.None; case Mono.Security.Protocol.Tls.ExchangeAlgorithmType.RsaKeyX: return global::System.Security.Authentication.ExchangeAlgorithmType.RsaKeyX; case Mono.Security.Protocol.Tls.ExchangeAlgorithmType.RsaSign: return global::System.Security.Authentication.ExchangeAlgorithmType.RsaSign; } throw new InvalidOperationException("Not supported exchange algorithm is in use. It is likely a bug in SslStream."); } } /// Gets a value that identifies the strength of the key exchange algorithm used by this instance. /// An value that specifies the strength of the algorithm, in bits. // Token: 0x1700053A RID: 1338 // (get) Token: 0x06000F37 RID: 3895 RVA: 0x00029D24 File Offset: 0x00027F24 public virtual int KeyExchangeStrength { get { this.CheckConnectionAuthenticated(); return this.ssl_stream.KeyExchangeStrength; } } /// Gets the certificate used to authenticate the local endpoint. /// An X509Certificate object that represents the certificate supplied for authentication or null if no certificate was supplied. /// Authentication failed or has not occurred. // Token: 0x1700053B RID: 1339 // (get) Token: 0x06000F38 RID: 3896 RVA: 0x00029D38 File Offset: 0x00027F38 public virtual X509Certificate LocalCertificate { get { this.CheckConnectionAuthenticated(); return (!this.IsServer) ? ((SslClientStream)this.ssl_stream).SelectedClientCertificate : this.ssl_stream.ServerCertificate; } } /// Gets the certificate used to authenticate the remote endpoint. /// An X509Certificate object that represents the certificate supplied for authentication or null if no certificate was supplied. /// Authentication failed or has not occurred. // Token: 0x1700053C RID: 1340 // (get) Token: 0x06000F39 RID: 3897 RVA: 0x00029D78 File Offset: 0x00027F78 public virtual X509Certificate RemoteCertificate { get { this.CheckConnectionAuthenticated(); return this.IsServer ? ((SslServerStream)this.ssl_stream).ClientCertificate : this.ssl_stream.ServerCertificate; } } /// Gets a value that indicates the security protocol used to authenticate this connection. /// The value that represents the protocol used for authentication. // Token: 0x1700053D RID: 1341 // (get) Token: 0x06000F3A RID: 3898 RVA: 0x00029DB8 File Offset: 0x00027FB8 public virtual global::System.Security.Authentication.SslProtocols SslProtocol { get { this.CheckConnectionAuthenticated(); SecurityProtocolType securityProtocol = this.ssl_stream.SecurityProtocol; if (securityProtocol == SecurityProtocolType.Default) { return global::System.Security.Authentication.SslProtocols.Default; } if (securityProtocol == SecurityProtocolType.Ssl2) { return global::System.Security.Authentication.SslProtocols.Ssl2; } if (securityProtocol == SecurityProtocolType.Ssl3) { return global::System.Security.Authentication.SslProtocols.Ssl3; } if (securityProtocol != SecurityProtocolType.Tls) { throw new InvalidOperationException("Not supported SSL/TLS protocol is in use. It is likely a bug in SslStream."); } return global::System.Security.Authentication.SslProtocols.Tls; } } // Token: 0x06000F3B RID: 3899 RVA: 0x00029E20 File Offset: 0x00028020 private X509Certificate OnCertificateSelection(global::System.Security.Cryptography.X509Certificates.X509CertificateCollection clientCerts, X509Certificate serverCert, string targetHost, global::System.Security.Cryptography.X509Certificates.X509CertificateCollection serverRequestedCerts) { string[] array = new string[(serverRequestedCerts == null) ? 0 : serverRequestedCerts.Count]; for (int i = 0; i < array.Length; i++) { array[i] = serverRequestedCerts[i].GetIssuerName(); } return this.selection_callback(this, targetHost, clientCerts, serverCert, array); } /// Called by clients to begin an asynchronous operation to authenticate the server and optionally the client. /// An object that indicates the status of the asynchronous operation. /// The name of the server that shares this . /// An delegate that references the method to invoke when the authentication is complete. /// A user-defined object that contains information about the operation. This object is passed to the delegate when the operation completes. /// /// is null. /// The authentication failed and left this object in an unusable state. /// Authentication has already occurred.-or-Server authentication using this was tried previously.-or- Authentication is already in progress. /// This object has been closed. // Token: 0x06000F3C RID: 3900 RVA: 0x00029E7C File Offset: 0x0002807C public virtual IAsyncResult BeginAuthenticateAsClient(string targetHost, AsyncCallback asyncCallback, object asyncState) { return this.BeginAuthenticateAsClient(targetHost, new global::System.Security.Cryptography.X509Certificates.X509CertificateCollection(), global::System.Security.Authentication.SslProtocols.Tls, false, asyncCallback, asyncState); } /// Called by clients to begin an asynchronous operation to authenticate the server and optionally the client using the specified certificates and security protocol. /// An object that indicates the status of the asynchronous operation. /// The name of the server that shares this . /// The containing client certificates. /// The value that represents the protocol used for authentication. /// A value that specifies whether the certificate revocation list is checked during authentication. /// An delegate that references the method to invoke when the authentication is complete. /// A user-defined object that contains information about the operation. This object is passed to the delegate when the operation completes. /// /// is null. /// /// is not a valid value. /// The authentication failed and left this object in an unusable state. /// Authentication has already occurred.-or-Server authentication using this was tried previously.-or- Authentication is already in progress. /// This object has been closed. // Token: 0x06000F3D RID: 3901 RVA: 0x00029E94 File Offset: 0x00028094 public virtual IAsyncResult BeginAuthenticateAsClient(string targetHost, global::System.Security.Cryptography.X509Certificates.X509CertificateCollection clientCertificates, global::System.Security.Authentication.SslProtocols sslProtocolType, bool checkCertificateRevocation, AsyncCallback asyncCallback, object asyncState) { if (this.IsAuthenticated) { throw new InvalidOperationException("This SslStream is already authenticated"); } SslClientStream sslClientStream = new SslClientStream(base.InnerStream, targetHost, !base.LeaveInnerStreamOpen, this.GetMonoSslProtocol(sslProtocolType), clientCertificates); sslClientStream.CheckCertRevocationStatus = checkCertificateRevocation; sslClientStream.PrivateKeyCertSelectionDelegate = delegate(X509Certificate cert, string host) { string certHashString = cert.GetCertHashString(); foreach (X509Certificate x509Certificate in clientCertificates) { if (!(x509Certificate.GetCertHashString() != certHashString)) { global::System.Security.Cryptography.X509Certificates.X509Certificate2 x509Certificate2 = x509Certificate as global::System.Security.Cryptography.X509Certificates.X509Certificate2; x509Certificate2 = x509Certificate2 ?? new global::System.Security.Cryptography.X509Certificates.X509Certificate2(x509Certificate); return x509Certificate2.PrivateKey; } } return null; }; if (this.validation_callback != null) { sslClientStream.ServerCertValidationDelegate = delegate(X509Certificate cert, int[] certErrors) { global::System.Security.Cryptography.X509Certificates.X509Chain x509Chain = new global::System.Security.Cryptography.X509Certificates.X509Chain(); global::System.Security.Cryptography.X509Certificates.X509Certificate2 x509Certificate3 = cert as global::System.Security.Cryptography.X509Certificates.X509Certificate2; if (x509Certificate3 == null) { x509Certificate3 = new global::System.Security.Cryptography.X509Certificates.X509Certificate2(cert); } if (!ServicePointManager.CheckCertificateRevocationList) { x509Chain.ChainPolicy.RevocationMode = global::System.Security.Cryptography.X509Certificates.X509RevocationMode.NoCheck; } SslPolicyErrors sslPolicyErrors = SslPolicyErrors.None; foreach (int num in certErrors) { int num2 = num; if (num2 != -2146762490) { if (num2 != -2146762481) { sslPolicyErrors |= SslPolicyErrors.RemoteCertificateChainErrors; } else { sslPolicyErrors |= SslPolicyErrors.RemoteCertificateNameMismatch; } } else { sslPolicyErrors |= SslPolicyErrors.RemoteCertificateNotAvailable; } } x509Chain.Build(x509Certificate3); foreach (global::System.Security.Cryptography.X509Certificates.X509ChainStatus x509ChainStatus in x509Chain.ChainStatus) { if (x509ChainStatus.Status != global::System.Security.Cryptography.X509Certificates.X509ChainStatusFlags.NoError) { if ((x509ChainStatus.Status & global::System.Security.Cryptography.X509Certificates.X509ChainStatusFlags.PartialChain) != global::System.Security.Cryptography.X509Certificates.X509ChainStatusFlags.NoError) { sslPolicyErrors |= SslPolicyErrors.RemoteCertificateNotAvailable; } else { sslPolicyErrors |= SslPolicyErrors.RemoteCertificateChainErrors; } } } return this.validation_callback(this, cert, x509Chain, sslPolicyErrors); }; } if (this.selection_callback != null) { sslClientStream.ClientCertSelectionDelegate = new CertificateSelectionCallback(this.OnCertificateSelection); } this.ssl_stream = sslClientStream; return this.BeginWrite(new byte[0], 0, 0, asyncCallback, asyncState); } /// Begins an asynchronous read operation that reads data from the stream and stores it in the specified array. /// An object that indicates the status of the asynchronous operation. /// A array that receives the bytes read from the stream. /// The zero-based location in at which to begin storing the data read from this stream. /// The maximum number of bytes to read from the stream. /// An delegate that references the method to invoke when the read operation is complete. /// A user-defined object that contains information about the read operation. This object is passed to the delegate when the operation completes. /// /// is null. /// /// /// /// . > the length of .-or- + count > the length of . /// The read operation failed.-or-Encryption is in use, but the data could not be decrypted. /// There is already a read operation in progress. /// This object has been closed. /// Authentication has not occurred. // Token: 0x06000F3E RID: 3902 RVA: 0x00029F5C File Offset: 0x0002815C public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState) { this.CheckConnectionAuthenticated(); return this.ssl_stream.BeginRead(buffer, offset, count, asyncCallback, asyncState); } /// Called by servers to begin an asynchronous operation to authenticate the client and optionally the server in a client-server connection. /// An object indicating the status of the asynchronous operation. /// The X509Certificate used to authenticate the server. /// An delegate that references the method to invoke when the authentication is complete. /// A user-defined object that contains information about the operation. This object is passed to the delegate when the operation completes. /// /// is null. /// The authentication failed and left this object in an unusable state. /// Authentication has already occurred.-or-Client authentication using this was tried previously.-or- Authentication is already in progress. /// This object has been closed. /// The method is not supported on Windows 95, Windows 98, or Windows Millennium. // Token: 0x06000F3F RID: 3903 RVA: 0x00029F84 File Offset: 0x00028184 public virtual IAsyncResult BeginAuthenticateAsServer(X509Certificate serverCertificate, AsyncCallback callback, object asyncState) { return this.BeginAuthenticateAsServer(serverCertificate, false, global::System.Security.Authentication.SslProtocols.Tls, false, callback, asyncState); } /// Called by servers to begin an asynchronous operation to authenticate the server and optionally the client using the specified certificates, requirements and security protocol. /// An object that indicates the status of the asynchronous operation. /// The X509Certificate used to authenticate the server. /// A value that specifies whether the client must supply a certificate for authentication. /// The value that represents the protocol used for authentication. /// A value that specifies whether the certificate revocation list is checked during authentication. /// An delegate that references the method to invoke when the authentication is complete. /// A user-defined object that contains information about the operation. This object is passed to the delegate when the operation completes. /// /// is null. /// /// is not a valid value. /// The authentication failed and left this object in an unusable state. /// Authentication has already occurred.-or-Server authentication using this was tried previously.-or- Authentication is already in progress. /// This object has been closed. /// The method is not supported on Windows 95, Windows 98, or Windows Millennium. // Token: 0x06000F40 RID: 3904 RVA: 0x00029F98 File Offset: 0x00028198 public virtual IAsyncResult BeginAuthenticateAsServer(X509Certificate serverCertificate, bool clientCertificateRequired, global::System.Security.Authentication.SslProtocols sslProtocolType, bool checkCertificateRevocation, AsyncCallback callback, object asyncState) { if (this.IsAuthenticated) { throw new InvalidOperationException("This SslStream is already authenticated"); } SslServerStream sslServerStream = new SslServerStream(base.InnerStream, serverCertificate, clientCertificateRequired, !base.LeaveInnerStreamOpen, this.GetMonoSslProtocol(sslProtocolType)); sslServerStream.CheckCertRevocationStatus = checkCertificateRevocation; sslServerStream.PrivateKeyCertSelectionDelegate = delegate(X509Certificate cert, string targetHost) { global::System.Security.Cryptography.X509Certificates.X509Certificate2 x509Certificate = (serverCertificate as global::System.Security.Cryptography.X509Certificates.X509Certificate2) ?? new global::System.Security.Cryptography.X509Certificates.X509Certificate2(serverCertificate); return (x509Certificate == null) ? null : x509Certificate.PrivateKey; }; if (this.validation_callback != null) { sslServerStream.ClientCertValidationDelegate = delegate(X509Certificate cert, int[] certErrors) { global::System.Security.Cryptography.X509Certificates.X509Chain x509Chain = null; if (cert is global::System.Security.Cryptography.X509Certificates.X509Certificate2) { x509Chain = new global::System.Security.Cryptography.X509Certificates.X509Chain(); x509Chain.Build((global::System.Security.Cryptography.X509Certificates.X509Certificate2)cert); } SslPolicyErrors sslPolicyErrors = ((certErrors.Length <= 0) ? SslPolicyErrors.None : SslPolicyErrors.RemoteCertificateChainErrors); return this.validation_callback(this, cert, x509Chain, sslPolicyErrors); }; } this.ssl_stream = sslServerStream; return this.BeginRead(new byte[0], 0, 0, callback, asyncState); } // Token: 0x06000F41 RID: 3905 RVA: 0x0002A044 File Offset: 0x00028244 private SecurityProtocolType GetMonoSslProtocol(global::System.Security.Authentication.SslProtocols ms) { if (ms == global::System.Security.Authentication.SslProtocols.Ssl2) { return SecurityProtocolType.Ssl2; } if (ms == global::System.Security.Authentication.SslProtocols.Ssl3) { return SecurityProtocolType.Ssl3; } if (ms != global::System.Security.Authentication.SslProtocols.Tls) { return SecurityProtocolType.Default; } return SecurityProtocolType.Tls; } /// Begins an asynchronous write operation that writes s from the specified buffer to the stream. /// An object indicating the status of the asynchronous operation. /// A array that supplies the bytes to be written to the stream. /// The zero-based location in at which to begin reading bytes to be written to the stream. /// An value that specifies the number of bytes to read from . /// An delegate that references the method to invoke when the write operation is complete. /// A user-defined object that contains information about the write operation. This object is passed to the delegate when the operation completes. /// /// is null. /// /// /// /// . > the length of .-or- + count > the length of . /// The write operation failed. /// There is already a write operation in progress. /// This object has been closed. /// Authentication has not occurred. // Token: 0x06000F42 RID: 3906 RVA: 0x0002A084 File Offset: 0x00028284 public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState) { this.CheckConnectionAuthenticated(); return this.ssl_stream.BeginWrite(buffer, offset, count, asyncCallback, asyncState); } /// Called by clients to authenticate the server and optionally the client in a client-server connection. /// The name of the server that shares this . /// /// is null. /// The authentication failed and left this object in an unusable state. /// Authentication has already occurred.-or-Server authentication using this was tried previously.-or- Authentication is already in progress. /// This object has been closed. // Token: 0x06000F43 RID: 3907 RVA: 0x0002A0AC File Offset: 0x000282AC public virtual void AuthenticateAsClient(string targetHost) { this.AuthenticateAsClient(targetHost, new global::System.Security.Cryptography.X509Certificates.X509CertificateCollection(), global::System.Security.Authentication.SslProtocols.Tls, false); } /// Called by clients to authenticate the server and optionally the client in a client-server connection. The authentication process uses the specified certificate collection and SSL protocol. /// The name of the server that will share this . /// The that contains client certificates. /// The value that represents the protocol used for authentication. /// A value that specifies whether the certificate revocation list is checked during authentication. // Token: 0x06000F44 RID: 3908 RVA: 0x0002A0C0 File Offset: 0x000282C0 public virtual void AuthenticateAsClient(string targetHost, global::System.Security.Cryptography.X509Certificates.X509CertificateCollection clientCertificates, global::System.Security.Authentication.SslProtocols sslProtocolType, bool checkCertificateRevocation) { this.EndAuthenticateAsClient(this.BeginAuthenticateAsClient(targetHost, clientCertificates, sslProtocolType, checkCertificateRevocation, null, null)); } /// Called by servers to authenticate the server and optionally the client in a client-server connection using the specified certificate. /// The certificate used to authenticate the server. /// /// is null. /// The authentication failed and left this object in an unusable state. /// Authentication has already occurred.-or-Client authentication using this was tried previously.-or- Authentication is already in progress. /// This object has been closed. /// The method is not supported on Windows 95, Windows 98, or Windows Millennium. // Token: 0x06000F45 RID: 3909 RVA: 0x0002A0E0 File Offset: 0x000282E0 public virtual void AuthenticateAsServer(X509Certificate serverCertificate) { this.AuthenticateAsServer(serverCertificate, false, global::System.Security.Authentication.SslProtocols.Tls, false); } /// Called by servers to begin an asynchronous operation to authenticate the server and optionally the client using the specified certificates, requirements and security protocol. /// The X509Certificate used to authenticate the server. /// A value that specifies whether the client must supply a certificate for authentication. /// The value that represents the protocol used for authentication. /// A value that specifies whether the certificate revocation list is checked during authentication. /// /// is null. /// /// is not a valid value. /// The authentication failed and left this object in an unusable state. /// Authentication has already occurred.-or-Client authentication using this was tried previously.-or- Authentication is already in progress. /// This object has been closed. /// The method is not supported on Windows 95, Windows 98, or Windows Millennium. // Token: 0x06000F46 RID: 3910 RVA: 0x0002A0F0 File Offset: 0x000282F0 public virtual void AuthenticateAsServer(X509Certificate serverCertificate, bool clientCertificateRequired, global::System.Security.Authentication.SslProtocols sslProtocolType, bool checkCertificateRevocation) { this.EndAuthenticateAsServer(this.BeginAuthenticateAsServer(serverCertificate, clientCertificateRequired, sslProtocolType, checkCertificateRevocation, null, null)); } /// Releases the unmanaged resources used by the and optionally releases the managed resources. /// true to release both managed and unmanaged resources; false to release only unmanaged resources. // Token: 0x06000F47 RID: 3911 RVA: 0x0002A110 File Offset: 0x00028310 protected override void Dispose(bool disposing) { if (disposing) { if (this.ssl_stream != null) { this.ssl_stream.Dispose(); } this.ssl_stream = null; } base.Dispose(disposing); } /// Ends a pending asynchronous server authentication operation started with a previous call to . /// An instance returned by a call to . /// /// is null. /// /// was not created by a call to . /// The authentication failed and left this object in an unusable state. /// There is no pending server authentication to complete. // Token: 0x06000F48 RID: 3912 RVA: 0x0002A148 File Offset: 0x00028348 public virtual void EndAuthenticateAsClient(IAsyncResult asyncResult) { this.CheckConnectionAuthenticated(); if (this.CanRead) { this.ssl_stream.EndRead(asyncResult); } else { this.ssl_stream.EndWrite(asyncResult); } } /// Ends a pending asynchronous client authentication operation started with a previous call to . /// An instance returned by a call to . /// /// is null. /// /// was not created by a call to . /// The authentication failed and left this object in an unusable state. /// There is no pending client authentication to complete. // Token: 0x06000F49 RID: 3913 RVA: 0x0002A184 File Offset: 0x00028384 public virtual void EndAuthenticateAsServer(IAsyncResult asyncResult) { this.CheckConnectionAuthenticated(); if (this.CanRead) { this.ssl_stream.EndRead(asyncResult); } else { this.ssl_stream.EndWrite(asyncResult); } } /// Ends an asynchronous read operation started with a previous call to . /// A value that specifies the number of bytes read from the underlying stream. /// An instance returned by a call to /// /// is null. /// /// was not created by a call to . /// There is no pending read operation to complete. /// The read operation failed. /// Authentication has not occurred. // Token: 0x06000F4A RID: 3914 RVA: 0x0002A1C0 File Offset: 0x000283C0 public override int EndRead(IAsyncResult asyncResult) { this.CheckConnectionAuthenticated(); return this.ssl_stream.EndRead(asyncResult); } /// Ends an asynchronous write operation started with a previous call to . /// An instance returned by a call to /// /// is null. /// /// was not created by a call to . /// There is no pending write operation to complete. /// The write operation failed. /// Authentication has not occurred. // Token: 0x06000F4B RID: 3915 RVA: 0x0002A1D4 File Offset: 0x000283D4 public override void EndWrite(IAsyncResult asyncResult) { this.CheckConnectionAuthenticated(); this.ssl_stream.EndWrite(asyncResult); } /// Causes any buffered data to be written to the underlying device. // Token: 0x06000F4C RID: 3916 RVA: 0x0002A1E8 File Offset: 0x000283E8 public override void Flush() { this.CheckConnectionAuthenticated(); base.InnerStream.Flush(); } /// Reads data from this stream and stores it in the specified array. /// A value that specifies the number of bytes read. When there is no more data to be read, returns 0. /// A array that receives the bytes read from this stream. /// A that contains the zero-based location in at which to begin storing the data read from this stream. /// A that contains the maximum number of bytes to read from this stream. /// /// is null. /// /// /// /// . > the length of .-or- + count > the length of . /// The read operation failed. Check the inner exception, if present to determine the cause of the failure. /// There is already a read operation in progress. /// This object has been closed. /// Authentication has not occurred. // Token: 0x06000F4D RID: 3917 RVA: 0x0002A1FC File Offset: 0x000283FC public override int Read(byte[] buffer, int offset, int count) { return this.EndRead(this.BeginRead(buffer, offset, count, null, null)); } /// Throws a . /// Always throws a . /// This value is ignored. /// This value is ignored. /// Seeking is not supported by objects. // Token: 0x06000F4E RID: 3918 RVA: 0x0002A210 File Offset: 0x00028410 public override long Seek(long offset, SeekOrigin origin) { throw new NotSupportedException("This stream does not support seek operations"); } /// Sets the length of the underlying stream. /// An value that specifies the length of the stream. // Token: 0x06000F4F RID: 3919 RVA: 0x0002A21C File Offset: 0x0002841C public override void SetLength(long value) { base.InnerStream.SetLength(value); } /// Write the specified number of s to the underlying stream using the specified buffer and offset. /// A array that supplies the bytes written to the stream. /// A that contains the zero-based location in at which to begin reading bytes to be written to the stream. /// A that contains the number of bytes to read from . /// /// is null. /// /// /// /// . > the length of .-or- + count > the length of . /// The write operation failed. /// There is already a write operation in progress. /// This object has been closed. /// Authentication has not occurred. // Token: 0x06000F50 RID: 3920 RVA: 0x0002A22C File Offset: 0x0002842C public override void Write(byte[] buffer, int offset, int count) { this.EndWrite(this.BeginWrite(buffer, offset, count, null, null)); } /// Writes the specified data to this stream. /// A array that supplies the bytes written to the stream. /// /// is null. /// The write operation failed. /// There is already a write operation in progress. /// This object has been closed. /// Authentication has not occurred. // Token: 0x06000F51 RID: 3921 RVA: 0x0002A240 File Offset: 0x00028440 public void Write(byte[] buffer) { this.Write(buffer, 0, buffer.Length); } // Token: 0x06000F52 RID: 3922 RVA: 0x0002A250 File Offset: 0x00028450 private void CheckConnectionAuthenticated() { if (!this.IsAuthenticated) { throw new InvalidOperationException("This operation is invalid until it is successfully authenticated"); } } // Token: 0x04000DAE RID: 3502 private SslStreamBase ssl_stream; // Token: 0x04000DAF RID: 3503 private RemoteCertificateValidationCallback validation_callback; // Token: 0x04000DB0 RID: 3504 private LocalCertificateSelectionCallback selection_callback; } }