internal static IFreeformEntity_Msg InitKeyExchangeEndG2H_SIM(this FreeformSecurityTableCollection secTables, IFreeformEntity_Msg request) { // store the partial key of the host FFTgt_B2B_Security_KeyExchange_PartialKey tgt = request.EntityPrimaryTarget as FFTgt_B2B_Security_KeyExchange_PartialKey; SECURITY_KEY_INDEX keyIndex = FreeformEncryptionHelper.GetSecurityKeyIndex(request); byte[] gmuPartialKey = secTables.CreatePartialKeyGmu(keyIndex); secTables.StoreOtherPartialKeyGmu(keyIndex, tgt.PartialKey); secTables.CreateCommonKey(keyIndex); // send the partial key of the gmu IFreeformEntity_Msg response = request.CopyTo(FF_FlowDirection.G2H, new FFCreateEntityRequest_G2H_ResponseRequired() { MessageType = FF_AppId_G2H_MessageTypes.FreeForm, Command = FF_AppId_G2H_Commands.ResponseRequest, SkipTransactionId = true, }); FFTgt_B2B_Security tgt2 = new FFTgt_B2B_Security() { SecurityData = new FFTgt_B2B_Security_KeyExchange_End() { PartialKey = gmuPartialKey, } }; response.AddTarget(tgt2); return(response); }
protected override void OnModifyMessage(ILogMethod method, FFMsg_G2H message) { FFTgt_B2B_Security target = message.GetTarget <FFTgt_B2B_Security>(); if (target == null || target.Targets.Count == 0) { throw new ArgumentNullException("No valid encrypted targets found"); } }
static void EncryptSecurity() { FFMsg_G2H msg = FreeformEntityFactory.CreateEntity <FFMsg_G2H>(FF_FlowDirection.G2H, new FFCreateEntityRequest_G2H_ResponseRequired() { Command = FF_AppId_G2H_Commands.ResponseRequest, MessageType = FF_AppId_G2H_MessageTypes.FreeForm, SessionID = FF_AppId_SessionIds.Security, TransactionID = 0xB1, IPAddress = IPADDR, }); FFTgt_B2B_Security tgt = new FFTgt_B2B_Security_ResponseRequired() { SecurityData = new FFTgt_B2B_Security_KeyExchange_Request(), }; msg.AddTarget(tgt); byte[] buf2 = FreeformEntityFactory.CreateBuffer(FF_FlowDirection.G2H, msg); var msgF = FreeformEntityFactory.CreateEntity <FFMsg_G2H>(FF_FlowDirection.G2H, buf2); FFMsg_H2G msg2 = msg.CopyTo(FF_FlowDirection.H2G, new FFCreateEntityRequest_H2G_ResponseRequired() { PollCode = FF_AppId_H2G_PollCodes.FreeformResponse, }) as FFMsg_H2G; FFTgt_B2B_Security tgt2 = new FFTgt_B2B_Security() { SecurityData = new FFTgt_B2B_Security_KeyExchange_PartialKey() { PartialKey = new byte[] { 10, 11, 12, 34, 56, 78, 96, 89, 44 }, } }; msg2.AddTarget(tgt2); byte[] buf3 = FreeformEntityFactory.CreateBuffer(FF_FlowDirection.H2G, msg2); var msgF3 = FreeformEntityFactory.CreateEntity <FFMsg_H2G>(FF_FlowDirection.H2G, buf3, IPADDR); ExecutionStepFactory.Current.Execute(msg); //byte[] buf1 = FreeformEntityFactory.CreateBuffer(FF_FlowDirection.H2G, msg2); //UdpFreeformEntity buffer = FreeformEntityFactory.CreateUdpEntity(FF_FlowDirection.G2H, buf1); //IFreeformEntity ff = FreeformEntityFactory.CreateEntity(FF_FlowDirection.G2H, buffer); //byte[] buf2 = FreeformEntityFactory.CreateBuffer(FF_FlowDirection.G2H, msg); }