コード例 #1
0
ファイル: Program.cs プロジェクト: bwrichte/TamperEvidentLogs
        public static void Main(string[] args)
        {
            HashTree hashTree = new HashTree(new SHA256Aggregator());
            for (int i = 0; i < 10; ++i)
            {
                hashTree.Append(Console.ReadLine());
            }

            for (int i = 0; i < 10; ++i)
            {
                Console.WriteLine(hashTree.GenerateMembershipProof(i));
            }

            Console.ReadLine();
        }
コード例 #2
0
        private void ProcessQueueMessages(List<CloudQueueMessage> msgs)
        {
            Trace.TraceInformation("WorkerB (RoleInstance {0}: ProcessQueueMessages start", GetRoleInstance());

            HashTree hashTree = new HashTree(new SHA256Aggregator());
            List<Tuple<CloudQueueMessage, Snapshot>> goodMsgs = new List<Tuple<CloudQueueMessage, Snapshot>>();
            foreach (CloudQueueMessage msg in msgs)
            {
                // Log and delete if this is a "poison" queue message (repeatedly processed
                // and always causes an error that prevents processing from completing).
                // Production applications should move the "poison" message to a "dead message"
                // queue for analysis rather than deleting the message.
                if (msg.DequeueCount > 5)
                {
                    Trace.TraceError(
                        "Deleting poison message: message {0} Role Instance {1}.",
                        msg.ToString(),
                        GetRoleInstance()
                        );
                    snapshotsQueue.DeleteMessage(msg);
                    continue;
                }

                // Parse summarized snapshot retrieved from queue.
                string[] snapshotParts = msg.AsString.Split(new char[] { ',' });
                string partitionKey = snapshotParts[0];
                string rowKey = snapshotParts[1];
                string restartFlag = snapshotParts[2];

                var retrieveOperation = TableOperation.Retrieve<Snapshot>(partitionKey, rowKey);
                var retrievedResult = snapshotsTable.Execute(retrieveOperation);
                var snapshot = retrievedResult.Result as Snapshot;

                if (snapshot == null)
                {
                    Trace.TraceError("WorkerB: Snapshot does not exist for RK {0}", rowKey);
                    continue;
                }

                // If this is a restart, verify that the shapshot has not already been logged
                if (restartFlag == "1")
                {
                    /*if (snapshot.Status == "Complete")
                    {
                    }*/
                }

                // Add snapshot value into history tree
                hashTree.Append(snapshot.SnapshotValue);
                goodMsgs.Add(new Tuple<CloudQueueMessage, Snapshot>(msg, snapshot));
            }

            // Snapshot commitment into bitcoin
            Transaction transaction = SnapshotCommitmentIntoBitcoin(
                hashTree.RootCommitmentString
                );

            if (transaction == null)
            {
                Trace.TraceError("Snapshot into Bitcoin failed, unable to continue.");
                return;
            }

            for (int i = 0; i < goodMsgs.Count; ++i)
            {
                Snapshot snapshot = goodMsgs[i].Item2;
                string proofText = hashTree.GenerateMembershipProof(i).ToString();

                // Save proof
                string proofName = snapshot.RowKey + ".proof";
                SaveBlob(proofName, proofText);

                var proof = new Proof
                {
                    ApplicationName = snapshot.ApplicationName, // Sets partition key
                    RowKey = snapshot.RowKey,
                    LogName = snapshot.LogName,
                    SnapshotValue = snapshot.SnapshotValue,
                    ProofBlobName = proofName,
                    CoinbaseTransactionID = transaction.ID
                };

                // Save in archive
                var upsertOperation = TableOperation.InsertOrReplace(proof);
                proofsArchiveTable.Execute(upsertOperation);

                // TODO: Decide if need to mark as complete

                var deleteOperation = TableOperation.Delete(snapshot);
                snapshotsTable.Execute(deleteOperation);

                // Delete the associated queue message
                snapshotsQueue.DeleteMessage(goodMsgs[i].Item1);
            }

            Trace.TraceInformation("WorkerB (RoleInstance {0}: ProcessQueueMessages complete",
               GetRoleInstance()
               );
        }