protected override bool PerformHandshake(InputStream buffer) { switch (_rtmpState) { case RTMPState.RTMP_STATE_NOT_INITIALIZED: if (buffer.AvaliableByteCounts < 1537) { return(true); } var handshakeType = buffer.ReadByte(); var temp = new byte[4]; _currentFPVersion = (uint)IPAddress.NetworkToHostOrder(BitConverter.ToInt32(buffer.GetBuffer(), (int)(buffer.Position + 4))); switch (handshakeType) { case 3: //plain return(PerformHandshake(buffer, false)); case 6: //encrypted return(PerformHandshake(buffer, true)); default: Logger.FATAL("Handshake type not implemented: {0}", handshakeType); return(false); } case RTMPState.RTMP_STATE_SERVER_RESPONSE_SENT: if (buffer.AvaliableByteCounts < 1537) { return(true); } buffer.Ignore(1536); _handshakeCompleted = true; _rtmpState = RTMPState.RTMP_STATE_DONE; if (_pKeyIn != null && _pKeyOut != null) { //insert the RTMPE protocol in the current protocol stack BaseProtocol pFarProtocol = FarProtocol; var pRTMPE = new RTMPEProtocol(_pKeyIn, _pKeyOut); ResetFarProtocol(); pFarProtocol.NearProtocol = pRTMPE; pRTMPE.NearProtocol = this; this.Log().Info("New protocol chain: {0}", pFarProtocol); //decrypt the leftovers Utils.RC4(new BufferWithOffset(buffer), _pKeyIn, buffer.AvaliableByteCounts); } return(true); default: Logger.FATAL("Invalid RTMP state: {0}", _rtmpState); return(false); } return(true); }
protected override bool PerformHandshake(InputStream buffer) { switch (_rtmpState) { case RTMPState.RTMP_STATE_NOT_INITIALIZED: if (buffer.AvaliableByteCounts < 1537) return true; var handshakeType = buffer.ReadByte(); var temp = new byte[4]; _currentFPVersion = (uint)IPAddress.NetworkToHostOrder(BitConverter.ToInt32(buffer.GetBuffer(), (int)(buffer.Position + 4))); switch (handshakeType) { case 3: //plain return PerformHandshake(buffer, false); case 6: //encrypted return PerformHandshake(buffer, true); default: Logger.FATAL("Handshake type not implemented: {0}", handshakeType); return false; } case RTMPState.RTMP_STATE_SERVER_RESPONSE_SENT: if (buffer.AvaliableByteCounts < 1537) return true; buffer.Ignore(1536); _handshakeCompleted = true; _rtmpState = RTMPState.RTMP_STATE_DONE; if (_pKeyIn != null && _pKeyOut != null) { //insert the RTMPE protocol in the current protocol stack BaseProtocol pFarProtocol = FarProtocol; var pRTMPE = new RTMPEProtocol(_pKeyIn, _pKeyOut); ResetFarProtocol(); pFarProtocol.NearProtocol = pRTMPE; pRTMPE.NearProtocol = this; this.Log().Info("New protocol chain: {0}", pFarProtocol); //decrypt the leftovers Utils.RC4(new BufferWithOffset(buffer), _pKeyIn, buffer.AvaliableByteCounts); } return true; default: Logger.FATAL("Invalid RTMP state: {0}", _rtmpState); return false; } return true; }
protected override bool PerformHandshake(InputStream buffer) { switch (_rtmpState) { case RTMPState.RTMP_STATE_NOT_INITIALIZED: return(PerformHandshakeStage1((string)CustomParameters[Defines.CONF_PROTOCOL] == Defines.CONF_PROTOCOL_OUTBOUND_RTMPE)); case RTMPState.RTMP_STATE_CLIENT_REQUEST_SENT: if (buffer.AvaliableByteCounts < 3073) { return(true); } _usedScheme = (byte)((string)CustomParameters[Defines.CONF_PROTOCOL] == Defines.CONF_PROTOCOL_OUTBOUND_RTMPE? 1: 0); if (!PerformHandshakeStage2(buffer, _usedScheme == 1)) { Logger.FATAL("Unable to handshake"); return(false); } if (!EnqueueForOutbound(OutputBuffer)) { Logger.FATAL("Unable to signal output data"); return(false); } if (_pKeyIn != null && _pKeyOut != null) { var pRTMPE = new RTMPEProtocol(_pKeyIn, _pKeyOut, (uint)OutputBuffer.Length); ResetFarProtocol(); _farProtocol.NearProtocol = pRTMPE; pRTMPE.NearProtocol = this; this.Log().Info("New protocol chain:{0}", _farProtocol); } buffer.Ignore(3073); _handshakeCompleted = true; return(true); default: Logger.FATAL("Invalid RTMP state:{0}", _rtmpState); return(false); } }
protected override bool PerformHandshake(InputStream buffer) { switch (_rtmpState) { case RTMPState.RTMP_STATE_NOT_INITIALIZED: return PerformHandshakeStage1((string)CustomParameters[Defines.CONF_PROTOCOL] == Defines.CONF_PROTOCOL_OUTBOUND_RTMPE); case RTMPState.RTMP_STATE_CLIENT_REQUEST_SENT: if (buffer.AvaliableByteCounts < 3073) return true; _usedScheme = (byte) ((string) CustomParameters[Defines.CONF_PROTOCOL] == Defines.CONF_PROTOCOL_OUTBOUND_RTMPE? 1: 0); if (!PerformHandshakeStage2(buffer, _usedScheme==1)) { Logger.FATAL("Unable to handshake"); return false; } if (!EnqueueForOutbound(OutputBuffer)) { Logger.FATAL("Unable to signal output data"); return false; } if (_pKeyIn != null && _pKeyOut != null) { var pRTMPE = new RTMPEProtocol(_pKeyIn, _pKeyOut, (uint)OutputBuffer.Length); ResetFarProtocol(); _farProtocol.NearProtocol = pRTMPE; pRTMPE.NearProtocol = this; this.Log().Info("New protocol chain:{0}",_farProtocol); } buffer.Ignore(3073); _handshakeCompleted = true; return true; default: Logger.FATAL("Invalid RTMP state:{0}",_rtmpState); return false; } }