protected MobileTlsContext(MobileAuthenticatedStream parent, MonoSslAuthenticationOptions options)
        {
            Parent           = parent;
            Options          = options;
            IsServer         = options.ServerMode;
            EnabledProtocols = options.EnabledSslProtocols;

            if (options.ServerMode)
            {
                LocalServerCertificate  = options.ServerCertificate;
                AskForClientCertificate = options.ClientCertificateRequired;
            }
            else
            {
                ClientCertificates = options.ClientCertificates;
                TargetHost         = options.TargetHost;
                ServerName         = options.TargetHost;
                if (!string.IsNullOrEmpty(ServerName))
                {
                    var pos = ServerName.IndexOf(':');
                    if (pos > 0)
                    {
                        ServerName = ServerName.Substring(0, pos);
                    }
                }
            }

            certificateValidator = (ICertificateValidator2)ChainValidationHelper.GetInternalValidator(
                parent.SslStream, parent.Provider, parent.Settings);
        }
Esempio n. 2
0
 public MonoBtlsContext(MNS.MobileAuthenticatedStream parent, MNS.MonoSslAuthenticationOptions options)
     : base(parent, options)
 {
     if (IsServer)
     {
         nativeServerCertificate = GetPrivateCertificate(LocalServerCertificate);
     }
 }
Esempio n. 3
0
 protected abstract MobileTlsContext CreateContext(MonoSslAuthenticationOptions options);
Esempio n. 4
0
        async Task ProcessAuthentication(bool runSynchronously, MonoSslAuthenticationOptions options, CancellationToken cancellationToken)
        {
            if (options.ServerMode)
            {
                if (options.ServerCertificate == null)
                {
                    throw new ArgumentException(nameof(options.ServerCertificate));
                }
            }
            else
            {
                if (options.TargetHost == null)
                {
                    throw new ArgumentException(nameof(options.TargetHost));
                }
                if (options.TargetHost.Length == 0)
                {
                    options.TargetHost = "?" + Interlocked.Increment(ref uniqueNameInteger).ToString(NumberFormatInfo.InvariantInfo);
                }
                TargetHost = options.TargetHost;
            }

            if (lastException != null)
            {
                lastException.Throw();
            }

            var asyncRequest = new AsyncHandshakeRequest(this, runSynchronously);

            if (Interlocked.CompareExchange(ref asyncHandshakeRequest, asyncRequest, null) != null)
            {
                throw GetInvalidNestedCallException();
            }
            // Make sure no other async requests can be started during the handshake.
            if (Interlocked.CompareExchange(ref asyncReadRequest, asyncRequest, null) != null)
            {
                throw GetInvalidNestedCallException();
            }
            if (Interlocked.CompareExchange(ref asyncWriteRequest, asyncRequest, null) != null)
            {
                throw GetInvalidNestedCallException();
            }

            AsyncProtocolResult result;

            try {
                lock (ioLock) {
                    if (xobileTlsContext != null)
                    {
                        throw new InvalidOperationException();
                    }
                    readBuffer.Reset();
                    writeBuffer.Reset();

                    xobileTlsContext = CreateContext(options);
                }

                Debug($"ProcessAuthentication({(IsServer ? "server" : "client")})");

                try {
                    result = await asyncRequest.StartOperation(cancellationToken).ConfigureAwait(false);
                } catch (Exception ex) {
                    result = new AsyncProtocolResult(SetException(GetSSPIException(ex)));
                }
            } finally {
                lock (ioLock) {
                    readBuffer.Reset();
                    writeBuffer.Reset();
                    asyncWriteRequest     = null;
                    asyncReadRequest      = null;
                    asyncHandshakeRequest = null;
                }
            }

            if (result.Error != null)
            {
                result.Error.Throw();
            }
        }
Esempio n. 5
0
 protected override MNS.MobileTlsContext CreateContext(MNS.MonoSslAuthenticationOptions options)
 {
     return(new AppleTlsContext(this, options));
 }