2
0

SslStream.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. //
  2. // SslStream.cs
  3. //
  4. // Author:
  5. // Martin Baulig <[email protected]>
  6. //
  7. // Copyright (c) 2015 Xamarin, Inc.
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining a copy
  10. // of this software and associated documentation files (the "Software"), to deal
  11. // in the Software without restriction, including without limitation the rights
  12. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. // copies of the Software, and to permit persons to whom the Software is
  14. // furnished to do so, subject to the following conditions:
  15. //
  16. // The above copyright notice and this permission notice shall be included in
  17. // all copies or substantial portions of the Software.
  18. //
  19. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. // THE SOFTWARE.
  26. #if SECURITY_DEP
  27. #if MONO_SECURITY_ALIAS
  28. extern alias MonoSecurity;
  29. #endif
  30. #if MONO_SECURITY_ALIAS
  31. using MonoSecurity::Mono.Security.Interface;
  32. #else
  33. using Mono.Security.Interface;
  34. #endif
  35. using CipherAlgorithmType = System.Security.Authentication.CipherAlgorithmType;
  36. using HashAlgorithmType = System.Security.Authentication.HashAlgorithmType;
  37. using ExchangeAlgorithmType = System.Security.Authentication.ExchangeAlgorithmType;
  38. #endif
  39. using System.IO;
  40. using System.Net;
  41. using System.Net.Security;
  42. using System.Security.Authentication;
  43. using System.Security.Cryptography.X509Certificates;
  44. using System.Security.Permissions;
  45. using System.Security.Principal;
  46. using System.Security.Cryptography;
  47. using System.Threading;
  48. using System.Threading.Tasks;
  49. using MNS = Mono.Net.Security;
  50. namespace System.Net.Security
  51. {
  52. public delegate X509Certificate ServerCertificateSelectionCallback (object sender, string hostName);
  53. /*
  54. * Internal delegates from the referencesource / corefx.
  55. */
  56. internal delegate bool RemoteCertValidationCallback (
  57. string host,
  58. X509Certificate certificate,
  59. X509Chain chain,
  60. SslPolicyErrors sslPolicyErrors);
  61. internal delegate X509Certificate LocalCertSelectionCallback (
  62. string targetHost,
  63. X509CertificateCollection localCertificates,
  64. X509Certificate remoteCertificate,
  65. string[] acceptableIssuers);
  66. internal delegate X509Certificate ServerCertSelectionCallback (string hostName);
  67. public class SslStream : AuthenticatedStream
  68. {
  69. #if SECURITY_DEP
  70. MonoTlsProvider provider;
  71. MonoTlsSettings settings;
  72. RemoteCertificateValidationCallback validationCallback;
  73. LocalCertificateSelectionCallback selectionCallback;
  74. bool explicitSettings;
  75. IMonoSslStream impl;
  76. internal IMonoSslStream Impl {
  77. get {
  78. CheckDisposed ();
  79. return impl;
  80. }
  81. }
  82. IMonoSslStream2 Impl2 => (IMonoSslStream2)Impl;
  83. internal MonoTlsProvider Provider {
  84. get {
  85. CheckDisposed ();
  86. return provider;
  87. }
  88. }
  89. static MonoTlsProvider GetProvider ()
  90. {
  91. return MonoTlsProviderFactory.GetProvider ();
  92. }
  93. public SslStream (Stream innerStream)
  94. : this (innerStream, false)
  95. {
  96. }
  97. public SslStream (Stream innerStream, bool leaveInnerStreamOpen)
  98. : base (innerStream, leaveInnerStreamOpen)
  99. {
  100. provider = GetProvider ();
  101. settings = MonoTlsSettings.CopyDefaultSettings ();
  102. impl = provider.CreateSslStreamInternal (this, innerStream, leaveInnerStreamOpen, settings);
  103. }
  104. public SslStream (Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback userCertificateValidationCallback)
  105. : this (innerStream, leaveInnerStreamOpen, userCertificateValidationCallback, null)
  106. {
  107. }
  108. public SslStream (Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback userCertificateValidationCallback, LocalCertificateSelectionCallback userCertificateSelectionCallback)
  109. : base (innerStream, leaveInnerStreamOpen)
  110. {
  111. provider = GetProvider ();
  112. settings = MonoTlsSettings.CopyDefaultSettings ();
  113. SetAndVerifyValidationCallback (userCertificateValidationCallback);
  114. SetAndVerifySelectionCallback (userCertificateSelectionCallback);
  115. impl = provider.CreateSslStream (innerStream, leaveInnerStreamOpen, settings);
  116. }
  117. [MonoLimitation ("encryptionPolicy is ignored")]
  118. public SslStream (Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback userCertificateValidationCallback, LocalCertificateSelectionCallback userCertificateSelectionCallback, EncryptionPolicy encryptionPolicy)
  119. : this (innerStream, leaveInnerStreamOpen, userCertificateValidationCallback, userCertificateSelectionCallback)
  120. {
  121. }
  122. internal SslStream (Stream innerStream, bool leaveInnerStreamOpen, MonoTlsProvider provider, MonoTlsSettings settings)
  123. : base (innerStream, leaveInnerStreamOpen)
  124. {
  125. this.provider = provider;
  126. this.settings = settings.Clone ();
  127. explicitSettings = true;
  128. impl = provider.CreateSslStreamInternal (this, innerStream, leaveInnerStreamOpen, settings);
  129. }
  130. internal static IMonoSslStream CreateMonoSslStream (Stream innerStream, bool leaveInnerStreamOpen, MonoTlsProvider provider, MonoTlsSettings settings)
  131. {
  132. var sslStream = new SslStream (innerStream, leaveInnerStreamOpen, provider, settings);
  133. return sslStream.Impl;
  134. }
  135. void SetAndVerifyValidationCallback (RemoteCertificateValidationCallback callback)
  136. {
  137. if (validationCallback == null) {
  138. validationCallback = callback;
  139. settings.RemoteCertificateValidationCallback = MNS.Private.CallbackHelpers.PublicToMono (callback);
  140. } else if ((callback != null && validationCallback != callback) || (explicitSettings & settings.RemoteCertificateValidationCallback != null)) {
  141. throw new InvalidOperationException (SR.Format (SR.net_conflicting_options, nameof (RemoteCertificateValidationCallback)));
  142. }
  143. }
  144. void SetAndVerifySelectionCallback (LocalCertificateSelectionCallback callback)
  145. {
  146. if (selectionCallback == null) {
  147. selectionCallback = callback;
  148. if (callback == null)
  149. settings.ClientCertificateSelectionCallback = null;
  150. else
  151. settings.ClientCertificateSelectionCallback = (t, lc, rc, ai) => callback (this, t, lc, rc, ai);
  152. } else if ((callback != null && selectionCallback != callback) || (explicitSettings && settings.ClientCertificateSelectionCallback != null)) {
  153. throw new InvalidOperationException (SR.Format (SR.net_conflicting_options, nameof (LocalCertificateSelectionCallback)));
  154. }
  155. }
  156. public virtual void AuthenticateAsClient (string targetHost)
  157. {
  158. Impl.AuthenticateAsClient (targetHost);
  159. }
  160. public virtual void AuthenticateAsClient (string targetHost, X509CertificateCollection clientCertificates, bool checkCertificateRevocation)
  161. {
  162. Impl.AuthenticateAsClient (targetHost, clientCertificates, SecurityProtocol.SystemDefaultSecurityProtocols, checkCertificateRevocation);
  163. }
  164. public virtual void AuthenticateAsClient (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
  165. {
  166. Impl.AuthenticateAsClient (targetHost, clientCertificates, enabledSslProtocols, checkCertificateRevocation);
  167. }
  168. public virtual IAsyncResult BeginAuthenticateAsClient (string targetHost, AsyncCallback asyncCallback, object asyncState)
  169. {
  170. return Impl.BeginAuthenticateAsClient (targetHost, asyncCallback, asyncState);
  171. }
  172. public virtual IAsyncResult BeginAuthenticateAsClient (string targetHost, X509CertificateCollection clientCertificates, bool checkCertificateRevocation, AsyncCallback asyncCallback, object asyncState)
  173. {
  174. return Impl.BeginAuthenticateAsClient (targetHost, clientCertificates, SecurityProtocol.SystemDefaultSecurityProtocols, checkCertificateRevocation, asyncCallback, asyncState);
  175. }
  176. public virtual IAsyncResult BeginAuthenticateAsClient (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation, AsyncCallback asyncCallback, object asyncState)
  177. {
  178. return Impl.BeginAuthenticateAsClient (targetHost, clientCertificates, enabledSslProtocols, checkCertificateRevocation, asyncCallback, asyncState);
  179. }
  180. public virtual void EndAuthenticateAsClient (IAsyncResult asyncResult)
  181. {
  182. Impl.EndAuthenticateAsClient (asyncResult);
  183. }
  184. public virtual void AuthenticateAsServer (X509Certificate serverCertificate)
  185. {
  186. Impl.AuthenticateAsServer (serverCertificate);
  187. }
  188. public virtual void AuthenticateAsServer (X509Certificate serverCertificate, bool clientCertificateRequired, bool checkCertificateRevocation)
  189. {
  190. Impl.AuthenticateAsServer (serverCertificate, clientCertificateRequired, SecurityProtocol.SystemDefaultSecurityProtocols, checkCertificateRevocation);
  191. }
  192. public virtual void AuthenticateAsServer (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
  193. {
  194. Impl.AuthenticateAsServer (serverCertificate, clientCertificateRequired, enabledSslProtocols, checkCertificateRevocation);
  195. }
  196. public virtual IAsyncResult BeginAuthenticateAsServer (X509Certificate serverCertificate, AsyncCallback asyncCallback, object asyncState)
  197. {
  198. return Impl.BeginAuthenticateAsServer (serverCertificate, asyncCallback, asyncState);
  199. }
  200. public virtual IAsyncResult BeginAuthenticateAsServer (X509Certificate serverCertificate, bool clientCertificateRequired, bool checkCertificateRevocation, AsyncCallback asyncCallback, object asyncState)
  201. {
  202. return Impl.BeginAuthenticateAsServer (serverCertificate, clientCertificateRequired, SecurityProtocol.SystemDefaultSecurityProtocols, checkCertificateRevocation, asyncCallback, asyncState);
  203. }
  204. public virtual IAsyncResult BeginAuthenticateAsServer (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation, AsyncCallback asyncCallback, object asyncState)
  205. {
  206. return Impl.BeginAuthenticateAsServer (serverCertificate, clientCertificateRequired, enabledSslProtocols, checkCertificateRevocation, asyncCallback, asyncState);
  207. }
  208. public virtual void EndAuthenticateAsServer (IAsyncResult asyncResult)
  209. {
  210. Impl.EndAuthenticateAsServer (asyncResult);
  211. }
  212. public TransportContext TransportContext => null;
  213. public virtual Task AuthenticateAsClientAsync (string targetHost)
  214. {
  215. return Impl.AuthenticateAsClientAsync (targetHost);
  216. }
  217. public virtual Task AuthenticateAsClientAsync (string targetHost, X509CertificateCollection clientCertificates, bool checkCertificateRevocation)
  218. {
  219. return Impl.AuthenticateAsClientAsync (targetHost, clientCertificates, SecurityProtocol.SystemDefaultSecurityProtocols, checkCertificateRevocation);
  220. }
  221. public virtual Task AuthenticateAsClientAsync (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
  222. {
  223. return Impl.AuthenticateAsClientAsync (targetHost, clientCertificates, enabledSslProtocols, checkCertificateRevocation);
  224. }
  225. public Task AuthenticateAsClientAsync (SslClientAuthenticationOptions sslClientAuthenticationOptions, CancellationToken cancellationToken)
  226. {
  227. SetAndVerifyValidationCallback (sslClientAuthenticationOptions.RemoteCertificateValidationCallback);
  228. SetAndVerifySelectionCallback (sslClientAuthenticationOptions.LocalCertificateSelectionCallback);
  229. return Impl2.AuthenticateAsClientAsync (new MNS.MonoSslClientAuthenticationOptions (sslClientAuthenticationOptions), cancellationToken);
  230. }
  231. public virtual Task AuthenticateAsServerAsync (X509Certificate serverCertificate)
  232. {
  233. return Impl.AuthenticateAsServerAsync (serverCertificate);
  234. }
  235. public virtual Task AuthenticateAsServerAsync (X509Certificate serverCertificate, bool clientCertificateRequired, bool checkCertificateRevocation)
  236. {
  237. return Impl.AuthenticateAsServerAsync (serverCertificate, clientCertificateRequired, SecurityProtocol.SystemDefaultSecurityProtocols, checkCertificateRevocation);
  238. }
  239. public virtual Task AuthenticateAsServerAsync (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
  240. {
  241. return Impl.AuthenticateAsServerAsync (serverCertificate, clientCertificateRequired, enabledSslProtocols, checkCertificateRevocation);
  242. }
  243. public Task AuthenticateAsServerAsync (SslServerAuthenticationOptions sslServerAuthenticationOptions, CancellationToken cancellationToken)
  244. {
  245. return Impl2.AuthenticateAsServerAsync (new MNS.MonoSslServerAuthenticationOptions (sslServerAuthenticationOptions), cancellationToken);
  246. }
  247. public virtual Task ShutdownAsync ()
  248. {
  249. return Impl.ShutdownAsync ();
  250. }
  251. public override bool IsAuthenticated {
  252. get { return Impl.IsAuthenticated; }
  253. }
  254. public override bool IsMutuallyAuthenticated {
  255. get { return Impl.IsMutuallyAuthenticated; }
  256. }
  257. public override bool IsEncrypted {
  258. get { return Impl.IsEncrypted; }
  259. }
  260. public override bool IsSigned {
  261. get { return Impl.IsSigned; }
  262. }
  263. public override bool IsServer {
  264. get { return Impl.IsServer; }
  265. }
  266. public virtual SslProtocols SslProtocol {
  267. get { return (SslProtocols)Impl.SslProtocol; }
  268. }
  269. public virtual bool CheckCertRevocationStatus {
  270. get { return Impl.CheckCertRevocationStatus; }
  271. }
  272. public virtual X509Certificate LocalCertificate {
  273. get { return Impl.LocalCertificate; }
  274. }
  275. public virtual X509Certificate RemoteCertificate {
  276. get { return Impl.RemoteCertificate; }
  277. }
  278. public virtual CipherAlgorithmType CipherAlgorithm {
  279. get { return (CipherAlgorithmType)Impl.CipherAlgorithm; }
  280. }
  281. public virtual int CipherStrength {
  282. get { return Impl.CipherStrength; }
  283. }
  284. public virtual HashAlgorithmType HashAlgorithm {
  285. get { return (HashAlgorithmType)Impl.HashAlgorithm; }
  286. }
  287. public virtual int HashStrength {
  288. get { return Impl.HashStrength; }
  289. }
  290. public virtual ExchangeAlgorithmType KeyExchangeAlgorithm {
  291. get { return (ExchangeAlgorithmType)Impl.KeyExchangeAlgorithm; }
  292. }
  293. public virtual int KeyExchangeStrength {
  294. get { return Impl.KeyExchangeStrength; }
  295. }
  296. public override bool CanSeek {
  297. get { return false; }
  298. }
  299. public override bool CanRead {
  300. get { return impl != null && impl.CanRead; }
  301. }
  302. public override bool CanTimeout {
  303. get { return InnerStream.CanTimeout; }
  304. }
  305. public override bool CanWrite {
  306. get { return impl != null && impl.CanWrite; }
  307. }
  308. public override int ReadTimeout {
  309. get { return Impl.ReadTimeout; }
  310. set { Impl.ReadTimeout = value; }
  311. }
  312. public override int WriteTimeout {
  313. get { return Impl.WriteTimeout; }
  314. set { Impl.WriteTimeout = value; }
  315. }
  316. public override long Length {
  317. get { return Impl.Length; }
  318. }
  319. public override long Position {
  320. get { return Impl.Position; }
  321. set {
  322. throw new NotSupportedException (SR.GetString (SR.net_noseek));
  323. }
  324. }
  325. public override void SetLength (long value)
  326. {
  327. Impl.SetLength (value);
  328. }
  329. public override long Seek (long offset, SeekOrigin origin)
  330. {
  331. throw new NotSupportedException (SR.GetString (SR.net_noseek));
  332. }
  333. public override Task FlushAsync (CancellationToken cancellationToken)
  334. {
  335. return InnerStream.FlushAsync (cancellationToken);
  336. }
  337. public override void Flush ()
  338. {
  339. InnerStream.Flush ();
  340. }
  341. void CheckDisposed ()
  342. {
  343. if (impl == null)
  344. throw new ObjectDisposedException ("SslStream");
  345. }
  346. protected override void Dispose (bool disposing)
  347. {
  348. try {
  349. if (impl != null && disposing) {
  350. impl.Dispose ();
  351. impl = null;
  352. }
  353. } finally {
  354. base.Dispose (disposing);
  355. }
  356. }
  357. public override int Read (byte[] buffer, int offset, int count)
  358. {
  359. return Impl.Read (buffer, offset, count);
  360. }
  361. public void Write (byte[] buffer)
  362. {
  363. Impl.Write (buffer);
  364. }
  365. public override void Write (byte[] buffer, int offset, int count)
  366. {
  367. Impl.Write (buffer, offset, count);
  368. }
  369. // [HostProtection (ExternalThreading=true)]
  370. public override IAsyncResult BeginRead (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState)
  371. {
  372. return Impl.BeginRead (buffer, offset, count, asyncCallback, asyncState);
  373. }
  374. public override int EndRead (IAsyncResult asyncResult)
  375. {
  376. return Impl.EndRead (asyncResult);
  377. }
  378. // [HostProtection (ExternalThreading=true)]
  379. public override IAsyncResult BeginWrite (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState)
  380. {
  381. return Impl.BeginWrite (buffer, offset, count, asyncCallback, asyncState);
  382. }
  383. public override void EndWrite (IAsyncResult asyncResult)
  384. {
  385. Impl.EndWrite (asyncResult);
  386. }
  387. #else // !SECURITY_DEP
  388. const string EXCEPTION_MESSAGE = "System.Net.Security.SslStream is not supported on the current platform.";
  389. public SslStream (Stream innerStream)
  390. : this (innerStream, false)
  391. {
  392. }
  393. public SslStream (Stream innerStream, bool leaveInnerStreamOpen)
  394. : base (innerStream, leaveInnerStreamOpen)
  395. {
  396. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  397. }
  398. public SslStream (Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback userCertificateValidationCallback)
  399. : this (innerStream, leaveInnerStreamOpen)
  400. {
  401. }
  402. public SslStream (Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback userCertificateValidationCallback, LocalCertificateSelectionCallback userCertificateSelectionCallback)
  403. : this (innerStream, leaveInnerStreamOpen)
  404. {
  405. }
  406. public SslStream (Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback userCertificateValidationCallback, LocalCertificateSelectionCallback userCertificateSelectionCallback, EncryptionPolicy encryptionPolicy)
  407. : this (innerStream, leaveInnerStreamOpen)
  408. {
  409. }
  410. public virtual void AuthenticateAsClient (string targetHost)
  411. {
  412. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  413. }
  414. public virtual void AuthenticateAsClient (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
  415. {
  416. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  417. }
  418. public virtual IAsyncResult BeginAuthenticateAsClient (string targetHost, AsyncCallback asyncCallback, object asyncState)
  419. {
  420. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  421. }
  422. public virtual IAsyncResult BeginAuthenticateAsClient (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation, AsyncCallback asyncCallback, object asyncState)
  423. {
  424. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  425. }
  426. public virtual void EndAuthenticateAsClient (IAsyncResult asyncResult)
  427. {
  428. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  429. }
  430. public virtual void AuthenticateAsServer (X509Certificate serverCertificate)
  431. {
  432. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  433. }
  434. public virtual void AuthenticateAsServer (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
  435. {
  436. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  437. }
  438. public virtual IAsyncResult BeginAuthenticateAsServer (X509Certificate serverCertificate, AsyncCallback asyncCallback, object asyncState)
  439. {
  440. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  441. }
  442. public virtual IAsyncResult BeginAuthenticateAsServer (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation, AsyncCallback asyncCallback, object asyncState)
  443. {
  444. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  445. }
  446. public virtual void EndAuthenticateAsServer (IAsyncResult asyncResult)
  447. {
  448. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  449. }
  450. public TransportContext TransportContext {
  451. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  452. }
  453. public virtual Task AuthenticateAsClientAsync (string targetHost)
  454. {
  455. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  456. }
  457. public virtual Task AuthenticateAsClientAsync (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
  458. {
  459. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  460. }
  461. public virtual Task AuthenticateAsServerAsync (X509Certificate serverCertificate)
  462. {
  463. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  464. }
  465. public virtual Task AuthenticateAsServerAsync (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
  466. {
  467. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  468. }
  469. public override bool IsAuthenticated {
  470. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  471. }
  472. public override bool IsMutuallyAuthenticated {
  473. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  474. }
  475. public override bool IsEncrypted {
  476. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  477. }
  478. public override bool IsSigned {
  479. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  480. }
  481. public override bool IsServer {
  482. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  483. }
  484. public virtual SslProtocols SslProtocol {
  485. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  486. }
  487. public virtual bool CheckCertRevocationStatus {
  488. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  489. }
  490. public virtual X509Certificate LocalCertificate {
  491. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  492. }
  493. public virtual X509Certificate RemoteCertificate {
  494. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  495. }
  496. public virtual CipherAlgorithmType CipherAlgorithm {
  497. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  498. }
  499. public virtual int CipherStrength {
  500. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  501. }
  502. public virtual HashAlgorithmType HashAlgorithm {
  503. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  504. }
  505. public virtual int HashStrength {
  506. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  507. }
  508. public virtual ExchangeAlgorithmType KeyExchangeAlgorithm {
  509. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  510. }
  511. public virtual int KeyExchangeStrength {
  512. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  513. }
  514. public override bool CanSeek {
  515. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  516. }
  517. public override bool CanRead {
  518. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  519. }
  520. public override bool CanTimeout {
  521. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  522. }
  523. public override bool CanWrite {
  524. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  525. }
  526. public override int ReadTimeout {
  527. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  528. set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  529. }
  530. public override int WriteTimeout {
  531. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  532. set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  533. }
  534. public override long Length {
  535. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  536. }
  537. public override long Position {
  538. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  539. set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  540. }
  541. public override void SetLength (long value)
  542. {
  543. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  544. }
  545. public override long Seek (long offset, SeekOrigin origin)
  546. {
  547. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  548. }
  549. public override void Flush ()
  550. {
  551. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  552. }
  553. protected override void Dispose (bool disposing)
  554. {
  555. }
  556. public override int Read (byte[] buffer, int offset, int count)
  557. {
  558. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  559. }
  560. public void Write (byte[] buffer)
  561. {
  562. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  563. }
  564. public override void Write (byte[] buffer, int offset, int count)
  565. {
  566. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  567. }
  568. public override IAsyncResult BeginRead (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState)
  569. {
  570. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  571. }
  572. public override int EndRead (IAsyncResult asyncResult)
  573. {
  574. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  575. }
  576. public override IAsyncResult BeginWrite (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState)
  577. {
  578. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  579. }
  580. public override void EndWrite (IAsyncResult asyncResult)
  581. {
  582. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  583. }
  584. #endif
  585. public SslApplicationProtocol NegotiatedApplicationProtocol => throw new PlatformNotSupportedException();
  586. }
  587. }