Пример #1
0
        private static InformationContext CreateWithID(int id)
        {
            InformationContext result = InformationContext.Create();

            result.ID = id;
            return(result);
        }
Пример #2
0
        public static void ProcessMessage(QueueEnvelope envelope, bool reportEnvelopeError = true)
        {
            try
            {
                InformationContext.Current.InitializeCloudStorageAccess(envelope.ActiveContainerName);
                if (envelope.SingleOperation != null)
                {
                    ProcessSingleOperation(envelope.SingleOperation);
                }
                if (envelope.OrderDependentOperationSequence != null)
                {
                    Exception firstException = null;
                    //envelope.OrderDependentOperationSequence.CollectionContent.ForEach(ProcessSingleOperation);
                    foreach (var singleOperation in envelope.OrderDependentOperationSequence.CollectionContent)
                    {
                        try
                        {
                            ProcessSingleOperation(singleOperation);
                        } catch (Exception ex)
                        {
                            firstException = ex;
                            ErrorSupport.ReportException(ex);
                        }
                    }
                    if (firstException != null)
                    {
                        throw firstException;
                    }
                }
            }
            catch (Exception ex)
            {
                if (reportEnvelopeError)
                {
                    ErrorSupport.ReportEnvelopeWithException(envelope, ex);
                }
                throw;
            } finally
            {
                InformationContext.ProcessAndClearCurrent();
            }

            counter++;
            if (counter >= 1000)
            {
                QueueSupport.ReportStatistics("Processed " + counter + " messages...");
                counter = 0;
            }
        }
Пример #3
0
 public static bool ProcessOwnerSubscriptionChains(IContainerOwner lockedOwner, string acquiredEtag, string containerName)
 {
     try
     {
         if (containerName != null)
         {
             InformationContext.Current.InitializeCloudStorageAccess(containerName: containerName);
         }
         string[]     blobs        = SubscribeSupport.GetChainRequestList(lockedOwner);
         var          chainContent = blobs.Select(blob => StorageSupport.RetrieveInformation(blob, typeof(SubscriptionChainRequestContent))).Cast <SubscriptionChainRequestContent>().ToArray();
         const double invalidSubscriptionSubmissionTimeInSeconds = 600;
         if (chainContent.Any(item => item.SubmitTime < DateTime.UtcNow.AddSeconds(-invalidSubscriptionSubmissionTimeInSeconds)))
         {
             return(false);
         }
         WorkerSupport.ExecuteSubscriptionChains(chainContent);
         foreach (string blob in blobs)
         {
             StorageSupport.DeleteBlob(blob);
         }
     }
     catch (Exception ex)
     {
         ErrorSupport.ReportException(ex);
         throw;
     }
     finally
     {
         SubscribeSupport.ReleaseChainLock(lockedOwner, acquiredEtag);
         if (containerName != null)
         {
             InformationContext.ProcessAndClearCurrent();
         }
     }
     counter++;
     if (counter >= 1000)
     {
         QueueSupport.ReportStatistics("Processed " + counter + " messages...");
         counter = 0;
     }
     return(true);
 }
Пример #4
0
 private static string FinishDeviceNegotiation(InformationContext iCtx, INegotiationProtocolMember protocolParty, string remainingDetails)
 {
     try
     {
         var result = CreateDeviceMembership.Execute(new CreateDeviceMembershipParameters
             {
                 Owner = iCtx.Owner,
                 ActiveSymmetricAESKey = protocolParty.NegotiationResults[0],
                 DeviceDescription = remainingDetails
             });
         CreateAndSendEmailValidationForDeviceJoinConfirmation.Execute(new CreateAndSendEmailValidationForDeviceJoinConfirmationParameters
             {
                 DeviceMembership = result.DeviceMembership,
                 OwningAccount = iCtx.Owner as TBAccount,
                 OwningGroup = iCtx.Owner as TBCollaboratingGroup,
             });
         return result.DeviceMembership.ID;
     }
     finally
     {
         iCtx.PerformFinalizingActions();
     }
 }
Пример #5
0
        private async static Task HandleDeviceNegotiations(InformationContext iCtx, WebSocketContext wsCtx, WebSocket socket, byte[] binaryMessage, string textMessage)
        {
            if(iCtx != InformationContext.Current)
                throw new InvalidDataException("InformationContext is mismatched during processing");
            bool playBob = false;
            INegotiationProtocolMember protocolParty = null;
            if (binaryMessage != null)
            {
                iCtx.AccessLockedItems(dict =>
                {
                    if (dict.ContainsKey("EKENEGOTIATIONPARTY") == false)
                    {
                        // Yes, the shared secret is fixed due to demo. We're fixing it to be separately requested or given by user... :-)
                        TheBallEKE protocolInstance = new TheBallEKE();
                        var decryptedSharedSecretPayload = EncryptionSupport.DecryptData(binaryMessage);
                        var nonse = decryptedSharedSecretPayload.Take(32).ToArray();
                        var secret = decryptedSharedSecretPayload.Skip(32).Take(32).ToArray();
                        long ticks = BitConverter.ToInt64(decryptedSharedSecretPayload, 64);
                        DateTime validUntilUtc = new DateTime(ticks, DateTimeKind.Utc);
                        if(DateTime.UtcNow > validUntilUtc)
                            throw new SecurityException("Shared secret payload is expired");
                        protocolInstance.InitiateCurrentSymmetricFromSecret(secret);
                        if(playBob)
                            protocolParty = new TheBallEKE.EKEBob(protocolInstance, true);
                        else
                            protocolParty = new TheBallEKE.EKEAlice(protocolInstance, true);
                        dict.Add("EKENEGOTIATIONPARTY", protocolParty);
                    }
                    else
                    {
                        protocolParty = (INegotiationProtocolMember)dict["EKENEGOTIATIONPARTY"];
                    }
                });
                if (protocolParty.SendMessageToOtherPartyAsync == null)
                {
                    protocolParty.SendMessageToOtherPartyAsync = async bytes => { await SendBinaryMessage(socket, bytes); };
                    if(playBob) // if we play bob we put the current message already to the pipeline
                        protocolParty.LatestMessageFromOtherParty = binaryMessage;
                }
                else
                {
                    // Alice plays first, so only after the second message we start putting messages from Bob
                    protocolParty.LatestMessageFromOtherParty = binaryMessage;
                }
                while (protocolParty.IsDoneWithProtocol == false && protocolParty.WaitForOtherParty == false)
                {
                    await protocolParty.PerformNextActionAsync();
                }

            }
            else
            {
                iCtx.AccessLockedItems(dict =>
                    {
                        if (dict.ContainsKey("EKENEGOTIATIONPARTY"))
                            protocolParty = (INegotiationProtocolMember) dict["EKENEGOTIATIONPARTY"];
                    });
                if (protocolParty != null && protocolParty.IsDoneWithProtocol) // Perform POST EKE operations
                {
                    iCtx.AccessLockedItems(dict => dict.Remove("EKENEGOTIATIONPARTY"));
                    string deviceID = FinishDeviceNegotiation(iCtx, protocolParty, textMessage);
                    await SendTextMessage(socket, deviceID);
                }
                //await SendTextMessage(socket, echoString);
            }
        }