Esempio n. 1
0
        public Task <ITunnel> CreateTunnelAsync(TunnelDestination tunnelEndpoint)
        {
            using (TraceSources.IapDesktop.TraceMethod().WithParameters(tunnelEndpoint))
            {
                var iapEndpoint = new IapTunnelingEndpoint(
                    this.authorizationService.Authorization.Credential,
                    tunnelEndpoint.Instance,
                    tunnelEndpoint.RemotePort,
                    IapTunnelingEndpoint.DefaultNetworkInterface,
                    Globals.UserAgent);


                // Start listener to enable clients to connect. Do not await
                // the listener as we want to continue listeining in the
                // background.
                var listener = SshRelayListener.CreateLocalListener(iapEndpoint);
                var cts      = new CancellationTokenSource();

                _ = listener.ListenAsync(cts.Token);

                // Return the tunnel which allows the listener to be stopped
                // via the CancellationTokenSource.
                return(Task.FromResult <ITunnel>(new Tunnel(iapEndpoint, listener, cts)));
            }
        }
Esempio n. 2
0
 public Tunnel(
     IapTunnelingEndpoint endpoint,
     SshRelayListener listener,
     CancellationTokenSource cancellationTokenSource)
 {
     this.Endpoint = endpoint;
     this.listener = listener;
     this.cancellationTokenSource = cancellationTokenSource;
 }
Esempio n. 3
0
        public Task <ITunnel> CreateTunnelAsync(
            TunnelDestination tunnelEndpoint,
            ISshRelayPolicy relayPolicy)
        {
            using (ApplicationTraceSources.Default.TraceMethod().WithParameters(tunnelEndpoint))
            {
                var clientCertificate =
                    (this.authorizationService.DeviceEnrollment != null &&
                     this.authorizationService.DeviceEnrollment.State == DeviceEnrollmentState.Enrolled)
                    ? this.authorizationService.DeviceEnrollment.Certificate
                    : null;

                if (clientCertificate != null)
                {
                    ApplicationTraceSources.Default.TraceInformation(
                        "Using client certificate (valid till {0})", clientCertificate.NotAfter);
                }

                var iapEndpoint = new IapTunnelingEndpoint(
                    this.authorizationService.Authorization.Credential,
                    tunnelEndpoint.Instance,
                    tunnelEndpoint.RemotePort,
                    IapTunnelingEndpoint.DefaultNetworkInterface,
                    Globals.UserAgent,
                    clientCertificate);

                // Start listener to enable clients to connect. Do not await
                // the listener as we want to continue listeining in the
                // background.
                var listener = SshRelayListener.CreateLocalListener(
                    iapEndpoint,
                    relayPolicy);
                var cts = new CancellationTokenSource();

                _ = listener.ListenAsync(cts.Token);

                // Return the tunnel which allows the listener to be stopped
                // via the CancellationTokenSource.
                return(Task.FromResult <ITunnel>(new Tunnel(iapEndpoint, listener, cts)));
            }
        }