/// <summary> /// Un-marshal a byte array to PDU struct. /// </summary> /// <param name="binaryReader">A binary reader.</param> internal override void FromBytes(BinaryReader binaryReader) { rpc_vers = binaryReader.ReadByte(); rpc_vers_minor = binaryReader.ReadByte(); PTYPE = (RpcePacketType)binaryReader.ReadByte(); pfc_flags = (RpceCoPfcFlags)binaryReader.ReadByte(); packed_drep = new DataRepresentationFormatLabel(); packed_drep.dataRepFormat = (RpceDataRepresentationFormat)binaryReader.ReadUInt16(); packed_drep.reserved = binaryReader.ReadUInt16(); frag_length = binaryReader.ReadUInt16(); auth_length = binaryReader.ReadUInt16(); call_id = binaryReader.ReadUInt32(); }
/// <summary> /// Un-marshal a byte array to PDU struct. /// </summary> /// <param name="binaryReader">A binary reader.</param> internal override void FromBytes(BinaryReader binaryReader) { rpc_vers = binaryReader.ReadByte(); rpc_vers_minor = binaryReader.ReadByte(); PTYPE = (RpcePacketType)binaryReader.ReadByte(); pfc_flags = (RpceCoPfcFlags)binaryReader.ReadByte(); packed_drep = new DataRepresentationFormatLabel(); packed_drep.dataRepFormat = (RpceDataRepresentationFormat)binaryReader.ReadUInt16(); packed_drep.reserved = binaryReader.ReadUInt16(); frag_length = binaryReader.ReadUInt16(); auth_length = binaryReader.ReadUInt16(); call_id = binaryReader.ReadUInt32(); if (packed_drep.dataRepFormat != RpceDataRepresentationFormat.IEEE_LittleEndian_ASCII) { frag_length = EndianUtility.ReverseByteOrder(frag_length); auth_length = EndianUtility.ReverseByteOrder(auth_length); call_id = EndianUtility.ReverseByteOrder(call_id); } }
/// <summary> /// Generate PFC_*** based on context and package type. /// </summary> /// <param name="context">Context of the session.</param> /// <param name="packageType">package type.</param> /// <returns>RFC_*** flag.</returns> internal static RpceCoPfcFlags GeneratePfcFlags(RpceContext context, RpcePacketType packageType) { RpceServerSessionContext sessionContext = context as RpceServerSessionContext; RpceCoPfcFlags flags = RpceCoPfcFlags.PFC_FIRST_FRAG | RpceCoPfcFlags.PFC_LAST_FRAG; if (sessionContext == null) //client-side { if (context.SupportsConcurrentMultiplexing) { flags |= RpceCoPfcFlags.PFC_CONC_MPX; } } else if ( //server-side (packageType == RpcePacketType.BindAck && sessionContext.ServerContext.SupportsConcurrentMultiplexing) || // first response, read server context sessionContext.SupportsConcurrentMultiplexing) // if it's not first response, we can read session context { flags |= RpceCoPfcFlags.PFC_CONC_MPX; } if ((packageType == RpcePacketType.Bind || packageType == RpcePacketType.BindAck || packageType == RpcePacketType.AlterContext || packageType == RpcePacketType.AlterContextResp) && context.SupportsHeaderSign) { if (sessionContext == null || //client-side sessionContext.ServerContext.SupportsHeaderSign) //server-side { flags |= RpceCoPfcFlags.PFC_SUPPORT_HEADER_SIGN; } } return(flags); }
public static RpceCoPdu DecodeCoPdu( RpceContext context, byte[] pduBytes) { if (context == null) { throw new ArgumentNullException("context"); } if (pduBytes == null) { throw new ArgumentNullException("pduBytes"); } RpceCoPdu pdu; //#2 byte is PTYPE RpcePacketType packageType = (RpcePacketType)pduBytes[2]; //#3 byte is PFC_*** flags RpceCoPfcFlags pfcFlags = (RpceCoPfcFlags)pduBytes[3]; RpceCoPfcFlags pfcFlagsNoFragment = RpceCoPfcFlags.PFC_FIRST_FRAG | RpceCoPfcFlags.PFC_LAST_FRAG; if (((pfcFlags & pfcFlagsNoFragment) != pfcFlagsNoFragment) && (packageType == RpcePacketType.Bind || packageType == RpcePacketType.BindAck || packageType == RpcePacketType.AlterContext || packageType == RpcePacketType.AlterContextResp || packageType == RpcePacketType.Auth3)) { //If it's a fragment and PTYPE is bind/bind_ack/alter_context/alter_context_resp //Windows RPC support version 5.0 only. //Bind fragment requires RPC ver 5.1. //We don't support it. throw new NotSupportedException("bind/bind_ack/alt_context/alt_context_resp/auth3 PDU fragment are not supported."); } else { switch (packageType) { case RpcePacketType.Bind: pdu = new RpceCoBindPdu(context, pduBytes); break; case RpcePacketType.BindAck: pdu = new RpceCoBindAckPdu(context, pduBytes); break; case RpcePacketType.BindNak: pdu = new RpceCoBindNakPdu(context, pduBytes); break; case RpcePacketType.AlterContext: pdu = new RpceCoAlterContextPdu(context, pduBytes); break; case RpcePacketType.AlterContextResp: pdu = new RpceCoAlterContextRespPdu(context, pduBytes); break; case RpcePacketType.Auth3: pdu = new RpceCoAuth3Pdu(context, pduBytes); break; case RpcePacketType.Request: pdu = new RpceCoRequestPdu(context, pduBytes); break; case RpcePacketType.Response: pdu = new RpceCoResponsePdu(context, pduBytes); break; case RpcePacketType.Fault: pdu = new RpceCoFaultPdu(context, pduBytes); break; case RpcePacketType.CoCancel: pdu = new RpceCoCancelPdu(context, pduBytes); break; case RpcePacketType.Orphaned: pdu = new RpceCoOrphanedPdu(context, pduBytes); break; case RpcePacketType.Shutdown: pdu = new RpceCoShutdownPdu(context, pduBytes); break; default: throw new InvalidOperationException( string.Format("Receive invalid packet - {0}.", packageType)); } } return(pdu); }
/// <summary> /// Create an instance of auth_verifier_co_t. /// </summary> /// <param name="packetType">PTYPE</param> /// <param name="stubLength">stub length</param> /// <param name="securityContext">security context</param> /// <param name="type">auth_type</param> /// <param name="level">auth_level</param> /// <param name="contextId">auth_context_id</param> /// <returns>an auth_verifier_co_t instance.</returns> internal static auth_verifier_co_t?AuthVerifierCreateInstance( RpcePacketType packetType, int stubLength, SecurityContext securityContext, RpceAuthenticationType type, RpceAuthenticationLevel level, uint contextId) { if (type == RpceAuthenticationType.RPC_C_AUTHN_NONE || level == RpceAuthenticationLevel.RPC_C_AUTHN_LEVEL_NONE) { return(null); } if (level <= RpceAuthenticationLevel.RPC_C_AUTHN_LEVEL_CONNECT) { if (packetType != RpcePacketType.Bind && packetType != RpcePacketType.BindAck && packetType != RpcePacketType.BindNak && packetType != RpcePacketType.AlterContext && packetType != RpcePacketType.AlterContextResp && packetType != RpcePacketType.Auth3) { return(null); } } //The authentication verifier is never present in bind_nak and shutdown PDUs if (packetType == RpcePacketType.BindNak || packetType == RpcePacketType.Shutdown) { return(null); } auth_verifier_co_t authVerifier = new auth_verifier_co_t(); //The sec_trailer structure MUST be 4-byte aligned with respect //to the beginning of the PDU. Padding octets MUST be used to //align the sec_trailer structure if its natural beginning is not //already 4-byte aligned. authVerifier.auth_pad_length = (byte)(Align(stubLength, STUB_PAD_LENGTH) - stubLength); authVerifier.auth_pad = new byte[authVerifier.auth_pad_length]; authVerifier.auth_type = (byte)type; authVerifier.auth_level = (byte)level; authVerifier.auth_reserved = 0; authVerifier.auth_context_id = contextId; if (securityContext != null) { if (packetType == RpcePacketType.Bind || packetType == RpcePacketType.BindAck || packetType == RpcePacketType.AlterContext || packetType == RpcePacketType.AlterContextResp || packetType == RpcePacketType.Auth3) { authVerifier.auth_value = securityContext.Token; } else if (level == RpceAuthenticationLevel.RPC_C_AUTHN_LEVEL_PKT_PRIVACY) { int authValueSize = Align( (int)securityContext.ContextSizes.SecurityTrailerSize, STUB_PAD_LENGTH); authVerifier.auth_value = new byte[authValueSize]; } else { // level == RpceAuthenticationLevel.RPC_C_AUTHN_LEVEL_PKT_INTEGRITY || // level == RpceAuthenticationLevel.RPC_C_AUTHN_LEVEL_PKT || // level == RpceAuthenticationLevel.RPC_C_AUTHN_LEVEL_CALL int authValueSize = Align( (int)securityContext.ContextSizes.MaxSignatureSize, STUB_PAD_LENGTH); authVerifier.auth_value = new byte[authValueSize]; } } return(authVerifier); }