using System.Net;
using System.Net.Sockets;
using System.Net.Security;
+using System.Threading;
using System.Threading.Tasks;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
class MonoTlsStream
{
#if SECURITY_DEP
- readonly IMonoTlsProvider provider;
+ readonly MonoTlsProvider provider;
readonly NetworkStream networkStream;
-#endif
readonly HttpWebRequest request;
- IMonoSslStream sslStream;
- WebExceptionStatus status;
+ readonly MonoTlsSettings settings;
internal HttpWebRequest Request {
get { return request; }
}
+ IMonoSslStream sslStream;
+
internal IMonoSslStream SslStream {
get { return sslStream; }
}
+#else
+ const string EXCEPTION_MESSAGE = "System.Net.Security.SslStream is not supported on the current platform.";
+#endif
+
+ WebExceptionStatus status;
internal WebExceptionStatus ExceptionStatus {
get { return status; }
get; set;
}
-#if SECURITY_DEP
-// readonly ChainValidationHelper validationHelper;
- readonly MonoTlsSettings settings;
-
public MonoTlsStream (HttpWebRequest request, NetworkStream networkStream)
{
+#if SECURITY_DEP
this.request = request;
this.networkStream = networkStream;
provider = request.TlsProvider ?? MonoTlsProviderFactory.GetProviderInternal ();
status = WebExceptionStatus.SecureChannelFailure;
- /*validationHelper =*/ ChainValidationHelper.Create (provider.Provider, ref settings, this);
+ ChainValidationHelper.Create (provider, ref settings, this);
+#else
+ status = WebExceptionStatus.SecureChannelFailure;
+ throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
+#endif
}
internal Stream CreateStream (byte[] buffer)
{
+#if SECURITY_DEP
sslStream = provider.CreateSslStream (networkStream, false, settings);
try {
+ var host = request.Host;
+ if (!string.IsNullOrEmpty (host)) {
+ var pos = host.IndexOf (':');
+ if (pos > 0)
+ host = host.Substring (0, pos);
+ }
+
sslStream.AuthenticateAsClient (
- request.Host, request.ClientCertificates,
+ host, request.ClientCertificates,
(SslProtocols)ServicePointManager.SecurityProtocol,
ServicePointManager.CheckCertificateRevocationList);
status = WebExceptionStatus.Success;
- } catch (Exception) {
+ } catch {
status = WebExceptionStatus.SecureChannelFailure;
throw;
} finally {
}
return sslStream.AuthenticatedStream;
- }
+#else
+ throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
#endif
+ }
}
}