internal override void RaiseDataReceivedEvent(RemoteDataEventArgs dataArg) { if (dataArg == null) { throw PSTraceSource.NewArgumentNullException("dataArg"); } RemoteDataObject <PSObject> receivedData = dataArg.ReceivedData; RemotingTargetInterface targetInterface = receivedData.TargetInterface; RemotingDataType dataType = receivedData.DataType; switch (dataType) { case RemotingDataType.SessionCapability: { RemoteSessionCapability remoteSessionCapability = null; try { remoteSessionCapability = RemotingDecoder.GetSessionCapability(receivedData.Data); } catch (PSRemotingDataStructureException exception2) { throw new PSRemotingDataStructureException(RemotingErrorIdStrings.ServerNotFoundCapabilityProperties, new object[] { exception2.Message, PSVersionInfo.BuildVersion, RemotingConstants.ProtocolVersion }); } RemoteSessionStateMachineEventArgs fsmEventArg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.NegotiationReceived) { RemoteSessionCapability = remoteSessionCapability }; this._stateMachine.RaiseEvent(fsmEventArg); if (this.NegotiationReceived != null) { RemoteSessionNegotiationEventArgs eventArgs = new RemoteSessionNegotiationEventArgs(remoteSessionCapability) { RemoteData = receivedData }; this.NegotiationReceived.SafeInvoke <RemoteSessionNegotiationEventArgs>(this, eventArgs); } return; } case RemotingDataType.CloseSession: { PSRemotingDataStructureException reason = new PSRemotingDataStructureException(RemotingErrorIdStrings.ClientRequestedToCloseSession); RemoteSessionStateMachineEventArgs args = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.Close, reason); this._stateMachine.RaiseEvent(args); return; } case RemotingDataType.CreateRunspacePool: this.CreateRunspacePoolReceived.SafeInvoke <RemoteDataEventArgs>(this, dataArg); return; case RemotingDataType.PublicKey: { string publicKey = RemotingDecoder.GetPublicKey(receivedData.Data); this.PublicKeyReceived.SafeInvoke <RemoteDataEventArgs <string> >(this, new RemoteDataEventArgs <string>(publicKey)); return; } } throw new PSRemotingDataStructureException(RemotingErrorIdStrings.ReceivedUnsupportedAction, new object[] { dataType }); }
private void HandleKeyExchangeTimeout(object sender, ElapsedEventArgs eventArgs) { this._keyExchangeTimer.Dispose(); PSRemotingDataStructureException reason = new PSRemotingDataStructureException(RemotingErrorIdStrings.ServerKeyExchangeFailed); this.RaiseEvent(new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.KeyReceiveFailed, reason)); }
private void ProcessEvents() { RemoteSessionStateMachineEventArgs arg = null; do { lock (this.syncObject) { if (this.processPendingEventsQueue.Count == 0) { this.eventsInProcess = false; break; } arg = this.processPendingEventsQueue.Dequeue(); } try { this.RaiseEventPrivate(arg); } catch (Exception exception) { PSRemotingDataStructureException reason = new PSRemotingDataStructureException(exception, RemotingErrorIdStrings.FatalErrorCausingClose, new object[0]); RemoteSessionStateMachineEventArgs args2 = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.Close, reason); this.RaiseEvent(args2, true); } this.RaiseStateMachineEvents(); }while (this.eventsInProcess); }
private void DoFatal(object sender, RemoteSessionStateMachineEventArgs eventArgs) { PSRemotingDataStructureException reason = new PSRemotingDataStructureException(eventArgs.Reason, RemotingErrorIdStrings.FatalErrorCausingClose, new object[0]); RemoteSessionStateMachineEventArgs arg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.Close, reason); this.RaiseEvent(arg, false); }
private bool RunClientNegotiationAlgorithm(RemoteSessionCapability serverRemoteSessionCapability) { Version protocolVersion = serverRemoteSessionCapability.ProtocolVersion; base._serverProtocolVersion = protocolVersion; Version version2 = base.Context.ClientCapability.ProtocolVersion; if ((!version2.Equals(protocolVersion) && ((version2 != RemotingConstants.ProtocolVersionWin7RTM) || (protocolVersion != RemotingConstants.ProtocolVersionWin7RC))) && ((version2 != RemotingConstants.ProtocolVersionCurrent) || ((protocolVersion != RemotingConstants.ProtocolVersionWin7RC) && (protocolVersion != RemotingConstants.ProtocolVersionWin7RTM)))) { PSRemotingDataStructureException exception = new PSRemotingDataStructureException(RemotingErrorIdStrings.ClientNegotiationFailed, new object[] { "protocolversion", protocolVersion, PSVersionInfo.BuildVersion, RemotingConstants.ProtocolVersion }); throw exception; } Version pSVersion = serverRemoteSessionCapability.PSVersion; if (!base.Context.ClientCapability.PSVersion.Equals(pSVersion)) { PSRemotingDataStructureException exception2 = new PSRemotingDataStructureException(RemotingErrorIdStrings.ClientNegotiationFailed, new object[] { "PSVersion", pSVersion.ToString(), PSVersionInfo.BuildVersion, RemotingConstants.ProtocolVersion }); throw exception2; } Version serializationVersion = serverRemoteSessionCapability.SerializationVersion; if (!base.Context.ClientCapability.SerializationVersion.Equals(serializationVersion)) { PSRemotingDataStructureException exception3 = new PSRemotingDataStructureException(RemotingErrorIdStrings.ClientNegotiationFailed, new object[] { "SerializationVersion", serializationVersion.ToString(), PSVersionInfo.BuildVersion, RemotingConstants.ProtocolVersion }); throw exception3; } return(true); }
/// <summary> /// Handles a fatal error message. Throws a well defined error message, /// which contains the reason for the fatal error as an inner exception. /// This way the internal details are not surfaced to the user. /// </summary> /// <param name="sender">Sender of this event, unused.</param> /// <param name="eventArgs">Arguments describing this event.</param> private void DoFatal(object sender, RemoteSessionStateMachineEventArgs eventArgs) { PSRemotingDataStructureException fatalError = new PSRemotingDataStructureException(eventArgs.Reason, RemotingErrorIdStrings.FatalErrorCausingClose); RemoteSessionStateMachineEventArgs closeEvent = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.Close, fatalError); RaiseEvent(closeEvent); }
internal override void RaiseDataReceivedEvent(RemoteDataEventArgs dataArg) { if (dataArg == null) { throw PSTraceSource.NewArgumentNullException("dataArg"); } RemoteDataObject<PSObject> receivedData = dataArg.ReceivedData; RemotingTargetInterface targetInterface = receivedData.TargetInterface; RemotingDataType dataType = receivedData.DataType; switch (dataType) { case RemotingDataType.SessionCapability: { RemoteSessionCapability remoteSessionCapability = null; try { remoteSessionCapability = RemotingDecoder.GetSessionCapability(receivedData.Data); } catch (PSRemotingDataStructureException exception2) { throw new PSRemotingDataStructureException(RemotingErrorIdStrings.ServerNotFoundCapabilityProperties, new object[] { exception2.Message, PSVersionInfo.BuildVersion, RemotingConstants.ProtocolVersion }); } RemoteSessionStateMachineEventArgs fsmEventArg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.NegotiationReceived) { RemoteSessionCapability = remoteSessionCapability }; this._stateMachine.RaiseEvent(fsmEventArg); if (this.NegotiationReceived != null) { RemoteSessionNegotiationEventArgs eventArgs = new RemoteSessionNegotiationEventArgs(remoteSessionCapability) { RemoteData = receivedData }; this.NegotiationReceived.SafeInvoke<RemoteSessionNegotiationEventArgs>(this, eventArgs); } return; } case RemotingDataType.CloseSession: { PSRemotingDataStructureException reason = new PSRemotingDataStructureException(RemotingErrorIdStrings.ClientRequestedToCloseSession); RemoteSessionStateMachineEventArgs args = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.Close, reason); this._stateMachine.RaiseEvent(args); return; } case RemotingDataType.CreateRunspacePool: this.CreateRunspacePoolReceived.SafeInvoke<RemoteDataEventArgs>(this, dataArg); return; case RemotingDataType.PublicKey: { string publicKey = RemotingDecoder.GetPublicKey(receivedData.Data); this.PublicKeyReceived.SafeInvoke<RemoteDataEventArgs<string>>(this, new RemoteDataEventArgs<string>(publicKey)); return; } } throw new PSRemotingDataStructureException(RemotingErrorIdStrings.ReceivedUnsupportedAction, new object[] { dataType }); }
private void ProcessSessionMessages(RemoteDataEventArgs arg) { if ((arg == null) || (arg.ReceivedData == null)) { throw PSTraceSource.NewArgumentNullException("arg"); } RemoteDataObject <PSObject> receivedData = arg.ReceivedData; RemotingTargetInterface targetInterface = receivedData.TargetInterface; RemotingDataType dataType = receivedData.DataType; switch (dataType) { case RemotingDataType.SessionCapability: { RemoteSessionCapability remoteSessionCapability = null; try { remoteSessionCapability = RemotingDecoder.GetSessionCapability(receivedData.Data); } catch (PSRemotingDataStructureException exception2) { throw new PSRemotingDataStructureException(RemotingErrorIdStrings.ClientNotFoundCapabilityProperties, new object[] { exception2.Message, PSVersionInfo.BuildVersion, RemotingConstants.ProtocolVersion }); } RemoteSessionStateMachineEventArgs args2 = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.NegotiationReceived) { RemoteSessionCapability = remoteSessionCapability }; this._stateMachine.RaiseEvent(args2, false); RemoteSessionNegotiationEventArgs eventArgs = new RemoteSessionNegotiationEventArgs(remoteSessionCapability); this.NegotiationReceived.SafeInvoke <RemoteSessionNegotiationEventArgs>(this, eventArgs); return; } case RemotingDataType.CloseSession: { PSRemotingDataStructureException reason = new PSRemotingDataStructureException(RemotingErrorIdStrings.ServerRequestedToCloseSession); RemoteSessionStateMachineEventArgs args = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.Close, reason); this._stateMachine.RaiseEvent(args, false); return; } case RemotingDataType.EncryptedSessionKey: { string encryptedSessionKey = RemotingDecoder.GetEncryptedSessionKey(receivedData.Data); this.EncryptedSessionKeyReceived.SafeInvoke <RemoteDataEventArgs <string> >(this, new RemoteDataEventArgs <string>(encryptedSessionKey)); return; } case RemotingDataType.PublicKeyRequest: this.PublicKeyRequestReceived.SafeInvoke <RemoteDataEventArgs <string> >(this, new RemoteDataEventArgs <string>(string.Empty)); return; } throw new PSRemotingDataStructureException(RemotingErrorIdStrings.ReceivedUnsupportedAction, new object[] { dataType }); }
private bool RunServerNegotiationAlgorithm(RemoteSessionCapability clientCapability, bool onConnect) { Version protocolVersion = clientCapability.ProtocolVersion; Version version2 = this._context.ServerCapability.ProtocolVersion; if (onConnect) { if (protocolVersion != version2) { PSRemotingDataStructureException exception = new PSRemotingDataStructureException(RemotingErrorIdStrings.ServerConnectFailedOnNegotiation, new object[] { "protocolversion", protocolVersion, PSVersionInfo.BuildVersion, RemotingConstants.ProtocolVersion }); throw exception; } } else { if ((protocolVersion == RemotingConstants.ProtocolVersionWin7RTM) && (version2 == RemotingConstants.ProtocolVersionCurrent)) { version2 = RemotingConstants.ProtocolVersionWin7RTM; this._context.ServerCapability.ProtocolVersion = version2; } if ((protocolVersion == RemotingConstants.ProtocolVersionWin7RC) && ((version2 == RemotingConstants.ProtocolVersionWin7RTM) || (version2 == RemotingConstants.ProtocolVersionCurrent))) { version2 = RemotingConstants.ProtocolVersionWin7RC; this._context.ServerCapability.ProtocolVersion = version2; } if ((protocolVersion.Major != version2.Major) || (protocolVersion.Minor < version2.Minor)) { PSRemotingDataStructureException exception2 = new PSRemotingDataStructureException(RemotingErrorIdStrings.ServerNegotiationFailed, new object[] { "protocolversion", protocolVersion, PSVersionInfo.BuildVersion, RemotingConstants.ProtocolVersion }); throw exception2; } } Version pSVersion = clientCapability.PSVersion; Version version4 = this._context.ServerCapability.PSVersion; if ((pSVersion.Major != version4.Major) || (pSVersion.Minor < version4.Minor)) { PSRemotingDataStructureException exception3 = new PSRemotingDataStructureException(RemotingErrorIdStrings.ServerNegotiationFailed, new object[] { "PSVersion", pSVersion, PSVersionInfo.BuildVersion, RemotingConstants.ProtocolVersion }); throw exception3; } Version serializationVersion = clientCapability.SerializationVersion; Version version6 = this._context.ServerCapability.SerializationVersion; if ((serializationVersion.Major == version6.Major) && (serializationVersion.Minor >= version6.Minor)) { return(true); } PSRemotingDataStructureException exception4 = new PSRemotingDataStructureException(RemotingErrorIdStrings.ServerNegotiationFailed, new object[] { "SerializationVersion", serializationVersion, PSVersionInfo.BuildVersion, RemotingConstants.ProtocolVersion }); throw exception4; }
private void HandleFatalError(Exception ex) { // Event handlers should not throw exceptions. But if they do we need to // handle them here to prevent the state machine from not responding when there are pending // events to process. // Enqueue a fatal error event if such an exception occurs; clear all existing events.. we are going to terminate the session PSRemotingDataStructureException fatalError = new PSRemotingDataStructureException(ex, RemotingErrorIdStrings.FatalErrorCausingClose); RemoteSessionStateMachineEventArgs closeEvent = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.Close, fatalError); RaiseEvent(closeEvent, true); }
/// <summary> /// Handles the timeout for key exchange /// </summary> /// <param name="sender">sender of this event</param> private void HandleKeyExchangeTimeout(object sender) { Dbg.Assert(_state == RemoteSessionState.EstablishedAndKeyRequested, "timeout should only happen when waiting for a key"); Timer tmp = Interlocked.Exchange(ref _keyExchangeTimer, null); if (tmp != null) { tmp.Dispose(); } PSRemotingDataStructureException exception = new PSRemotingDataStructureException(RemotingErrorIdStrings.ServerKeyExchangeFailed); RaiseEvent(new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.KeyReceiveFailed, exception)); } // SetStateHandler
private void ProcessSessionMessages(RemoteDataEventArgs arg) { if ((arg == null) || (arg.ReceivedData == null)) { throw PSTraceSource.NewArgumentNullException("arg"); } RemoteDataObject<PSObject> receivedData = arg.ReceivedData; RemotingTargetInterface targetInterface = receivedData.TargetInterface; RemotingDataType dataType = receivedData.DataType; switch (dataType) { case RemotingDataType.SessionCapability: { RemoteSessionCapability remoteSessionCapability = null; try { remoteSessionCapability = RemotingDecoder.GetSessionCapability(receivedData.Data); } catch (PSRemotingDataStructureException exception2) { throw new PSRemotingDataStructureException(RemotingErrorIdStrings.ClientNotFoundCapabilityProperties, new object[] { exception2.Message, PSVersionInfo.BuildVersion, RemotingConstants.ProtocolVersion }); } RemoteSessionStateMachineEventArgs args2 = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.NegotiationReceived) { RemoteSessionCapability = remoteSessionCapability }; this._stateMachine.RaiseEvent(args2, false); RemoteSessionNegotiationEventArgs eventArgs = new RemoteSessionNegotiationEventArgs(remoteSessionCapability); this.NegotiationReceived.SafeInvoke<RemoteSessionNegotiationEventArgs>(this, eventArgs); return; } case RemotingDataType.CloseSession: { PSRemotingDataStructureException reason = new PSRemotingDataStructureException(RemotingErrorIdStrings.ServerRequestedToCloseSession); RemoteSessionStateMachineEventArgs args = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.Close, reason); this._stateMachine.RaiseEvent(args, false); return; } case RemotingDataType.EncryptedSessionKey: { string encryptedSessionKey = RemotingDecoder.GetEncryptedSessionKey(receivedData.Data); this.EncryptedSessionKeyReceived.SafeInvoke<RemoteDataEventArgs<string>>(this, new RemoteDataEventArgs<string>(encryptedSessionKey)); return; } case RemotingDataType.PublicKeyRequest: this.PublicKeyRequestReceived.SafeInvoke<RemoteDataEventArgs<string>>(this, new RemoteDataEventArgs<string>(string.Empty)); return; } throw new PSRemotingDataStructureException(RemotingErrorIdStrings.ReceivedUnsupportedAction, new object[] { dataType }); }
/// <summary> /// This method is used by the input queue dispatching mechanism. /// It examines the data and takes appropriate actions. /// </summary> /// <param name="dataArg"> /// The received client data. /// </param> /// <exception cref="ArgumentNullException"> /// If the parameter is null. /// </exception> internal override void RaiseDataReceivedEvent(RemoteDataEventArgs dataArg) { if (dataArg == null) { throw PSTraceSource.NewArgumentNullException("dataArg"); } RemoteDataObject <PSObject> rcvdData = dataArg.ReceivedData; RemotingTargetInterface targetInterface = rcvdData.TargetInterface; RemotingDataType dataType = rcvdData.DataType; Dbg.Assert(targetInterface == RemotingTargetInterface.Session, "targetInterface must be Session"); switch (dataType) { case RemotingDataType.CreateRunspacePool: { // At this point, the negotiation is complete, so // need to import the clients public key CreateRunspacePoolReceived.SafeInvoke(this, dataArg); } break; case RemotingDataType.CloseSession: PSRemotingDataStructureException reasonOfClose = new PSRemotingDataStructureException(RemotingErrorIdStrings.ClientRequestedToCloseSession); RemoteSessionStateMachineEventArgs closeSessionArg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.Close, reasonOfClose); _stateMachine.RaiseEvent(closeSessionArg); break; case RemotingDataType.SessionCapability: RemoteSessionCapability capability = null; try { capability = RemotingDecoder.GetSessionCapability(rcvdData.Data); } catch (PSRemotingDataStructureException dse) { // this will happen if expected properties are not // received for session capability throw new PSRemotingDataStructureException(RemotingErrorIdStrings.ServerNotFoundCapabilityProperties, dse.Message, PSVersionInfo.GitCommitId, RemotingConstants.ProtocolVersion); } RemoteSessionStateMachineEventArgs capabilityArg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.NegotiationReceived); capabilityArg.RemoteSessionCapability = capability; _stateMachine.RaiseEvent(capabilityArg); if (NegotiationReceived != null) { RemoteSessionNegotiationEventArgs negotiationArg = new RemoteSessionNegotiationEventArgs(capability); negotiationArg.RemoteData = rcvdData; NegotiationReceived.SafeInvoke(this, negotiationArg); } break; case RemotingDataType.PublicKey: { string remotePublicKey = RemotingDecoder.GetPublicKey(rcvdData.Data); PublicKeyReceived.SafeInvoke(this, new RemoteDataEventArgs <string>(remotePublicKey)); } break; default: throw new PSRemotingDataStructureException(RemotingErrorIdStrings.ReceivedUnsupportedAction, dataType); } }
// TODO: If this is not used remove this // internal override event EventHandler<RemoteDataEventArgs> DataReceived; /// <summary> /// This processes the object received from transport which are /// targeted for session /// </summary> /// <param name="arg"> /// argument contains the data object /// </param> private void ProcessSessionMessages(RemoteDataEventArgs arg) { if (arg == null || arg.ReceivedData == null) { throw PSTraceSource.NewArgumentNullException("arg"); } RemoteDataObject<PSObject> rcvdData = arg.ReceivedData; RemotingTargetInterface targetInterface = rcvdData.TargetInterface; Dbg.Assert(targetInterface == RemotingTargetInterface.Session, "targetInterface must be Session"); RemotingDataType dataType = rcvdData.DataType; switch (dataType) { case RemotingDataType.CloseSession: PSRemotingDataStructureException reasonOfClose = new PSRemotingDataStructureException(RemotingErrorIdStrings.ServerRequestedToCloseSession); RemoteSessionStateMachineEventArgs closeSessionArg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.Close, reasonOfClose); _stateMachine.RaiseEvent(closeSessionArg); break; case RemotingDataType.SessionCapability: RemoteSessionCapability capability = null; try { capability = RemotingDecoder.GetSessionCapability(rcvdData.Data); } catch (PSRemotingDataStructureException dse) { // this will happen if expected properties are not // received for session capability throw new PSRemotingDataStructureException(RemotingErrorIdStrings.ClientNotFoundCapabilityProperties, dse.Message, PSVersionInfo.BuildVersion, RemotingConstants.ProtocolVersion); } RemoteSessionStateMachineEventArgs capabilityArg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.NegotiationReceived); capabilityArg.RemoteSessionCapability = capability; _stateMachine.RaiseEvent(capabilityArg); RemoteSessionNegotiationEventArgs negotiationArg = new RemoteSessionNegotiationEventArgs(capability); NegotiationReceived.SafeInvoke(this, negotiationArg); break; case RemotingDataType.EncryptedSessionKey: { String encryptedSessionKey = RemotingDecoder.GetEncryptedSessionKey(rcvdData.Data); EncryptedSessionKeyReceived.SafeInvoke(this, new RemoteDataEventArgs<string>(encryptedSessionKey)); } break; case RemotingDataType.PublicKeyRequest: { PublicKeyRequestReceived.SafeInvoke(this, new RemoteDataEventArgs<string>(String.Empty)); } break; default: { throw new PSRemotingDataStructureException(RemotingErrorIdStrings.ReceivedUnsupportedAction, dataType); } } }
/// <summary> /// Handles a fatal error message. Throws a well defined error message, /// which contains the reason for the fatal error as an inner exception. /// This way the internal details are not surfaced to the user /// </summary> /// <param name="sender">sender of this event, unused</param> /// <param name="eventArgs">arguments describing this event</param> private void DoFatal(object sender, RemoteSessionStateMachineEventArgs eventArgs) { PSRemotingDataStructureException fatalError = new PSRemotingDataStructureException(eventArgs.Reason, RemotingErrorIdStrings.FatalErrorCausingClose); RemoteSessionStateMachineEventArgs closeEvent = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.Close, fatalError); RaiseEvent(closeEvent); }
/// <summary> /// This is the handler for MessageReceived event. It dispatches the data to various components /// that uses the data. /// </summary> /// <param name="sender"></param> /// <param name="fsmEventArg"> /// This parameter contains the FSM event. /// </param> /// /// <exception cref="ArgumentNullException"> /// If the parameter <paramref name="fsmEventArg"/> is null. /// </exception> /// <exception cref="ArgumentException"> /// If the parameter <paramref name="fsmEventArg"/> does not contain remote data. /// </exception> internal void DoMessageReceived(object sender, RemoteSessionStateMachineEventArgs fsmEventArg) { using (s_trace.TraceEventHandlers()) { if (fsmEventArg == null) { throw PSTraceSource.NewArgumentNullException("fsmEventArg"); } if (fsmEventArg.RemoteData == null) { throw PSTraceSource.NewArgumentException("fsmEventArg"); } Dbg.Assert(_state == RemoteSessionState.Established || _state == RemoteSessionState.EstablishedAndKeyExchanged || _state == RemoteSessionState.EstablishedAndKeyReceived || _state == RemoteSessionState.EstablishedAndKeySent, //server session will never be in this state.. TODO- remove this "State must be Established or EstablishedAndKeySent or EstablishedAndKeyReceived or EstablishedAndKeyExchanged"); RemotingTargetInterface targetInterface = fsmEventArg.RemoteData.TargetInterface; RemotingDataType dataType = fsmEventArg.RemoteData.DataType; Guid clientRunspacePoolId; ServerRunspacePoolDriver runspacePoolDriver; //string errorMessage = null; RemoteDataEventArgs remoteDataForSessionArg = null; switch (targetInterface) { case RemotingTargetInterface.Session: { switch (dataType) { // GETBACK case RemotingDataType.CreateRunspacePool: remoteDataForSessionArg = new RemoteDataEventArgs(fsmEventArg.RemoteData); _session.SessionDataStructureHandler.RaiseDataReceivedEvent(remoteDataForSessionArg); break; default: Dbg.Assert(false, "Should never reach here"); break; } } break; case RemotingTargetInterface.RunspacePool: // GETBACK clientRunspacePoolId = fsmEventArg.RemoteData.RunspacePoolId; runspacePoolDriver = _session.GetRunspacePoolDriver(clientRunspacePoolId); if (runspacePoolDriver != null) { runspacePoolDriver.DataStructureHandler.ProcessReceivedData(fsmEventArg.RemoteData); } else { s_trace.WriteLine(@"Server received data for Runspace (id: {0}), but the Runspace cannot be found", clientRunspacePoolId); PSRemotingDataStructureException reasonOfFailure = new PSRemotingDataStructureException(RemotingErrorIdStrings.RunspaceCannotBeFound, clientRunspacePoolId); RemoteSessionStateMachineEventArgs runspaceNotFoundArg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.FatalError, reasonOfFailure); RaiseEvent(runspaceNotFoundArg); } break; case RemotingTargetInterface.PowerShell: clientRunspacePoolId = fsmEventArg.RemoteData.RunspacePoolId; runspacePoolDriver = _session.GetRunspacePoolDriver(clientRunspacePoolId); runspacePoolDriver.DataStructureHandler.DispatchMessageToPowerShell(fsmEventArg.RemoteData); break; default: s_trace.WriteLine("Server received data unknown targetInterface: {0}", targetInterface); PSRemotingDataStructureException reasonOfFailure2 = new PSRemotingDataStructureException(RemotingErrorIdStrings.ReceivedUnsupportedRemotingTargetInterfaceType, targetInterface); RemoteSessionStateMachineEventArgs unknownTargetArg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.FatalError, reasonOfFailure2); RaiseEvent(unknownTargetArg); break; } } }
private void OnSignalCompleted(object sender, EventArgs e) { PSRemotingDataStructureException reason = new PSRemotingDataStructureException(RemotingErrorIdStrings.PipelineStopped); this.InvocationStateInfoReceived.SafeInvoke<RemoteDataEventArgs<PSInvocationStateInfo>>(this, new RemoteDataEventArgs<PSInvocationStateInfo>(new PSInvocationStateInfo(PSInvocationState.Stopped, reason))); }
/// <summary> /// This is the server side remote session capability negotiation algorithm. /// </summary> /// <param name="clientCapability"> /// This is the client capability that the server received from client. /// </param> /// <param name="onConnect"> /// If the negotiation is on a connect (and not create) /// </param> /// <returns> /// The method returns true if the capability negotiation is successful. /// Otherwise, it returns false. /// </returns> /// <exception cref="PSRemotingDataStructureException"> /// 1. PowerShell server does not support the PSVersion {1} negotiated by the client. /// Make sure the client is compatible with the build {2} of PowerShell. /// 2. PowerShell server does not support the SerializationVersion {1} negotiated by the client. /// Make sure the client is compatible with the build {2} of PowerShell. /// </exception> private bool RunServerNegotiationAlgorithm(RemoteSessionCapability clientCapability, bool onConnect) { Dbg.Assert(clientCapability != null, "Client capability cache must be non-null"); Version clientProtocolVersion = clientCapability.ProtocolVersion; Version serverProtocolVersion = Context.ServerCapability.ProtocolVersion; if (onConnect) { bool connectSupported = false; // Win10 server can support reconstruct/reconnect for all 2.x protocol versions // that support reconstruct/reconnect, Protocol 2.2+ // Major protocol version differences (2.x -> 3.x) are not supported. if ((serverProtocolVersion == RemotingConstants.ProtocolVersionWin10RTM) && (clientProtocolVersion.Major == serverProtocolVersion.Major)) { if (clientProtocolVersion.Minor == RemotingConstants.ProtocolVersionWin8RTM.Minor) { // Report that server is Win8 version to the client // Protocol: 2.2 connectSupported = true; serverProtocolVersion = RemotingConstants.ProtocolVersionWin8RTM; Context.ServerCapability.ProtocolVersion = serverProtocolVersion; } else if (clientProtocolVersion.Minor > RemotingConstants.ProtocolVersionWin8RTM.Minor) { // All other minor versions are supported and the server returns its full capability // Protocol: 2.3, 2.4, 2.5 ... connectSupported = true; } } if (!connectSupported) { // Throw for protocol versions 2.x that don't support disconnect/reconnect. // Protocol: < 2.2 PSRemotingDataStructureException reasonOfFailure = new PSRemotingDataStructureException(RemotingErrorIdStrings.ServerConnectFailedOnNegotiation, RemoteDataNameStrings.PS_STARTUP_PROTOCOL_VERSION_NAME, clientProtocolVersion, PSVersionInfo.BuildVersion, RemotingConstants.ProtocolVersion); throw reasonOfFailure; } } else { // Win10 server can support Win8 client if (clientProtocolVersion == RemotingConstants.ProtocolVersionWin8RTM && ( (serverProtocolVersion == RemotingConstants.ProtocolVersionWin10RTM) )) { // - report that server is Win8 version to the client serverProtocolVersion = RemotingConstants.ProtocolVersionWin8RTM; Context.ServerCapability.ProtocolVersion = serverProtocolVersion; } // Win8, Win10 server can support Win7 client if (clientProtocolVersion == RemotingConstants.ProtocolVersionWin7RTM && ( (serverProtocolVersion == RemotingConstants.ProtocolVersionWin8RTM) || (serverProtocolVersion == RemotingConstants.ProtocolVersionWin10RTM) )) { // - report that server is Win7 version to the client serverProtocolVersion = RemotingConstants.ProtocolVersionWin7RTM; Context.ServerCapability.ProtocolVersion = serverProtocolVersion; } // Win7, Win8, Win10 server can support Win7 RC client if (clientProtocolVersion == RemotingConstants.ProtocolVersionWin7RC && ( (serverProtocolVersion == RemotingConstants.ProtocolVersionWin7RTM) || (serverProtocolVersion == RemotingConstants.ProtocolVersionWin8RTM) || (serverProtocolVersion == RemotingConstants.ProtocolVersionWin10RTM) )) { // - report that server is RC version to the client serverProtocolVersion = RemotingConstants.ProtocolVersionWin7RC; Context.ServerCapability.ProtocolVersion = serverProtocolVersion; } if (!((clientProtocolVersion.Major == serverProtocolVersion.Major) && (clientProtocolVersion.Minor >= serverProtocolVersion.Minor))) { PSRemotingDataStructureException reasonOfFailure = new PSRemotingDataStructureException(RemotingErrorIdStrings.ServerNegotiationFailed, RemoteDataNameStrings.PS_STARTUP_PROTOCOL_VERSION_NAME, clientProtocolVersion, PSVersionInfo.BuildVersion, RemotingConstants.ProtocolVersion); throw reasonOfFailure; } } // PSVersion Check Version clientPSVersion = clientCapability.PSVersion; Version serverPSVersion = Context.ServerCapability.PSVersion; if (!((clientPSVersion.Major == serverPSVersion.Major) && (clientPSVersion.Minor >= serverPSVersion.Minor))) { PSRemotingDataStructureException reasonOfFailure = new PSRemotingDataStructureException(RemotingErrorIdStrings.ServerNegotiationFailed, RemoteDataNameStrings.PSVersion, clientPSVersion, PSVersionInfo.BuildVersion, RemotingConstants.ProtocolVersion); throw reasonOfFailure; } // SerializationVersion check Version clientSerVersion = clientCapability.SerializationVersion; Version serverSerVersion = Context.ServerCapability.SerializationVersion; if (!((clientSerVersion.Major == serverSerVersion.Major) && (clientSerVersion.Minor >= serverSerVersion.Minor))) { PSRemotingDataStructureException reasonOfFailure = new PSRemotingDataStructureException(RemotingErrorIdStrings.ServerNegotiationFailed, RemoteDataNameStrings.SerializationVersion, clientSerVersion, PSVersionInfo.BuildVersion, RemotingConstants.ProtocolVersion); throw reasonOfFailure; } return true; }
/// <summary> /// This method is used by the input queue dispatching mechanism. /// It examines the data and takes appropriate actions. /// </summary> /// <param name="dataArg"> /// The received client data. /// </param> /// /// <exception cref="ArgumentNullException"> /// If the parameter is null. /// </exception> internal override void RaiseDataReceivedEvent(RemoteDataEventArgs dataArg) { if (dataArg == null) { throw PSTraceSource.NewArgumentNullException("dataArg"); } RemoteDataObject<PSObject> rcvdData = dataArg.ReceivedData; RemotingTargetInterface targetInterface = rcvdData.TargetInterface; RemotingDataType dataType = rcvdData.DataType; Dbg.Assert(targetInterface == RemotingTargetInterface.Session, "targetInterface must be Session"); switch (dataType) { case RemotingDataType.CreateRunspacePool: { // At this point, the negotiation is complete, so // need to import the clients public key CreateRunspacePoolReceived.SafeInvoke(this, dataArg); } break; case RemotingDataType.CloseSession: PSRemotingDataStructureException reasonOfClose = new PSRemotingDataStructureException(RemotingErrorIdStrings.ClientRequestedToCloseSession); RemoteSessionStateMachineEventArgs closeSessionArg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.Close, reasonOfClose); _stateMachine.RaiseEvent(closeSessionArg); break; case RemotingDataType.SessionCapability: RemoteSessionCapability capability = null; try { capability = RemotingDecoder.GetSessionCapability(rcvdData.Data); } catch (PSRemotingDataStructureException dse) { // this will happen if expected properties are not // received for session capability throw new PSRemotingDataStructureException(RemotingErrorIdStrings.ServerNotFoundCapabilityProperties, dse.Message, PSVersionInfo.BuildVersion, RemotingConstants.ProtocolVersion); } RemoteSessionStateMachineEventArgs capabilityArg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.NegotiationReceived); capabilityArg.RemoteSessionCapability = capability; _stateMachine.RaiseEvent(capabilityArg); if (NegotiationReceived != null) { RemoteSessionNegotiationEventArgs negotiationArg = new RemoteSessionNegotiationEventArgs(capability); negotiationArg.RemoteData = rcvdData; NegotiationReceived.SafeInvoke(this, negotiationArg); } break; case RemotingDataType.PublicKey: { string remotePublicKey = RemotingDecoder.GetPublicKey(rcvdData.Data); PublicKeyReceived.SafeInvoke(this, new RemoteDataEventArgs<string>(remotePublicKey)); } break; default: throw new PSRemotingDataStructureException(RemotingErrorIdStrings.ReceivedUnsupportedAction, dataType); } }
private void ProcessEvents() { RemoteSessionStateMachineEventArgs arg = null; do { lock (this.syncObject) { if (this.processPendingEventsQueue.Count == 0) { this.eventsInProcess = false; break; } arg = this.processPendingEventsQueue.Dequeue(); } try { this.RaiseEventPrivate(arg); } catch (Exception exception) { PSRemotingDataStructureException reason = new PSRemotingDataStructureException(exception, RemotingErrorIdStrings.FatalErrorCausingClose, new object[0]); RemoteSessionStateMachineEventArgs args2 = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.Close, reason); this.RaiseEvent(args2, true); } this.RaiseStateMachineEvents(); } while (this.eventsInProcess); }
private void HandleKeyExchangeTimeout(object sender, ElapsedEventArgs eventArgs) { this._keyExchangeTimer.Dispose(); PSRemotingDataStructureException reason = new PSRemotingDataStructureException(RemotingErrorIdStrings.ClientKeyExchangeFailed); this.RaiseEvent(new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.KeyReceiveFailed, reason), false); }
// TODO: If this is not used remove this // internal override event EventHandler<RemoteDataEventArgs> DataReceived; /// <summary> /// This processes the object received from transport which are /// targeted for session /// </summary> /// <param name="arg"> /// argument contains the data object /// </param> private void ProcessSessionMessages(RemoteDataEventArgs arg) { if (arg == null || arg.ReceivedData == null) { throw PSTraceSource.NewArgumentNullException("arg"); } RemoteDataObject <PSObject> rcvdData = arg.ReceivedData; RemotingTargetInterface targetInterface = rcvdData.TargetInterface; Dbg.Assert(targetInterface == RemotingTargetInterface.Session, "targetInterface must be Session"); RemotingDataType dataType = rcvdData.DataType; switch (dataType) { case RemotingDataType.CloseSession: PSRemotingDataStructureException reasonOfClose = new PSRemotingDataStructureException(RemotingErrorIdStrings.ServerRequestedToCloseSession); RemoteSessionStateMachineEventArgs closeSessionArg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.Close, reasonOfClose); _stateMachine.RaiseEvent(closeSessionArg); break; case RemotingDataType.SessionCapability: RemoteSessionCapability capability = null; try { capability = RemotingDecoder.GetSessionCapability(rcvdData.Data); } catch (PSRemotingDataStructureException dse) { // this will happen if expected properties are not // received for session capability throw new PSRemotingDataStructureException(RemotingErrorIdStrings.ClientNotFoundCapabilityProperties, dse.Message, PSVersionInfo.GitCommitId, RemotingConstants.ProtocolVersion); } RemoteSessionStateMachineEventArgs capabilityArg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.NegotiationReceived); capabilityArg.RemoteSessionCapability = capability; _stateMachine.RaiseEvent(capabilityArg); RemoteSessionNegotiationEventArgs negotiationArg = new RemoteSessionNegotiationEventArgs(capability); NegotiationReceived.SafeInvoke(this, negotiationArg); break; case RemotingDataType.EncryptedSessionKey: { String encryptedSessionKey = RemotingDecoder.GetEncryptedSessionKey(rcvdData.Data); EncryptedSessionKeyReceived.SafeInvoke(this, new RemoteDataEventArgs <string>(encryptedSessionKey)); } break; case RemotingDataType.PublicKeyRequest: { PublicKeyRequestReceived.SafeInvoke(this, new RemoteDataEventArgs <string>(String.Empty)); } break; default: { throw new PSRemotingDataStructureException(RemotingErrorIdStrings.ReceivedUnsupportedAction, dataType); } } }
private bool RunClientNegotiationAlgorithm(RemoteSessionCapability serverRemoteSessionCapability) { Version protocolVersion = serverRemoteSessionCapability.ProtocolVersion; base._serverProtocolVersion = protocolVersion; Version version2 = base.Context.ClientCapability.ProtocolVersion; if ((!version2.Equals(protocolVersion) && ((version2 != RemotingConstants.ProtocolVersionWin7RTM) || (protocolVersion != RemotingConstants.ProtocolVersionWin7RC))) && ((version2 != RemotingConstants.ProtocolVersionCurrent) || ((protocolVersion != RemotingConstants.ProtocolVersionWin7RC) && (protocolVersion != RemotingConstants.ProtocolVersionWin7RTM)))) { PSRemotingDataStructureException exception = new PSRemotingDataStructureException(RemotingErrorIdStrings.ClientNegotiationFailed, new object[] { "protocolversion", protocolVersion, PSVersionInfo.BuildVersion, RemotingConstants.ProtocolVersion }); throw exception; } Version pSVersion = serverRemoteSessionCapability.PSVersion; if (!base.Context.ClientCapability.PSVersion.Equals(pSVersion)) { PSRemotingDataStructureException exception2 = new PSRemotingDataStructureException(RemotingErrorIdStrings.ClientNegotiationFailed, new object[] { "PSVersion", pSVersion.ToString(), PSVersionInfo.BuildVersion, RemotingConstants.ProtocolVersion }); throw exception2; } Version serializationVersion = serverRemoteSessionCapability.SerializationVersion; if (!base.Context.ClientCapability.SerializationVersion.Equals(serializationVersion)) { PSRemotingDataStructureException exception3 = new PSRemotingDataStructureException(RemotingErrorIdStrings.ClientNegotiationFailed, new object[] { "SerializationVersion", serializationVersion.ToString(), PSVersionInfo.BuildVersion, RemotingConstants.ProtocolVersion }); throw exception3; } return true; }
/// <summary> /// Verifies the negotiation packet received from the server /// </summary> /// <param name="serverRemoteSessionCapability"> /// Capabilities of remote session /// </param> /// <returns> /// The method returns true if the capability negotiation is successful. /// Otherwise, it returns false. /// </returns> /// <exception cref="PSRemotingDataStructureException"> /// 1. PowerShell client does not support the PSVersion {1} negotiated by the server. /// Make sure the server is compatible with the build {2} of PowerShell. /// 2. PowerShell client does not support the SerializationVersion {1} negotiated by the server. /// Make sure the server is compatible with the build {2} of PowerShell. /// </exception> private bool RunClientNegotiationAlgorithm(RemoteSessionCapability serverRemoteSessionCapability) { Dbg.Assert(serverRemoteSessionCapability != null, "server capability cache must be non-null"); // ProtocolVersion check Version serverProtocolVersion = serverRemoteSessionCapability.ProtocolVersion; _serverProtocolVersion = serverProtocolVersion; Version clientProtocolVersion = Context.ClientCapability.ProtocolVersion; if ( clientProtocolVersion.Equals(serverProtocolVersion) || (clientProtocolVersion == RemotingConstants.ProtocolVersionWin7RTM && serverProtocolVersion == RemotingConstants.ProtocolVersionWin7RC) || (clientProtocolVersion == RemotingConstants.ProtocolVersionWin8RTM && (serverProtocolVersion == RemotingConstants.ProtocolVersionWin7RC || serverProtocolVersion == RemotingConstants.ProtocolVersionWin7RTM )) || (clientProtocolVersion == RemotingConstants.ProtocolVersionWin10RTM && (serverProtocolVersion == RemotingConstants.ProtocolVersionWin7RC || serverProtocolVersion == RemotingConstants.ProtocolVersionWin7RTM || serverProtocolVersion == RemotingConstants.ProtocolVersionWin8RTM )) ) { //passed negotiation check } else { PSRemotingDataStructureException reasonOfFailure = new PSRemotingDataStructureException(RemotingErrorIdStrings.ClientNegotiationFailed, RemoteDataNameStrings.PS_STARTUP_PROTOCOL_VERSION_NAME, serverProtocolVersion, PSVersionInfo.GitCommitId, RemotingConstants.ProtocolVersion); throw reasonOfFailure; } // PSVersion check Version serverPSVersion = serverRemoteSessionCapability.PSVersion; Version clientPSVersion = Context.ClientCapability.PSVersion; if (!clientPSVersion.Equals(serverPSVersion)) { PSRemotingDataStructureException reasonOfFailure = new PSRemotingDataStructureException(RemotingErrorIdStrings.ClientNegotiationFailed, RemoteDataNameStrings.PSVersion, serverPSVersion.ToString(), PSVersionInfo.GitCommitId, RemotingConstants.ProtocolVersion); throw reasonOfFailure; } // Serialization Version check Version serverSerVersion = serverRemoteSessionCapability.SerializationVersion; Version clientSerVersion = Context.ClientCapability.SerializationVersion; if (!clientSerVersion.Equals(serverSerVersion)) { PSRemotingDataStructureException reasonOfFailure = new PSRemotingDataStructureException(RemotingErrorIdStrings.ClientNegotiationFailed, RemoteDataNameStrings.SerializationVersion, serverSerVersion.ToString(), PSVersionInfo.GitCommitId, RemotingConstants.ProtocolVersion); throw reasonOfFailure; } return(true); }
/// <summary> /// Verifies the negotiation packet received from the server /// </summary> /// <param name="serverRemoteSessionCapability"> /// Capabilities of remote session /// </param> /// <returns> /// The method returns true if the capability negotiation is successful. /// Otherwise, it returns false. /// </returns> /// <exception cref="PSRemotingDataStructureException"> /// 1. PowerShell client does not support the PSVersion {1} negotiated by the server. /// Make sure the server is compatible with the build {2} of PowerShell. /// 2. PowerShell client does not support the SerializationVersion {1} negotiated by the server. /// Make sure the server is compatible with the build {2} of PowerShell. /// </exception> private bool RunClientNegotiationAlgorithm(RemoteSessionCapability serverRemoteSessionCapability) { Dbg.Assert(serverRemoteSessionCapability != null, "server capability cache must be non-null"); // ProtocolVersion check Version serverProtocolVersion = serverRemoteSessionCapability.ProtocolVersion; _serverProtocolVersion = serverProtocolVersion; Version clientProtocolVersion = Context.ClientCapability.ProtocolVersion; if ( clientProtocolVersion.Equals(serverProtocolVersion) || (clientProtocolVersion == RemotingConstants.ProtocolVersionWin7RTM && serverProtocolVersion == RemotingConstants.ProtocolVersionWin7RC) || (clientProtocolVersion == RemotingConstants.ProtocolVersionWin8RTM && (serverProtocolVersion == RemotingConstants.ProtocolVersionWin7RC || serverProtocolVersion == RemotingConstants.ProtocolVersionWin7RTM )) || (clientProtocolVersion == RemotingConstants.ProtocolVersionWin10RTM && (serverProtocolVersion == RemotingConstants.ProtocolVersionWin7RC || serverProtocolVersion == RemotingConstants.ProtocolVersionWin7RTM || serverProtocolVersion == RemotingConstants.ProtocolVersionWin8RTM )) ) { //passed negotiation check } else { PSRemotingDataStructureException reasonOfFailure = new PSRemotingDataStructureException(RemotingErrorIdStrings.ClientNegotiationFailed, RemoteDataNameStrings.PS_STARTUP_PROTOCOL_VERSION_NAME, serverProtocolVersion, PSVersionInfo.BuildVersion, RemotingConstants.ProtocolVersion); throw reasonOfFailure; } // PSVersion check Version serverPSVersion = serverRemoteSessionCapability.PSVersion; Version clientPSVersion = Context.ClientCapability.PSVersion; if (!clientPSVersion.Equals(serverPSVersion)) { PSRemotingDataStructureException reasonOfFailure = new PSRemotingDataStructureException(RemotingErrorIdStrings.ClientNegotiationFailed, RemoteDataNameStrings.PSVersion, serverPSVersion.ToString(), PSVersionInfo.BuildVersion, RemotingConstants.ProtocolVersion); throw reasonOfFailure; } // Serialization Version check Version serverSerVersion = serverRemoteSessionCapability.SerializationVersion; Version clientSerVersion = Context.ClientCapability.SerializationVersion; if (!clientSerVersion.Equals(serverSerVersion)) { PSRemotingDataStructureException reasonOfFailure = new PSRemotingDataStructureException(RemotingErrorIdStrings.ClientNegotiationFailed, RemoteDataNameStrings.SerializationVersion, serverSerVersion.ToString(), PSVersionInfo.BuildVersion, RemotingConstants.ProtocolVersion); throw reasonOfFailure; } return true; }
private bool RunServerNegotiationAlgorithm(RemoteSessionCapability clientCapability, bool onConnect) { Version protocolVersion = clientCapability.ProtocolVersion; Version version2 = this._context.ServerCapability.ProtocolVersion; if (onConnect) { if (protocolVersion != version2) { PSRemotingDataStructureException exception = new PSRemotingDataStructureException(RemotingErrorIdStrings.ServerConnectFailedOnNegotiation, new object[] { "protocolversion", protocolVersion, PSVersionInfo.BuildVersion, RemotingConstants.ProtocolVersion }); throw exception; } } else { if ((protocolVersion == RemotingConstants.ProtocolVersionWin7RTM) && (version2 == RemotingConstants.ProtocolVersionCurrent)) { version2 = RemotingConstants.ProtocolVersionWin7RTM; this._context.ServerCapability.ProtocolVersion = version2; } if ((protocolVersion == RemotingConstants.ProtocolVersionWin7RC) && ((version2 == RemotingConstants.ProtocolVersionWin7RTM) || (version2 == RemotingConstants.ProtocolVersionCurrent))) { version2 = RemotingConstants.ProtocolVersionWin7RC; this._context.ServerCapability.ProtocolVersion = version2; } if ((protocolVersion.Major != version2.Major) || (protocolVersion.Minor < version2.Minor)) { PSRemotingDataStructureException exception2 = new PSRemotingDataStructureException(RemotingErrorIdStrings.ServerNegotiationFailed, new object[] { "protocolversion", protocolVersion, PSVersionInfo.BuildVersion, RemotingConstants.ProtocolVersion }); throw exception2; } } Version pSVersion = clientCapability.PSVersion; Version version4 = this._context.ServerCapability.PSVersion; if ((pSVersion.Major != version4.Major) || (pSVersion.Minor < version4.Minor)) { PSRemotingDataStructureException exception3 = new PSRemotingDataStructureException(RemotingErrorIdStrings.ServerNegotiationFailed, new object[] { "PSVersion", pSVersion, PSVersionInfo.BuildVersion, RemotingConstants.ProtocolVersion }); throw exception3; } Version serializationVersion = clientCapability.SerializationVersion; Version version6 = this._context.ServerCapability.SerializationVersion; if ((serializationVersion.Major == version6.Major) && (serializationVersion.Minor >= version6.Minor)) { return true; } PSRemotingDataStructureException exception4 = new PSRemotingDataStructureException(RemotingErrorIdStrings.ServerNegotiationFailed, new object[] { "SerializationVersion", serializationVersion, PSVersionInfo.BuildVersion, RemotingConstants.ProtocolVersion }); throw exception4; }
internal void DoMessageReceived(object sender, RemoteSessionStateMachineEventArgs fsmEventArg) { using (_trace.TraceEventHandlers()) { Guid runspacePoolId; if (fsmEventArg == null) { throw PSTraceSource.NewArgumentNullException("fsmEventArg"); } if (fsmEventArg.RemoteData == null) { throw PSTraceSource.NewArgumentException("fsmEventArg"); } RemotingTargetInterface targetInterface = fsmEventArg.RemoteData.TargetInterface; RemotingDataType dataType = fsmEventArg.RemoteData.DataType; RemoteDataEventArgs arg = null; switch (targetInterface) { case RemotingTargetInterface.Session: switch (dataType) { case RemotingDataType.CreateRunspacePool: { arg = new RemoteDataEventArgs(fsmEventArg.RemoteData); this._session.SessionDataStructureHandler.RaiseDataReceivedEvent(arg); } break; } return; case RemotingTargetInterface.RunspacePool: { runspacePoolId = fsmEventArg.RemoteData.RunspacePoolId; ServerRunspacePoolDriver runspacePoolDriver = this._session.GetRunspacePoolDriver(runspacePoolId); if (runspacePoolDriver == null) { break; } runspacePoolDriver.DataStructureHandler.ProcessReceivedData(fsmEventArg.RemoteData); return; } case RemotingTargetInterface.PowerShell: runspacePoolId = fsmEventArg.RemoteData.RunspacePoolId; this._session.GetRunspacePoolDriver(runspacePoolId).DataStructureHandler.DispatchMessageToPowerShell(fsmEventArg.RemoteData); return; default: goto Label_0151; } _trace.WriteLine("Server received data for Runspace (id: {0}), \r\n but the Runspace cannot be found", new object[] { runspacePoolId }); PSRemotingDataStructureException reason = new PSRemotingDataStructureException(RemotingErrorIdStrings.RunspaceCannotBeFound, new object[] { runspacePoolId }); RemoteSessionStateMachineEventArgs args2 = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.FatalError, reason); this.RaiseEvent(args2); return; Label_0151:; _trace.WriteLine("Server received data unknown targetInterface: {0}", new object[] { targetInterface }); PSRemotingDataStructureException exception2 = new PSRemotingDataStructureException(RemotingErrorIdStrings.ReceivedUnsupportedRemotingTargetInterfaceType, new object[] { targetInterface }); RemoteSessionStateMachineEventArgs args3 = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.FatalError, exception2); this.RaiseEvent(args3); } }
internal void DoMessageReceived(object sender, RemoteSessionStateMachineEventArgs fsmEventArg) { using (_trace.TraceEventHandlers()) { Guid runspacePoolId; if (fsmEventArg == null) { throw PSTraceSource.NewArgumentNullException("fsmEventArg"); } if (fsmEventArg.RemoteData == null) { throw PSTraceSource.NewArgumentException("fsmEventArg"); } RemotingTargetInterface targetInterface = fsmEventArg.RemoteData.TargetInterface; RemotingDataType dataType = fsmEventArg.RemoteData.DataType; RemoteDataEventArgs arg = null; switch (targetInterface) { case RemotingTargetInterface.Session: switch (dataType) { case RemotingDataType.CreateRunspacePool: { arg = new RemoteDataEventArgs(fsmEventArg.RemoteData); this._session.SessionDataStructureHandler.RaiseDataReceivedEvent(arg); } break; } return; case RemotingTargetInterface.RunspacePool: { runspacePoolId = fsmEventArg.RemoteData.RunspacePoolId; ServerRunspacePoolDriver runspacePoolDriver = this._session.GetRunspacePoolDriver(runspacePoolId); if (runspacePoolDriver == null) { break; } runspacePoolDriver.DataStructureHandler.ProcessReceivedData(fsmEventArg.RemoteData); return; } case RemotingTargetInterface.PowerShell: runspacePoolId = fsmEventArg.RemoteData.RunspacePoolId; this._session.GetRunspacePoolDriver(runspacePoolId).DataStructureHandler.DispatchMessageToPowerShell(fsmEventArg.RemoteData); return; default: goto Label_0151; } _trace.WriteLine("Server received data for Runspace (id: {0}), \r\n but the Runspace cannot be found", new object[] { runspacePoolId }); PSRemotingDataStructureException reason = new PSRemotingDataStructureException(RemotingErrorIdStrings.RunspaceCannotBeFound, new object[] { runspacePoolId }); RemoteSessionStateMachineEventArgs args2 = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.FatalError, reason); this.RaiseEvent(args2); return; Label_0151 :; _trace.WriteLine("Server received data unknown targetInterface: {0}", new object[] { targetInterface }); PSRemotingDataStructureException exception2 = new PSRemotingDataStructureException(RemotingErrorIdStrings.ReceivedUnsupportedRemotingTargetInterfaceType, new object[] { targetInterface }); RemoteSessionStateMachineEventArgs args3 = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.FatalError, exception2); this.RaiseEvent(args3); } }
private void HandleFatalError(Exception ex) { // Event handlers should not throw exceptions. But if they do we need to // handle them here to prevent the state machine from hanging when there are pending // events to process. // Enqueue a fatal error event if such an exception occurs; clear all existing events.. we are going to terminate the session PSRemotingDataStructureException fatalError = new PSRemotingDataStructureException(ex, RemotingErrorIdStrings.FatalErrorCausingClose); RemoteSessionStateMachineEventArgs closeEvent = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.Close, fatalError); RaiseEvent(closeEvent, true); }