SslStream.platformnotsupported.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. //
  2. // SslStream.cs
  3. //
  4. // Author:
  5. // Rolf Bjarne Kvinge <[email protected]>
  6. //
  7. // Copyright (c) 2016 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. using System.IO;
  27. using System.Security.Authentication;
  28. using System.Security.Cryptography.X509Certificates;
  29. using System.Threading.Tasks;
  30. namespace System.Net.Security
  31. {
  32. /*
  33. * These two are defined by the referencesource; add them here to make
  34. * it easy to switch between the two implementations.
  35. */
  36. internal delegate bool RemoteCertValidationCallback (
  37. string host,
  38. X509Certificate certificate,
  39. X509Chain chain,
  40. SslPolicyErrors sslPolicyErrors);
  41. internal delegate X509Certificate LocalCertSelectionCallback (
  42. string targetHost,
  43. X509CertificateCollection localCertificates,
  44. X509Certificate remoteCertificate,
  45. string[] acceptableIssuers);
  46. public class SslStream : AuthenticatedStream
  47. {
  48. const string EXCEPTION_MESSAGE = "System.Net.Security.SslStream is not supported on the current platform.";
  49. public SslStream (Stream innerStream)
  50. : this (innerStream, false)
  51. {
  52. }
  53. public SslStream (Stream innerStream, bool leaveInnerStreamOpen)
  54. : base (innerStream, leaveInnerStreamOpen)
  55. {
  56. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  57. }
  58. public SslStream (Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback userCertificateValidationCallback)
  59. : this (innerStream, leaveInnerStreamOpen)
  60. {
  61. }
  62. public SslStream (Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback userCertificateValidationCallback, LocalCertificateSelectionCallback userCertificateSelectionCallback)
  63. : this (innerStream, leaveInnerStreamOpen)
  64. {
  65. }
  66. public SslStream (Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback userCertificateValidationCallback, LocalCertificateSelectionCallback userCertificateSelectionCallback, EncryptionPolicy encryptionPolicy)
  67. : this (innerStream, leaveInnerStreamOpen)
  68. {
  69. }
  70. public virtual void AuthenticateAsClient (string targetHost)
  71. {
  72. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  73. }
  74. public virtual void AuthenticateAsClient (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
  75. {
  76. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  77. }
  78. public virtual IAsyncResult BeginAuthenticateAsClient (string targetHost, AsyncCallback asyncCallback, object asyncState)
  79. {
  80. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  81. }
  82. public virtual IAsyncResult BeginAuthenticateAsClient (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation, AsyncCallback asyncCallback, object asyncState)
  83. {
  84. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  85. }
  86. public virtual void EndAuthenticateAsClient (IAsyncResult asyncResult)
  87. {
  88. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  89. }
  90. public virtual void AuthenticateAsServer (X509Certificate serverCertificate)
  91. {
  92. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  93. }
  94. public virtual void AuthenticateAsServer (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
  95. {
  96. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  97. }
  98. public virtual IAsyncResult BeginAuthenticateAsServer (X509Certificate serverCertificate, AsyncCallback asyncCallback, object asyncState)
  99. {
  100. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  101. }
  102. public virtual IAsyncResult BeginAuthenticateAsServer (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation, AsyncCallback asyncCallback, object asyncState)
  103. {
  104. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  105. }
  106. public virtual void EndAuthenticateAsServer (IAsyncResult asyncResult)
  107. {
  108. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  109. }
  110. public TransportContext TransportContext {
  111. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  112. }
  113. public virtual Task AuthenticateAsClientAsync (string targetHost)
  114. {
  115. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  116. }
  117. public virtual Task AuthenticateAsClientAsync (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
  118. {
  119. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  120. }
  121. public virtual Task AuthenticateAsServerAsync (X509Certificate serverCertificate)
  122. {
  123. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  124. }
  125. public virtual Task AuthenticateAsServerAsync (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
  126. {
  127. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  128. }
  129. public virtual Task ShutdownAsync ()
  130. {
  131. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  132. }
  133. public override bool IsAuthenticated {
  134. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  135. }
  136. public override bool IsMutuallyAuthenticated {
  137. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  138. }
  139. public override bool IsEncrypted {
  140. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  141. }
  142. public override bool IsSigned {
  143. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  144. }
  145. public override bool IsServer {
  146. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  147. }
  148. public virtual SslProtocols SslProtocol {
  149. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  150. }
  151. public virtual bool CheckCertRevocationStatus {
  152. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  153. }
  154. public virtual X509Certificate LocalCertificate {
  155. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  156. }
  157. public virtual X509Certificate RemoteCertificate {
  158. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  159. }
  160. public virtual CipherAlgorithmType CipherAlgorithm {
  161. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  162. }
  163. public virtual int CipherStrength {
  164. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  165. }
  166. public virtual HashAlgorithmType HashAlgorithm {
  167. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  168. }
  169. public virtual int HashStrength {
  170. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  171. }
  172. public virtual ExchangeAlgorithmType KeyExchangeAlgorithm {
  173. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  174. }
  175. public virtual int KeyExchangeStrength {
  176. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  177. }
  178. public override bool CanSeek {
  179. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  180. }
  181. public override bool CanRead {
  182. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  183. }
  184. public override bool CanTimeout {
  185. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  186. }
  187. public override bool CanWrite {
  188. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  189. }
  190. public override int ReadTimeout {
  191. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  192. set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  193. }
  194. public override int WriteTimeout {
  195. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  196. set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  197. }
  198. public override long Length {
  199. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  200. }
  201. public override long Position {
  202. get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  203. set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
  204. }
  205. public override void SetLength (long value)
  206. {
  207. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  208. }
  209. public override long Seek (long offset, SeekOrigin origin)
  210. {
  211. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  212. }
  213. public override void Flush ()
  214. {
  215. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  216. }
  217. protected override void Dispose (bool disposing)
  218. {
  219. }
  220. public override int Read (byte[] buffer, int offset, int count)
  221. {
  222. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  223. }
  224. public void Write (byte[] buffer)
  225. {
  226. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  227. }
  228. public override void Write (byte[] buffer, int offset, int count)
  229. {
  230. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  231. }
  232. public override IAsyncResult BeginRead (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState)
  233. {
  234. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  235. }
  236. public override int EndRead (IAsyncResult asyncResult)
  237. {
  238. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  239. }
  240. public override IAsyncResult BeginWrite (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState)
  241. {
  242. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  243. }
  244. public override void EndWrite (IAsyncResult asyncResult)
  245. {
  246. throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
  247. }
  248. }
  249. }